CodeForces ~ 996

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 (1n1091≤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 (2n1052≤n≤105) — the number of entrances.

The second line contains nn integers a1,a2,,ana1,a2,…,an (0ai1090≤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+5;
const int INF = 0x3f3f3f3f;
int n, ans;
int main()
{
    scanf("%d", &n);
    int MIN = INF;
    for (int i = 1; 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 0;
}

 

 

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 (n50n≤50) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having kk (k2nk≤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 (1n501≤n≤50, 1k2n1≤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 1xk1≤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 1xk1≤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 ircc, 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 (1n1001≤n≤100), the number of pairs of people.

The second line contains 2n2n integers a1,a2,,a2na1,a2,…,a2n. For each ii with 1in1≤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 11233244112323441122334411233244→11232344→11223344 in two steps. Note that the sequence 11233244113232441133224411233244→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,,vnv1→,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 vivi→ or vi−vi→. In other words, if his position is currently p=(x,y)p=(x,y), he will either move to p+vip+vi→ or pvip−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.5106|p|≤1.5⋅106 so that he can stay safe.

Input

The first line contains a single integer nn (1n1051≤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=1civip=∑i=1ncivi→, satisfies |p|1.5106|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

 

转载于:https://www.cnblogs.com/Lis-/p/9255956.html

数据治理是确保数据准确性、可靠性、安全性、可用性和完整性的体系和框架。它定义了组织内部如何使用、存储、保护和共享数据的规则和流程。数据治理的重要性随着数字化转型的加速而日益凸显,它能够提高决策效率、增强业务竞争力、降低风险,并促进业务创新。有效的数据治理体系可以确保数据在采集、存储、处理、共享和保护等环节的合规性和有效性。 数据质量管理是数据治理中的关键环节,它涉及数据质量评估、数据清洗、标准化和监控。高质量的数据能够提升业务决策的准确性,优化业务流程,并挖掘潜在的商业价值。随着大数据和人工智能技术的发展,数据质量管理在确保数据准确性和可靠性方面的作用愈发重要。企业需要建立完善的数据质量管理和校验机制,并通过数据清洗和标准化提高数据质量。 数据安全与隐私保护是数据治理中的另一个重要领域。随着数据量的快速增长和互联网技术的迅速发展,数据安全与隐私保护面临前所未有的挑战。企业需要加强数据安全与隐私保护的法律法规和技术手段,采用数据加密、脱敏和备份恢复等技术手段,以及加强培训和教育,提高安全意识和技能水平。 数据流程管理与监控是确保数据质量、提高数据利用率、保护数据安全的重要环节。有效的数据流程管理可以确保数据流程的合规性和高效性,而实时监控则有助于及时发现并解决潜在问题。企业需要设计合理的数据流程架构,制定详细的数据管理流程规范,并运用数据审计和可视化技术手段进行监控。 数据资产管理是将数据视为组织的重要资产,通过有效的管理和利用,为组织带来经济价值。数据资产管理涵盖数据的整个生命周期,包括数据的创建、存储、处理、共享、使用和保护。它面临的挑战包括数据量的快速增长、数据类型的多样化和数据更新的迅速性。组织需要建立完善的数据管理体系,提高数据处理和分析能力,以应对这些挑战。同时,数据资产的分类与评估、共享与使用规范也是数据资产管理的重要组成部分,需要制定合理的标准和规范,确保数据共享的安全性和隐私保护,以及建立合理的利益分配和权益保障机制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值