Jump Rope


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

Tom is playing jump rope with his friends but they think it's too easy, so they decide to add some maths to the mix.

Every player is assigned a random number, and they must form a single file line and take turns jumping over the rope. The game master maintains a counter, and every time someone jumps over the rope, their number is deducted from the counter. If the counter goes to or below 0 on your turn, you are out, and the counter resets to 100 on the next turn. Otherwise, you rejoin the end of the line. Tom wants you to compute who the winner is given the starting information so he can cheat to always win.

Input

The first line contains an integer n\ (1\leq n \leq 1000) detailing the number of players in the game.

The next line contains n space separated integers a_i\ (1 \leq a_i \leq 100), which represents the assigned numbers of each of the players. The line starts in the order they appear.

Output

Output the assigned number of the player who is the last one standing according to the above rules.

Example

Input 1
5
37 50 10 6 63
Output 1
10

The game proceeds as outlined below, with each step showing the counter on top and the current state of the line on the bottom

100
37 50 10 6 63

63
50 10 6 63 37

13
10 6 63 37 50

3
6 63 37 50 10

100
63 37 50 10

37
37 50 10 63

100
50 10 63

50
10 63 50

40
63 50 10

100
50 10

50
10 50

40
50 10

10
Input 2
4
33 3 12 99
Output 2
3

The game proceeds as follows:

100
33 3 12 99

67
3 12 99 33

64
12 99 33 3

52
99 33 3 12

100
33 3 12

67
3 12 33

64
12 3 33

52
3 33 12

49
33 12 3

16
12 3 33

4
3 33 12

1
33 12 3

100
12 3

88
3 12

...

13
3 12

9
12 3

3

Comments

There are no comments at the moment.