CodeForces  996B

Allen wants to enter a fan zone that occupies a round square and has nn entrances.

There already is a queue of aiai people in front of the ii-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.

Allen uses the following strategy to enter the fan zone:

  • Initially he stands in the end of the queue in front of the first entrance.
  • Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance).

Determine the entrance through which Allen will finally enter the fan zone.

Input

The first line contains a single integer nn (2≤n≤1052≤n≤105) — the number of entrances.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the number of people in queues. These numbers do not include Allen.

Output

Print a single integer — the number of entrance that Allen will use.

Examples

Input

4
2 3 2 0

Output

3

Input

2
10 10

Output

1

Input

6
5 2 6 5 7 4

Output

6

Note

In the first example the number of people (not including Allen) changes as follows: 

[2,3,2,0]→[1,2,1,0]→[0,1,0,0]

The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.

In the second example the number of people (not including Allen) changes as follows: 

[10,10]→[9,9]→[8,8]→[7,7]→[6,6]→[5,5]→[4,4]→[3,3]→[2,2]→[1,1]→[0,0]

In the third example the number of people (not including Allen) changes as follows: 

[5,2,6,5,7,4]→[4,1,5,4,6,3]→[3,0,4,3,5,2]→[2,0,3,2,4,1]→[1,0,2,1,3,0]→[0,0,1,0,2,0].

 

题意:

Allen面前有 n 个门,只有当他面前的这一个门的排队人是 0 的时候,他才能进去这一个门,否则就往后移一个门

起初他是站在第一个门的,每隔一个单位时间移动一个位置

思路:

1、周期

当 n = 4 时:

n                         1                           2                                   3                                    4            

people               0+4*k                  1+4*k                             2+4*k                             3+4*k   

只有 people 等于这个数的时候,可以在这个门前进入

( 当第一个门前 1个人的时候可以进入,第二个门前 2个人的时候可以进入.......)


满足条件式:

a[i] <= i -1 + n * k  ( i 从 0开始的)


CODE:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(n))
int a[100000+10];

int main()
{
    int n,k;
    scanf("%d",&n);

    for (int i=0; i<n; i++)
        scanf("%d",&a[i]);

    int t=0;
    int flag=0;
    for(int t=0;; t++)
    {
        for (int i=0; i<n; i++)
        {
            if (a[i] <= i + n*t)
            {
                printf("%d",i+1);
                flag=1;
                break;
            }
        }
        if(flag==1)
                break;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值