luogu#P5133. tb148 的客人
tb148 的客人
Background
After tb148 bought a lot of ingredients using coupons, he invited many guests to have a meal.
Problem Description
tb148 and his guests each have an ID number (consecutive positive integers starting from ). Currently, they are sitting around a round table in a random order, not by their IDs. In one operation, we may simultaneously let any number of guests move one position clockwise or counterclockwise; we call this one operation. During this process, a position may have no guest or multiple guests. Find the minimum number of seconds needed so that each position still has exactly one person, and the guests' IDs in clockwise order (or in counterclockwise order) are exactly .
Input Format
The input contains two lines.
The first line is a positive integer .
The second line contains space-separated positive integers, a permutation of , representing the guests' IDs in clockwise order at the beginning.
Output Format
Output one integer, the answer.
4
1 4 2 3
1
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5