Under construction

Still being built. Things may change

Even More Secure Prison

Time limit1sMemory limit1024 MB

Summary
Pressing a segment rotates the disk by its value and removes that segment. Find the press that leaves the lexicographically smallest remaining sequence.
Level

Medium6 of 10

Topics
Array, Greedy
Solved
No attempts yet

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 nn segments. The ii-th segment contains a positive integer aia_i. The sequence written on the disk is read clockwise, starting from the segment that points straight up. When you press the ii-th segment (counting clockwise from the top), the disk turns aia_i segments counterclockwise, and the pressed segment is locked and is no longer part of the sequence.

For example, if the disk currently holds a=[4,3,1,2,1,8]a = [4, 3, 1, 2, 1, 8] and you press a4=2a_4 = 2, the disk turns 2 segments counterclockwise into the state [1,2,1,8,4,3][1, 2, 1, 8, 4, 3]. Then the pressed segment is locked, and the resulting sequence is [1,1,8,4,3][1, 1, 8, 4, 3].

A sequence x1,x2,…,xtx_1, x_2, \ldots, x_t is lexicographically smaller than y1,y2,…,yty_1, y_2, \ldots, y_t if there is a 0≤k≤t0 \le k \le t such that xi=yix_i = y_i for all i<ki < k and xk<ykx_k < y_k. In other words, the first few elements (possibly none) are equal, and the next element of xx is smaller than the corresponding element of yy.

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 nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), the number of segments on the disk. The second line contains nn integers aia_i (0≤ai<n0 \le a_i < n), 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.

Examples3

  1. Example 1

    Input
    4
    1 2 3 3
    
    Expected output
    4
    
  2. Example 2

    Input
    4
    1 1 1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    4
    1 2 1 2
    
    Expected output
    4