atcoder#ABC268E. [ABC268E] Chinese Restaurant (Three-Star Version)
[ABC268E] Chinese Restaurant (Three-Star Version)
Score : points
Problem Statement
Person , Person , , and Person are sitting around a turntable in counterclockwise order, evenly spaced. Dish is in front of Person on the table. You may perform the following operation or more times:
- Rotate the turntable by one -th of a counterclockwise turn. The dish that was in front of Person right before the rotation is now in front of Person .
When you are finished, Person gains frustration of , where is the minimum integer such that Dish is in front of either Person or Person . Find the minimum possible sum of frustration of the people.
What is $a \bmod m$?
For an integer a and a positive integer m, a \bmod m denotes the integer x between 0 and (m-1) (inclusive) such that (a-x) is a multiple of m. (It can be proved that such x is unique.)Constraints
- if .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
1 2 0 3
2
The figure below shows the table after one operation.
Here, the sum of their frustration is because:
- Person gains a frustration of since Dish is in front of Person ;
- Person gains a frustration of since Dish is in front of Person ;
- Person gains a frustration of since Dish is in front of Person ;
- Person gains a frustration of since Dish is in front of Person .
We cannot make the sum of their frustration less than , so the answer is .
3
0 1 2
0
10
3 9 6 1 7 2 8 0 5 4
20