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][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][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][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].

  第一秒的时候这个人站在第一个数上,这个人每秒钟向前移动一步,每移动一步区间中的所有的数都会减一,直到他恰好走到一个数减为零的地方,输出该位置的序号。

  显而易见。只是一个循环,周期已知,步长已知,故而可推算出每个数在第几圈的时候减为零 nk*(i-1)==Ai (n是序列的长的,k是最少需要的圈数,i是位置的序列,Ai是第i个数的值) ,k最小的那个位置即为答案。

  

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; LL con[];
int main()
{
LL i,p,j,n;
LL mid;
scanf("%lld",&n);
for(i=;i<n;i++)
{
scanf("%lld",&con[i]);
mid=ceil((double)(con[i]-i)/n);
con[i]=mid;
}
LL head=,spot=;
for(i=;i<n;i++)
{
if(con[i]<head)
{
head=con[i];
spot=i+;
}
}
printf("%lld\n",spot);
return ;
}

CodeForces - 996B的更多相关文章

  1. CodeForces 996B World Cup(思维)

    https://codeforces.com/problemset/problem/996/B 题意: 圆形球场有n个门,Allen想要进去看比赛.Allen采取以下方案进入球场:开始Allen站在第 ...

  2. 【Codeforces 996B】World Cup

    [链接] 我是链接,点我呀:) [题意] [题解] 你可以找出来a[i]里面的最小值mi,显然是这个数字最可能先变成0,但还不确定. 然后用mi/n得到你最少需要走多少圈才能让那个mi变成" ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. mysql 8 server windows 安装经验分享

    windows下安装一般分为文件/msi安装文件 本章我们说的是文件行的mysql server 安装 下载地址:https://dev.mysql.com/downloads/mysql/ 下载完后 ...

  2. Kafka在大型应用中的 20 项最佳实践

    原标题:Kafka如何做到1秒处理1500万条消息? Apache Kafka 是一款流行的分布式数据流平台,它已经广泛地被诸如 New Relic(数据智能平台).Uber.Square(移动支付公 ...

  3. C++函数中的那些坑

    平时写程序时,我们可能或多或少对一些用法感到朦胧,下面我对一些易困惑大家,或者易用错的地方作点介绍. 一.函数的一些注意点 1.函数返回类型不能是数组类型或函数类型,但可以是指向数组或函数的指针. 2 ...

  4. bug:margin塌陷

    margin塌陷:两个嵌套的div,内部div的margin-top失效,内部对于外部的div并没有产生一个margin值,而是外部的div相对于上面的div产生了一个margin值. 弥补方法: 1 ...

  5. P4169 [Violet]天使玩偶/SJY摆棋子

    题目背景 感谢@浮尘ii 提供的一组hack数据 题目描述 Ayu 在七年前曾经收到过一个天使玩偶,当时她把它当作时间囊埋在了地下.而七年后 的今天,Ayu 却忘了她把天使玩偶埋在了哪里,所以她决定仅 ...

  6. 【SYZOJ279】滑稽♂树(树套树)

    [SYZOJ279]滑稽♂树(树套树) 题面 SYZOJ CJOJ 题目描述 zzsyz实验楼里面种了一棵滑稽树,只有滑稽之力达到大乘期的oier才能看到.虽然我们看不到,但是还是知道一些信息: 这真 ...

  7. MSSQL DBA权限获取WEBSHELL的过程

    前言 本文主要通过一个案例来演示一下当MSSQL是DBA权限,且不知道路径的时候如何去获取WEBSHELL.当然这种方式对站库分离的无效.我测试的环境是在Win7 64位下,数据库是SQLServer ...

  8. Linux(五)shell编程基础

    一.Linux shell简介 1.shell概述 Shell 是用户与内核进行交互操作的一种接口,目前最流行的 Shell 称为 bash Shell          Shell 是一门编程语言& ...

  9. spark streaming (二)

    一.基础核心概念 1.StreamingContext详解 (一) 有两种创建StreamingContext的方式:             val conf = new SparkConf().s ...

  10. 解题:POI 2012 Cloakroom

    题面 首先,单独处理每个询问复杂度显然不可承受,还是考虑通过排序使得限制更容易达到:按照$a$将物品排序,按照$m$将询问排序,这样肯定是要不断添加物品才能达到要求,顺着做一遍就行了 然后发现$b$的 ...