Even More Secure Prison
Time limit1sMemory limit1024 MB
Pressing a segment rotates the disk by its value and removes that segment. Find the press that leaves the lexicographically smallest remaining sequence.
Problem
After Cletus Kasady escaped from the San Quentin prison, the guards decided to build a maximum security cell and upgrade the security systems, including installing new combination locks.
The dial of such a lock is a rotating disk with segments. The -th segment contains a positive integer . The sequence written on the disk is read clockwise, starting from the segment that points straight up. When you press the -th segment (counting clockwise from the top), the disk turns segments counterclockwise, and the pressed segment is locked and is no longer part of the sequence.
For example, if the disk currently holds and you press , the disk turns 2 segments counterclockwise into the state . Then the pressed segment is locked, and the resulting sequence is .
A sequence is lexicographically smaller than if there is a such that for all and . In other words, the first few elements (possibly none) are equal, and the next element of is smaller than the corresponding element of .
The door opens when the sequence on the disk is lexicographically minimal among all sequences that can be obtained by pressing one segment. Find the segment to press.
Input
The first line contains a single integer (), the number of segments on the disk. The second line contains integers (), separated by spaces, in clockwise order starting from the top.
Output
Print a single integer, the number of the segment to press so that the resulting sequence is lexicographically minimal. If there are several answers, print any of them.