An array of elements can be rotated to the right by taking the last element and moving it to the front. For example, rotating to the right once results in .
An array is considered rotational if it can be rotated some number of times to the right, where , and result in the original array. For example, the array is considered rotational.
One modification of an array consists of increasing or decreasing an element's value by . Given an array , can you determine the minimum number of modifications needed in order to convert an array to a rotational array?
Input Specification
The first line will contain the integer , the number of elements.
The second line will contain integers, , the elements of the array.
Output Specification
Output the minimum number of modifications needed to convert to a rotational array.
Subtasks
For 3/15 of the points, .
For an additional 5/15 of the points, .
Sample Input
4
1 2 2 2
Sample Output
1
Explanation For Sample
We can increase the first element's value to , which transforms it into a rotational array. This is exactly one modification.
Comments