Allen has a LOT of money. He has nn dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 11, 55, 1010, 2020, 100100. What is the minimum number of bills Allen could receive after withdrawing his entire balance?

Input

The first and only line of input contains a single integer nn (1≤n≤1091≤n≤109).

Output

Output the minimum number of bills that Allen could receive.

Examples

Input
125
Output
3
Input
43
Output
5
Input
1000000000
Output
10000000

Note

In the first sample case, Allen can withdraw this with a 100100 dollar bill, a 2020dollar bill, and a 55 dollar bill. There is no way for Allen to receive 125125 dollars in one or two bills.

In the second sample case, Allen can withdraw two 2020 dollar bills and three 11 dollar bills.

In the third sample case, Allen can withdraw 100000000100000000 (ten million!) 100100 dollar bills.

解题思路:简单贪心

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

题意:有n 个元素,而你会按顺序每个等一分钟,看哪个先到0,每过一分钟,都要减1

思路:你可以把每个元素算出一个步数,至少第几步才可以排到这个,首先看这个元素是否>n,大于的话说明还要走几圈,可以算出这个圈数再来算步数

这是我的方法,但是后来看了下大牛的方法,直接算出圈数,选最小的圈数的那个,有相同的圈数的话选最先出现的那个,这样方便了很多

引用大牛博客https://blog.csdn.net/ZscDst/article/details/80807353

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+;
const int INF = 0x3f3f3f3f;
int n, ans;
int main()
{
scanf("%d", &n);
int MIN = INF;
for (int i = ; i <= n; i++)
{
int a; scanf("%d", &a);
if(MIN > (a-i+n)/n)//x*n+i=a =》x=abs(a-i)/n
{
MIN = (a-i+n)/n;
ans = i;
}
}
printf("%d\n", ans);
return ;
}

Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.

Allen's future parking lot can be represented as a rectangle with 44 rows and nn (n≤50n≤50) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having kk (k≤2nk≤2n) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places.

 Illustration to the first example.

However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space.

Allen knows he will be a very busy man, and will only have time to move cars at most 2000020000 times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important.

Input

The first line of the input contains two space-separated integers nn and kk (1≤n≤501≤n≤50, 1≤k≤2n1≤k≤2n), representing the number of columns and the number of cars, respectively.

The next four lines will contain nn integers each between 00 and kk inclusive, representing the initial state of the parking lot. The rows are numbered 11 to 44 from top to bottom and the columns are numbered 11 to nn from left to right.

In the first and last line, an integer 1≤x≤k1≤x≤k represents a parking spot assigned to car xx (you can only move this car to this place), while the integer 00 represents a empty space (you can't move any car to this place).

In the second and third line, an integer 1≤x≤k1≤x≤k represents initial position of car xx, while the integer 00 represents an empty space (you can move any car to this place).

Each xx between 11 and kk appears exactly once in the second and third line, and exactly once in the first and fourth line.

Output

If there is a sequence of moves that brings all of the cars to their parking spaces, with at most 2000020000 car moves, then print mm, the number of moves, on the first line. On the following mm lines, print the moves (one move per line) in the format ii rr cc, which corresponds to Allen moving car ii to the neighboring space at row rr and column cc.

If it is not possible for Allen to move all the cars to the correct spaces with at most 2000020000 car moves, print a single line with the integer −1−1.

Examples

Input
4 5
1 2 0 4
1 2 0 4
5 0 0 3
0 5 0 3
Output
6
1 1 1
2 1 2
4 1 4
3 4 4
5 3 2
5 4 2
Input
1 2
1
2
1
2
Output
-1
Input
1 2
1
1
2
2
Output
2
1 1 1
2 4 1

Note

In the first sample test case, all cars are in front of their spots except car 55, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most 2000020000 will be accepted.

In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible.

引用大牛博客:https://blog.csdn.net/ZscDst/article/details/80821376

Allen is hosting a formal dinner party. 2n2n people come to the event in nn pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.

Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.

Input

The first line contains a single integer nn (1≤n≤1001≤n≤100), the number of pairs of people.

The second line contains 2n2n integers a1,a2,…,a2na1,a2,…,a2n. For each ii with 1≤i≤n1≤i≤n, iiappears exactly twice. If aj=ak=iaj=ak=i, that means that the jj-th and kk-th people in the line form a couple.

Output

Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.

Examples

Input
4
1 1 2 3 3 2 4 4
Output
2
Input
3
1 1 2 2 3 3
Output
0
Input
3
3 1 2 3 1 2
Output
3

Note

In the first sample case, we can transform 11233244→11232344→1122334411233244→11232344→11223344 in two steps. Note that the sequence 11233244→11323244→1133224411233244→11323244→11332244 also works in the same number of steps.

The second sample case already satisfies the constraints; therefore we need 00 swaps.

思路:简单贪心,只要遍历一遍,然后再找到当前元素交换过来即可

For a vector v⃗ =(x,y)v→=(x,y), define |v|=x2+y2−−−−−−√|v|=x2+y2.

Allen had a bit too much to drink at the bar, which is at the origin. There are nnvectors v1→,v2→,⋯,vn→v1→,v2→,⋯,vn→. Allen will make nn moves. As Allen's sense of direction is impaired, during the ii-th move he will either move in the direction vi→vi→ or −vi→−vi→. In other words, if his position is currently p=(x,y)p=(x,y), he will either move to p+vi→p+vi→ or p−vi→p−vi→.

Allen doesn't want to wander too far from home (which happens to also be the bar). You need to help him figure out a sequence of moves (a sequence of signs for the vectors) such that his final position pp satisfies |p|≤1.5⋅106|p|≤1.5⋅106 so that he can stay safe.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of moves.

Each of the following lines contains two space-separated integers xixi and yiyi, meaning that vi→=(xi,yi)vi→=(xi,yi). We have that |vi|≤106|vi|≤106 for all ii.

Output

Output a single line containing nn integers c1,c2,⋯,cnc1,c2,⋯,cn, each of which is either 11 or −1−1. Your solution is correct if the value of p=∑ni=1civi→p=∑i=1ncivi→, satisfies |p|≤1.5⋅106|p|≤1.5⋅106.

It can be shown that a solution always exists under the given constraints.

Examples

Input
3
999999 0
0 999999
999999 0
Output
1 1 -1 
Input
1
-824590 246031
Output
1 
Input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
Output
1 1 1 1 1 1 1 -1 

思路:贪心+随机算法,(随机算法没听过,今天算是初次见面了)
大牛博客:https://blog.csdn.net/ZscDst/article/details/80818824

CodeForces ~ 996的更多相关文章

  1. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...

  2. CodeForces 996B World Cup(思维)

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

  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. 架构探险笔记12-安全控制框架Shiro

    什么是Shiro Shiro是Apache组织下的一款轻量级Java安全框架.Spring Security相对来说比较臃肿. 官网 Shiro提供的服务 1.Authentication(认证) 2 ...

  2. BigInteger 类 和 BigDecimal 类

    一 .BigInteger BigInteger类在计算和处理任意大小的整数方面是很有用的. BigInteger 任意大的整数,原则上是,只要你的计算机的内存足够大,可以有无限位的. BigInte ...

  3. 【MySQL】【2】数字排序问题

    --我用的方案 SELECT * FROM TABLE_Q ORDER BY CAST(ID AS SIGNED) ASC 备注: 不做特殊处理的话,数字位数不一样时排序有问题,比如10会比2小. 其 ...

  4. Maven依赖标红线,非jar包冲突问题

    Maven依赖标红线 在pom中引入依赖fastdfs-client时,该依赖可以正常引入,但是查看Maven Project时,该依赖下总是有几个依赖报红线,并不是依赖冲突,测试代码无法正常运行.想 ...

  5. [luogu P1169] [ZJOI2007]棋盘制作

    [luogu P1169] [ZJOI2007]棋盘制作 题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的 ...

  6. zkw线段树模板题

    学了zkw线段树,觉得没什么必要刷专题的吧(切不动啊).. 那先放一个模板题吧(我绝不会和你说搬了一道树状数组模板题的!!!) 题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加 ...

  7. angular组件之间的通讯

    组件通讯,意在不同的指令和组件之间共享信息.如何在两个多个组件之间共享信息呢. 最近在项目上,组件跟组件之间可能是父子关系,兄弟关系,爷孙关系都有.....我也找找了很多关于组件之间通讯的方法,不同的 ...

  8. mac ci框架安装使用 memcached存session

    mac 安装memcached brew info memcached brew install memcached brew install memcached 安装过程具体不详细多讲 memcac ...

  9. linux command mktemp

    Linux command mktemp [Purpose]        Learning linux command mktemp to create a temporary file or di ...

  10. html页面标题增加图标方法

    有些网站的网页标题部分有图标,很带感.方法很简单: 在<head></head>部分增加下列一行代码即可. <link rel="shortcut icon&q ...