contestId
int64
0
1.01k
name
stringlengths
2
58
tags
sequencelengths
0
11
title
stringclasses
523 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
test_cases
listlengths
0
402
timeConsumedMillis
int64
0
8k
memoryConsumedBytes
int64
0
537M
score
float64
-1
3.99
__index_level_0__
int64
0
621k
622
The Sum of the k-th Powers
[ "math" ]
null
null
There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109<=+<=7 (so you should find the remainder after dividing the answer by the value 109<=+<=7).
The only line contains two integers *n*,<=*k* (1<=≤<=*n*<=≤<=109,<=0<=≤<=*k*<=≤<=106).
Print the only integer *a* — the remainder after dividing the value of the sum by the value 109<=+<=7.
[ "4 1\n", "4 2\n", "4 3\n", "4 0\n" ]
[ "10\n", "30\n", "100\n", "4\n" ]
none
[ { "input": "4 1", "output": "10" }, { "input": "4 2", "output": "30" }, { "input": "4 3", "output": "100" }, { "input": "4 0", "output": "4" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "1" }, { "input": "1 0", "output": "1" }, { "input": "1 1000000", "output": "1" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "100 100", "output": "568830579" }, { "input": "10000 100", "output": "352711099" }, { "input": "100 10000", "output": "859998022" }, { "input": "1000000000 1000000", "output": "617381606" }, { "input": "1000000 1000000", "output": "997878755" }, { "input": "999999 1000000", "output": "504760730" }, { "input": "77674473 447444", "output": "838207299" }, { "input": "333312494 795258", "output": "393290476" }, { "input": "761637147 673329", "output": "223778667" }, { "input": "335185991 514401", "output": "412595240" }, { "input": "203702132 355473", "output": "229710810" }, { "input": "1000000000 999935", "output": "729344740" } ]
2,000
171,929,600
0
1,387
356
Knight Tournament
[ "data structures", "dsu" ]
null
null
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows: - There are *n* knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to *n*. - The tournament consisted of *m* fights, in the *i*-th fight the knights that were still in the game with numbers at least *l**i* and at most *r**i* have fought for the right to continue taking part in the tournament. - After the *i*-th fight among all participants of the fight only one knight won — the knight number *x**i*, he continued participating in the tournament. Other knights left the tournament. - The winner of the last (the *m*-th) fight (the knight number *x**m*) became the winner of the tournament. You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number *b* was conquered by the knight number *a*, if there was a fight with both of these knights present and the winner was the knight number *a*. Write the code that calculates for each knight, the name of the knight that beat him.
The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th fight. It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.
Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0.
[ "4 3\n1 2 1\n1 3 3\n1 4 4\n", "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n" ]
[ "3 1 4 0 ", "0 8 4 6 4 8 6 1 " ]
Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.
[ { "input": "4 3\n1 2 1\n1 3 3\n1 4 4", "output": "3 1 4 0 " }, { "input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1", "output": "0 8 4 6 4 8 6 1 " }, { "input": "2 1\n1 2 1", "output": "0 1 " }, { "input": "2 1\n1 2 2", "output": "2 0 " }, { "input": "3 1\n1 3 1", "output": "0 1 1 " }, { "input": "3 1\n1 3 2", "output": "2 0 2 " }, { "input": "3 1\n1 3 3", "output": "3 3 0 " }, { "input": "3 2\n1 2 1\n1 3 3", "output": "3 1 0 " }, { "input": "3 2\n1 2 2\n1 3 2", "output": "2 0 2 " }, { "input": "3 2\n2 3 3\n1 3 3", "output": "3 3 0 " }, { "input": "11 6\n1 2 2\n7 8 7\n3 4 4\n6 9 6\n5 10 10\n2 11 11", "output": "2 11 4 11 10 10 6 7 6 11 0 " }, { "input": "10 6\n9 10 10\n6 7 7\n2 4 2\n2 5 5\n1 7 5\n4 10 8", "output": "5 5 2 2 8 7 5 0 10 8 " }, { "input": "11 8\n3 5 5\n8 9 9\n4 6 6\n8 10 10\n5 7 7\n2 7 2\n10 11 11\n1 11 1", "output": "0 1 5 5 6 7 2 9 10 11 1 " }, { "input": "10 7\n7 8 7\n7 9 9\n5 9 5\n5 10 10\n1 2 2\n3 4 4\n2 10 4", "output": "2 4 4 0 10 5 9 7 5 4 " }, { "input": "11 5\n8 10 9\n6 10 7\n6 11 11\n3 5 5\n1 11 1", "output": "0 1 5 5 1 7 11 9 7 9 1 " }, { "input": "10 6\n6 7 6\n5 7 5\n3 7 4\n2 8 2\n2 10 10\n1 10 10", "output": "10 10 4 2 4 5 6 2 10 0 " }, { "input": "11 7\n7 8 8\n5 6 5\n1 3 3\n7 9 9\n5 10 10\n10 11 11\n1 11 4", "output": "3 3 4 0 10 5 8 9 10 11 4 " }, { "input": "10 7\n8 9 9\n3 4 3\n2 3 2\n1 5 2\n6 7 6\n6 10 10\n1 10 10", "output": "2 10 2 3 2 10 6 9 10 0 " }, { "input": "11 6\n1 2 1\n8 9 9\n3 5 5\n3 6 6\n9 10 10\n1 11 10", "output": "10 1 5 5 6 10 10 9 10 0 10 " }, { "input": "10 5\n1 2 1\n8 10 8\n3 6 4\n4 7 7\n1 8 7", "output": "7 1 4 7 4 4 0 7 8 8 " }, { "input": "4 3\n1 2 2\n1 3 3\n1 4 4", "output": "2 3 4 0 " } ]
31
0
0
1,391
225
Dice Tower
[ "constructive algorithms", "greedy" ]
null
null
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees). Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower. The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower. Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
[ "3\n6\n3 2\n5 4\n2 4\n", "3\n3\n2 6\n4 1\n5 3\n" ]
[ "YES", "NO" ]
none
[ { "input": "3\n6\n3 2\n5 4\n2 4", "output": "YES" }, { "input": "3\n3\n2 6\n4 1\n5 3", "output": "NO" }, { "input": "1\n3\n2 1", "output": "YES" }, { "input": "2\n2\n3 1\n1 5", "output": "NO" }, { "input": "3\n2\n1 4\n5 3\n6 4", "output": "NO" }, { "input": "4\n3\n5 6\n1 3\n1 5\n4 1", "output": "NO" }, { "input": "2\n2\n3 1\n1 3", "output": "YES" }, { "input": "3\n2\n1 4\n3 1\n4 6", "output": "YES" }, { "input": "4\n3\n5 6\n1 5\n5 1\n1 5", "output": "YES" }, { "input": "5\n1\n2 3\n5 3\n5 4\n5 1\n3 5", "output": "NO" }, { "input": "10\n5\n1 3\n2 3\n6 5\n6 5\n4 5\n1 3\n1 2\n3 2\n4 2\n1 2", "output": "NO" }, { "input": "15\n4\n2 1\n2 4\n6 4\n5 3\n4 1\n4 2\n6 3\n4 5\n3 5\n2 6\n5 6\n1 5\n3 5\n6 4\n3 2", "output": "NO" }, { "input": "20\n6\n3 2\n4 6\n3 6\n6 4\n5 1\n1 5\n2 6\n1 2\n1 4\n5 3\n2 3\n6 2\n5 4\n2 6\n1 3\n4 6\n4 5\n6 3\n3 1\n6 2", "output": "NO" }, { "input": "25\n4\n1 2\n4 1\n3 5\n2 1\n3 5\n6 5\n3 5\n5 6\n1 2\n2 4\n6 2\n2 3\n2 4\n6 5\n2 3\n6 3\n2 3\n1 3\n2 1\n3 1\n5 6\n3 1\n6 4\n3 6\n2 3", "output": "NO" }, { "input": "100\n3\n6 5\n5 1\n3 2\n1 5\n3 6\n5 4\n2 6\n4 1\n6 3\n4 5\n1 5\n1 4\n4 2\n2 6\n5 4\n4 1\n1 3\n6 5\n5 1\n2 1\n2 4\n2 1\n3 6\n4 1\n6 3\n2 3\n5 1\n2 6\n6 4\n3 5\n4 1\n6 5\n1 5\n1 5\n2 3\n4 1\n5 3\n6 4\n1 3\n5 3\n4 1\n1 4\n2 1\n6 2\n1 5\n6 2\n6 2\n4 5\n4 2\n5 6\n6 3\n1 3\n2 3\n5 4\n6 5\n3 1\n1 2\n4 1\n1 3\n1 3\n6 5\n4 6\n3 1\n2 1\n2 3\n3 2\n4 1\n1 5\n4 1\n6 3\n1 5\n4 5\n4 2\n4 5\n2 6\n2 1\n3 5\n4 6\n4 2\n4 5\n2 4\n3 1\n6 4\n5 6\n3 1\n1 4\n4 5\n6 3\n6 3\n2 1\n5 1\n3 6\n3 5\n2 1\n4 6\n4 2\n5 6\n3 1\n3 5\n3 6", "output": "NO" }, { "input": "99\n3\n2 1\n6 2\n3 6\n1 3\n5 1\n2 6\n4 6\n6 4\n6 4\n6 5\n3 6\n2 6\n1 5\n2 3\n4 6\n1 4\n4 1\n2 3\n4 5\n4 1\n5 1\n1 2\n6 5\n4 6\n6 5\n6 2\n3 6\n6 4\n2 1\n3 1\n2 1\n6 2\n3 5\n4 1\n5 3\n3 1\n1 5\n3 6\n6 2\n1 5\n2 1\n5 1\n4 1\n2 6\n5 4\n4 2\n2 1\n1 5\n1 3\n4 6\n4 6\n4 5\n2 3\n6 2\n3 2\n2 1\n4 6\n6 2\n3 5\n3 6\n3 1\n2 3\n2 1\n3 6\n6 5\n6 3\n1 2\n5 1\n1 4\n6 2\n5 3\n1 3\n5 4\n2 3\n6 3\n1 5\n1 2\n2 6\n5 6\n5 6\n3 5\n3 1\n4 6\n3 1\n4 5\n4 2\n3 5\n6 2\n2 4\n4 6\n6 2\n4 2\n2 3\n2 4\n1 5\n1 4\n3 5\n1 2\n4 5", "output": "NO" }, { "input": "98\n6\n4 2\n1 2\n3 2\n2 1\n2 1\n3 2\n2 3\n6 5\n4 6\n1 5\n4 5\n5 1\n6 5\n1 4\n1 2\n2 4\n6 5\n4 5\n4 6\n3 1\n2 3\n4 1\n4 2\n6 5\n3 2\n4 2\n5 1\n2 4\n1 3\n4 5\n3 2\n1 2\n3 1\n3 2\n3 6\n6 4\n3 6\n3 5\n4 6\n6 5\n3 5\n3 2\n4 2\n6 4\n1 3\n2 4\n5 3\n2 3\n1 3\n5 6\n5 3\n5 3\n4 6\n4 6\n3 6\n4 1\n6 5\n6 2\n1 5\n2 1\n6 2\n5 4\n6 3\n1 5\n2 3\n2 6\n5 6\n2 6\n5 1\n3 2\n6 2\n6 2\n1 2\n2 1\n3 5\n2 1\n4 6\n1 4\n4 5\n3 2\n3 2\n5 4\n1 3\n5 1\n2 3\n6 2\n2 6\n1 5\n5 1\n5 4\n5 1\n5 4\n2 1\n6 5\n1 4\n6 5\n1 2\n3 5", "output": "NO" }, { "input": "97\n3\n2 1\n6 5\n4 1\n6 5\n3 2\n1 2\n6 3\n6 4\n6 3\n1 3\n1 3\n3 1\n3 6\n3 2\n5 6\n4 2\n3 6\n1 5\n2 6\n3 2\n6 2\n2 1\n2 4\n1 3\n3 1\n2 6\n3 6\n4 6\n6 2\n5 1\n6 3\n2 6\n3 6\n2 4\n4 5\n6 5\n4 1\n5 6\n6 2\n5 4\n5 1\n6 5\n1 4\n2 1\n4 5\n4 5\n4 1\n5 4\n1 4\n2 6\n2 6\n1 5\n5 6\n3 2\n2 3\n1 4\n4 1\n3 6\n6 2\n5 3\n6 2\n4 5\n6 2\n2 6\n6 5\n1 4\n2 6\n3 5\n2 6\n4 1\n4 5\n1 3\n4 2\n3 2\n1 2\n5 6\n1 5\n3 5\n2 1\n1 2\n1 2\n6 4\n5 1\n1 2\n2 4\n6 3\n4 5\n1 5\n4 2\n5 1\n3 1\n6 4\n4 2\n1 5\n4 6\n2 1\n2 6", "output": "NO" }, { "input": "96\n4\n1 5\n1 5\n4 6\n1 2\n4 2\n3 2\n4 6\n6 4\n6 3\n6 2\n4 1\n6 4\n5 1\n2 4\n5 6\n6 5\n3 2\n6 2\n3 1\n1 4\n3 2\n6 2\n2 4\n1 3\n5 4\n1 3\n6 2\n6 2\n5 6\n1 4\n4 2\n6 2\n3 1\n6 5\n3 1\n4 2\n6 3\n3 2\n3 6\n1 3\n5 6\n6 4\n1 4\n5 4\n2 6\n3 5\n5 4\n5 1\n2 4\n1 5\n1 3\n1 2\n1 3\n6 4\n6 3\n4 5\n4 1\n3 6\n1 2\n6 4\n1 2\n2 3\n2 1\n4 6\n1 3\n5 1\n4 5\n5 4\n6 3\n2 6\n5 1\n6 2\n3 1\n3 1\n5 4\n3 1\n5 6\n2 6\n5 6\n4 2\n6 5\n3 2\n6 5\n2 3\n6 4\n6 2\n1 2\n4 1\n1 2\n6 3\n2 1\n5 1\n6 5\n5 4\n4 5\n1 2", "output": "NO" }, { "input": "5\n1\n2 3\n3 5\n4 5\n5 4\n5 3", "output": "YES" }, { "input": "10\n5\n1 3\n3 1\n6 3\n6 3\n4 6\n3 1\n1 4\n3 1\n4 6\n1 3", "output": "YES" }, { "input": "15\n4\n2 1\n2 6\n6 5\n5 1\n1 5\n2 1\n6 5\n5 1\n5 1\n6 2\n6 5\n5 1\n5 1\n6 5\n2 6", "output": "YES" }, { "input": "20\n6\n3 2\n4 2\n3 5\n4 2\n5 3\n5 4\n2 3\n2 3\n4 5\n3 5\n3 2\n2 4\n4 5\n2 4\n3 2\n4 2\n5 4\n3 2\n3 5\n2 4", "output": "YES" }, { "input": "25\n4\n1 2\n1 5\n5 6\n1 2\n5 1\n5 6\n5 1\n6 5\n2 1\n2 6\n2 6\n2 6\n2 6\n5 6\n2 6\n6 5\n2 1\n1 5\n1 2\n1 2\n6 5\n1 2\n6 5\n6 2\n2 6", "output": "YES" }, { "input": "100\n3\n6 5\n1 5\n2 1\n5 1\n6 5\n5 1\n6 2\n1 2\n6 5\n5 1\n5 1\n1 5\n2 6\n6 2\n5 6\n1 2\n1 5\n5 6\n1 5\n1 2\n2 6\n1 2\n6 2\n1 5\n6 2\n2 6\n1 5\n6 2\n6 5\n5 6\n1 5\n5 6\n5 1\n5 1\n2 1\n1 2\n5 6\n6 5\n1 5\n5 1\n1 2\n1 5\n1 2\n2 6\n5 1\n2 6\n2 6\n5 6\n2 6\n6 5\n6 5\n1 5\n2 1\n5 6\n5 6\n1 2\n2 1\n1 2\n1 2\n1 2\n5 6\n6 2\n1 5\n1 2\n2 1\n2 6\n1 2\n5 1\n1 5\n6 5\n5 1\n5 1\n2 6\n5 6\n6 2\n1 2\n5 1\n6 2\n2 1\n5 6\n2 1\n1 5\n6 5\n6 5\n1 2\n1 2\n5 1\n6 2\n6 2\n1 2\n1 5\n6 5\n5 6\n1 2\n6 5\n2 1\n6 5\n1 5\n5 6\n6 5", "output": "YES" }, { "input": "99\n3\n2 1\n2 6\n6 2\n1 5\n1 5\n6 2\n6 5\n6 5\n6 2\n5 6\n6 5\n6 2\n5 1\n2 6\n6 5\n1 5\n1 5\n2 6\n5 1\n1 5\n1 5\n2 1\n5 6\n6 5\n5 6\n2 6\n6 2\n6 5\n1 2\n1 2\n1 2\n2 6\n5 6\n1 2\n5 6\n1 2\n5 1\n6 5\n2 6\n5 1\n1 2\n1 5\n1 5\n6 2\n5 1\n2 6\n1 2\n5 1\n1 5\n6 5\n6 5\n5 6\n2 1\n2 6\n2 6\n1 2\n6 2\n2 6\n5 6\n6 5\n1 5\n2 1\n1 2\n6 2\n5 6\n6 5\n2 1\n1 5\n1 5\n2 6\n5 1\n1 2\n5 6\n2 1\n6 5\n5 1\n2 1\n6 2\n6 5\n6 5\n5 6\n1 2\n6 5\n1 2\n5 1\n2 1\n5 1\n2 6\n2 1\n6 2\n2 6\n2 6\n2 1\n2 1\n5 1\n1 5\n5 6\n2 1\n5 6", "output": "YES" }, { "input": "98\n6\n4 2\n2 3\n2 3\n2 3\n2 3\n2 3\n3 2\n5 4\n4 2\n5 4\n5 4\n5 4\n5 3\n4 5\n2 3\n4 2\n5 3\n5 4\n4 5\n3 5\n3 2\n4 2\n2 4\n5 4\n2 3\n2 4\n5 4\n4 2\n3 5\n5 4\n2 3\n2 4\n3 5\n2 3\n3 5\n4 2\n3 5\n5 3\n4 2\n5 3\n5 3\n2 3\n2 4\n4 5\n3 2\n4 2\n3 5\n3 2\n3 5\n5 4\n3 5\n3 5\n4 2\n4 2\n3 2\n4 5\n5 4\n2 3\n5 4\n2 4\n2 3\n4 5\n3 5\n5 4\n3 2\n2 3\n5 3\n2 3\n5 3\n2 3\n2 3\n2 4\n2 3\n2 3\n5 3\n2 3\n4 2\n4 2\n5 4\n2 3\n2 3\n4 5\n3 2\n5 3\n3 2\n2 4\n2 4\n5 3\n5 4\n4 5\n5 3\n4 5\n2 4\n5 3\n4 2\n5 4\n2 4\n5 3", "output": "YES" }, { "input": "97\n3\n2 1\n5 6\n1 2\n5 6\n2 6\n2 1\n6 2\n6 5\n6 2\n1 5\n1 2\n1 2\n6 2\n2 6\n6 5\n2 6\n6 5\n5 1\n6 2\n2 6\n2 6\n1 2\n2 6\n1 2\n1 5\n6 2\n6 5\n6 5\n2 6\n1 5\n6 5\n6 2\n6 2\n2 6\n5 6\n5 6\n1 5\n6 5\n2 6\n5 6\n1 5\n5 6\n1 5\n1 2\n5 1\n5 1\n1 5\n5 1\n1 5\n6 2\n6 2\n5 1\n6 5\n2 1\n2 6\n1 5\n1 5\n6 2\n2 6\n5 6\n2 6\n5 6\n2 6\n6 2\n5 6\n1 2\n6 2\n5 6\n6 2\n1 5\n5 6\n1 5\n2 6\n2 6\n2 1\n6 5\n5 1\n5 1\n1 2\n2 1\n2 1\n6 2\n1 5\n2 1\n2 1\n6 2\n5 1\n5 1\n2 6\n1 5\n1 2\n6 2\n2 6\n5 1\n6 5\n1 2\n6 2", "output": "YES" }, { "input": "96\n4\n1 5\n5 1\n6 5\n2 1\n2 1\n2 6\n6 5\n6 5\n6 2\n2 6\n1 5\n6 5\n1 5\n2 6\n6 5\n5 6\n2 1\n2 6\n1 2\n1 5\n2 6\n2 6\n2 1\n1 5\n5 1\n1 2\n2 6\n2 6\n6 5\n1 5\n2 1\n2 6\n1 2\n5 6\n1 5\n2 6\n6 2\n2 6\n6 5\n1 5\n6 5\n6 5\n1 5\n5 1\n6 2\n5 1\n5 1\n1 5\n2 6\n5 1\n1 5\n2 1\n1 2\n6 2\n6 2\n5 6\n1 5\n6 5\n2 1\n6 5\n2 1\n2 1\n1 2\n6 2\n1 2\n1 5\n5 1\n5 6\n6 5\n6 2\n1 5\n2 6\n1 2\n1 2\n5 1\n1 5\n6 5\n6 2\n6 5\n2 6\n5 6\n2 1\n5 6\n2 1\n6 5\n2 6\n2 1\n1 5\n2 1\n6 2\n1 2\n1 5\n5 6\n5 1\n5 6\n2 1", "output": "YES" }, { "input": "3\n6\n3 2\n5 4\n2 6", "output": "NO" }, { "input": "4\n1\n2 3\n2 3\n2 3\n1 3", "output": "NO" }, { "input": "2\n6\n3 2\n6 4", "output": "NO" }, { "input": "3\n6\n3 2\n5 6\n2 4", "output": "NO" }, { "input": "2\n5\n6 3\n4 5", "output": "NO" }, { "input": "2\n6\n3 2\n6 5", "output": "NO" }, { "input": "2\n1\n3 2\n1 2", "output": "NO" }, { "input": "2\n3\n5 1\n3 5", "output": "NO" }, { "input": "2\n1\n2 3\n1 2", "output": "NO" }, { "input": "2\n1\n2 3\n2 1", "output": "NO" }, { "input": "3\n1\n4 5\n4 1\n4 5", "output": "NO" }, { "input": "2\n4\n2 6\n5 4", "output": "NO" }, { "input": "2\n6\n3 2\n6 2", "output": "NO" }, { "input": "2\n3\n2 1\n3 5", "output": "NO" }, { "input": "2\n3\n1 2\n3 1", "output": "NO" }, { "input": "2\n3\n2 6\n5 3", "output": "NO" }, { "input": "3\n3\n1 2\n3 2\n3 1", "output": "NO" }, { "input": "3\n5\n3 1\n1 3\n2 3", "output": "NO" }, { "input": "2\n6\n2 4\n6 5", "output": "NO" }, { "input": "2\n6\n4 5\n6 5", "output": "NO" }, { "input": "2\n6\n3 5\n3 6", "output": "NO" }, { "input": "2\n4\n1 2\n4 5", "output": "NO" }, { "input": "2\n3\n2 6\n3 1", "output": "NO" } ]
30
0
0
1,395
0
none
[ "none" ]
null
null
One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties: - *G* has exactly *n* vertices, numbered from 1 to *n*. - For all pairs of vertices *i* and *j*, where *i*<=≠<=*j*, there is an edge connecting them if and only if characters *s**i* and *s**j* are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not. Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph *G*, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string *s*, such that if Vasya used this *s* he would produce the given graph *G*.
The first line of the input contains two integers *n* and *m*  — the number of vertices and edges in the graph found by Petya, respectively. Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*) — the edges of the graph *G*. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.
In the first line print "Yes" (without the quotes), if the string *s* Petya is interested in really exists and "No" (without the quotes) otherwise. If the string *s* exists, then print it on the second line of the output. The length of *s* must be exactly *n*, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with *G*. If there are multiple possible answers, you may print any of them.
[ "2 1\n1 2\n", "4 3\n1 2\n1 3\n1 4\n" ]
[ "Yes\naa\n", "No\n" ]
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.
[ { "input": "2 1\n1 2", "output": "Yes\naa" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "No" }, { "input": "4 4\n1 2\n1 3\n1 4\n3 4", "output": "Yes\nbacc" }, { "input": "1 0", "output": "Yes\na" }, { "input": "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2", "output": "Yes\naaaaaaaa" }, { "input": "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2", "output": "Yes\naaaaaaaa" }, { "input": "4 3\n4 3\n2 4\n2 3", "output": "Yes\naccc" }, { "input": "4 2\n4 3\n1 2", "output": "Yes\naacc" }, { "input": "5 3\n1 2\n1 3\n4 5", "output": "No" }, { "input": "6 4\n1 2\n1 3\n4 5\n4 6", "output": "No" }, { "input": "6 4\n1 2\n2 3\n4 5\n4 6", "output": "No" }, { "input": "6 4\n3 2\n1 3\n6 5\n4 6", "output": "No" }, { "input": "6 4\n1 2\n1 3\n4 6\n5 6", "output": "No" }, { "input": "7 13\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n2 5\n2 7\n3 7\n7 4\n7 6\n7 1\n7 5", "output": "No" }, { "input": "8 18\n3 7\n2 5\n5 3\n3 8\n8 6\n6 3\n6 4\n4 8\n1 2\n6 1\n2 7\n2 4\n4 5\n4 3\n6 5\n1 4\n5 7\n3 1", "output": "No" }, { "input": "20 55\n20 11\n14 5\n4 9\n17 5\n16 5\n20 16\n11 17\n2 14\n14 19\n9 15\n20 19\n5 18\n15 20\n1 16\n12 20\n4 7\n16 19\n17 19\n16 12\n19 9\n11 13\n18 17\n10 8\n20 1\n16 8\n1 13\n11 12\n13 18\n4 13\n14 10\n9 13\n8 9\n6 9\n2 13\n10 16\n19 1\n7 17\n20 4\n12 8\n3 2\n18 10\n6 13\n14 9\n7 9\n19 7\n8 15\n20 6\n16 13\n14 13\n19 8\n7 14\n6 2\n9 1\n7 1\n10 6", "output": "No" }, { "input": "15 84\n11 9\n3 11\n13 10\n2 12\n5 9\n1 7\n14 4\n14 2\n14 1\n11 8\n1 8\n14 10\n4 15\n10 5\n5 12\n13 11\n6 14\n5 7\n12 11\n9 1\n10 15\n2 6\n7 15\n14 9\n9 7\n11 14\n8 15\n12 7\n13 6\n2 9\n9 6\n15 3\n12 15\n6 15\n4 6\n4 1\n9 12\n10 7\n6 1\n11 10\n2 3\n5 2\n13 2\n13 3\n12 6\n4 3\n5 8\n12 1\n9 15\n14 5\n12 14\n10 1\n9 4\n7 13\n3 6\n15 1\n13 9\n11 1\n10 4\n9 3\n8 12\n13 12\n6 7\n12 10\n4 12\n13 15\n2 10\n3 8\n1 5\n15 2\n4 11\n2 1\n10 8\n14 3\n14 8\n8 7\n13 1\n5 4\n11 2\n6 8\n5 15\n2 4\n9 8\n9 10", "output": "No" }, { "input": "15 13\n13 15\n13 3\n14 3\n10 7\n2 5\n5 12\n12 11\n9 2\n13 7\n7 4\n12 10\n15 7\n6 13", "output": "No" }, { "input": "6 6\n1 4\n3 4\n6 4\n2 6\n5 3\n3 2", "output": "No" }, { "input": "4 6\n4 2\n3 1\n3 4\n3 2\n4 1\n2 1", "output": "Yes\naaaa" }, { "input": "4 4\n3 2\n2 4\n1 2\n3 4", "output": "Yes\nabcc" }, { "input": "4 3\n1 3\n1 4\n3 4", "output": "Yes\nacaa" }, { "input": "4 4\n1 2\n4 1\n3 4\n3 1", "output": "Yes\nbacc" }, { "input": "4 4\n4 2\n3 4\n3 1\n2 3", "output": "Yes\nacbc" }, { "input": "4 5\n3 1\n2 1\n3 4\n2 4\n3 2", "output": "Yes\nabbc" }, { "input": "4 4\n4 1\n3 1\n3 2\n3 4", "output": "Yes\nacba" }, { "input": "4 5\n3 4\n2 1\n3 1\n4 1\n2 3", "output": "Yes\nbabc" }, { "input": "4 4\n1 3\n3 4\n2 1\n3 2", "output": "Yes\naabc" }, { "input": "4 3\n2 1\n1 4\n2 4", "output": "Yes\naaca" }, { "input": "4 4\n2 4\n1 2\n1 3\n1 4", "output": "Yes\nbaca" }, { "input": "4 2\n3 1\n2 4", "output": "Yes\nacac" }, { "input": "4 4\n4 2\n2 1\n3 2\n1 4", "output": "Yes\nabca" }, { "input": "4 5\n4 1\n2 4\n2 1\n2 3\n3 1", "output": "Yes\nbbac" }, { "input": "4 4\n1 2\n3 1\n2 4\n2 3", "output": "Yes\nabac" }, { "input": "4 2\n2 3\n1 4", "output": "Yes\nacca" }, { "input": "4 4\n2 1\n1 4\n2 3\n3 1", "output": "Yes\nbaac" }, { "input": "4 3\n3 2\n1 2\n1 3", "output": "Yes\naaac" }, { "input": "4 4\n3 2\n2 4\n3 4\n4 1", "output": "Yes\naccb" }, { "input": "4 5\n4 2\n3 2\n4 3\n4 1\n2 1", "output": "Yes\nabcb" }, { "input": "4 4\n3 1\n2 4\n1 4\n3 4", "output": "Yes\nacab" }, { "input": "4 5\n3 1\n4 3\n4 1\n2 1\n2 4", "output": "Yes\nbacb" }, { "input": "4 4\n2 4\n3 4\n1 2\n4 1", "output": "Yes\naacb" }, { "input": "4 5\n1 4\n4 3\n4 2\n3 2\n1 3", "output": "Yes\nacbb" }, { "input": "2 0", "output": "Yes\nac" }, { "input": "3 0", "output": "No" }, { "input": "3 1\n1 2", "output": "Yes\naac" }, { "input": "3 2\n1 2\n3 2", "output": "Yes\nabc" }, { "input": "3 3\n1 2\n1 3\n2 3", "output": "Yes\naaa" }, { "input": "3 1\n2 3", "output": "Yes\nacc" }, { "input": "3 1\n1 3", "output": "Yes\naca" }, { "input": "4 3\n1 2\n2 3\n3 4", "output": "No" }, { "input": "5 9\n4 3\n4 2\n3 1\n5 1\n4 1\n2 1\n5 2\n3 2\n5 4", "output": "Yes\nbbabc" }, { "input": "6 9\n1 4\n1 6\n3 6\n5 4\n2 6\n3 5\n4 6\n1 5\n5 6", "output": "No" }, { "input": "8 21\n4 7\n7 8\n6 4\n8 5\n8 1\n3 4\n4 8\n4 5\n6 7\n6 8\n7 1\n4 2\n1 5\n6 5\n8 2\n3 6\n5 2\n7 5\n1 2\n7 2\n4 1", "output": "No" }, { "input": "4 3\n1 4\n1 3\n2 4", "output": "No" }, { "input": "4 4\n1 3\n1 4\n2 3\n2 4", "output": "No" }, { "input": "4 3\n1 3\n2 4\n3 4", "output": "No" }, { "input": "4 3\n1 3\n2 4\n1 4", "output": "No" }, { "input": "5 6\n1 2\n2 4\n2 5\n3 4\n3 5\n4 5", "output": "No" }, { "input": "6 10\n1 5\n1 4\n3 4\n3 6\n1 2\n3 5\n2 5\n2 6\n1 6\n4 6", "output": "No" }, { "input": "4 3\n1 2\n3 4\n2 3", "output": "No" } ]
77
5,120,000
0
1,401
818
Card Game Again
[ "binary search", "data structures", "number theory", "two pointers" ]
null
null
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck. After receiving the deck and the magic number, Vova removes *x* (possibly *x*<==<=0) cards from the top of the deck, *y* (possibly *y*<==<=0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards *x*<=+<=1, *x*<=+<=2, ... *n*<=-<=*y*<=-<=1, *n*<=-<=*y* from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by *k*. So Vova received a deck (possibly not a valid one) and a number *k*, and now he wonders, how many ways are there to choose *x* and *y* so the deck he will get after removing *x* cards from the top and *y* cards from the bottom is valid?
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards.
Print the number of ways to choose *x* and *y* so the resulting deck is valid.
[ "3 4\n6 2 8\n", "3 6\n9 1 14\n" ]
[ "4\n", "1\n" ]
In the first example the possible values of *x* and *y* are: 1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1.
[ { "input": "3 4\n6 2 8", "output": "4" }, { "input": "3 6\n9 1 14", "output": "1" }, { "input": "5 1\n1 3 1 3 1", "output": "15" }, { "input": "5 1\n5 5 5 5 5", "output": "15" }, { "input": "5 1\n5 4 4 4 4", "output": "15" }, { "input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5050" }, { "input": "100 1\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1", "output": "5050" }, { "input": "100 5\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5", "output": "4713" }, { "input": "100 6\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3", "output": "4580" }, { "input": "100 72\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5", "output": "4549" }, { "input": "100 72\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3", "output": "4123" }, { "input": "2 999634589\n31607 31627", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 2\n1", "output": "0" }, { "input": "1 3\n1", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 5\n3", "output": "0" }, { "input": "1 6\n4", "output": "0" }, { "input": "1 7\n2", "output": "0" }, { "input": "1 8\n3", "output": "0" }, { "input": "1 9\n5", "output": "0" }, { "input": "1 10\n3", "output": "0" }, { "input": "2 1\n1 1", "output": "3" }, { "input": "2 2\n2 2", "output": "3" }, { "input": "2 3\n1 2", "output": "0" }, { "input": "2 4\n1 2", "output": "0" }, { "input": "2 5\n1 1", "output": "0" }, { "input": "2 6\n2 1", "output": "0" }, { "input": "2 7\n1 4", "output": "0" }, { "input": "2 8\n5 3", "output": "0" }, { "input": "2 9\n2 2", "output": "0" }, { "input": "2 10\n6 1", "output": "0" }, { "input": "3 1\n1 1 1", "output": "6" }, { "input": "3 2\n2 2 1", "output": "5" }, { "input": "3 3\n2 1 2", "output": "0" }, { "input": "3 4\n2 2 2", "output": "3" }, { "input": "3 5\n1 1 2", "output": "0" }, { "input": "3 6\n4 3 2", "output": "3" }, { "input": "3 7\n3 4 1", "output": "0" }, { "input": "3 8\n5 1 4", "output": "0" }, { "input": "3 9\n3 2 1", "output": "0" }, { "input": "3 10\n6 5 5", "output": "2" }, { "input": "4 1\n1 1 1 1", "output": "10" }, { "input": "4 2\n2 2 1 2", "output": "9" }, { "input": "4 3\n2 1 1 1", "output": "0" }, { "input": "4 4\n2 2 1 1", "output": "3" }, { "input": "4 5\n2 3 2 1", "output": "0" }, { "input": "4 6\n1 1 3 3", "output": "0" }, { "input": "4 7\n1 1 2 2", "output": "0" }, { "input": "4 8\n5 4 5 5", "output": "0" }, { "input": "4 9\n1 1 4 2", "output": "0" }, { "input": "4 10\n2 6 2 1", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "15" }, { "input": "5 2\n2 2 1 2 1", "output": "13" }, { "input": "5 3\n2 1 1 2 1", "output": "0" }, { "input": "5 4\n2 2 1 3 1", "output": "4" }, { "input": "5 5\n2 3 1 1 3", "output": "0" }, { "input": "5 6\n3 4 3 4 3", "output": "10" }, { "input": "5 7\n3 1 3 2 4", "output": "0" }, { "input": "5 8\n2 2 3 3 1", "output": "0" }, { "input": "5 9\n3 1 3 3 4", "output": "7" }, { "input": "5 10\n3 6 6 1 5", "output": "3" }, { "input": "6 1\n1 1 1 1 1 1", "output": "21" }, { "input": "6 2\n1 2 2 1 1 1", "output": "14" }, { "input": "6 3\n2 2 2 2 1 2", "output": "0" }, { "input": "6 4\n1 3 3 3 3 2", "output": "0" }, { "input": "6 5\n2 3 3 2 1 2", "output": "0" }, { "input": "6 6\n1 2 4 1 4 4", "output": "0" }, { "input": "6 7\n2 2 4 3 2 1", "output": "0" }, { "input": "6 8\n3 2 3 5 5 3", "output": "0" }, { "input": "6 9\n1 4 1 2 1 1", "output": "0" }, { "input": "6 10\n1 2 5 6 6 6", "output": "11" }, { "input": "7 1\n1 1 1 1 1 1 1", "output": "28" }, { "input": "7 2\n1 1 2 2 2 2 1", "output": "24" }, { "input": "7 3\n2 2 1 1 2 2 2", "output": "0" }, { "input": "7 4\n3 2 1 2 1 1 1", "output": "8" }, { "input": "7 5\n2 3 3 3 2 3 2", "output": "0" }, { "input": "7 6\n3 4 4 1 4 3 2", "output": "15" }, { "input": "7 7\n4 2 4 4 1 4 4", "output": "0" }, { "input": "7 8\n4 4 2 4 2 5 3", "output": "18" }, { "input": "7 9\n2 1 3 4 4 5 4", "output": "0" }, { "input": "7 10\n6 3 3 5 3 6 1", "output": "10" }, { "input": "8 1\n1 1 1 1 1 1 1 1", "output": "36" }, { "input": "8 2\n1 1 1 1 1 1 1 2", "output": "8" }, { "input": "8 3\n1 1 2 2 1 1 2 2", "output": "0" }, { "input": "8 4\n2 3 2 3 3 3 2 3", "output": "10" }, { "input": "8 5\n1 3 1 2 2 2 1 3", "output": "0" }, { "input": "8 6\n4 2 4 2 1 2 1 4", "output": "0" }, { "input": "8 7\n2 2 1 4 4 4 2 2", "output": "0" }, { "input": "8 8\n5 2 1 2 4 2 2 4", "output": "21" }, { "input": "8 9\n4 4 2 2 5 5 4 1", "output": "0" }, { "input": "8 10\n2 1 4 4 3 4 4 6", "output": "0" }, { "input": "9 1\n1 1 1 1 1 1 1 1 1", "output": "45" }, { "input": "9 2\n1 1 1 2 1 1 2 2 2", "output": "36" }, { "input": "9 3\n1 1 1 2 2 1 1 2 1", "output": "0" }, { "input": "9 4\n1 1 2 1 2 1 1 1 1", "output": "15" }, { "input": "9 5\n3 2 3 2 3 1 1 3 2", "output": "0" }, { "input": "9 6\n2 1 1 3 2 4 1 2 2", "output": "21" }, { "input": "9 7\n4 3 2 1 2 3 3 4 4", "output": "0" }, { "input": "9 8\n5 5 2 1 3 1 3 1 3", "output": "0" }, { "input": "9 9\n2 4 1 4 4 3 3 4 1", "output": "18" }, { "input": "9 10\n4 3 2 5 2 2 2 2 6", "output": "23" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "55" }, { "input": "10 2\n2 2 2 2 2 2 2 1 2 1", "output": "53" }, { "input": "10 3\n2 2 1 1 2 2 2 2 1 2", "output": "0" }, { "input": "10 4\n1 1 2 3 3 1 2 2 2 3", "output": "26" }, { "input": "10 5\n3 3 2 2 3 1 1 1 3 1", "output": "0" }, { "input": "10 6\n4 4 4 3 2 1 1 1 2 4", "output": "27" }, { "input": "10 7\n4 2 2 2 3 3 2 4 4 3", "output": "0" }, { "input": "10 8\n5 4 1 4 3 2 1 2 3 3", "output": "24" }, { "input": "10 9\n1 2 3 4 5 2 3 5 5 4", "output": "12" }, { "input": "10 10\n5 3 2 5 1 2 5 1 5 1", "output": "35" }, { "input": "1 1000000000\n1", "output": "0" }, { "input": "1 1000000000\n1000000000", "output": "1" }, { "input": "1 100000000\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" } ]
77
7,065,600
0
1,404
831
Unimodal Array
[ "implementation" ]
null
null
Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array.
Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower).
[ "6\n1 5 5 5 4 2\n", "5\n10 20 30 20 10\n", "4\n1 2 1 2\n", "7\n3 3 3 3 3 3 3\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n" ]
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
[ { "input": "6\n1 5 5 5 4 2", "output": "YES" }, { "input": "5\n10 20 30 20 10", "output": "YES" }, { "input": "4\n1 2 1 2", "output": "NO" }, { "input": "7\n3 3 3 3 3 3 3", "output": "YES" }, { "input": "6\n5 7 11 11 2 1", "output": "YES" }, { "input": "1\n7", "output": "YES" }, { "input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "YES" }, { "input": "5\n5 5 6 6 1", "output": "NO" }, { "input": "3\n4 4 2", "output": "YES" }, { "input": "4\n4 5 5 6", "output": "NO" }, { "input": "3\n516 516 515", "output": "YES" }, { "input": "5\n502 503 508 508 507", "output": "YES" }, { "input": "10\n538 538 538 538 538 538 538 538 538 538", "output": "YES" }, { "input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426", "output": "YES" }, { "input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513", "output": "YES" }, { "input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337", "output": "YES" }, { "input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479", "output": "YES" }, { "input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393", "output": "YES" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "YES" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "YES" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "YES" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "YES" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "YES" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "YES" }, { "input": "1\n1000", "output": "YES" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1", "output": "YES" }, { "input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999", "output": "NO" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "NO" }, { "input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "NO" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "NO" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "NO" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "NO" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "NO" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n2 1 1", "output": "NO" }, { "input": "3\n2 1 2", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "YES" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "YES" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "NO" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "NO" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "2\n1 3", "output": "YES" }, { "input": "2\n1 2", "output": "YES" }, { "input": "5\n2 2 1 1 1", "output": "NO" }, { "input": "4\n1 3 2 2", "output": "NO" }, { "input": "6\n1 2 1 2 2 1", "output": "NO" }, { "input": "2\n4 2", "output": "YES" }, { "input": "3\n3 2 2", "output": "NO" }, { "input": "9\n1 2 2 3 3 4 3 2 1", "output": "NO" }, { "input": "4\n5 5 4 4", "output": "NO" }, { "input": "2\n2 1", "output": "YES" }, { "input": "5\n5 4 3 2 1", "output": "YES" }, { "input": "7\n4 3 3 3 3 3 3", "output": "NO" }, { "input": "5\n1 2 3 4 5", "output": "YES" }, { "input": "3\n2 2 1", "output": "YES" }, { "input": "3\n4 3 3", "output": "NO" }, { "input": "7\n1 5 5 4 3 3 1", "output": "NO" }, { "input": "6\n3 3 1 2 2 1", "output": "NO" }, { "input": "5\n1 2 1 2 1", "output": "NO" }, { "input": "2\n5 1", "output": "YES" }, { "input": "9\n1 2 3 4 4 3 2 2 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "2\n5 4", "output": "YES" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 7 8 9 99", "output": "YES" }, { "input": "4\n1 2 3 4", "output": "YES" }, { "input": "3\n5 5 2", "output": "YES" }, { "input": "4\n1 4 2 3", "output": "NO" }, { "input": "2\n3 2", "output": "YES" }, { "input": "5\n1 2 2 1 1", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "5\n1 2 3 2 2", "output": "NO" }, { "input": "5\n5 6 6 5 5", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n5 4 3 3 2", "output": "NO" }, { "input": "7\n1 3 3 3 2 1 1", "output": "NO" }, { "input": "9\n5 6 6 5 5 4 4 3 3", "output": "NO" }, { "input": "6\n1 5 5 3 2 2", "output": "NO" }, { "input": "5\n2 1 3 3 1", "output": "NO" }, { "input": "2\n4 3", "output": "YES" }, { "input": "5\n3 2 2 1 1", "output": "NO" }, { "input": "4\n5 4 3 2", "output": "YES" }, { "input": "4\n4 4 1 1", "output": "NO" }, { "input": "4\n3 3 1 1", "output": "NO" }, { "input": "4\n4 4 2 2", "output": "NO" }, { "input": "5\n4 4 3 2 2", "output": "NO" }, { "input": "8\n4 4 4 4 5 6 7 8", "output": "NO" }, { "input": "5\n3 5 4 4 3", "output": "NO" }, { "input": "6\n2 5 3 3 2 2", "output": "NO" }, { "input": "4\n5 5 2 2", "output": "NO" }, { "input": "5\n1 2 2 3 5", "output": "NO" } ]
15
0
0
1,405
32
Reconnaissance
[ "brute force" ]
A. Reconnaissance
2
256
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment. Ways (1,<=2) and (2,<=1) should be regarded as different.
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
[ "5 10\n10 20 50 60 65\n", "5 1\n55 30 29 31 55\n" ]
[ "6\n", "6\n" ]
none
[ { "input": "5 10\n10 20 50 60 65", "output": "6" }, { "input": "5 1\n55 30 29 31 55", "output": "6" }, { "input": "6 10\n4 6 4 1 9 3", "output": "30" }, { "input": "7 100\n19 1694 261 162 1 234 513", "output": "8" }, { "input": "8 42\n37 53 74 187 568 22 5 65", "output": "20" }, { "input": "10 4\n11 6 76 49 28 20 57 152 5 32", "output": "4" }, { "input": "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 310 382 770 337 18 189 570 177 29 54 855 171 205 291 299 935 620 180 114 358 88 292 118 400 218 537 369 60 683 192 13 537 59 824 264 191 3 300", "output": "2404" } ]
62
0
0
1,409
262
Roma and Lucky Numbers
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { "input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "output": "6" }, { "input": "4 2\n194041605 706221269 69909135 257655784", "output": "3" }, { "input": "4 2\n9581849 67346651 530497 272158241", "output": "4" }, { "input": "3 47\n378261451 163985731 230342101", "output": "3" }, { "input": "2 3\n247776868 480572137", "output": "1" }, { "input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796", "output": "7" }, { "input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085", "output": "40" }, { "input": "1 8\n55521105", "output": "1" }, { "input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843", "output": "44" }, { "input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601", "output": "22" }, { "input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105", "output": "20" }, { "input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629", "output": "44" }, { "input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191", "output": "8" }, { "input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529", "output": "38" }, { "input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547", "output": "18" }, { "input": "1 1\n44", "output": "0" }, { "input": "1 1\n4", "output": "1" }, { "input": "10 3\n444 447 774 777 7777 4447 4 7 7 4", "output": "8" } ]
186
6,656,000
3
1,411
801
Vicious Keyboard
[ "brute force" ]
null
null
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
[ "VK\n", "VV\n", "V\n", "VKKKKKKKKKVVVVVVVVVK\n", "KVKV\n" ]
[ "1\n", "1\n", "0\n", "3\n", "1\n" ]
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear. For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring. For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
[ { "input": "VK", "output": "1" }, { "input": "VV", "output": "1" }, { "input": "V", "output": "0" }, { "input": "VKKKKKKKKKVVVVVVVVVK", "output": "3" }, { "input": "KVKV", "output": "1" }, { "input": "VKKVVVKVKVK", "output": "5" }, { "input": "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV", "output": "14" }, { "input": "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK", "output": "32" }, { "input": "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK", "output": "32" }, { "input": "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK", "output": "21" }, { "input": "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV", "output": "25" }, { "input": "KKVVKVVKVVKKVVKKVKVVKKV", "output": "7" }, { "input": "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV", "output": "24" }, { "input": "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV", "output": "35" }, { "input": "VKVVVKKKVKVVKVKVKVKVKVV", "output": "9" }, { "input": "KKKKVKKVKVKVKKKVVVVKK", "output": "6" }, { "input": "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK", "output": "9" }, { "input": "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK", "output": "22" }, { "input": "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK", "output": "25" }, { "input": "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK", "output": "29" }, { "input": "KKVKVVVKKVV", "output": "3" }, { "input": "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK", "output": "16" }, { "input": "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV", "output": "13" }, { "input": "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV", "output": "26" }, { "input": "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV", "output": "26" }, { "input": "K", "output": "0" }, { "input": "VKVK", "output": "2" }, { "input": "VKVV", "output": "2" }, { "input": "KV", "output": "0" }, { "input": "KK", "output": "1" }, { "input": "KKVK", "output": "2" }, { "input": "KKKK", "output": "1" }, { "input": "KKV", "output": "1" }, { "input": "KKVKVK", "output": "3" }, { "input": "VKKVK", "output": "2" }, { "input": "VKKK", "output": "2" }, { "input": "KKK", "output": "1" }, { "input": "KVV", "output": "1" }, { "input": "KKVKV", "output": "2" }, { "input": "VVK", "output": "1" }, { "input": "VVVKVKVKVKVKVKVK", "output": "8" }, { "input": "KVVVK", "output": "2" }, { "input": "VVVKK", "output": "2" }, { "input": "KKVV", "output": "1" }, { "input": "KKKKKKK", "output": "1" }, { "input": "VKKKVK", "output": "3" }, { "input": "KKVVV", "output": "1" }, { "input": "VVVVVV", "output": "1" }, { "input": "KKKV", "output": "1" }, { "input": "VVKVV", "output": "2" }, { "input": "VKVKKK", "output": "3" }, { "input": "VKKV", "output": "1" }, { "input": "VKKVV", "output": "2" }, { "input": "VVKKVV", "output": "2" }, { "input": "KKVVKKV", "output": "2" }, { "input": "KKKKK", "output": "1" }, { "input": "VKVVKKVKKVVKVKKVKKKVKKVKVKK", "output": "10" }, { "input": "VKVKVV", "output": "3" }, { "input": "VKVVKVV", "output": "3" }, { "input": "VVV", "output": "1" }, { "input": "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV", "output": "1" }, { "input": "VVKKKKKKVKK", "output": "3" }, { "input": "KVKVKVV", "output": "3" } ]
77
5,529,600
3
1,413
637
Chat Order
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
514
28,569,600
3
1,416
104
Blackjack
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" }, { "input": "22", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "0" }, { "input": "6", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "0" }, { "input": "9", "output": "0" }, { "input": "13", "output": "4" }, { "input": "14", "output": "4" }, { "input": "16", "output": "4" }, { "input": "17", "output": "4" }, { "input": "19", "output": "4" }, { "input": "21", "output": "4" }, { "input": "23", "output": "0" }, { "input": "24", "output": "0" } ]
122
4,710,400
0
1,417
914
Substrings in a String
[ "bitmasks", "brute force", "data structures", "string suffix structures", "strings" ]
null
null
Given a string *s*, process *q* queries, each having one of the following forms: - 1<=*i*<=*c* — Change the *i*-th character in the string to *c*. - 2<=*l*<=*r*<=*y* — Consider the substring of *s* starting at position *l* and ending at position *r*. Output the number of times *y* occurs as a substring in it.
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=105) of lowercase English letters. The second line contains an integer *q* (1<=≤<=*q*<=≤<=105)  — the number of queries to process. The next *q* lines describe the queries and may have one of the following forms: - 1<=*i*<=*c* (1<=≤<=*i*<=≤<=|*s*|) - 2<=*l*<=*r*<=*y* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) *c* is a lowercase English letter and *y* is a non-empty string consisting of only lowercase English letters. The sum of |*y*| over all queries of second type is at most 105. It is guaranteed that there is at least one query of second type. All strings are 1-indexed. |*s*| is the length of the string *s*.
For each query of type 2, output the required answer in a separate line.
[ "ababababa\n3\n2 1 7 aba\n1 5 c\n2 1 7 aba\n", "abcdcbc\n5\n2 1 7 bc\n1 4 b\n2 4 7 bc\n1 2 a\n2 1 4 aa\n" ]
[ "3\n1\n", "2\n2\n1\n" ]
Consider the first sample case. Initially, the string aba occurs 3 times in the range [1, 7]. Note that two occurrences may overlap. After the update, the string becomes ababcbaba and now aba occurs only once in the range [1, 7].
[]
15
0
0
1,418
479
Expression
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, { "input": "3\n1\n5", "output": "20" }, { "input": "6\n7\n1", "output": "48" }, { "input": "1\n8\n3", "output": "27" }, { "input": "9\n7\n2", "output": "126" }, { "input": "1\n1\n10", "output": "20" }, { "input": "9\n1\n1", "output": "18" }, { "input": "10\n5\n6", "output": "300" }, { "input": "8\n9\n7", "output": "504" }, { "input": "4\n2\n10", "output": "80" }, { "input": "2\n8\n3", "output": "48" }, { "input": "3\n5\n7", "output": "105" }, { "input": "1\n10\n1", "output": "12" }, { "input": "2\n2\n2", "output": "8" }, { "input": "5\n6\n1", "output": "35" }, { "input": "10\n1\n1", "output": "20" }, { "input": "1\n6\n1", "output": "8" }, { "input": "1\n9\n1", "output": "11" }, { "input": "2\n1\n2", "output": "6" }, { "input": "2\n6\n1", "output": "14" }, { "input": "9\n2\n1", "output": "27" }, { "input": "1\n9\n2", "output": "20" }, { "input": "1\n3\n1", "output": "5" }, { "input": "2\n1\n1", "output": "4" } ]
31
0
-1
1,420
14
Young Photographer
[ "implementation" ]
B. Young Photographer
2
64
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
[ "3 3\n0 7\n14 2\n4 6\n" ]
[ "1\n" ]
none
[ { "input": "3 3\n0 7\n14 2\n4 6", "output": "1" }, { "input": "1 1\n0 10", "output": "0" }, { "input": "2 2\n1 2\n3 2", "output": "0" }, { "input": "3 2\n1 2\n2 3\n3 4", "output": "-1" }, { "input": "2 4\n10 4\n1 5", "output": "0" }, { "input": "1 10\n1 9", "output": "1" }, { "input": "1 10\n123 12", "output": "2" }, { "input": "1 17\n10 17", "output": "0" }, { "input": "1 22\n22 33", "output": "0" }, { "input": "1 3\n1 2", "output": "1" }, { "input": "2 5\n0 3\n2 1", "output": "3" }, { "input": "3 3\n7 3\n6 4\n3 7", "output": "1" }, { "input": "4 9\n8 6\n11 5\n5 11\n8 3", "output": "1" }, { "input": "2 4\n1 4\n4 0", "output": "0" }, { "input": "3 7\n5 8\n7 5\n4 7", "output": "0" }, { "input": "4 7\n8 2\n5 7\n8 2\n5 8", "output": "0" }, { "input": "2 3\n4 1\n4 1", "output": "0" }, { "input": "3 8\n7 2\n3 7\n5 2", "output": "3" }, { "input": "4 0\n9 1\n8 1\n8 4\n4 5", "output": "4" }, { "input": "4 7\n2 5\n3 6\n3 5\n7 4", "output": "2" }, { "input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16", "output": "2" }, { "input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2", "output": "19" }, { "input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18", "output": "0" }, { "input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101", "output": "0" }, { "input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88", "output": "0" }, { "input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11", "output": "5" }, { "input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32", "output": "6" }, { "input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50", "output": "4" }, { "input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121", "output": "0" }, { "input": "1 21\n973 373", "output": "352" }, { "input": "2 212\n831 551\n810 753", "output": "541" }, { "input": "3 404\n690 728\n820 260\n186 402", "output": "-1" }, { "input": "4 906\n548 906\n830 457\n228 638\n464 167", "output": "-1" }, { "input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62", "output": "-1" }, { "input": "3 183\n416 335\n773 648\n434 198", "output": "-1" }, { "input": "3 868\n251 927\n862 464\n157 756", "output": "112" }, { "input": "3 242\n397 208\n951 279\n570 622", "output": "-1" }, { "input": "3 618\n543 800\n38 94\n293 179", "output": "-1" }, { "input": "3 993\n378 81\n127 911\n16 737", "output": "615" }, { "input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842", "output": "-1" }, { "input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478", "output": "-1" }, { "input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393", "output": "-1" }, { "input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348", "output": "-1" }, { "input": "1 21\n0 1000", "output": "0" } ]
310
3,584,000
0
1,421
158
Taxi
[ "*special", "greedy", "implementation" ]
null
null
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
[ "5\n1 2 4 3 3\n", "8\n2 3 4 4 2 1 3 1\n" ]
[ "4\n", "5\n" ]
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
[ { "input": "5\n1 2 4 3 3", "output": "4" }, { "input": "8\n2 3 4 4 2 1 3 1", "output": "5" }, { "input": "5\n4 4 4 4 4", "output": "5" }, { "input": "12\n1 1 1 1 1 1 1 1 1 1 1 1", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "4\n3 2 1 3", "output": "3" }, { "input": "4\n2 4 1 3", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n4", "output": "1" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n2 2", "output": "1" }, { "input": "2\n3 3", "output": "2" }, { "input": "2\n4 4", "output": "2" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n3 1", "output": "1" }, { "input": "2\n4 1", "output": "2" }, { "input": "2\n2 3", "output": "2" }, { "input": "2\n4 2", "output": "2" }, { "input": "2\n4 3", "output": "2" }, { "input": "4\n2 2 1 1", "output": "2" }, { "input": "4\n3 1 3 1", "output": "2" }, { "input": "4\n1 4 1 4", "output": "3" }, { "input": "4\n2 2 3 3", "output": "3" }, { "input": "4\n2 4 4 2", "output": "3" }, { "input": "4\n3 3 4 4", "output": "4" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "3\n1 3 1", "output": "2" }, { "input": "3\n4 1 1", "output": "2" }, { "input": "3\n3 2 2", "output": "2" }, { "input": "3\n2 4 2", "output": "2" }, { "input": "3\n3 4 3", "output": "3" }, { "input": "3\n2 2 1", "output": "2" }, { "input": "3\n1 3 3", "output": "2" }, { "input": "3\n4 4 1", "output": "3" }, { "input": "3\n3 3 2", "output": "3" }, { "input": "3\n4 2 4", "output": "3" }, { "input": "3\n4 3 4", "output": "3" }, { "input": "3\n4 3 2", "output": "3" }, { "input": "3\n3 1 4", "output": "2" }, { "input": "3\n2 1 4", "output": "2" }, { "input": "3\n3 1 2", "output": "2" }, { "input": "4\n4 4 3 2", "output": "4" }, { "input": "4\n1 4 3 1", "output": "3" }, { "input": "4\n2 2 4 1", "output": "3" }, { "input": "4\n3 2 1 2", "output": "2" }, { "input": "5\n2 4 2 3 4", "output": "4" }, { "input": "5\n1 3 4 1 3", "output": "3" }, { "input": "5\n1 1 2 4 2", "output": "3" }, { "input": "5\n1 3 2 3 2", "output": "3" }, { "input": "8\n1 1 2 1 1 1 3 2", "output": "3" }, { "input": "78\n2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "39" }, { "input": "7\n2 2 2 1 2 1 2", "output": "3" }, { "input": "9\n3 1 2 1 1 1 1 1 1", "output": "3" }, { "input": "10\n3 1 2 2 2 2 2 2 1 2", "output": "5" }, { "input": "18\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1", "output": "9" }, { "input": "26\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1", "output": "13" } ]
156
3,481,600
3
1,430
149
Division into Teams
[ "greedy", "math", "sortings" ]
null
null
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the game begins. There are *n* boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic *a**i* (the larger it is, the better the boy plays). Let's denote the number of players in the first team as *x*, the number of players in the second team as *y*, the individual numbers of boys who play for the first team as *p**i* and the individual numbers of boys who play for the second team as *q**i*. Division *n* boys into two teams is considered fair if three conditions are fulfilled: - Each boy plays for exactly one team (*x*<=+<=*y*<==<=*n*). - The sizes of teams differ in no more than one (|*x*<=-<=*y*|<=≤<=1). - The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
The first line contains the only integer *n* (2<=≤<=*n*<=≤<=105) which represents the number of guys in the yard. The next line contains *n* positive space-separated integers, *a**i* (1<=≤<=*a**i*<=≤<=104), the *i*-th number represents the *i*-th boy's playing skills.
On the first line print an integer *x* — the number of boys playing for the first team. On the second line print *x* integers — the individual numbers of boys playing for the first team. On the third line print an integer *y* — the number of boys playing for the second team, on the fourth line print *y* integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: *x*<=+<=*y*<==<=*n*, |*x*<=-<=*y*|<=≤<=1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
[ "3\n1 2 1\n", "5\n2 3 3 1 1\n" ]
[ "2\n1 2 \n1\n3 \n", "3\n4 1 3 \n2\n5 2 \n" ]
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled.
[ { "input": "3\n1 2 1", "output": "2\n1 2 \n1\n3 " }, { "input": "5\n2 3 3 1 1", "output": "3\n4 1 3 \n2\n5 2 " }, { "input": "10\n2 2 2 2 2 2 2 1 2 2", "output": "5\n8 2 4 6 9 \n5\n1 3 5 7 10 " }, { "input": "10\n2 3 3 1 3 1 1 1 2 2", "output": "5\n4 7 1 10 3 \n5\n6 8 9 2 5 " }, { "input": "10\n2 3 2 3 3 1 1 3 1 1", "output": "5\n6 9 1 2 5 \n5\n7 10 3 4 8 " }, { "input": "11\n1 3 1 2 1 2 2 2 1 1 1", "output": "6\n1 5 10 4 7 2 \n5\n3 9 11 6 8 " }, { "input": "11\n54 83 96 75 33 27 36 35 26 22 77", "output": "6\n10 6 8 1 11 3 \n5\n9 5 7 4 2 " }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "6\n1 3 5 7 9 11 \n5\n2 4 6 8 10 " }, { "input": "2\n1 1", "output": "1\n1 \n1\n2 " }, { "input": "2\n35 36", "output": "1\n1 \n1\n2 " }, { "input": "25\n1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 1", "output": "13\n1 10 17 22 2 5 7 9 13 15 18 20 24 \n12\n4 11 21 25 3 6 8 12 14 16 19 23 " }, { "input": "27\n2 1 1 3 1 2 1 1 3 2 3 1 3 2 1 3 2 3 2 1 2 3 2 2 1 2 1", "output": "14\n2 5 8 15 25 1 10 17 21 24 4 11 16 22 \n13\n3 7 12 20 27 6 14 19 23 26 9 13 18 " }, { "input": "30\n2 2 2 3 4 3 4 4 3 2 3 2 2 4 1 4 2 4 2 2 1 4 3 2 1 3 1 1 4 3", "output": "15\n15 25 28 2 10 13 19 24 6 11 26 5 8 16 22 \n15\n21 27 1 3 12 17 20 4 9 23 30 7 14 18 29 " }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "50\n14 27 34 63 70 89 94 23 30 44 90 1 13 20 51 59 66 88 97 7 31 53 64 21 38 87 98 11 33 43 49 62 9 18 35 52 73 84 3 45 47 78 86 26 65 4 36 69 79 85 \n50\n17 32 56 68 81 91 12 25 37 80 100 8 15 39 54 61 77 96 2 29 42 55 71 22 76 95 6 24 41 48 60 93 10 28 40 57 74 99 5 46 67 83 19 58 75 16 50 72 82 92 " }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "50\n26 20 68 7 19 89 65 93 14 62 94 3 73 8 12 43 32 18 56 28 59 15 27 96 34 51 55 41 38 48 82 72 63 5 67 47 61 99 64 33 24 80 13 17 4 90 71 74 45 95 \n50\n30 37 97 31 78 23 92 36 50 88 11 52 66 85 10 87 16 81 77 54 42 21 76 2 86 98 100 53 75 70 69 58 60 22 84 57 39 35 25 79 44 1 9 49 6 83 46 29 91 40 " }, { "input": "100\n2382 7572 9578 1364 2325 2929 7670 5574 2836 2440 6553 1751 929 8785 6894 9373 9308 7338 6380 9541 9951 6785 8993 9942 5087 7544 6582 7139 8458 7424 9759 8199 9464 8817 7625 6200 4955 9373 9500 3062 849 4210 9337 5466 2190 8150 4971 3145 869 5675 1975 161 1998 378 5229 9000 8958 761 358 434 7636 8295 4406 73 375 812 2473 3652 9067 3052 5287 2850 6987 5442 2625 8894 8733 791 9763 5258 8259 9530 2050 7334 2118 2726 8221 5527 8827 1585 8334 8898 6399 6217 7400 2576 5164 9063 6247 9433", "output": "50\n64 59 54 58 66 49 4 12 53 85 5 10 96 86 72 70 48 42 37 25 55 71 44 8 36 99 93 27 15 28 18 30 2 61 46 87 62 29 14 89 92 23 98 17 16 100 39 20 31 24 \n50\n52 65 60 78 41 13 90 51 83 45 1 67 75 9 6 40 68 63 47 97 80 74 88 50 94 19 11 22 73 84 95 26 35 7 32 81 91 77 34 76 57 56 69 43 38 33 82 3 79 21 " }, { "input": "3\n1 2 3", "output": "2\n1 3 \n1\n2 " }, { "input": "3\n10 10 10", "output": "2\n1 3 \n1\n2 " }, { "input": "3\n5 10 10", "output": "2\n1 3 \n1\n2 " }, { "input": "5\n6 1 1 1 1", "output": "3\n2 4 1 \n2\n3 5 " }, { "input": "5\n1 100 2 200 3", "output": "3\n1 5 4 \n2\n3 2 " } ]
280
9,830,400
3
1,431
54
Presents
[ "implementation" ]
A. Presents
2
256
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following *N* days. Besides, he is guided by the principle: - on each holiday day the Hedgehog will necessarily receive a present, - he receives presents at least every *K* days (i.e., if he received a present on the *i*-th day, he will receive the next present no later than on the *i*<=+<=*K*-th day). For the given *N* and *K*, as well as the list of holidays among the following *N* days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer).
The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*). The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them.
Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days.
[ "5 2\n1 3\n", "10 1\n3 6 7 8\n" ]
[ "3", "10" ]
none
[ { "input": "5 2\n1 3", "output": "3" }, { "input": "10 1\n3 6 7 8", "output": "10" }, { "input": "5 5\n1 3", "output": "1" }, { "input": "10 3\n3 3 6 9", "output": "3" }, { "input": "5 2\n0", "output": "2" }, { "input": "1 1\n0", "output": "1" }, { "input": "5 1\n0", "output": "5" }, { "input": "5 1\n1 2", "output": "5" }, { "input": "5 2\n0", "output": "2" }, { "input": "10 3\n2 4 8", "output": "4" }, { "input": "10 1\n0", "output": "10" }, { "input": "10 2\n1 5", "output": "5" }, { "input": "10 1\n0", "output": "10" }, { "input": "10 1\n0", "output": "10" }, { "input": "15 5\n0", "output": "3" }, { "input": "15 1\n1 3", "output": "15" }, { "input": "15 2\n1 10", "output": "7" }, { "input": "15 1\n0", "output": "15" }, { "input": "15 3\n1 11", "output": "5" }, { "input": "20 1\n3 7 9 20", "output": "20" }, { "input": "20 3\n1 11", "output": "7" }, { "input": "20 2\n6 6 9 10 15 19 20", "output": "12" }, { "input": "20 1\n0", "output": "20" }, { "input": "20 1\n1 13", "output": "20" }, { "input": "25 1\n9 2 6 8 10 14 15 17 18 23", "output": "25" }, { "input": "25 1\n0", "output": "25" }, { "input": "25 1\n4 8 10 13 24", "output": "25" }, { "input": "25 1\n1 14", "output": "25" }, { "input": "25 1\n0", "output": "25" }, { "input": "100 3\n0", "output": "33" }, { "input": "100 10\n0", "output": "10" }, { "input": "100 23\n22 2 9 18 22 23 30 44 50 55 58 61 70 71 73 76 79 82 85 88 94 95 99", "output": "22" }, { "input": "100 5\n10 2 17 21 34 52 58 60 64 68 95", "output": "24" }, { "input": "100 4\n2 29 63", "output": "26" }, { "input": "150 16\n9 19 31 47 53 57 96 105 108 120", "output": "13" }, { "input": "150 52\n5 11 37 60 67 86", "output": "6" }, { "input": "150 4\n7 21 54 106 108 109 119 123", "output": "40" }, { "input": "150 3\n0", "output": "50" }, { "input": "150 21\n21 22 26 30 36 39 52 59 62 66 68 78 86 92 96 103 108 113 118 119 125 139", "output": "22" }, { "input": "300 15\n14 3 38 52 57 142 157 175 201 209 238 258 288 294 299", "output": "26" }, { "input": "300 2\n14 29 94 122 123 158 160 164 191 200 202 208 246 272 286", "output": "153" }, { "input": "300 5\n16 22 38 72 78 108 116 140 147 160 189 209 214 227 252 294 300", "output": "66" }, { "input": "300 8\n4 27 76 155 260", "output": "40" }, { "input": "300 24\n20 18 76 80 81 85 103 110 112 129 145 151 172 180 184 201 205 241 257 268 276", "output": "24" }, { "input": "350 22\n11 38 111 115 176 194 204 207 231 274 307 348", "output": "21" }, { "input": "350 22\n73 1 4 8 10 14 16 19 28 37 41 42 43 55 56 64 66 67 79 80 84 87 96 99 101 103 119 120 121 122 127 128 135 141 142 143 148 156 159 160 161 166 167 169 173 189 201 202 205 219 223 227 233 242 243 244 250 257 260 262 263 264 273 291 301 302 305 306 307 314 326 336 342 345", "output": "73" }, { "input": "350 26\n10 13 16 81 99 144 191 223 258 316 329", "output": "18" }, { "input": "350 16\n12 31 76 103 116 191 201 241 256 260 291 306 336", "output": "24" }, { "input": "350 28\n5 23 104 135 305 331", "output": "14" }, { "input": "365 34\n6 80 94 208 256 325 349", "output": "14" }, { "input": "365 19\n7 47 114 139 210 226 266 279", "output": "22" }, { "input": "365 8\n32 1 13 22 25 33 72 80 86 96 117 132 145 146 156 176 177 179 188 198 203 218 225 235 253 256 267 279 286 294 303 333 363", "output": "61" }, { "input": "365 8\n55 3 12 26 28 36 45 47 59 61 65 82 90 103 109 114 117 121 123 126 134 142 144 146 151 154 168 175 189 193 195 197 199 210 212 214 230 232 241 248 254 267 271 291 304 306 308 311 315 317 318 334 335 346 354 365", "output": "74" }, { "input": "365 2\n2 96 241", "output": "183" }, { "input": "365 42\n10 8 66 77 148 161 183 231 301 340 350", "output": "14" }, { "input": "365 40\n30 1 14 21 31 32 36 56 59 68 96 119 131 137 166 179 181 202 235 248 272 294 309 315 322 327 334 341 347 362 365", "output": "30" }, { "input": "365 31\n19 13 18 27 33 46 58 86 114 178 187 198 228 233 240 255 277 332 348 351", "output": "22" }, { "input": "365 54\n21 28 42 56 65 66 67 76 81 85 89 123 132 136 153 195 215 249 294 296 300 355", "output": "22" }, { "input": "365 5\n5 10 31 121 235 322", "output": "74" }, { "input": "365 81\n2 1 75", "output": "5" }, { "input": "365 21\n4 1 17 344 345", "output": "19" }, { "input": "11 2\n5 3 6 7 9 10", "output": "7" }, { "input": "5 3\n2 2 4", "output": "2" }, { "input": "362 360\n0", "output": "1" }, { "input": "18 4\n4 1 9 10 18", "output": "6" } ]
62
0
0
1,433
471
MUH and Cube Walls
[ "string suffix structures", "strings" ]
null
null
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of different heights. Horace was the first to finish making his wall. He called his wall an elephant. The wall consists of *w* towers. The bears also finished making their wall but they didn't give it a name. Their wall consists of *n* towers. Horace looked at the bears' tower and wondered: in how many parts of the wall can he "see an elephant"? He can "see an elephant" on a segment of *w* contiguous towers if the heights of the towers on the segment match as a sequence the heights of the towers in Horace's wall. In order to see as many elephants as possible, Horace can raise and lower his wall. He even can lower the wall below the ground level (see the pictures to the samples for clarification). Your task is to count the number of segments where Horace can "see an elephant".
The first line contains two integers *n* and *w* (1<=≤<=*n*,<=*w*<=≤<=2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=≤<=*b**i*<=≤<=109) — the heights of the towers in the elephant's wall.
Print the number of segments in the bears' wall where Horace can "see an elephant".
[ "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n" ]
[ "2" ]
The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray.
[ { "input": "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2", "output": "2" }, { "input": "5 1\n8 71 1 24 2\n31", "output": "5" }, { "input": "6 3\n2 2 2 2 2 2\n5 5 5", "output": "4" }, { "input": "1 1\n576560149\n691846236", "output": "1" }, { "input": "10 5\n5 10 8 10 11 9 11 12 10 15\n4 2 4 5 3", "output": "2" }, { "input": "10 10\n6 8 1 2 5 1 4 24 2 4\n6 8 1 2 5 1 4 24 2 4", "output": "1" }, { "input": "10 10\n6 8 1 2 5 1 14 24 12 4\n7 9 2 3 6 2 15 25 13 5", "output": "1" }, { "input": "8 4\n1 2 3 4 5 6 7 8\n10 11 12 13", "output": "5" }, { "input": "10 5\n172960147 951061917 502625539 319177159 720665763 402410416 880790711 734191412 452846733 449904402\n640219326 792464591 173792179 691347674 125427306", "output": "0" }, { "input": "10 3\n2 3 3 2 1 1 3 1 3 1\n2 1 2", "output": "0" }, { "input": "10 5\n260725416 260725506 260725422 260725512 260725428 260725518 260725434 260725524 260725440 260725530\n925033135 925033225 925033141 925033231 925033147", "output": "3" }, { "input": "2 2\n1000000000 10\n1 20", "output": "0" }, { "input": "7 3\n1 1 1 1 1 1 1\n1000 1256 1512", "output": "0" }, { "input": "3 3\n1 132 3\n2 1 3", "output": "0" }, { "input": "53 3\n1 3 4 4 5 7 10 14 19 25 32 40 49 59 70 82 95 109 124 140 157 175 194 214 235 257 280 304 329 355 382 410 439 469 500 532 565 599 634 670 707 745 784 824 865 907 950 994 1039 1085 1132 1180 1229\n1 2 40", "output": "0" } ]
15
0
-1
1,436
436
Feed with Candy
[ "greedy" ]
null
null
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has *n* candies of two types (fruit drops and caramel drops), the *i*-th candy hangs at the height of *h**i* centimeters above the floor of the house, its mass is *m**i*. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most *x* centimeter high jumps. When Om Nom eats a candy of mass *y*, he gets stronger and the height of his jump increases by *y* centimeters. What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?
The first line contains two integers, *n* and *x* (1<=≤<=*n*,<=*x*<=≤<=2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following *n* lines contains three integers *t**i*,<=*h**i*,<=*m**i* (0<=≤<=*t**i*<=≤<=1; 1<=≤<=*h**i*,<=*m**i*<=≤<=2000) — the type, height and the mass of the *i*-th candy. If number *t**i* equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop.
Print a single integer — the maximum number of candies Om Nom can eat.
[ "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5\n" ]
[ "4\n" ]
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. 1. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. 1. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. 1. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4.
[ { "input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4" }, { "input": "5 2\n1 15 2\n1 11 2\n0 17 2\n0 16 1\n1 18 2", "output": "0" }, { "input": "6 2\n1 17 3\n1 6 1\n0 4 2\n1 10 1\n1 7 3\n1 5 1", "output": "0" }, { "input": "7 2\n1 14 1\n1 9 2\n0 6 3\n0 20 2\n0 4 2\n0 3 1\n0 9 2", "output": "0" }, { "input": "8 2\n0 20 3\n1 5 2\n1 4 1\n1 7 1\n0 1 3\n1 5 3\n1 7 2\n1 3 1", "output": "2" }, { "input": "9 2\n0 1 1\n1 8 2\n1 11 1\n0 9 1\n1 18 2\n1 7 3\n1 8 3\n0 16 1\n0 12 2", "output": "1" }, { "input": "10 2\n0 2 3\n1 5 2\n0 7 3\n1 15 2\n0 14 3\n1 19 1\n1 5 3\n0 2 2\n0 10 2\n0 10 3", "output": "9" }, { "input": "2 1\n0 1 1\n1 2 1", "output": "2" }, { "input": "2 1\n1 1 1\n0 2 1", "output": "2" }, { "input": "2 1\n0 1 1\n0 2 1", "output": "1" }, { "input": "2 1\n1 1 1\n1 2 1", "output": "1" }, { "input": "2 1\n0 1 1\n1 3 1", "output": "1" }, { "input": "2 1\n1 1 1\n0 3 1", "output": "1" }, { "input": "1 1\n1 2 1", "output": "0" }, { "input": "3 4\n1 1 2\n1 4 100\n0 104 1", "output": "3" }, { "input": "3 4\n1 1 100\n1 4 2\n0 104 1", "output": "3" }, { "input": "3 100\n0 1 1\n1 1 1\n1 1 1", "output": "3" }, { "input": "4 20\n0 10 10\n0 20 50\n1 40 1\n1 40 1", "output": "4" }, { "input": "4 2\n0 1 1\n0 2 3\n1 4 1\n1 5 1", "output": "4" }, { "input": "3 10\n0 9 1\n0 10 10\n1 20 1", "output": "3" }, { "input": "3 5\n0 4 1\n0 5 10\n1 15 5", "output": "3" }, { "input": "3 4\n0 2 1\n0 3 3\n1 6 5", "output": "3" }, { "input": "3 3\n0 1 1\n0 2 100\n1 10 1", "output": "3" }, { "input": "3 2\n0 1 1\n0 2 2\n1 4 4", "output": "3" }, { "input": "5 3\n0 1 5\n0 1 5\n0 1 5\n1 1 10\n1 1 1", "output": "5" }, { "input": "3 2\n0 1 1\n0 2 2\n1 4 2", "output": "3" }, { "input": "4 10\n0 20 1\n1 1 9\n1 2 11\n1 3 8", "output": "3" }, { "input": "7 1\n0 1 99\n1 100 1\n0 100 1\n0 101 1000\n1 1000 1\n0 1000 1\n1 1000 1", "output": "7" }, { "input": "4 3\n0 1 1\n0 2 100\n0 3 1\n1 100 1", "output": "3" }, { "input": "3 3\n0 1 100\n0 2 1\n1 100 100", "output": "3" }, { "input": "3 2\n0 1 1\n0 2 100\n1 10 1", "output": "3" }, { "input": "3 1\n0 1 1\n1 1 5\n0 7 1", "output": "3" }, { "input": "3 5\n0 2 3\n1 9 10\n0 4 4", "output": "3" }, { "input": "3 3\n0 2 1\n0 3 2\n1 5 10", "output": "3" } ]
545
819,200
3
1,438
842
Gleb And Pizza
[ "geometry" ]
null
null
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust. The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the origin, and crust around the main part of the width *d*. Pieces of sausage are also circles. The radius of the *i* -th piece of the sausage is *r**i*, and the center is given as a pair (*x**i*, *y**i*). Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=&lt;<=*r*<=≤<=500) — the radius of pizza and the width of crust. Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105). Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<=≤<=*x**i*,<=*y**i*<=≤<=500, 0<=≤<=*r**i*<=≤<=500), where *x**i* and *y**i* are coordinates of the center of *i*-th peace of sausage, *r**i* — radius of *i*-th peace of sausage.
Output the number of pieces of sausage that lay on the crust.
[ "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n", "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n" ]
[ "2\n", "0\n" ]
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
[ { "input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1", "output": "2" }, { "input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2", "output": "0" }, { "input": "1 0\n1\n1 1 0", "output": "0" }, { "input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1", "output": "4" }, { "input": "9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0", "output": "0" }, { "input": "10 2\n11\n1 1 0\n2 2 3\n3 3 0\n4 4 0\n5 5 0\n6 6 0\n7 7 4\n8 8 7\n9 9 3\n10 10 100\n9 0 1", "output": "2" }, { "input": "5 3\n1\n500 500 10", "output": "0" } ]
124
0
0
1,439
813
Army Creation
[ "binary search", "data structures" ]
null
null
As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires. In the game Vova can hire *n* different warriors; *i*th warrior has the type *a**i*. Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than *k* warriors of this type in the army. Of course, Vova wants his army to be as large as possible. To make things more complicated, Vova has to consider *q* different plans of creating his army. *i*th plan allows him to hire only warriors whose numbers are not less than *l**i* and not greater than *r**i*. Help Vova to determine the largest size of a balanced army for each plan. Be aware that the plans are given in a modified way. See input section for details.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100000). The second line contains *n* integers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=100000). The third line contains one integer *q* (1<=≤<=*q*<=≤<=100000). Then *q* lines follow. *i*th line contains two numbers *x**i* and *y**i* which represent *i*th plan (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*). You have to keep track of the answer to the last plan (let's call it *last*). In the beginning *last*<==<=0. Then to restore values of *l**i* and *r**i* for the *i*th plan, you have to do the following: 1. *l**i*<==<=((*x**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. *r**i*<==<=((*y**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. If *l**i*<=&gt;<=*r**i*, swap *l**i* and *r**i*.
Print *q* numbers. *i*th number must be equal to the maximum size of a balanced army when considering *i*th plan.
[ "6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6\n" ]
[ "2\n4\n1\n3\n2\n" ]
In the first example the real plans are: 1. 1 2 1. 1 6 1. 6 6 1. 2 4 1. 4 6
[ { "input": "6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6", "output": "2\n4\n1\n3\n2" }, { "input": "5 5\n3 4 4 2 1\n5\n5 5\n5 4\n5 4\n3 4\n5 5", "output": "1\n2\n2\n2\n1" }, { "input": "5 5\n2 1 2 4 1\n5\n5 3\n1 1\n5 1\n2 1\n2 3", "output": "4\n1\n2\n2\n5" }, { "input": "10 5\n4 5 7 3 5 6 6 8 10 9\n5\n10 8\n9 8\n7 5\n8 10\n5 8", "output": "9\n2\n3\n3\n8" }, { "input": "20 5\n9 5 4 10 2 1 8 9 7 4 1 5 4 9 8 10 5 8 4 10\n5\n9 13\n17 13\n6 12\n13 11\n8 8", "output": "5\n17\n7\n19\n1" }, { "input": "100 5\n45 51 23 10 62 69 48 47 47 59 58 14 54 34 66 78 92 66 42 25 96 68 35 50 58 77 87 100 57 42 43 76 24 70 26 98 33 11 41 9 17 65 53 23 45 5 24 98 73 91 92 73 51 68 82 95 24 61 88 3 64 74 28 7 77 49 55 62 64 4 51 86 72 26 65 82 13 55 31 44 10 59 83 16 27 67 2 36 52 12 3 26 36 38 58 25 23 3 69 16\n5\n13 49\n86 62\n91 77\n84 50\n33 66", "output": "37\n77\n15\n35\n68" }, { "input": "1 1\n1\n1\n1 1", "output": "1" }, { "input": "1 5\n8\n9\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "5 1\n10 7 6 6 6\n8\n5 2\n4 5\n2 1\n5 2\n3 1\n3 1\n4 1\n5 2", "output": "3\n1\n1\n2\n3\n2\n2\n1" } ]
46
0
0
1,441
681
A Good Contest
[ "implementation" ]
null
null
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155", "output": "NO" }, { "input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968", "output": "NO" }, { "input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290", "output": "NO" }, { "input": "1\na 2400 2401", "output": "YES" }, { "input": "1\nfucker 4000 4000", "output": "NO" }, { "input": "1\nJora 2400 2401", "output": "YES" }, { "input": "1\nACA 2400 2420", "output": "YES" }, { "input": "1\nAca 2400 2420", "output": "YES" }, { "input": "1\nSub_d 2401 2402", "output": "YES" }, { "input": "2\nHack 2400 2401\nDum 1243 555", "output": "YES" }, { "input": "1\nXXX 2400 2500", "output": "YES" }, { "input": "1\nfucker 2400 2401", "output": "YES" }, { "input": "1\nX 2400 2500", "output": "YES" }, { "input": "1\nvineet 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2500", "output": "YES" }, { "input": "1\naaaaa 2400 2401", "output": "YES" }, { "input": "1\nhoge 2400 2401", "output": "YES" }, { "input": "1\nInfinity 2400 2468", "output": "YES" }, { "input": "1\nBurunduk1 2400 2401", "output": "YES" }, { "input": "1\nFuck 2400 2401", "output": "YES" }, { "input": "1\nfuck 2400 2401", "output": "YES" }, { "input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "YES" }, { "input": "1\nalex 2400 2401", "output": "YES" }, { "input": "1\nA 2400 2401", "output": "YES" }, { "input": "1\na 2400 2455", "output": "YES" }, { "input": "1\nlol 2400 2401", "output": "YES" }, { "input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214", "output": "YES" }, { "input": "1\naaaaaa 2400 2401", "output": "YES" }, { "input": "1\nBurunduk1 2400 2500", "output": "YES" }, { "input": "1\nds 2400 2410", "output": "YES" }, { "input": "1\nas 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2401", "output": "YES" }, { "input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537", "output": "YES" }, { "input": "1\ncaonima 2400 2401", "output": "YES" }, { "input": "1\narr 2400 2500", "output": "YES" }, { "input": "1\nx 2400 2401", "output": "YES" }, { "input": "1\narrr 2400 2500", "output": "YES" }, { "input": "1\nabc 2400 2405", "output": "YES" }, { "input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nBurunduk1 2400 2537", "output": "YES" }, { "input": "1\nHELLO 2400 2401", "output": "YES" }, { "input": "1\neatmore 2400 2500", "output": "YES" }, { "input": "1\nb 2400 2401", "output": "YES" }, { "input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nApplejack 2400 2410", "output": "YES" }, { "input": "1\nabacaba 2400 2451", "output": "YES" }, { "input": "1\nrekt_n00b 2500 2600", "output": "YES" } ]
0
0
-1
1,442
592
PawnChess
[ "implementation" ]
null
null
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed. Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*. There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner. Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players. Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color. Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
[ "........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n", "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n" ]
[ "A\n", "B\n" ]
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
[ { "input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.", "output": "B" }, { "input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.", "output": "A" }, { "input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n........\n...BB.B.\nW.WWWW.W", "output": "A" }, { "input": "BB......\nW....BBW\n........\n.B.B.BBB\n....BB..\nB....BB.\n...WWWW.\n....WW..", "output": "A" }, { "input": ".B.B..B.\nB.B....B\n...B.B.B\n..B.W..B\n.BBB.B.B\nB.BB.B.B\nBB..BBBB\nW.W.W.WW", "output": "B" }, { "input": "..BB....\n.B.B.B.B\n..B.B...\n..B..B.B\nWWWBWWB.\n.BB...B.\n..BBB...\n......W.", "output": "B" }, { "input": "..BB....\n.WBWBWBB\n.....BBB\n..WW....\n.W.W...W\nWWW...W.\n.W....W.\nW...W.W.", "output": "A" }, { "input": "....BB..\nBB......\n.B.....B\nWW..WWW.\n...BB.B.\nB...BB..\n..W..WWW\n...W...W", "output": "B" }, { "input": "B...BBBB\n...BBB..\nBBWBWW.W\n.B..BB.B\nW..W..WW\nW.WW....\n........\nWW.....W", "output": "A" }, { "input": ".B......\n.B....B.\n...W....\n......W.\nW.WWWW.W\nW.WW....\n..WWW...\n..W...WW", "output": "A" }, { "input": "B.......\nBBB.....\n.B....B.\n.W.BWB.W\n......B.\nW..WW...\n...W....\nW...W..W", "output": "A" }, { "input": ".....B..\n........\n........\n.BB..B..\n..BB....\n........\n....WWW.\n......W.", "output": "B" }, { "input": "B.B...B.\n...BBBBB\n....B...\n...B...B\nB.B.B..B\n........\n........\nWWW..WW.", "output": "B" }, { "input": "B.B...B.\n........\n.......B\n.BB....B\n.....W..\n.W.WW.W.\n...W.WW.\nW..WW..W", "output": "A" }, { "input": "......B.\nB....B..\n...B.BB.\n...B....\n........\n..W....W\nWW......\n.W....W.", "output": "B" }, { "input": ".BBB....\nB.B.B...\nB.BB.B..\nB.BB.B.B\n........\n........\nW.....W.\n..WW..W.", "output": "B" }, { "input": "..B..BBB\n........\n........\n........\n...W.W..\n...W..W.\nW.......\n..W...W.", "output": "A" }, { "input": "........\n.B.B....\n...B..BB\n........\n........\nW...W...\nW...W...\nW.WW.W..", "output": "A" }, { "input": "B....BB.\n...B...B\n.B......\n........\n........\n........\n........\n....W..W", "output": "B" }, { "input": "...BB.BB\nBB...B..\n........\n........\n........\n........\n..W..W..\n......W.", "output": "A" }, { "input": "...BB...\n........\n........\n........\n........\n........\n......W.\nWW...WW.", "output": "A" }, { "input": "...B.B..\n........\n........\n........\n........\n........\n........\nWWW...WW", "output": "A" }, { "input": "BBBBBBB.\n........\n........\n........\n........\n........\n........\n.WWWWWWW", "output": "A" }, { "input": ".BBBBBB.\nB.......\n........\n........\n........\n........\n........\n.WWWWWWW", "output": "B" }, { "input": ".BBBBBBB\n........\n........\n........\n........\n........\n........\nWWWWWWW.", "output": "A" }, { "input": ".BBBBBB.\n.......B\n........\n........\n........\n........\n........\nWWWWWWW.", "output": "B" }, { "input": "B..BB...\n..B...B.\n.WBB...B\nBW......\nW.B...W.\n..BBW.B.\nBW..BB..\n......W.", "output": "B" }, { "input": "B.BBBBBB\nB..BBB.B\nW.BB.W.B\nB.BWBB.B\nBWBWBBBB\n...BBBBB\nB.B...BB\nWW..WW.W", "output": "B" }, { "input": "BBBB.BBB\nBBBB.B.B\nB.B..BBB\nB.BB.BWW\nB.BB.BBB\nB.BB.BBB\n..BW.BB.\nW.WWWWWW", "output": "B" }, { "input": "BBBB.BBB\n.B....WB\nBB.B...B\nWWWW.WWB\nBB...BWW\nWWW..BBB\nW.BW.BB.\nWWWWWWW.", "output": "B" }, { "input": "B.BBBBBB\nW.WWBBBW\nW.BB.WBB\nW.W.BBBW\nW.BWW.WB\nB..B..BB\nB.B.W.BB\nWWWWW.WW", "output": "B" }, { "input": "BBBBBB.B\n.BBWBB.B\nWWW..B.W\n..WW.W.W\nBWB..W.W\n..BW.B.W\nB..B....\nWWWW.WWW", "output": "B" }, { "input": ".B...BB.\nWBB.BWBB\n.BWBW...\n..W...B.\nWB.BWW..\nWBW.....\n.W..W.B.\n.W.W.WW.", "output": "A" }, { "input": ".B..BBBB\nBB...WWB\nB..B.W.B\nWB.W...B\n...W.WW.\nW.....W.\nWB.W.W.W\n.WW...WW", "output": "A" }, { "input": "B.BBBBBB\nW.BB.W.B\nW.BBW...\n..WWWW.B\n....W..B\n.WW.W..W\n.W..WW.W\nW.W....W", "output": "A" }, { "input": "........\n.B......\n.W......\n........\n....B...\n........\n........\n.......W", "output": "B" } ]
109
23,142,400
3
1,446
1,009
Intercity Travelling
[ "combinatorics", "math", "probabilities" ]
null
null
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car. The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km. Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey. Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on. For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$. Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey. Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$.
The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov. The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested.
Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$.
[ "2\n1 2\n", "4\n1 3 3 7\n" ]
[ "5\n", "60\n" ]
none
[ { "input": "2\n1 2", "output": "5" }, { "input": "4\n1 3 3 7", "output": "60" }, { "input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100", "output": "758086002" }, { "input": "1\n12", "output": "12" } ]
93
0
0
1,449
960
Subsequence Counting
[ "bitmasks", "constructive algorithms", "greedy", "implementation" ]
null
null
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_subsequence <=≥<=*d* Pikachu was finally left with *X* subsequences. However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers *X* and *d*. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018. Note the number of elements in the output array should not be more than 104. If no answer is possible, print <=-<=1.
The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109).
Output should consist of two lines. First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array. Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=&lt;<=1018). If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
[ "10 5\n", "4 2\n" ]
[ "6\n5 50 7 15 6 100", "4\n10 100 1000 10000" ]
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid. Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid.
[ { "input": "10 5", "output": "6\n1 1 1 7 13 19 " }, { "input": "4 2", "output": "3\n1 1 4 " }, { "input": "4 1", "output": "3\n1 1 3 " }, { "input": "1 1", "output": "1\n1 " }, { "input": "63 1", "output": "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 " }, { "input": "98 88", "output": "15\n1 1 1 1 1 1 90 90 90 90 90 179 268 357 446 " }, { "input": "746 173", "output": "37\n1 1 1 1 1 1 1 1 1 175 175 175 175 175 175 175 349 349 349 349 349 349 523 523 523 523 523 697 697 697 871 1045 1219 1393 1567 1741 1915 " }, { "input": "890 553", "output": "43\n1 1 1 1 1 1 1 1 1 555 555 555 555 555 555 555 555 1109 1109 1109 1109 1109 1109 1663 1663 1663 1663 1663 2217 2217 2217 2217 2771 2771 2771 3325 3879 4433 4987 5541 6095 6649 7203 " }, { "input": "883 1000", "output": "40\n1 1 1 1 1 1 1 1 1 1002 1002 1002 1002 1002 1002 1002 1002 2003 2003 2003 2003 2003 2003 3004 3004 3004 3004 3004 4005 4005 4005 4005 5006 6007 7008 8009 9010 10011 11012 12013 " }, { "input": "1 1000", "output": "1\n1 " }, { "input": "695 188", "output": "35\n1 1 1 1 1 1 1 1 1 190 190 190 190 190 190 190 379 379 379 379 379 568 568 568 568 757 757 946 1135 1324 1513 1702 1891 2080 2269 " }, { "input": "2060 697", "output": "19\n1 1 1 1 1 1 1 1 1 1 1 699 699 699 1397 1397 2095 2793 3491 " }, { "input": "70 3321", "output": "12\n1 1 1 1 1 1 3323 3323 6645 9967 13289 16611 " }, { "input": "6358 1646", "output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 3295 3295 3295 3295 3295 3295 3295 4942 4942 4942 4942 4942 4942 6589 6589 6589 6589 8236 8236 9883 11530 13177 14824 16471 18118 19765 21412 " }, { "input": "167959139 481199252", "output": "154\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 1443597760 1443597760 1443597760..." }, { "input": "641009859 54748096", "output": "192\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 1094..." }, { "input": "524125987 923264237", "output": "289\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846..." }, { "input": "702209411 496813081", "output": "276\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 99362616..." }, { "input": "585325539 365329221", "output": "243\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 73065844..." }, { "input": "58376259 643910770", "output": "196\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821..." }, { "input": "941492387 72235422", "output": "194\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470..." }, { "input": "824608515 940751563", "output": "192\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 188..." }, { "input": "2691939 514300407", "output": "107\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225..." }, { "input": "802030518 598196518", "output": "283\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 11..." }, { "input": "685146646 26521171", "output": "199\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 5304234..." }, { "input": "863230070 895037311", "output": "290\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 179..." }, { "input": "41313494 468586155", "output": "194\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 1405758469 1405758469 1405..." }, { "input": "219396918 747167704", "output": "226\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 14943..." }, { "input": "102513046 615683844", "output": "179\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 123136..." }, { "input": "985629174 189232688", "output": "310\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 37846537..." }, { "input": "458679894 912524637", "output": "272\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825..." }, { "input": "341796022 486073481", "output": "238\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 ..." }, { "input": "519879446 764655030", "output": "323\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529..." }, { "input": "452405440 586588704", "output": "268\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173..." }, { "input": "335521569 160137548", "output": "311\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 ..." }, { "input": "808572289 733686393", "output": "192\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 146..." }, { "input": "691688417 162011045", "output": "233\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 32402209..." }, { "input": "869771841 30527185", "output": "292\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 6105437..." }, { "input": "752887969 604076030", "output": "195\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 12..." }, { "input": "930971393 177624874", "output": "344\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 35524975..." }, { "input": "109054817 751173719", "output": "122\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 150234..." }, { "input": "992170945 324722563", "output": "258\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 64944512..." }, { "input": "170254369 48014511", "output": "164\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 144043537 144043537 144043537 14404353..." }, { "input": "248004555 280013594", "output": "239\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 56..." }, { "input": "131120683 148529734", "output": "235\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 2970..." }, { "input": "604171403 722078578", "output": "158\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 2..." }, { "input": "487287531 295627423", "output": "243\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 ..." }, { "input": "665370955 18919371", "output": "228\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 3783874..." }, { "input": "843454379 297500920", "output": "209\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 59500184..." }, { "input": "21537803 166017060", "output": "116\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 498051184 498051184 498051184 498051184 49805118..." }, { "input": "904653932 739565904", "output": "323\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 147..." }, { "input": "787770060 313114749", "output": "293\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 62622950..." }, { "input": "260820780 181630889", "output": "271\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 36..." }, { "input": "43603670 268405779", "output": "182\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 805217341 805217341 805217..." }, { "input": "1000000000 1000000000", "output": "274\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 20000000..." }, { "input": "15000 1", "output": "66\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 11 11 11 11 13 13 13 15 17 19 21 23 25 27 " }, { "input": "1048576 1", "output": "21\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 " }, { "input": "1000000000 1", "output": "274\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 19 ..." }, { "input": "100000000 1", "output": "232\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 19 19 19 19 19 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 2..." }, { "input": "1000000 1", "output": "106\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 15 17 19 21 23 25 27 " }, { "input": "536870911 1", "output": "435\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ..." }, { "input": "10009 1", "output": "54\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 11 11 13 15 17 19 21 23 25 " }, { "input": "10001 1", "output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 13 15 17 19 21 " } ]
1,000
102,400
0
1,450
721
Journey
[ "dp", "graphs" ]
null
null
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units. Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it.
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes. It is guaranteed, that there is at most one road between each pair of showplaces.
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line. Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them. If there are multiple answers, print any of them.
[ "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n" ]
[ "3\n1 2 4 \n", "4\n1 2 4 6 \n", "3\n1 3 5 \n" ]
none
[ { "input": "4 3 13\n1 2 5\n2 3 7\n2 4 8", "output": "3\n1 2 4 " }, { "input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "output": "4\n1 2 4 6 " }, { "input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2", "output": "3\n1 3 5 " }, { "input": "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4", "output": "10\n1 2 7 5 8 9 3 6 4 10 " }, { "input": "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9", "output": "3\n1 6 10 " }, { "input": "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "output": "4\n1 2 3 4 " }, { "input": "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "output": "3\n1 3 4 " }, { "input": "10 45 8\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 8 1\n1 9 1\n1 10 1\n2 3 1\n2 4 1\n2 5 1\n2 6 1\n2 7 1\n2 8 1\n2 9 1\n2 10 1\n3 4 1\n3 5 1\n3 6 1\n3 7 1\n3 8 1\n3 9 1\n3 10 1\n4 5 1\n4 6 1\n4 7 1\n4 8 1\n4 9 1\n4 10 1\n5 6 1\n5 7 1\n5 8 1\n5 9 1\n5 10 1\n6 7 1\n6 8 1\n6 9 1\n6 10 1\n7 8 1\n7 9 1\n7 10 1\n8 9 1\n8 10 1\n9 10 1", "output": "9\n1 2 3 4 5 6 7 8 10 " }, { "input": "2 1 1\n1 2 1", "output": "2\n1 2 " }, { "input": "12 12 8\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1", "output": "6\n1 9 10 11 8 12 " }, { "input": "12 12 5\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1", "output": "6\n1 9 10 11 8 12 " }, { "input": "12 12 4\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 2\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1", "output": "4\n1 7 6 12 " }, { "input": "11 11 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1", "output": "8\n1 4 5 6 3 7 8 11 " }, { "input": "11 11 7\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1", "output": "8\n1 4 5 6 3 7 8 11 " }, { "input": "11 11 6\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1", "output": "6\n1 2 3 7 8 11 " }, { "input": "12 12 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 12 1\n12 10 1\n10 9 1\n11 1 1", "output": "8\n1 4 5 6 3 7 8 12 " }, { "input": "4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100", "output": "3\n1 3 4 " }, { "input": "4 4 10\n2 1 1\n2 3 1\n1 3 1\n3 4 1", "output": "3\n1 3 4 " }, { "input": "5 5 200\n1 2 100\n2 4 100\n1 3 1\n3 4 1\n4 5 1", "output": "4\n1 3 4 5 " }, { "input": "5 5 2\n1 2 1\n1 3 1\n3 4 1\n2 5 1\n4 2 1", "output": "3\n1 2 5 " }, { "input": "4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000", "output": "2\n1 4 " } ]
3,000
103,628,800
0
1,454
964
Splits
[ "math" ]
null
null
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$. For a given $n$, find out the number of different weights of its splits.
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output one integer — the answer to the problem.
[ "7\n", "8\n", "9\n" ]
[ "4\n", "5\n", "5\n" ]
In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
[ { "input": "7", "output": "4" }, { "input": "8", "output": "5" }, { "input": "9", "output": "5" }, { "input": "1", "output": "1" }, { "input": "286", "output": "144" }, { "input": "48", "output": "25" }, { "input": "941", "output": "471" }, { "input": "45154", "output": "22578" }, { "input": "60324", "output": "30163" }, { "input": "91840", "output": "45921" }, { "input": "41909", "output": "20955" }, { "input": "58288", "output": "29145" }, { "input": "91641", "output": "45821" }, { "input": "62258", "output": "31130" }, { "input": "79811", "output": "39906" }, { "input": "88740", "output": "44371" }, { "input": "12351", "output": "6176" }, { "input": "1960", "output": "981" }, { "input": "29239", "output": "14620" }, { "input": "85801", "output": "42901" }, { "input": "43255", "output": "21628" }, { "input": "13439", "output": "6720" }, { "input": "35668", "output": "17835" }, { "input": "19122", "output": "9562" }, { "input": "60169", "output": "30085" }, { "input": "50588", "output": "25295" }, { "input": "2467", "output": "1234" }, { "input": "39315", "output": "19658" }, { "input": "29950", "output": "14976" }, { "input": "17286", "output": "8644" }, { "input": "7359066", "output": "3679534" }, { "input": "1016391", "output": "508196" }, { "input": "7928871", "output": "3964436" }, { "input": "3968891", "output": "1984446" }, { "input": "2636452", "output": "1318227" }, { "input": "5076901", "output": "2538451" }, { "input": "9870265", "output": "4935133" }, { "input": "2453786", "output": "1226894" }, { "input": "7263670", "output": "3631836" }, { "input": "1890845", "output": "945423" }, { "input": "574128507", "output": "287064254" }, { "input": "648476655", "output": "324238328" }, { "input": "97349542", "output": "48674772" }, { "input": "716489761", "output": "358244881" }, { "input": "858771038", "output": "429385520" }, { "input": "520778784", "output": "260389393" }, { "input": "439004204", "output": "219502103" }, { "input": "589992198", "output": "294996100" }, { "input": "371106544", "output": "185553273" }, { "input": "894241590", "output": "447120796" }, { "input": "123957268", "output": "61978635" }, { "input": "234149297", "output": "117074649" }, { "input": "789954052", "output": "394977027" }, { "input": "667978920", "output": "333989461" }, { "input": "154647261", "output": "77323631" }, { "input": "751453521", "output": "375726761" }, { "input": "848862308", "output": "424431155" }, { "input": "323926781", "output": "161963391" }, { "input": "576768825", "output": "288384413" }, { "input": "31293802", "output": "15646902" }, { "input": "2", "output": "2" }, { "input": "1000000000", "output": "500000001" }, { "input": "3", "output": "2" } ]
0
0
-1
1,455
595
Vitaly and Night
[ "constructive algorithms", "implementation" ]
null
null
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on. Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively. Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
[ "2 2\n0 0 0 1\n1 0 1 1\n", "1 3\n1 1 0 1 0 0\n" ]
[ "3\n", "2\n" ]
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
[ { "input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3" }, { "input": "1 3\n1 1 0 1 0 0", "output": "2" }, { "input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1", "output": "8" }, { "input": "1 5\n1 0 1 1 1 0 1 1 1 1", "output": "5" }, { "input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "99" }, { "input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "6" }, { "input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "100" }, { "input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0", "output": "8" }, { "input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "1 1\n0 0", "output": "0" }, { "input": "1 1\n0 1", "output": "1" }, { "input": "1 1\n1 0", "output": "1" }, { "input": "1 1\n1 1", "output": "1" } ]
155
614,400
3
1,456
446
DZY Loves Fibonacci Numbers
[ "data structures", "math", "number theory" ]
null
null
In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Moreover, there are *m* queries, each query has one of the two types: 1. Format of the query "1 *l* *r*". In reply to the query, you need to add *F**i*<=-<=*l*<=+<=1 to each element *a**i*, where *l*<=≤<=*i*<=≤<=*r*. 1. Format of the query "2 *l* *r*". In reply to the query you should output the value of modulo 1000000009 (109<=+<=9). Help DZY reply to all the queries.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — initial array *a*. Then, *m* lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1<=≤<=*l*<=≤<=*r*<=≤<=*n* holds.
For each query of the second type, print the value of the sum on a single line.
[ "4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3\n" ]
[ "17\n12\n" ]
After the first query, *a* = [2, 3, 5, 7]. For the second query, *sum* = 2 + 3 + 5 + 7 = 17. After the third query, *a* = [2, 4, 6, 9]. For the fourth query, *sum* = 2 + 4 + 6 = 12.
[ { "input": "4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3", "output": "17\n12" }, { "input": "2 2\n1 2\n2 1 2\n2 1 2", "output": "3\n3" }, { "input": "10 20\n56 12 68 23 41 29 97 69 79 76\n1 3 5\n1 8 9\n2 3 10\n1 7 10\n2 1 10\n1 5 10\n2 2 4\n1 2 4\n1 5 6\n2 1 2\n2 4 5\n1 1 5\n1 8 9\n2 5 8\n2 4 7\n2 9 10\n2 4 9\n1 2 10\n1 2 9\n2 7 8", "output": "488\n563\n105\n69\n71\n256\n210\n175\n373\n217" } ]
30
0
-1
1,458
612
Replace To Make Regular Bracket Sequence
[ "data structures", "expression parsing", "math" ]
null
null
You are given string *s* consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;. The following definition of a regular bracket sequence is well-known, so you can be familiar with it. Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings &lt;*s*1&gt;*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS. For example the string "[[(){}]&lt;&gt;]" is RBS, but the strings "[)()" and "][()()" are not. Determine the least number of replaces to make the string *s* RBS.
The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106.
If it's impossible to get RBS from *s* print Impossible. Otherwise print the least number of replaces needed to get RBS from *s*.
[ "[&lt;}){}\n", "{()}[]\n", "]]\n" ]
[ "2", "0", "Impossible" ]
none
[ { "input": "[<}){}", "output": "2" }, { "input": "{()}[]", "output": "0" }, { "input": "]]", "output": "Impossible" }, { "input": ">", "output": "Impossible" }, { "input": "{}", "output": "0" }, { "input": "{}", "output": "0" }, { "input": "{]", "output": "1" }, { "input": "{]", "output": "1" }, { "input": "{]", "output": "1" }, { "input": "[]{[]({)([", "output": "Impossible" }, { "input": "(([{>}{[{[)]]>>]", "output": "7" }, { "input": "((<>)[]<]><]", "output": "3" }, { "input": "[[([[(>]>)))[<)>", "output": "6" }, { "input": "({)[}<)](}", "output": "5" }, { "input": "(}{)[<][)(]}", "output": "6" }, { "input": ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([", "output": "Impossible" }, { "input": "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>[[>{>>>[<]}<>>)[>]<{)<[><(<]][>(>]>][(<][{]}(()<[()[>><<])<]})]<]}{)", "output": "45" }, { "input": "[<<{{((}[}<<)<)>})(][{>}})((>)<[)[>}[})[)>()[()[((}<<(>)<>](<>(}[>})[[[{)<}<<(}{>>}[<([[])<><)]<{>}[>>>{({>)}]})>)", "output": "42" }, { "input": "(<[([(<({>(}{]>[(})])}])()<<}{]{[>]>(>>[(>>}[){(}<[{(()]{{<(<{][[{<><{<{)<>>]}}}{)(}{})}[<))>>}((({>){({}{{]}]>>}})>))", "output": "43" }, { "input": "{(]}<([]<]{>]<{<({{{<>))}[({(}{)[}({>]}}<<)}<]))(<>(>{>{{{)<}({<]<>{)(>[)>{({}<([<[[)]><>{]}}(>]{}<)[})]}]]}]}>}", "output": "40" }, { "input": "<(([)]<[}>{)>][[(<()({{{>>((]<}<{{<>}><<[)}[[)([[)[)}<]<{(<>){([)><{[([[][({])})<][(}]}>>[){)[({>){(}[}})>}>]>)]}))})>}]", "output": "45" }, { "input": ")(", "output": "Impossible" }, { "input": "[[[[[[[[", "output": "Impossible" } ]
77
7,065,600
0
1,459
626
Cards
[ "constructive algorithms", "dp", "math" ]
null
null
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n" ]
[ "G\n", "BR\n", "B\n" ]
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
[ { "input": "2\nRB", "output": "G" }, { "input": "3\nGRG", "output": "BR" }, { "input": "5\nBBBBB", "output": "B" }, { "input": "1\nR", "output": "R" }, { "input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB", "output": "BGR" }, { "input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BG" }, { "input": "7\nBBBGBRG", "output": "BGR" }, { "input": "5\nGRRGR", "output": "BGR" }, { "input": "3\nGBR", "output": "BGR" }, { "input": "1\nB", "output": "B" }, { "input": "2\nBB", "output": "B" }, { "input": "1\nG", "output": "G" }, { "input": "2\nBG", "output": "R" }, { "input": "3\nBGB", "output": "GR" }, { "input": "2\nGG", "output": "G" }, { "input": "3\nGBG", "output": "BR" }, { "input": "4\nBGBG", "output": "BGR" }, { "input": "1\nR", "output": "R" }, { "input": "2\nBR", "output": "G" }, { "input": "3\nBRB", "output": "GR" }, { "input": "2\nRG", "output": "B" }, { "input": "3\nBGR", "output": "BGR" }, { "input": "4\nRBGB", "output": "BGR" }, { "input": "3\nGGR", "output": "BR" }, { "input": "4\nGGRB", "output": "BGR" }, { "input": "5\nBGBGR", "output": "BGR" }, { "input": "2\nRR", "output": "R" }, { "input": "3\nRBR", "output": "BG" }, { "input": "4\nRRBB", "output": "BGR" }, { "input": "3\nRRG", "output": "BG" }, { "input": "4\nBRRG", "output": "BGR" }, { "input": "5\nRBRBG", "output": "BGR" }, { "input": "4\nRGGR", "output": "BGR" }, { "input": "5\nBRGRG", "output": "BGR" }, { "input": "6\nGRRGBB", "output": "BGR" }, { "input": "150\nGRGBBBBRBGGBGBBGBBBBGRBBRRBBGRRGGGBRBBRGRRRRGBGRRBGBGBGRBBBGBBBGBGBRGBRRRRRGGGRGRBBGBRGGGRBBRGBBGRGGGBBRBRRGRGRRGRRGRRRGBGBRRGGRGGBRBGGGBBBRGRGBRGRRRR", "output": "BGR" }, { "input": "16\nRRGRRRRRRGGRGRRR", "output": "BGR" }, { "input": "190\nBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "GR" }, { "input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR", "output": "BGR" }, { "input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "G" }, { "input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BGR" }, { "input": "200\nGRGRRGRBRRRGGGRGGRRRRRBBGRRGRBBGRRGBGRRBBRBBRRBBBGRBRGGGGBGGBRRBBRGRBGGRRGGBBRBGGRGBBRRBBRGBRRBGBRBGBBRGGRRRGGGBRGGGGRRRBBRRGRGRBRRGRBBGGRBBRGRGRBGRBBRGGBBBGRGBBGGBGBGBBRRBGRGRGGBRRGRGGGGGBRGGGGBBBBRB", "output": "BGR" }, { "input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "BGR" }, { "input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG", "output": "BGR" }, { "input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB", "output": "BGR" }, { "input": "3\nGGB", "output": "BR" } ]
62
0
0
1,464
0
none
[ "none" ]
null
null
An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states *i*, *j* and *k* are selected, where *i*<=&lt;<=*j*<=&lt;<=*k*. After that the following process happens: 1. initially the atom is in the state *i*,1. we spend *E**k*<=-<=*E**i* energy to put the atom in the state *k*,1. the atom emits a photon with useful energy *E**k*<=-<=*E**j* and changes its state to the state *j*,1. the atom spontaneously changes its state to the state *i*, losing energy *E**j*<=-<=*E**i*,1. the process repeats from step 1. Let's define the energy conversion efficiency as , i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that *E**k*<=-<=*E**i*<=≤<=*U*. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*. The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=&lt;<=*E*2...<=&lt;<=*E**n*<=≤<=109). It is guaranteed that all *E**i* are given in increasing order.
If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "4 4\n1 3 5 7\n", "10 8\n10 13 15 16 17 19 20 22 24 25\n", "3 1\n2 5 10\n" ]
[ "0.5\n", "0.875\n", "-1\n" ]
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f68f268de4eb2242167e6ec64e6b8aa60a5703ae.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "4 4\n1 3 5 7", "output": "0.5" }, { "input": "10 8\n10 13 15 16 17 19 20 22 24 25", "output": "0.875" }, { "input": "3 1\n2 5 10", "output": "-1" }, { "input": "5 3\n4 6 8 9 10", "output": "0.5" }, { "input": "10 128\n110 121 140 158 174 188 251 271 272 277", "output": "0.86554621848739499157" }, { "input": "20 17\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265", "output": "0.92857142857142860315" }, { "input": "30 23\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 171 173 174 175 181 187 190 191 193 195 196", "output": "0.95652173913043481157" }, { "input": "50 64\n257 258 350 375 1014 1017 1051 1097 1169 1177 1223 1836 1942 1983 2111 2131 2341 2418 2593 2902 2948 3157 3243 3523 3566 4079 4499 4754 5060 5624 6279 6976 7011 7071 7278 7366 7408 7466 7526 7837 7934 8532 8577 8680 9221 9271 9327 9411 9590 9794", "output": "0.91891891891891896993" }, { "input": "5 2\n4 6 8 9 10", "output": "0.5" }, { "input": "10 2\n110 121 140 158 174 188 251 271 272 277", "output": "-1" }, { "input": "30 5\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 171 173 174 175 181 187 190 191 193 195 196", "output": "0.80000000000000004441" }, { "input": "10 6\n110 121 140 158 174 188 251 271 272 277", "output": "0.83333333333333337034" }, { "input": "20 4\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265", "output": "0.25" }, { "input": "3 1000000000\n1 2 1000000000", "output": "0.99999999900000002828" }, { "input": "3 1\n1 2 3", "output": "-1" }, { "input": "5 1000000000\n1 2 3 999999999 1000000000", "output": "0.99999999900000002828" }, { "input": "10 199\n1 3 190 191 193 195 196 197 199 200", "output": "0.98994974874371854945" }, { "input": "10 300\n80 100 103 140 146 159 392 393 396 398", "output": "0.98993288590604022747" }, { "input": "10 92\n44 119 252 281 303 323 351 363 377 392", "output": "0.77528089887640450062" }, { "input": "4 2\n1 3 5 7", "output": "-1" }, { "input": "8 2\n1 3 7 9 15 17 23 25", "output": "-1" }, { "input": "3 5\n1 2 10", "output": "-1" }, { "input": "4 7\n1 5 8 9", "output": "0.42857142857142854764" } ]
93
7,065,600
0
1,467
127
Canvas Frames
[ "implementation" ]
null
null
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want to break the sticks or glue them together. To make a *h*<=×<=*w*-sized frame, he needs two sticks whose lengths equal *h* and two sticks whose lengths equal *w*. Specifically, to make a square frame (when *h*<==<=*w*), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
[ "5\n2 4 3 2 3\n", "13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n", "4\n3 3 3 5\n" ]
[ "1", "3", "0" ]
none
[ { "input": "5\n2 4 3 2 3", "output": "1" }, { "input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3" }, { "input": "4\n3 3 3 5", "output": "0" }, { "input": "2\n3 5", "output": "0" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "0" }, { "input": "14\n2 4 2 6 2 3 4 1 4 5 4 3 4 1", "output": "2" }, { "input": "33\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36", "output": "5" }, { "input": "1\n1", "output": "0" }, { "input": "1\n10", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "3\n1 2 2", "output": "0" }, { "input": "3\n3 2 1", "output": "0" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "4\n1 2 1 2", "output": "1" }, { "input": "4\n1 100 1 100", "output": "1" }, { "input": "4\n10 100 100 10", "output": "1" }, { "input": "4\n1 2 3 3", "output": "0" }, { "input": "4\n8 5 9 13", "output": "0" }, { "input": "4\n100 100 100 100", "output": "1" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "5\n1 4 4 1 1", "output": "1" }, { "input": "5\n1 100 1 1 100", "output": "1" }, { "input": "5\n100 100 1 1 100", "output": "1" }, { "input": "5\n100 1 100 100 100", "output": "1" }, { "input": "5\n100 100 100 100 100", "output": "1" }, { "input": "6\n1 1 1 1 1 1", "output": "1" }, { "input": "6\n1 1 5 1 1 5", "output": "1" }, { "input": "6\n1 100 100 1 1 1", "output": "1" }, { "input": "6\n100 1 1 100 1 100", "output": "1" }, { "input": "6\n1 2 3 2 3 1", "output": "1" }, { "input": "6\n1 50 1 100 50 100", "output": "1" }, { "input": "6\n10 10 10 12 13 14", "output": "0" }, { "input": "7\n1 1 1 1 1 1 1", "output": "1" }, { "input": "7\n1 2 1 1 1 1 1", "output": "1" }, { "input": "7\n1 2 2 1 2 1 2", "output": "1" }, { "input": "7\n1 1 2 2 1 2 3", "output": "1" }, { "input": "7\n1 3 2 2 3 1 4", "output": "1" }, { "input": "7\n1 3 4 3 5 4 6", "output": "1" }, { "input": "7\n7 6 5 4 3 2 1", "output": "0" }, { "input": "8\n1 2 1 2 2 2 2 2", "output": "2" }, { "input": "8\n1 2 2 1 1 2 2 2", "output": "1" }, { "input": "8\n1 2 2 2 3 1 1 3", "output": "1" }, { "input": "8\n1 2 3 4 1 2 3 4", "output": "2" }, { "input": "8\n1 1 1 1 2 3 2 3", "output": "2" }, { "input": "8\n1 2 3 4 5 5 5 5", "output": "1" }, { "input": "8\n1 2 1 3 4 1 5 6", "output": "0" }, { "input": "8\n1 2 3 4 5 6 1 7", "output": "0" }, { "input": "8\n8 6 3 4 5 2 1 7", "output": "0" }, { "input": "8\n100 100 100 100 100 100 100 100", "output": "2" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10\n19 9 14 14 19 5 5 18 10 17", "output": "1" }, { "input": "10\n72 86 73 25 84 29 33 34 20 29", "output": "0" }, { "input": "10\n93 93 99 98 91 96 92 98 94 98", "output": "1" }, { "input": "13\n35 6 21 30 67 55 70 39 75 72 11 13 69", "output": "0" }, { "input": "17\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100", "output": "1" }, { "input": "18\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27", "output": "1" }, { "input": "23\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35", "output": "1" }, { "input": "30\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27", "output": "1" }, { "input": "33\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51", "output": "1" }, { "input": "38\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89", "output": "3" }, { "input": "40\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90", "output": "1" }, { "input": "43\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96", "output": "4" }, { "input": "49\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91", "output": "4" }, { "input": "57\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89", "output": "6" }, { "input": "67\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23", "output": "8" }, { "input": "74\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91", "output": "7" }, { "input": "87\n10 19 83 58 15 48 26 58 89 46 50 34 81 40 25 51 62 85 9 80 71 44 100 22 30 48 74 69 54 40 38 81 66 42 40 90 60 20 75 24 74 98 28 62 79 65 65 6 14 23 3 59 29 24 64 13 8 38 29 85 75 81 36 42 3 63 99 24 72 92 35 8 71 19 77 77 66 3 79 65 15 18 15 69 60 77 91", "output": "11" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "100\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5", "output": "23" }, { "input": "100\n70 70 75 70 74 70 70 73 72 73 74 75 70 74 73 70 70 74 72 72 75 70 73 72 70 75 73 70 74 70 73 75 71 74 70 71 75 74 75 71 74 70 73 73 70 75 71 73 73 74 73 74 71 73 73 71 72 71 70 75 74 74 72 72 71 72 75 75 70 73 71 73 72 71 70 75 71 75 73 75 73 72 75 71 73 71 72 74 75 70 70 74 75 73 70 73 73 75 71 74", "output": "24" }, { "input": "100\n99 98 98 99 98 98 98 100 98 99 99 98 99 98 98 98 99 99 98 99 99 100 98 100 98 98 98 99 98 100 100 98 100 99 100 98 99 99 99 98 100 98 100 99 99 99 98 100 98 98 98 100 100 99 98 98 100 100 100 99 98 99 99 99 100 99 99 98 99 98 99 100 100 98 98 100 100 99 99 99 98 98 98 100 99 99 100 99 100 99 98 100 98 100 98 98 99 98 99 98", "output": "24" }, { "input": "100\n94 87 92 91 94 89 93 94 87 93 93 94 89 91 87 87 92 91 87 94 90 89 92 92 87 88 90 90 90 89 90 92 91 91 89 88 93 89 88 94 91 89 88 87 92 89 91 87 88 90 88 92 90 87 93 94 94 92 92 87 90 88 88 91 94 93 87 94 93 93 87 90 92 92 90 88 88 90 92 91 90 88 89 91 91 88 90 93 90 94 94 93 90 91 91 93 94 94 92 93", "output": "24" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "25" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "7\n13 13 13 13 6 2 3", "output": "1" }, { "input": "8\n1 1 1 1 1 1 1 1", "output": "2" }, { "input": "5\n100 100 99 99 5", "output": "1" }, { "input": "8\n2 2 2 2 2 2 2 2", "output": "2" }, { "input": "8\n1 2 3 4 5 6 7 7", "output": "0" }, { "input": "8\n4 4 4 4 4 4 4 4", "output": "2" }, { "input": "10\n1 1 1 1 1 1 1 1 2 2", "output": "2" }, { "input": "4\n100 100 100 99", "output": "0" }, { "input": "4\n2 2 2 2", "output": "1" }, { "input": "5\n100 100 99 99 2", "output": "1" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "5\n2 2 3 4 4", "output": "1" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13", "output": "0" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "4\n4 4 4 4", "output": "1" }, { "input": "5\n1 1 2 3 3", "output": "1" }, { "input": "5\n30 30 30 1 1", "output": "1" } ]
62
0
3
1,468
633
Spy Syndrome 2
[ "data structures", "dp", "hashing", "implementation", "sortings", "string suffix structures", "strings" ]
null
null
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique. For a given sentence, the cipher is processed as: 1. Convert all letters of the sentence to lowercase. 1. Reverse each of the words of the sentence individually. 1. Remove all the spaces in the sentence. For example, when this cipher is applied to the sentence Kira is childish and he hates losing the resulting string is ariksihsidlihcdnaehsetahgnisol Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*. The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered while deciphering the text. Each of the next *m* lines contains a non-empty word *w**i* (|*w**i*|<=≤<=1<=000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1<=000<=000.
Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.
[ "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n", "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n" ]
[ "Kira is childish and he hates losing \n", "HI there HeLLo \n" ]
In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them.
[ { "input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote", "output": "Kira is childish and he hates losing " }, { "input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello", "output": "HI there HeLLo " }, { "input": "71\nbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n8\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab " }, { "input": "11\naaaaaaaaaaa\n3\naaaa\naaaaa\naaaaaa", "output": "aaaaaa aaaaa " }, { "input": "5\ncbaed\n6\nbc\nea\nab\ncd\nabc\nde", "output": "abc de " }, { "input": "5\nlehet\n3\nel\nhel\nte", "output": "hel te " }, { "input": "3\naab\n2\na\nbaa", "output": "baa " }, { "input": "3\naab\n2\naa\nbaa", "output": "baa " }, { "input": "9\naaaaaaaaa\n2\naa\naaa", "output": "aaa aa aa aa " }, { "input": "7\nabababc\n2\nba\ncba", "output": "ba ba cba " }, { "input": "7\nkirkirk\n2\nrik\nkrik", "output": "rik krik " } ]
93
0
0
1,469
770
Maximize Sum of Digits
[ "*special", "implementation", "math" ]
null
null
Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
The first line contains the positive integer *x* (1<=≤<=*x*<=≤<=1018) — the integer which Anton has.
Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.
[ "100\n", "48\n", "521\n" ]
[ "99\n", "48\n", "499\n" ]
none
[ { "input": "100", "output": "99" }, { "input": "48", "output": "48" }, { "input": "521", "output": "499" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input": "39188", "output": "38999" }, { "input": "5", "output": "5" }, { "input": "6", "output": "6" }, { "input": "7", "output": "7" }, { "input": "8", "output": "8" }, { "input": "9", "output": "9" }, { "input": "10", "output": "9" }, { "input": "59999154", "output": "59998999" }, { "input": "1000", "output": "999" }, { "input": "10000", "output": "9999" }, { "input": "100000", "output": "99999" }, { "input": "1000000", "output": "999999" }, { "input": "10000000", "output": "9999999" }, { "input": "100000000", "output": "99999999" }, { "input": "1000000000", "output": "999999999" }, { "input": "10000000000", "output": "9999999999" }, { "input": "100000000000", "output": "99999999999" }, { "input": "1000000000000", "output": "999999999999" }, { "input": "10000000000000", "output": "9999999999999" }, { "input": "100000000000000", "output": "99999999999999" }, { "input": "1000000000000000", "output": "999999999999999" }, { "input": "10000000000000000", "output": "9999999999999999" }, { "input": "100000000000000000", "output": "99999999999999999" }, { "input": "1000000000000000000", "output": "999999999999999999" }, { "input": "999999990", "output": "999999989" }, { "input": "666666899789879", "output": "599999999999999" }, { "input": "65499992294999000", "output": "59999999999999999" }, { "input": "9879100000000099", "output": "8999999999999999" }, { "input": "9991919190909919", "output": "9989999999999999" }, { "input": "978916546899999999", "output": "899999999999999999" }, { "input": "5684945999999999", "output": "4999999999999999" }, { "input": "999999999999999999", "output": "999999999999999999" }, { "input": "999999999999990999", "output": "999999999999989999" }, { "input": "999999999999999990", "output": "999999999999999989" }, { "input": "909999999999999999", "output": "899999999999999999" }, { "input": "199999999999999999", "output": "199999999999999999" }, { "input": "299999999999999999", "output": "299999999999999999" }, { "input": "999999990009999999", "output": "999999989999999999" }, { "input": "999000000001999999", "output": "998999999999999999" }, { "input": "999999999991", "output": "999999999989" }, { "input": "999999999992", "output": "999999999989" }, { "input": "79320", "output": "78999" }, { "input": "99004", "output": "98999" }, { "input": "99088", "output": "98999" }, { "input": "99737", "output": "98999" }, { "input": "29652", "output": "28999" }, { "input": "59195", "output": "58999" }, { "input": "19930", "output": "19899" }, { "input": "49533", "output": "48999" }, { "input": "69291", "output": "68999" }, { "input": "59452", "output": "58999" }, { "input": "11", "output": "9" }, { "input": "110", "output": "99" }, { "input": "111", "output": "99" }, { "input": "119", "output": "99" }, { "input": "118", "output": "99" }, { "input": "1100", "output": "999" }, { "input": "1199", "output": "999" }, { "input": "1109", "output": "999" }, { "input": "1190", "output": "999" }, { "input": "12", "output": "9" }, { "input": "120", "output": "99" }, { "input": "121", "output": "99" }, { "input": "129", "output": "99" }, { "input": "128", "output": "99" }, { "input": "1200", "output": "999" }, { "input": "1299", "output": "999" }, { "input": "1209", "output": "999" }, { "input": "1290", "output": "999" }, { "input": "13", "output": "9" }, { "input": "130", "output": "99" }, { "input": "131", "output": "99" }, { "input": "139", "output": "99" }, { "input": "138", "output": "99" }, { "input": "1300", "output": "999" }, { "input": "1399", "output": "999" }, { "input": "1309", "output": "999" }, { "input": "1390", "output": "999" }, { "input": "14", "output": "9" }, { "input": "140", "output": "99" }, { "input": "141", "output": "99" }, { "input": "149", "output": "99" }, { "input": "148", "output": "99" }, { "input": "1400", "output": "999" }, { "input": "1499", "output": "999" }, { "input": "1409", "output": "999" }, { "input": "1490", "output": "999" }, { "input": "15", "output": "9" }, { "input": "150", "output": "99" }, { "input": "151", "output": "99" }, { "input": "159", "output": "99" }, { "input": "158", "output": "99" }, { "input": "1500", "output": "999" }, { "input": "1599", "output": "999" }, { "input": "1509", "output": "999" }, { "input": "1590", "output": "999" }, { "input": "16", "output": "9" }, { "input": "160", "output": "99" }, { "input": "161", "output": "99" }, { "input": "169", "output": "99" }, { "input": "168", "output": "99" }, { "input": "1600", "output": "999" }, { "input": "1699", "output": "999" }, { "input": "1609", "output": "999" }, { "input": "1690", "output": "999" }, { "input": "17", "output": "9" }, { "input": "170", "output": "99" }, { "input": "171", "output": "99" }, { "input": "179", "output": "99" }, { "input": "178", "output": "99" }, { "input": "1700", "output": "999" }, { "input": "1799", "output": "999" }, { "input": "1709", "output": "999" }, { "input": "1790", "output": "999" }, { "input": "18", "output": "18" }, { "input": "180", "output": "99" }, { "input": "181", "output": "99" }, { "input": "189", "output": "189" }, { "input": "188", "output": "99" }, { "input": "1800", "output": "999" }, { "input": "1899", "output": "1899" }, { "input": "1809", "output": "999" }, { "input": "1890", "output": "999" }, { "input": "19", "output": "19" }, { "input": "190", "output": "189" }, { "input": "191", "output": "189" }, { "input": "199", "output": "199" }, { "input": "198", "output": "198" }, { "input": "1900", "output": "1899" }, { "input": "1999", "output": "1999" }, { "input": "1909", "output": "1899" }, { "input": "1990", "output": "1989" }, { "input": "20", "output": "19" }, { "input": "200", "output": "199" }, { "input": "201", "output": "199" }, { "input": "209", "output": "199" }, { "input": "208", "output": "199" }, { "input": "2000", "output": "1999" }, { "input": "2099", "output": "1999" }, { "input": "2009", "output": "1999" }, { "input": "2090", "output": "1999" }, { "input": "21", "output": "19" }, { "input": "210", "output": "199" }, { "input": "211", "output": "199" }, { "input": "219", "output": "199" }, { "input": "218", "output": "199" }, { "input": "2100", "output": "1999" }, { "input": "2199", "output": "1999" }, { "input": "2109", "output": "1999" }, { "input": "2190", "output": "1999" }, { "input": "22", "output": "19" }, { "input": "220", "output": "199" }, { "input": "221", "output": "199" }, { "input": "229", "output": "199" }, { "input": "228", "output": "199" }, { "input": "2200", "output": "1999" }, { "input": "2299", "output": "1999" }, { "input": "2209", "output": "1999" }, { "input": "2290", "output": "1999" }, { "input": "23", "output": "19" }, { "input": "230", "output": "199" }, { "input": "231", "output": "199" }, { "input": "239", "output": "199" }, { "input": "238", "output": "199" }, { "input": "2300", "output": "1999" }, { "input": "2399", "output": "1999" }, { "input": "2309", "output": "1999" }, { "input": "2390", "output": "1999" }, { "input": "24", "output": "19" }, { "input": "240", "output": "199" }, { "input": "241", "output": "199" }, { "input": "249", "output": "199" }, { "input": "248", "output": "199" }, { "input": "2400", "output": "1999" }, { "input": "2499", "output": "1999" }, { "input": "2409", "output": "1999" }, { "input": "2490", "output": "1999" }, { "input": "25", "output": "19" }, { "input": "250", "output": "199" }, { "input": "251", "output": "199" }, { "input": "259", "output": "199" }, { "input": "258", "output": "199" }, { "input": "2500", "output": "1999" }, { "input": "2599", "output": "1999" }, { "input": "2509", "output": "1999" }, { "input": "2590", "output": "1999" }, { "input": "26", "output": "19" }, { "input": "260", "output": "199" }, { "input": "261", "output": "199" }, { "input": "269", "output": "199" }, { "input": "268", "output": "199" }, { "input": "2600", "output": "1999" }, { "input": "2699", "output": "1999" }, { "input": "2609", "output": "1999" }, { "input": "2690", "output": "1999" }, { "input": "27", "output": "19" }, { "input": "270", "output": "199" }, { "input": "271", "output": "199" }, { "input": "279", "output": "199" }, { "input": "278", "output": "199" }, { "input": "2700", "output": "1999" }, { "input": "2799", "output": "1999" }, { "input": "2709", "output": "1999" }, { "input": "2790", "output": "1999" }, { "input": "28", "output": "28" }, { "input": "280", "output": "199" }, { "input": "281", "output": "199" }, { "input": "289", "output": "289" }, { "input": "288", "output": "199" }, { "input": "2800", "output": "1999" }, { "input": "2899", "output": "2899" }, { "input": "2809", "output": "1999" }, { "input": "2890", "output": "1999" }, { "input": "29", "output": "29" }, { "input": "290", "output": "289" }, { "input": "291", "output": "289" }, { "input": "299", "output": "299" }, { "input": "298", "output": "298" }, { "input": "2900", "output": "2899" }, { "input": "2999", "output": "2999" }, { "input": "2909", "output": "2899" }, { "input": "2990", "output": "2989" }, { "input": "999", "output": "999" }, { "input": "999", "output": "999" }, { "input": "890", "output": "889" }, { "input": "995", "output": "989" }, { "input": "999", "output": "999" }, { "input": "989", "output": "989" }, { "input": "999", "output": "999" }, { "input": "999", "output": "999" }, { "input": "991", "output": "989" }, { "input": "999", "output": "999" }, { "input": "9929", "output": "9899" }, { "input": "4999", "output": "4999" }, { "input": "9690", "output": "8999" }, { "input": "8990", "output": "8989" }, { "input": "9982", "output": "9899" }, { "input": "9999", "output": "9999" }, { "input": "1993", "output": "1989" }, { "input": "9367", "output": "8999" }, { "input": "8939", "output": "8899" }, { "input": "9899", "output": "9899" }, { "input": "99999", "output": "99999" }, { "input": "93929", "output": "89999" }, { "input": "99999", "output": "99999" }, { "input": "38579", "output": "29999" }, { "input": "79096", "output": "78999" }, { "input": "72694", "output": "69999" }, { "input": "99999", "output": "99999" }, { "input": "99999", "output": "99999" }, { "input": "99992", "output": "99989" }, { "input": "27998", "output": "19999" }, { "input": "460999", "output": "399999" }, { "input": "999999", "output": "999999" }, { "input": "999999", "output": "999999" }, { "input": "998999", "output": "998999" }, { "input": "999999", "output": "999999" }, { "input": "999929", "output": "999899" }, { "input": "999999", "output": "999999" }, { "input": "999999", "output": "999999" }, { "input": "979199", "output": "899999" }, { "input": "999999", "output": "999999" }, { "input": "9899999", "output": "9899999" }, { "input": "9699959", "output": "8999999" }, { "input": "9999999", "output": "9999999" }, { "input": "9997099", "output": "9989999" }, { "input": "8992091", "output": "8989999" }, { "input": "9599295", "output": "8999999" }, { "input": "2999902", "output": "2999899" }, { "input": "9999953", "output": "9999899" }, { "input": "9999999", "output": "9999999" }, { "input": "9590999", "output": "8999999" } ]
1,000
0
0
1,473
911
Tree Destruction
[ "constructive algorithms", "dfs and similar", "graphs", "greedy", "trees" ]
null
null
You are given an unweighted tree with *n* vertices. Then *n*<=-<=1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 1. add the length of the simple path between them to the answer; 1. remove one of the chosen leaves from the tree. Initial answer (before applying operations) is 0. Obviously after *n*<=-<=1 such operations the tree will consist of a single vertex. Calculate the maximal possible answer you can achieve, and construct a sequence of operations that allows you to achieve this answer!
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105) — the number of vertices in the tree. Next *n*<=-<=1 lines describe the edges of the tree in form *a**i*,<=*b**i* (1<=≤<=*a**i*, *b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). It is guaranteed that given graph is a tree.
In the first line print one integer number — maximal possible answer. In the next *n*<=-<=1 lines print the operations in order of their applying in format *a**i*,<=*b**i*,<=*c**i*, where *a**i*,<=*b**i* — pair of the leaves that are chosen in the current operation (1<=≤<=*a**i*, *b**i*<=≤<=*n*), *c**i* (1<=≤<=*c**i*<=≤<=*n*, *c**i*<==<=*a**i* or *c**i*<==<=*b**i*) — choosen leaf that is removed from the tree in the current operation. See the examples for better understanding.
[ "3\n1 2\n1 3\n", "5\n1 2\n1 3\n2 4\n2 5\n" ]
[ "3\n2 3 3\n2 1 1\n", "9\n3 5 5\n4 3 3\n4 1 1\n4 2 2\n" ]
none
[ { "input": "3\n1 2\n1 3", "output": "3\n2 3 3\n2 1 1" }, { "input": "5\n1 2\n1 3\n2 4\n2 5", "output": "9\n3 5 5\n4 3 3\n4 1 1\n4 2 2" }, { "input": "2\n1 2", "output": "1\n2 1 1" }, { "input": "4\n1 3\n1 4\n1 2", "output": "5\n3 4 4\n2 3 3\n2 1 1" }, { "input": "4\n2 1\n1 3\n3 4", "output": "6\n4 2 2\n4 1 1\n4 3 3" }, { "input": "4\n4 3\n3 2\n2 1", "output": "6\n4 1 1\n4 2 2\n4 3 3" }, { "input": "5\n2 1\n2 3\n2 4\n2 5", "output": "7\n1 4 4\n1 5 5\n3 1 1\n3 2 2" }, { "input": "5\n4 5\n4 1\n1 2\n2 3", "output": "10\n3 5 5\n3 4 4\n3 1 1\n3 2 2" }, { "input": "5\n1 4\n4 3\n3 2\n2 5", "output": "10\n5 1 1\n5 4 4\n5 3 3\n5 2 2" }, { "input": "6\n4 5\n4 1\n4 6\n4 2\n4 3", "output": "9\n1 5 5\n1 6 6\n1 3 3\n2 1 1\n2 4 4" }, { "input": "6\n6 5\n6 2\n2 3\n5 4\n4 1", "output": "15\n3 1 1\n3 4 4\n3 5 5\n3 6 6\n3 2 2" }, { "input": "6\n1 5\n5 4\n4 2\n2 6\n6 3", "output": "15\n3 1 1\n3 5 5\n3 4 4\n3 2 2\n3 6 6" }, { "input": "7\n7 5\n7 3\n7 6\n7 4\n7 1\n7 2", "output": "11\n1 5 5\n1 3 3\n1 6 6\n1 4 4\n2 1 1\n2 7 7" }, { "input": "7\n7 6\n7 5\n7 2\n7 1\n5 4\n5 3", "output": "15\n3 6 6\n3 2 2\n1 4 4\n3 1 1\n3 7 7\n3 5 5" }, { "input": "7\n2 7\n7 6\n6 5\n5 4\n4 1\n1 3", "output": "21\n2 3 3\n2 1 1\n2 4 4\n2 5 5\n2 6 6\n2 7 7" }, { "input": "8\n8 6\n8 7\n8 2\n8 5\n8 1\n8 4\n8 3", "output": "13\n1 6 6\n1 7 7\n1 5 5\n1 4 4\n1 3 3\n2 1 1\n2 8 8" }, { "input": "8\n6 3\n3 7\n6 1\n1 2\n3 5\n5 4\n2 8", "output": "26\n8 7 7\n4 8 8\n4 2 2\n4 1 1\n4 6 6\n4 3 3\n4 5 5" }, { "input": "8\n4 1\n1 3\n3 6\n6 2\n2 7\n7 5\n5 8", "output": "28\n8 4 4\n8 1 1\n8 3 3\n8 6 6\n8 2 2\n8 7 7\n8 5 5" }, { "input": "9\n3 2\n3 1\n3 8\n3 5\n3 6\n3 9\n3 4\n3 7", "output": "15\n1 8 8\n1 5 5\n1 6 6\n1 9 9\n1 4 4\n1 7 7\n2 1 1\n2 3 3" }, { "input": "9\n2 6\n6 1\n2 8\n6 7\n1 5\n7 3\n8 9\n5 4", "output": "30\n4 3 3\n4 7 7\n9 4 4\n9 5 5\n9 1 1\n9 6 6\n9 2 2\n9 8 8" }, { "input": "9\n9 4\n4 6\n6 2\n2 1\n1 3\n3 5\n5 8\n8 7", "output": "36\n7 9 9\n7 4 4\n7 6 6\n7 2 2\n7 1 1\n7 3 3\n7 5 5\n7 8 8" }, { "input": "10\n3 2\n3 7\n3 6\n3 8\n3 1\n3 5\n3 9\n3 4\n3 10", "output": "17\n1 7 7\n1 6 6\n1 8 8\n1 5 5\n1 9 9\n1 4 4\n1 10 10\n2 1 1\n2 3 3" }, { "input": "10\n8 2\n8 10\n10 3\n2 4\n3 6\n8 1\n2 7\n10 9\n4 5", "output": "35\n5 9 9\n6 1 1\n6 7 7\n5 6 6\n5 3 3\n5 10 10\n5 8 8\n5 2 2\n5 4 4" }, { "input": "10\n7 10\n10 6\n6 4\n4 5\n5 8\n8 2\n2 1\n1 3\n3 9", "output": "45\n7 9 9\n7 3 3\n7 1 1\n7 2 2\n7 8 8\n7 5 5\n7 4 4\n7 6 6\n7 10 10" }, { "input": "4\n3 4\n4 1\n1 2", "output": "6\n3 2 2\n3 1 1\n3 4 4" }, { "input": "5\n1 4\n4 2\n2 3\n3 5", "output": "10\n5 1 1\n5 4 4\n5 2 2\n5 3 3" }, { "input": "6\n5 3\n3 6\n6 1\n1 4\n4 2", "output": "15\n5 2 2\n5 4 4\n5 1 1\n5 6 6\n5 3 3" }, { "input": "7\n1 2\n2 3\n3 6\n6 7\n7 4\n4 5", "output": "21\n5 1 1\n5 2 2\n5 3 3\n5 6 6\n5 7 7\n5 4 4" }, { "input": "8\n6 2\n2 1\n1 8\n8 5\n5 7\n7 3\n3 4", "output": "28\n4 6 6\n4 2 2\n4 1 1\n4 8 8\n4 5 5\n4 7 7\n4 3 3" }, { "input": "9\n1 6\n6 4\n4 5\n5 9\n9 8\n8 7\n7 3\n3 2", "output": "36\n2 1 1\n2 6 6\n2 4 4\n2 5 5\n2 9 9\n2 8 8\n2 7 7\n2 3 3" }, { "input": "10\n5 1\n1 6\n6 2\n2 8\n8 3\n3 4\n4 10\n10 9\n9 7", "output": "45\n7 5 5\n7 1 1\n7 6 6\n7 2 2\n7 8 8\n7 3 3\n7 4 4\n7 10 10\n7 9 9" }, { "input": "4\n3 4\n3 1\n3 2", "output": "5\n1 4 4\n2 1 1\n2 3 3" }, { "input": "5\n1 4\n1 2\n1 3\n1 5", "output": "7\n3 4 4\n3 5 5\n2 3 3\n2 1 1" }, { "input": "6\n5 3\n5 6\n5 1\n5 4\n5 2", "output": "9\n1 3 3\n1 6 6\n1 4 4\n2 1 1\n2 5 5" }, { "input": "7\n1 2\n1 3\n1 6\n1 7\n1 4\n1 5", "output": "11\n3 6 6\n3 7 7\n3 4 4\n3 5 5\n2 3 3\n2 1 1" }, { "input": "8\n6 2\n6 1\n6 8\n6 5\n6 7\n6 3\n6 4", "output": "13\n1 8 8\n1 5 5\n1 7 7\n1 3 3\n1 4 4\n2 1 1\n2 6 6" }, { "input": "9\n1 6\n1 4\n1 5\n1 9\n1 8\n1 7\n1 3\n1 2", "output": "15\n3 6 6\n3 4 4\n3 5 5\n3 9 9\n3 8 8\n3 7 7\n2 3 3\n2 1 1" }, { "input": "10\n5 1\n5 6\n5 2\n5 8\n5 3\n5 4\n5 10\n5 9\n5 7", "output": "17\n1 6 6\n1 8 8\n1 3 3\n1 4 4\n1 10 10\n1 9 9\n1 7 7\n2 1 1\n2 5 5" }, { "input": "10\n4 10\n10 5\n5 1\n1 6\n6 8\n8 9\n9 2\n9 3\n9 7", "output": "42\n4 3 3\n4 7 7\n2 4 4\n2 10 10\n2 5 5\n2 1 1\n2 6 6\n2 8 8\n2 9 9" }, { "input": "10\n5 8\n8 4\n4 9\n9 6\n6 1\n6 2\n6 7\n6 3\n6 10", "output": "35\n5 2 2\n5 7 7\n5 3 3\n5 10 10\n5 1 1\n5 6 6\n5 9 9\n5 4 4\n5 8 8" }, { "input": "10\n5 6\n6 7\n7 3\n7 8\n7 4\n7 2\n7 1\n7 10\n7 9", "output": "24\n5 3 3\n5 8 8\n5 4 4\n5 2 2\n5 10 10\n5 9 9\n5 1 1\n5 7 7\n5 6 6" } ]
46
0
0
1,476
747
Mammoth's Genome Decoding
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????", "output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT" }, { "input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "===" }, { "input": "4\n??A?", "output": "CGAT" }, { "input": "4\n?C??", "output": "ACGT" }, { "input": "4\nT???", "output": "TACG" }, { "input": "4\n???G", "output": "ACTG" }, { "input": "4\n??AC", "output": "GTAC" }, { "input": "8\n?C?AA???", "output": "CCGAAGTT" }, { "input": "12\n???A?G???A?T", "output": "ACCACGGGTATT" }, { "input": "16\n?????C??CAG??T??", "output": "AAACCCGGCAGGTTTT" }, { "input": "20\n???A?G??C?GC???????G", "output": "AAAAAGCCCCGCGGTTTTTG" }, { "input": "24\n?TG???AT?A?CTTG??T?GCT??", "output": "ATGAAAATCACCTTGCCTGGCTGG" }, { "input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?", "output": "AACTGAAGAGGTCCCGAGTTTTCCACGT" }, { "input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?", "output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT" }, { "input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?", "output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT" }, { "input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??", "output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT" }, { "input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??", "output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT" }, { "input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?", "output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT" }, { "input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG", "output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG" }, { "input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??", "output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT" }, { "input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?", "output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT" }, { "input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C", "output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC" }, { "input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??", "output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT" }, { "input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG", "output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG" }, { "input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG", "output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG" }, { "input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?", "output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG" }, { "input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C", "output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC" }, { "input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?", "output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT" }, { "input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???", "output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT" }, { "input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????", "output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT" }, { "input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT", "output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT" }, { "input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG", "output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG" }, { "input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA", "output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA" }, { "input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??", "output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT" }, { "input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C", "output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC" }, { "input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C", "output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC" }, { "input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G", "output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG" }, { "input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?", "output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT" }, { "input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT", "output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT" }, { "input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?", "output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT" }, { "input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??", "output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT" }, { "input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA", "output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA" }, { "input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?", "output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT" }, { "input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G", "output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG" }, { "input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA", "output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA" }, { "input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?", "output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT" }, { "input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?", "output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG" }, { "input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT", "output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT" }, { "input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA", "output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA" }, { "input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G", "output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG" }, { "input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?", "output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT" }, { "input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T", "output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT" }, { "input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T", "output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT" }, { "input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????", "output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT" }, { "input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??", "output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT" }, { "input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??", "output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT" }, { "input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?", "output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT" }, { "input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT", "output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT" }, { "input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?", "output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT" }, { "input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??", "output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT" }, { "input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?", "output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT" }, { "input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?", "output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT" }, { "input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C", "output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC" }, { "input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC", "output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC" }, { "input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG", "output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG" }, { "input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?", "output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT" }, { "input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC", "output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC" }, { "input": "8\n???AAA??", "output": "===" }, { "input": "12\nC??CC??????C", "output": "===" }, { "input": "4\nG??G", "output": "===" }, { "input": "4\nTT??", "output": "===" }, { "input": "4\nACAC", "output": "===" }, { "input": "8\nACGT???T", "output": "ACGTACGT" }, { "input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG" }, { "input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "4\nAA?T", "output": "===" }, { "input": "4\nAAAA", "output": "===" }, { "input": "8\nAAA?????", "output": "===" }, { "input": "10\nACGT??????", "output": "===" }, { "input": "6\nACGACG", "output": "===" }, { "input": "5\nAAAAA", "output": "===" }, { "input": "8\nGGGGAA??", "output": "===" }, { "input": "5\nATGCA", "output": "===" }, { "input": "4\nTTTT", "output": "===" }, { "input": "4\nACCG", "output": "===" }, { "input": "8\nACGTA?GT", "output": "ACGTACGT" } ]
92
2,252,800
-1
1,480
785
Anton and Fairy Tale
[ "binary search", "math" ]
null
null
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..." More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of *n* grains was full. Then, every day (starting with the first day) the following happens: - *m* grains are brought to the barn. If *m* grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). - Sparrows come and eat grain. In the *i*-th day *i* sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing. Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018) — the capacity of the barn and the number of grains that are brought every day.
Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.
[ "5 2\n", "8 1\n" ]
[ "4\n", "5\n" ]
In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens: - At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. - At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. - At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. - At the end of the second day two sparrows come. 5 - 2 = 3 grains remain. - At the beginning of the third day two grains are brought. The barn becomes full again. - At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain. - At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain. - At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty. So the answer is 4, because by the end of the fourth day the barn becomes empty.
[ { "input": "5 2", "output": "4" }, { "input": "8 1", "output": "5" }, { "input": "32 5", "output": "12" }, { "input": "1024 1024", "output": "1024" }, { "input": "58044 52909", "output": "53010" }, { "input": "996478063 658866858", "output": "658892843" }, { "input": "570441179141911871 511467058318039545", "output": "511467058661475480" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000000000 1000000000000000000", "output": "1000000000000000000" }, { "input": "1000000000000000000 999999999999997145", "output": "999999999999997221" }, { "input": "1 1000000000000000000", "output": "1" }, { "input": "1000000000000000000 1", "output": "1414213563" }, { "input": "999999998765257149 10", "output": "1414213571" }, { "input": "999999998765257150 10", "output": "1414213571" }, { "input": "999999998765257151 10", "output": "1414213571" }, { "input": "999999998765257152 10", "output": "1414213572" }, { "input": "999999998765257153 10", "output": "1414213572" }, { "input": "762078938126917521 107528", "output": "1234675418" }, { "input": "762078938126917522 107528", "output": "1234675418" }, { "input": "762078938126917523 107528", "output": "1234675418" }, { "input": "762078938126917524 107528", "output": "1234675419" }, { "input": "762078938126917525 107528", "output": "1234675419" }, { "input": "443233170968441395 1048576", "output": "942571991" }, { "input": "443233170968441396 1048576", "output": "942571991" }, { "input": "443233170968441397 1048576", "output": "942571992" }, { "input": "1833551251625340 1359260576251", "output": "1359321110406" }, { "input": "1835002539467264 2810548418174", "output": "2810608952329" }, { "input": "1840276176082280 8084185033189", "output": "8084245567345" }, { "input": "262133107905 256256256256", "output": "256256364670" }, { "input": "262133108160 256256256256", "output": "256256364670" }, { "input": "262133108161 256256256256", "output": "256256364670" }, { "input": "262133108162 256256256256", "output": "256256364671" }, { "input": "399823373917798976 326385530977846185", "output": "326385531361089823" }, { "input": "836052329491347820 327211774155929609", "output": "327211775164731428" }, { "input": "870979176282270170 16", "output": "1319832715" }, { "input": "930580173005562081 4", "output": "1364243511" }, { "input": "831613653237860272 154", "output": "1289661856" }, { "input": "867842613106376421 178", "output": "1317454248" }, { "input": "939156247712499033 1902", "output": "1370517314" }, { "input": "975385203286047886 1326", "output": "1396701153" }, { "input": "953065701826839766 4023", "output": "1380631201" }, { "input": "989294657400388618 7447", "output": "1406630820" }, { "input": "885695753008586140 42775", "output": "1330979102" }, { "input": "921924708582134992 158903", "output": "1358043072" }, { "input": "802352815201515314 183504", "output": "1266953266" }, { "input": "861953807629839929 1299632", "output": "1314276256" }, { "input": "925155772916259712 1929889", "output": "1362191462" }, { "input": "961384732784775860 5046017", "output": "1391685648" }, { "input": "910494856396204496 39891744", "output": "1389332262" }, { "input": "946723811969753348 17975168", "output": "1394001194" }, { "input": "992316381103677158 1849603453", "output": "3258373398" }, { "input": "828545340972193305 1027686877", "output": "2314967219" }, { "input": "946697532222325132 16179805162", "output": "17555812078" }, { "input": "982926487795873985 19357888587", "output": "20759977363" }, { "input": "892753091050063317 2037020896", "output": "3373249237" }, { "input": "928982046623612170 45215104320", "output": "46578175853" }, { "input": "845950022554437217 1553155668877", "output": "1554456398264" }, { "input": "882178982422953366 1792038785005", "output": "1793367075026" }, { "input": "847407611288100389 9111983407070", "output": "9113285250762" }, { "input": "883636566861649242 15350866523198", "output": "15352195899906" }, { "input": "988545172809612094 126043487780965", "output": "126044893781768" }, { "input": "824774128383160945 152286665864389", "output": "152287950093217" }, { "input": "889067279135046636 783632221444127", "output": "783633554323452" }, { "input": "925296230413628192 1609871104560255", "output": "1609872463741155" }, { "input": "892888041747308306 15921193742955831", "output": "15921195067317449" }, { "input": "929116997320857159 16747432626071959", "output": "16747433976901012" }, { "input": "810365749050428005 176443295773423092", "output": "176443296899409285" }, { "input": "846594708918944153 177269538951506516", "output": "177269540108507095" }, { "input": "2 1", "output": "2" }, { "input": "2 2", "output": "2" }, { "input": "3 1", "output": "3" }, { "input": "3 2", "output": "3" }, { "input": "3 3", "output": "3" }, { "input": "4 1", "output": "3" }, { "input": "4 2", "output": "4" }, { "input": "256 20", "output": "42" }, { "input": "78520 8", "output": "404" }, { "input": "1367064836 777314907868410435", "output": "1367064836" }, { "input": "658866858 996478063", "output": "658866858" }, { "input": "10 648271718824741275", "output": "10" }, { "input": "326385530977846185 399823373917798976", "output": "326385530977846185" }, { "input": "327211774155929609 836052329491347820", "output": "327211774155929609" }, { "input": "2570 566042149577952145", "output": "2570" }, { "input": "512486308421983105 512486308421983105", "output": "512486308421983105" }, { "input": "262144 262144", "output": "262144" }, { "input": "314159265358979323 314159265358979323", "output": "314159265358979323" }, { "input": "16 5", "output": "10" }, { "input": "29 16", "output": "21" }, { "input": "24 14", "output": "18" }, { "input": "28 18", "output": "22" }, { "input": "8 11", "output": "8" }, { "input": "500000000500004239 4242", "output": "1000004242" }, { "input": "500000000500004240 4242", "output": "1000004242" }, { "input": "500000000500004241 4242", "output": "1000004242" }, { "input": "500000000500004242 4242", "output": "1000004242" }, { "input": "500000000500004243 4242", "output": "1000004243" }, { "input": "500000000500004244 4242", "output": "1000004243" }, { "input": "500000000500004245 4242", "output": "1000004243" }, { "input": "163162808800191208 163162808800191206", "output": "163162808800191208" }, { "input": "328584130811799021 328584130811799020", "output": "328584130811799021" }, { "input": "89633000579612779 89633000579612778", "output": "89633000579612779" }, { "input": "924211674273037668 924211674273037666", "output": "924211674273037668" }, { "input": "758790352261429854 758790352261429851", "output": "758790352261429853" }, { "input": "39154349371830603 39154349371830597", "output": "39154349371830600" }, { "input": "313727604417502165 313727604417502155", "output": "313727604417502159" }, { "input": "1000000000000000000 999999999999999999", "output": "1000000000000000000" }, { "input": "1000000000000000000 999999999999999998", "output": "1000000000000000000" }, { "input": "1000000000000000000 999999999999999997", "output": "999999999999999999" }, { "input": "1000000000000000000 999999999999999996", "output": "999999999999999999" }, { "input": "1000000000000000000 999999999999999995", "output": "999999999999999998" }, { "input": "1 5", "output": "1" }, { "input": "1 100", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "6 9", "output": "6" }, { "input": "1000000000000000000 2", "output": "1414213564" }, { "input": "1 10", "output": "1" }, { "input": "5 15", "output": "5" }, { "input": "12 1", "output": "6" }, { "input": "1000000000000000000 100000000000000000", "output": "100000001341640786" }, { "input": "100 200", "output": "100" }, { "input": "1 1000000000000000", "output": "1" }, { "input": "100000000000000000 1", "output": "447213596" }, { "input": "1000000000000000000 1000000000000000", "output": "1000001413506279" }, { "input": "1 9", "output": "1" }, { "input": "1000000000000000000 4", "output": "1414213566" }, { "input": "1000000000000 10000000000000", "output": "1000000000000" }, { "input": "1 100000", "output": "1" }, { "input": "3 7", "output": "3" }, { "input": "2 3", "output": "2" }, { "input": "1 8", "output": "1" }, { "input": "5 10", "output": "5" }, { "input": "10 11", "output": "10" }, { "input": "10 100", "output": "10" }, { "input": "5 16", "output": "5" }, { "input": "2 10", "output": "2" }, { "input": "10836 16097", "output": "10836" }, { "input": "16808 75250", "output": "16808" }, { "input": "900000000000169293 1", "output": "1341640788" }, { "input": "1 10000000", "output": "1" }, { "input": "2 100", "output": "2" }, { "input": "10 20", "output": "10" }, { "input": "10 10000", "output": "10" }, { "input": "4 5", "output": "4" }, { "input": "1 2", "output": "1" }, { "input": "1000000000000000000 5", "output": "1414213567" }, { "input": "2 5", "output": "2" }, { "input": "4 6", "output": "4" }, { "input": "999999998765257147 1", "output": "1414213563" }, { "input": "3 10", "output": "3" }, { "input": "997270248313594436 707405570208615798", "output": "707405570970015402" }, { "input": "1 100000000000", "output": "1" }, { "input": "6 1000000", "output": "6" }, { "input": "16808 282475250", "output": "16808" }, { "input": "1000000007 100000000000007", "output": "1000000007" }, { "input": "1 1000", "output": "1" }, { "input": "1000000000000000 10000000000000000", "output": "1000000000000000" }, { "input": "1000000000000000000 100", "output": "1414213662" }, { "input": "1000000000000000000 9", "output": "1414213571" }, { "input": "900000000000169293 171", "output": "1341640957" }, { "input": "1 999999999999", "output": "1" }, { "input": "10000 10000000000000", "output": "10000" }, { "input": "1 9999999999999", "output": "1" }, { "input": "695968090125646936 429718492544794353", "output": "429718493274519777" }, { "input": "2 5000", "output": "2" }, { "input": "8 100", "output": "8" }, { "input": "2 7", "output": "2" }, { "input": "999999999999999999 1", "output": "1414213563" }, { "input": "5 8", "output": "5" }, { "input": "1000000000000000000 99999999999999999", "output": "100000001341640785" }, { "input": "100000000000000000 100000000000000000", "output": "100000000000000000" }, { "input": "5 6", "output": "5" }, { "input": "1000000000000000000 1000000000", "output": "2414213562" }, { "input": "1 10000", "output": "1" }, { "input": "22 11", "output": "16" }, { "input": "10 10000000", "output": "10" }, { "input": "3 8", "output": "3" }, { "input": "10 123123", "output": "10" }, { "input": "3 5", "output": "3" }, { "input": "1000000000000000000 10", "output": "1414213572" }, { "input": "10000000000000 45687987897897", "output": "10000000000000" }, { "input": "5 4", "output": "5" }, { "input": "5000 123456789", "output": "5000" }, { "input": "7 100", "output": "7" }, { "input": "1000000000000000000 500000000000", "output": "501414213209" }, { "input": "8 7", "output": "8" }, { "input": "1 10000000000", "output": "1" }, { "input": "1000000000000000000 15", "output": "1414213577" }, { "input": "1 123456789", "output": "1" }, { "input": "2 1000", "output": "2" }, { "input": "5 11", "output": "5" }, { "input": "1 1000000000", "output": "1" }, { "input": "1000000000000000000 499999999999999999", "output": "500000000999999999" }, { "input": "1 100000000", "output": "1" }, { "input": "619768314833382029 108339531052386197", "output": "108339532063750408" }, { "input": "5 100", "output": "5" }, { "input": "2 10000", "output": "2" }, { "input": "1000000000000000000 500000000000000000", "output": "500000001000000000" }, { "input": "143 3", "output": "20" }, { "input": "2 6", "output": "2" }, { "input": "100 1000000000", "output": "100" }, { "input": "2 100000000000000000", "output": "2" }, { "input": "100000000000000000 1000000000000000000", "output": "100000000000000000" }, { "input": "999999999999999999 123456789", "output": "1537670351" }, { "input": "1 99999", "output": "1" }, { "input": "1000000000000000000 9999999999", "output": "11414213554" }, { "input": "5 100000000000000000", "output": "5" }, { "input": "6 999999", "output": "6" }, { "input": "100 10000000", "output": "100" }, { "input": "4 100", "output": "4" }, { "input": "1000000000 1000000000000000", "output": "1000000000" }, { "input": "10 100000", "output": "10" }, { "input": "5 15555555", "output": "5" }, { "input": "5 155555", "output": "5" }, { "input": "200 9999999999", "output": "200" }, { "input": "3 200", "output": "3" }, { "input": "1000000000000000000 490000000000000000", "output": "490000001009950494" }, { "input": "2 4", "output": "2" }, { "input": "5 15555", "output": "5" }, { "input": "5 7", "output": "5" }, { "input": "10040 200000", "output": "10040" }, { "input": "1000000000000000000 60000000000000000", "output": "60000001371130920" }, { "input": "10 1000000000000", "output": "10" }, { "input": "1 45", "output": "1" } ]
514
25,600,000
0
1,482
441
Valera and Antique Items
[ "implementation" ]
null
null
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
[ "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n" ]
[ "3\n1 2 3\n", "0\n\n" ]
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
[ { "input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3" }, { "input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0" }, { "input": "2 100001\n1 895737\n1 541571", "output": "0" }, { "input": "1 1000000\n1 1000000", "output": "0" }, { "input": "1 1000000\n1 561774", "output": "1\n1" }, { "input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "2\n1 2" }, { "input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000", "output": "0" }, { "input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236", "output": "3\n1 2 3" }, { "input": "1 50001\n1 50000", "output": "1\n1" } ]
109
0
3
1,485
0
none
[ "none" ]
null
null
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches *p*1, it'll move to *p*2, again, choosing one of the shortest ways, then to *p*3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order. While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.
The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robot traveled the *k*-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.
The only line of input should contain the minimum possible length of the sequence.
[ "4\nRURD\n", "6\nRRULDD\n", "26\nRRRULURURUULULLLDLDDRDRDLD\n", "3\nRLL\n", "4\nLRLR\n" ]
[ "2\n", "2\n", "7\n", "2\n", "4\n" ]
The illustrations to the first three tests are given below. <img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1f.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/c7b4534f24cbad48148bcba24bc44f37bf7a2dbf.png" style="max-width: 100.0%;max-height: 100.0%;"/> The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.
[ { "input": "4\nRURD", "output": "2" }, { "input": "6\nRRULDD", "output": "2" }, { "input": "26\nRRRULURURUULULLLDLDDRDRDLD", "output": "7" }, { "input": "3\nRLL", "output": "2" }, { "input": "4\nLRLR", "output": "4" }, { "input": "5\nLRDLR", "output": "4" }, { "input": "10\nDDRDUULUDD", "output": "3" }, { "input": "1\nD", "output": "1" } ]
2,000
5,222,400
0
1,489
864
Fair Game
[ "implementation", "sortings" ]
null
null
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards.
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
[ "4\n11\n27\n27\n11\n", "2\n6\n6\n", "6\n10\n20\n30\n20\n10\n20\n", "6\n1\n1\n2\n2\n3\n3\n" ]
[ "YES\n11 27\n", "NO\n", "NO\n", "NO\n" ]
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct. In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
[ { "input": "4\n11\n27\n27\n11", "output": "YES\n11 27" }, { "input": "2\n6\n6", "output": "NO" }, { "input": "6\n10\n20\n30\n20\n10\n20", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n3\n3", "output": "NO" }, { "input": "2\n1\n100", "output": "YES\n1 100" }, { "input": "2\n1\n1", "output": "NO" }, { "input": "2\n100\n100", "output": "NO" }, { "input": "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43", "output": "NO" }, { "input": "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32", "output": "YES\n14 32" }, { "input": "2\n50\n100", "output": "YES\n50 100" }, { "input": "2\n99\n100", "output": "YES\n99 100" }, { "input": "4\n4\n4\n5\n5", "output": "YES\n4 5" }, { "input": "10\n10\n10\n10\n10\n10\n23\n23\n23\n23\n23", "output": "YES\n10 23" }, { "input": "20\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n11\n11\n11\n11\n11\n11\n11\n11\n11\n11", "output": "YES\n11 34" }, { "input": "40\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30", "output": "YES\n20 30" }, { "input": "58\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "YES\n1 100" }, { "input": "98\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99", "output": "YES\n2 99" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\n1 100" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2", "output": "YES\n1 2" }, { "input": "100\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "output": "YES\n12 49" }, { "input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94", "output": "YES\n15 94" }, { "input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42", "output": "YES\n33 42" }, { "input": "100\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35", "output": "YES\n16 35" }, { "input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44", "output": "YES\n33 44" }, { "input": "100\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98", "output": "YES\n54 98" }, { "input": "100\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "output": "YES\n12 81" }, { "input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "NO" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "NO" }, { "input": "40\n20\n20\n30\n30\n20\n20\n20\n30\n30\n20\n20\n30\n30\n30\n30\n20\n30\n30\n30\n30\n20\n20\n30\n30\n30\n20\n30\n20\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n30", "output": "NO" }, { "input": "58\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n100\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n1\n1\n1\n1\n1", "output": "NO" }, { "input": "98\n2\n99\n99\n99\n99\n2\n99\n99\n99\n2\n2\n99\n2\n2\n2\n2\n99\n99\n2\n99\n2\n2\n99\n99\n99\n99\n2\n2\n99\n2\n99\n99\n2\n2\n99\n2\n99\n2\n99\n2\n2\n2\n99\n2\n2\n2\n2\n99\n99\n99\n99\n2\n2\n2\n2\n2\n2\n2\n2\n99\n2\n99\n99\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n2\n99\n2\n99\n2\n2\n2\n99\n99\n99\n99\n99\n99\n2\n99\n99\n2\n2\n2\n2\n2\n99\n99\n99\n2", "output": "NO" }, { "input": "100\n100\n1\n100\n1\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n1\n100\n1\n100\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n1\n100\n1\n1\n100\n100\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n100\n100\n100\n100\n1\n100\n100\n1\n100\n100\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n100\n1\n1\n100\n1\n100\n100\n1\n100\n1\n100", "output": "NO" }, { "input": "100\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n1\n100\n1\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n1\n100\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n100\n1\n100\n1\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n36\n100\n1\n100\n1\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n1\n1\n100\n100\n100\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n1\n100", "output": "NO" }, { "input": "100\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n2\n1\n27\n1\n1\n1\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1", "output": "NO" }, { "input": "100\n99\n99\n100\n99\n99\n100\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n100\n99\n99\n99\n100\n99\n10\n99\n100\n100\n100\n99\n100\n100\n100\n100\n100\n100\n100\n99\n100\n100\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n100\n100\n99\n99\n99\n99\n99\n99\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n100\n100", "output": "NO" }, { "input": "100\n29\n43\n43\n29\n43\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n43\n43\n29\n29\n43\n43\n43\n29\n43\n43\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n29\n29\n29\n29\n43\n29\n43\n43\n29\n29\n43\n43\n29\n29\n95\n29\n29\n29\n43\n43\n29\n29\n29\n29\n29\n43\n43\n43\n43\n29\n29\n43\n43\n43\n43\n43\n43\n29\n43\n43\n43\n43\n43\n43\n29\n43\n29\n43", "output": "NO" }, { "input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n98\n88\n98\n88\n98\n88\n88\n88\n88\n88\n98\n98\n88\n98\n98\n98\n88\n88\n88\n98\n98\n88\n88\n88\n98\n88\n98\n88\n98\n88\n88\n98\n98\n98\n88\n88\n98\n98\n88\n88\n88\n88\n88\n98\n98\n98\n88\n98\n88\n88\n98\n98\n88\n98\n88\n88\n98\n88\n88\n98\n27\n88\n88\n88\n98\n98\n88\n88\n98\n98\n98\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88", "output": "NO" }, { "input": "100\n50\n1\n1\n50\n50\n50\n50\n1\n50\n100\n50\n50\n50\n100\n1\n100\n1\n100\n50\n50\n50\n50\n50\n1\n50\n1\n100\n1\n1\n50\n100\n50\n50\n100\n50\n50\n100\n1\n50\n50\n100\n1\n1\n50\n1\n100\n50\n50\n100\n100\n1\n100\n1\n50\n100\n50\n50\n1\n1\n50\n100\n50\n100\n100\n100\n50\n50\n1\n1\n50\n100\n1\n50\n100\n100\n1\n50\n50\n50\n100\n50\n50\n100\n1\n50\n50\n50\n50\n1\n50\n50\n50\n50\n1\n50\n50\n100\n1\n50\n100", "output": "NO" }, { "input": "100\n45\n45\n45\n45\n45\n45\n44\n44\n44\n43\n45\n44\n44\n45\n44\n44\n45\n44\n43\n44\n43\n43\n43\n45\n43\n45\n44\n45\n43\n44\n45\n45\n45\n45\n45\n45\n45\n45\n43\n45\n43\n43\n45\n44\n45\n45\n45\n44\n45\n45\n45\n45\n45\n45\n44\n43\n45\n45\n43\n44\n45\n45\n45\n45\n44\n45\n45\n45\n43\n43\n44\n44\n43\n45\n43\n45\n45\n45\n44\n44\n43\n43\n44\n44\n44\n43\n45\n43\n44\n43\n45\n43\n43\n45\n45\n44\n45\n43\n43\n45", "output": "NO" }, { "input": "100\n12\n12\n97\n15\n97\n12\n15\n97\n12\n97\n12\n12\n97\n12\n15\n12\n12\n15\n12\n12\n97\n12\n12\n15\n15\n12\n97\n15\n12\n97\n15\n12\n12\n15\n15\n15\n97\n15\n97\n12\n12\n12\n12\n12\n97\n12\n97\n12\n15\n15\n12\n15\n12\n15\n12\n12\n12\n12\n12\n12\n12\n12\n97\n97\n12\n12\n97\n12\n97\n97\n15\n97\n12\n97\n97\n12\n12\n12\n97\n97\n15\n12\n12\n15\n12\n15\n97\n97\n12\n15\n12\n12\n97\n12\n15\n15\n15\n15\n12\n12", "output": "NO" }, { "input": "12\n2\n3\n1\n3\n3\n1\n2\n1\n2\n1\n3\n2", "output": "NO" }, { "input": "48\n99\n98\n100\n100\n99\n100\n99\n100\n100\n98\n99\n98\n98\n99\n98\n99\n98\n100\n100\n98\n100\n98\n99\n100\n98\n99\n98\n99\n99\n100\n98\n99\n99\n98\n100\n99\n98\n99\n98\n100\n100\n100\n99\n98\n99\n98\n100\n100", "output": "NO" }, { "input": "4\n1\n3\n3\n3", "output": "NO" }, { "input": "6\n1\n1\n1\n1\n2\n2", "output": "NO" }, { "input": "4\n1\n1\n1\n2", "output": "NO" }, { "input": "4\n1\n2\n2\n2", "output": "NO" }, { "input": "4\n1\n2\n3\n4", "output": "NO" }, { "input": "8\n1\n1\n2\n2\n3\n3\n4\n4", "output": "NO" }, { "input": "4\n1\n3\n2\n4", "output": "NO" }, { "input": "4\n10\n10\n10\n20", "output": "NO" }, { "input": "4\n11\n12\n13\n13", "output": "NO" }, { "input": "4\n1\n1\n1\n3", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n2\n2", "output": "NO" }, { "input": "10\n1\n1\n2\n2\n2\n3\n3\n4\n4\n4", "output": "NO" } ]
46
0
0
1,492
574
Bear and Elections
[ "greedy", "implementation" ]
null
null
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?
The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
[ "5\n5 1 11 2 8\n", "4\n1 8 8 8\n", "2\n7 6\n" ]
[ "4\n", "6\n", "0\n" ]
In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
[ { "input": "5\n5 1 11 2 8", "output": "4" }, { "input": "4\n1 8 8 8", "output": "6" }, { "input": "2\n7 6", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "10\n100 200 57 99 1 1000 200 200 200 500", "output": "451" }, { "input": "16\n7 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "932" }, { "input": "100\n47 64 68 61 68 66 69 61 69 65 69 63 62 60 68 65 64 65 65 62 63 68 60 70 63 63 65 67 70 69 68 69 61 65 63 60 60 65 61 60 70 66 66 65 62 60 65 68 61 62 67 64 66 65 67 68 60 69 70 63 65 62 64 65 67 67 69 68 66 69 70 67 65 70 60 66 70 67 67 64 69 69 66 68 60 64 62 62 68 69 67 69 60 70 69 68 62 63 68 66", "output": "23" }, { "input": "2\n96 97", "output": "1" }, { "input": "2\n1000 1000", "output": "1" }, { "input": "3\n999 1000 1000", "output": "2" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "7\n10 940 926 990 946 980 985", "output": "817" }, { "input": "10\n5 3 4 5 5 2 1 8 4 1", "output": "2" }, { "input": "15\n17 15 17 16 13 17 13 16 14 14 17 17 13 15 17", "output": "1" }, { "input": "20\n90 5 62 9 50 7 14 43 44 44 56 13 71 22 43 35 52 60 73 54", "output": "0" }, { "input": "30\n27 85 49 7 77 38 4 68 23 28 81 100 40 9 78 38 1 60 60 49 98 44 45 92 46 39 98 24 37 39", "output": "58" }, { "input": "51\n90 47 100 12 21 96 2 68 84 60 2 9 33 8 45 13 59 50 100 93 22 97 4 81 51 2 3 78 19 16 25 63 52 34 79 32 34 87 7 42 96 93 30 33 33 43 69 8 63 58 57", "output": "8" }, { "input": "77\n1000 2 2 3 1 1 1 3 3 2 1 1 3 2 2 2 3 2 3 1 3 1 1 2 2 2 3 1 1 2 2 2 3 2 1 3 3 1 2 3 3 3 2 1 3 2 1 3 3 2 3 3 2 1 3 1 1 1 2 3 2 3 1 3 1 2 1 2 2 2 1 2 2 3 2 2 2", "output": "0" }, { "input": "91\n3 92 89 83 85 80 91 94 95 82 92 95 80 88 90 85 81 90 87 86 94 88 90 87 88 82 95 84 84 93 83 95 91 85 89 88 88 85 87 90 93 80 89 95 94 92 93 86 83 82 86 84 91 80 90 95 84 86 84 85 84 92 82 84 83 91 87 95 94 95 90 95 86 92 86 80 95 86 88 80 82 87 84 83 91 93 81 81 91 89 88", "output": "89" }, { "input": "100\n1 3 71 47 64 82 58 61 61 35 52 36 57 62 63 54 52 21 78 100 24 94 4 80 99 62 43 72 21 70 90 4 23 14 72 4 76 49 71 96 96 99 78 7 32 11 14 61 19 69 1 68 100 77 86 54 14 86 47 53 30 88 67 66 61 70 17 63 40 5 99 53 38 31 91 18 41 5 77 61 53 30 87 21 23 54 52 17 23 75 58 99 99 63 20 1 78 72 28 11", "output": "90" }, { "input": "100\n1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "99" }, { "input": "94\n3 100 100 99 99 99 100 99 99 99 99 99 100 99 100 100 99 100 99 99 100 99 100 99 100 100 100 99 100 99 100 99 100 99 99 99 100 99 99 99 99 99 100 99 100 100 99 100 99 99 99 99 100 99 100 99 99 99 100 100 99 100 100 99 99 100 100 100 99 100 99 99 99 99 99 100 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 99 100 100", "output": "97" }, { "input": "97\n99 99 98 98 100 98 99 99 98 100 100 100 99 99 100 99 99 98 99 99 98 98 98 100 100 99 98 99 100 98 99 98 98 100 98 99 100 98 98 99 98 98 99 98 100 99 99 99 99 98 98 98 100 99 100 100 99 99 100 99 99 98 98 98 100 100 98 100 100 99 98 99 100 98 98 98 98 99 99 98 98 99 100 100 98 98 99 98 99 100 98 99 100 98 99 99 100", "output": "2" }, { "input": "100\n100 55 70 81 73 51 6 75 45 85 33 61 98 63 11 59 1 8 14 28 78 74 44 80 7 69 7 5 90 73 43 78 64 64 43 92 59 70 80 19 33 39 31 70 38 85 24 23 86 79 98 56 92 63 92 4 36 8 79 74 2 81 54 13 69 44 49 63 17 76 78 99 42 36 47 71 19 90 9 58 83 53 27 2 35 51 65 59 90 51 74 87 84 48 98 44 84 100 84 93", "output": "1" }, { "input": "100\n100 637 498 246 615 901 724 673 793 33 282 908 477 185 185 969 34 859 90 70 107 492 227 918 919 131 620 182 802 703 779 184 403 891 448 499 628 553 905 392 70 396 8 575 66 908 992 496 792 174 667 355 836 610 855 377 244 827 836 808 667 354 800 114 746 556 75 894 162 367 99 718 394 273 833 776 151 433 315 470 759 12 552 613 85 793 775 649 225 86 296 624 557 201 209 595 697 527 282 168", "output": "749" }, { "input": "100\n107 172 549 883 564 56 399 970 173 990 224 217 601 381 948 631 159 958 512 136 61 584 633 202 652 355 26 723 663 237 410 721 688 552 699 24 748 186 461 88 34 243 872 205 471 298 654 693 244 33 359 533 471 116 386 653 654 887 531 303 335 829 319 340 827 89 602 191 422 289 361 200 593 421 592 402 256 813 606 589 741 9 148 893 3 142 50 169 219 360 642 45 810 818 507 624 561 743 303 111", "output": "729" }, { "input": "90\n670 694 651 729 579 539 568 551 707 638 604 544 502 531 775 805 558 655 506 729 802 778 653 737 591 770 594 535 588 604 658 713 779 705 504 563 513 651 529 572 505 553 515 750 621 574 727 774 714 725 665 798 670 747 751 635 755 798 635 717 583 682 517 546 740 802 743 507 658 700 645 671 533 594 506 633 768 584 672 666 703 522 530 501 592 528 678 708 619 786", "output": "111" }, { "input": "90\n10 265 429 431 343 305 806 746 284 313 503 221 594 351 83 653 232 431 427 610 458 88 255 215 529 205 492 549 55 694 535 104 45 327 816 432 595 549 454 141 216 557 250 415 531 494 190 749 718 380 78 447 784 347 196 814 16 780 262 462 776 315 160 307 593 694 692 41 528 725 376 777 337 44 438 630 345 502 384 184 742 429 570 361 394 267 820 778 662 377", "output": "714" }, { "input": "95\n800 280 176 472 587 763 588 838 760 378 667 231 566 278 713 305 354 815 140 220 188 409 109 180 251 268 474 590 853 143 235 691 313 785 386 92 783 471 43 342 718 592 678 404 256 362 239 504 163 85 521 81 356 73 754 589 380 159 196 862 838 509 149 42 366 630 467 292 698 123 187 796 576 37 689 800 186 518 488 432 159 860 349 799 282 304 880 283 23 312 55 507 734 370 490", "output": "52" }, { "input": "100\n95 88 84 85 74 97 100 52 91 94 62 66 90 56 86 66 95 73 79 68 54 67 99 52 82 62 81 71 93 85 72 72 95 52 72 63 57 90 92 89 88 77 84 78 95 59 72 86 98 64 89 64 80 70 54 93 88 86 79 78 94 64 89 66 50 90 54 82 52 96 99 54 81 66 83 79 69 80 51 73 81 69 93 82 76 52 58 87 93 92 52 67 78 63 63 87 77 95 58 78", "output": "4" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "100\n999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "2" }, { "input": "100\n901 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "99" }, { "input": "4\n8 5 11 3", "output": "2" }, { "input": "3\n3 10 1", "output": "4" } ]
62
1,740,800
3
1,494
192
Funky Numbers
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712", "output": "NO" }, { "input": "190492", "output": "YES" }, { "input": "5722367", "output": "NO" }, { "input": "816761542", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "NO" }, { "input": "9", "output": "YES" }, { "input": "10", "output": "NO" }, { "input": "12", "output": "YES" }, { "input": "13", "output": "YES" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "16", "output": "YES" }, { "input": "17", "output": "NO" }, { "input": "18", "output": "YES" }, { "input": "19", "output": "NO" }, { "input": "20", "output": "YES" }, { "input": "41", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "69", "output": "YES" }, { "input": "82", "output": "NO" }, { "input": "85", "output": "NO" }, { "input": "736", "output": "NO" }, { "input": "895", "output": "YES" }, { "input": "934", "output": "YES" }, { "input": "6213", "output": "YES" }, { "input": "7405", "output": "NO" }, { "input": "9919", "output": "NO" }, { "input": "40942", "output": "YES" }, { "input": "41992", "output": "NO" }, { "input": "68535", "output": "NO" }, { "input": "405718", "output": "NO" }, { "input": "1046146", "output": "YES" }, { "input": "3761248", "output": "YES" }, { "input": "6195181", "output": "YES" }, { "input": "35354345", "output": "NO" }, { "input": "81282830", "output": "NO" }, { "input": "187719774", "output": "NO" }, { "input": "296798673", "output": "NO" }, { "input": "938938476", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "999887464", "output": "YES" }, { "input": "999111944", "output": "NO" }, { "input": "999966520", "output": "YES" }, { "input": "999912080", "output": "NO" }, { "input": "999992017", "output": "YES" }, { "input": "999990474", "output": "NO" }, { "input": "999999190", "output": "YES" }, { "input": "999999125", "output": "NO" }, { "input": "999999940", "output": "YES" }, { "input": "999999995", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "83495494", "output": "NO" }, { "input": "968022000", "output": "YES" }, { "input": "399980000", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "999999998", "output": "NO" } ]
62
0
0
1,497
792
Counting-out Rhyme
[ "implementation" ]
null
null
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8,<=10,<=13,<=14,<=16] currently in the circle, the leader is child 13 and *a**i*<==<=12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step.
The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1). The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109).
Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step.
[ "7 5\n10 4 11 4 1\n", "3 2\n2 5\n" ]
[ "4 2 5 6 1 \n", "3 2 \n" ]
Let's consider first example: - In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader. - In the final step child 1 is eliminated, child 3 becomes the leader.
[ { "input": "7 5\n10 4 11 4 1", "output": "4 2 5 6 1 " }, { "input": "3 2\n2 5", "output": "3 2 " }, { "input": "2 1\n1", "output": "2 " }, { "input": "2 1\n2", "output": "1 " }, { "input": "2 1\n3", "output": "2 " }, { "input": "10 7\n5 10 4 3 8 10 6", "output": "6 8 3 9 2 4 10 " }, { "input": "10 8\n12 6 12 15 20 8 17 12", "output": "3 10 6 8 2 9 4 5 " }, { "input": "12 10\n76 58 82 54 97 46 17 40 36 15", "output": "5 9 12 1 3 10 8 11 2 4 " }, { "input": "12 6\n76 61 94 15 66 26", "output": "5 12 6 2 7 3 " }, { "input": "90 10\n1045 8705 6077 3282 1459 9809 383 6206 2674 7274", "output": "56 39 45 20 17 55 14 85 51 33 " }, { "input": "100 30\n601771 913885 829106 91674 465657 367068 142461 873149 294276 916519 720701 370006 551782 321506 68525 570684 81178 724855 564907 661130 10112 983124 799801 100639 766045 862312 513021 232094 979480 408554", "output": "72 89 16 26 85 73 29 99 63 30 8 46 70 19 100 93 36 54 65 77 17 79 62 64 21 69 42 82 68 1 " }, { "input": "3 2\n20148340 81473314", "output": "2 3 " }, { "input": "3 2\n301633543 643389490", "output": "2 3 " }, { "input": "6 5\n532623340 628883728 583960589 690950241 488468353", "output": "5 3 6 1 4 " }, { "input": "6 2\n458995521 294343587", "output": "4 1 " }, { "input": "68 1\n5", "output": "6 " } ]
62
0
3
1,499
412
Poster
[ "greedy", "implementation" ]
null
null
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on. Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left. Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
In *t* lines, print the actions the programmers need to make. In the *i*-th line print: - "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder". The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
[ "2 2\nR1\n", "2 1\nR1\n", "6 4\nGO?GO!\n" ]
[ "PRINT 1\nLEFT\nPRINT R\n", "PRINT R\nRIGHT\nPRINT 1\n", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n" ]
Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
[ { "input": "2 2\nR1", "output": "PRINT 1\nLEFT\nPRINT R" }, { "input": "2 1\nR1", "output": "PRINT R\nRIGHT\nPRINT 1" }, { "input": "6 4\nGO?GO!", "output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G" }, { "input": "7 3\nME,YOU.", "output": "LEFT\nLEFT\nPRINT M\nRIGHT\nPRINT E\nRIGHT\nPRINT ,\nRIGHT\nPRINT Y\nRIGHT\nPRINT O\nRIGHT\nPRINT U\nRIGHT\nPRINT ." }, { "input": "10 1\nEK5JQMS5QN", "output": "PRINT E\nRIGHT\nPRINT K\nRIGHT\nPRINT 5\nRIGHT\nPRINT J\nRIGHT\nPRINT Q\nRIGHT\nPRINT M\nRIGHT\nPRINT S\nRIGHT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT N" }, { "input": "85 84\n73IW80UODC8B,UR7S8WMNATV0JSRF4W0B2VV8LCAX6SGCYY8?LHDKJEO29WXQWT9.WY1VY7408S1W04GNDZPK", "output": "RIGHT\nPRINT K\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT G\nLEFT\nPRINT 4\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT 1\nLEFT\nPRINT S\nLEFT\nPRINT 8\nLEFT\nPRINT 0\nLEFT\nPRINT 4\nLEFT\nPRINT 7\nLEFT\nPRINT Y\nLEFT\nPRINT V\nLEFT\nPRINT 1\nLEFT\nPRINT Y\nLEFT\nPRINT W\nLEFT\nPRINT .\nLEFT\nPRINT 9\nLEFT\nPRINT T\nLEFT\nPRINT W\nLEFT\nPRINT Q\nLEFT\nPRINT X\nLEFT\nPRINT W\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT O\nLEFT\nPRINT E\nLEFT\nPRINT J\nLEFT\nPRINT K\nLEFT\nPRINT D\n..." }, { "input": "59 53\n7NWD!9PC11C8S4TQABBTJO,?CO6YGOM!W0QR94CZJBD9U1YJY23YB354,8F", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT F\nLEFT\nPRINT 8\nLEFT\nPRINT ,\nLEFT\nPRINT 4\nLEFT\nPRINT 5\nLEFT\nPRINT 3\nLEFT\nPRINT B\nLEFT\nPRINT Y\nLEFT\nPRINT 3\nLEFT\nPRINT 2\nLEFT\nPRINT Y\nLEFT\nPRINT J\nLEFT\nPRINT Y\nLEFT\nPRINT 1\nLEFT\nPRINT U\nLEFT\nPRINT 9\nLEFT\nPRINT D\nLEFT\nPRINT B\nLEFT\nPRINT J\nLEFT\nPRINT Z\nLEFT\nPRINT C\nLEFT\nPRINT 4\nLEFT\nPRINT 9\nLEFT\nPRINT R\nLEFT\nPRINT Q\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRIN..." }, { "input": "100 79\nF2.58O.L4A!QX!,.,YQUE.RZW.ENQCZKUFNG?.J6FT?L59BIHKFB?,44MAHSTD8?Z.UP3N!76YW6KVI?4AKWDPP0?3HPERM3PCUR", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT R\nLEFT\nPRINT U\nLEFT\nPRINT C\nLEFT\nPRINT P\nLEFT\nPRINT 3\nLEFT\nPRINT M\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT 3\nLEFT\nPRINT ?\nLEFT\nPRINT 0\nLEFT\nPRINT P\nLEFT\nPRINT P\nLEFT\nPRINT D\nLEFT\nPRINT W\nLEFT\nPRINT K\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT ?\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT K\nLEFT\nPRIN..." }, { "input": "1 1\n!", "output": "PRINT !" }, { "input": "34 20\n.C0QPPSWQKGBSH0,VGM!N,5SX.M9Q,D1DT", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT T\nLEFT\nPRINT D\nLEFT\nPRINT 1\nLEFT\nPRINT D\nLEFT\nPRINT ,\nLEFT\nPRINT Q\nLEFT\nPRINT 9\nLEFT\nPRINT M\nLEFT\nPRINT .\nLEFT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT 5\nLEFT\nPRINT ,\nLEFT\nPRINT N\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT V\nLEFT\nPRINT ,\nLEFT\nPRINT 0\nLEFT\nPRINT H\nLEFT\nPRINT S\nLEFT\nPRINT B\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT Q\nLEFT\nPRINT W\nLEFT\nPRINT S\n..." }, { "input": "99 98\nR8MZTEG240LNHY33H7.2CMWM73ZK,P5R,RGOA,KYKMIOG7CMPNHV3R2KM,N374IP8HN97XVMG.PSIPS8H3AXFGK0CJ76,EVKRZ9", "output": "RIGHT\nPRINT 9\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT K\nLEFT\nPRINT V\nLEFT\nPRINT E\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT 7\nLEFT\nPRINT J\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT K\nLEFT\nPRINT G\nLEFT\nPRINT F\nLEFT\nPRINT X\nLEFT\nPRINT A\nLEFT\nPRINT 3\nLEFT\nPRINT H\nLEFT\nPRINT 8\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT I\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT .\nLEFT\nPRINT G\nLEFT\nPRINT M\nLEFT\nPRINT V\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT N\nLEFT\nPRINT H\n..." }, { "input": "98 72\n.1?7CJ!EFZHO5WUKDZV,0EE92PTAGY078WKN!!41E,Q7381U60!9C,VONEZ6!SFFNDBI86MACX0?D?9!U2UV7S,977PNDSF0HY", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT Y\nLEFT\nPRINT H\nLEFT\nPRINT 0\nLEFT\nPRINT F\nLEFT\nPRINT S\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT P\nLEFT\nPRINT 7\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT ,\nLEFT\nPRINT S\nLEFT\nPRINT 7\nLEFT\nPRINT V\nLEFT\nPRINT U\nLEFT\nPRINT 2\nLEFT\nPRINT U\nLEFT\nPRINT !\nLEFT\nPRINT 9\nLEFT\nPRINT ?\nLEFT\nPRINT D\nLEFT\n..." }, { "input": "97 41\nGQSPZGGRZ0KWUMI79GOXP7!RR9E?Z5YO?6WUL!I7GCXRS8T,PEFQM7CZOUG8HLC7198J1?C69JD00Q!QY1AK!27I?WB?UAUIG", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT G\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT P\nRIGHT\nPRINT Z\nRIGHT\nPRINT G\nRIGHT\nPRINT G\nRIGHT\nPRINT R\nRIGHT\nPRINT Z\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT W\nRIGHT\nPRINT U\nRIGHT\nPRINT M\nRIGHT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT 9\nRIGHT\n..." }, { "input": "96 28\nZCF!PLS27YGXHK8P46H,C.A7MW90ED,4BA!T0!XKIR2GE0HD..YZ0O20O8TA7E35G5YT3L4W5ESSYBHG8.TIQENS4I.R8WE,", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT Z\nRIGHT\nPRINT C\nRIGHT\nPRINT F\nRIGHT\nPRINT !\nRIGHT\nPRINT P\nRIGHT\nPRINT L\nRIGHT\nPRINT S\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT Y\nRIGHT\nPRINT G\nRIGHT\nPRINT X\nRIGHT\nPRINT H\nRIGHT\nPRINT K\nRIGHT\nPRINT 8\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT 6\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT .\nRIGH..." }, { "input": "15 3\n!..!?!,!,..,?!.", "output": "LEFT\nLEFT\nPRINT !\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT !\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT ,\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ." }, { "input": "93 81\nGMIBVKYLURQLWHBGTFNJZZAZNUJJTPQKCPGDMGCDTTGXOANWKTDZSIYBUPFUXGQHCMVIEQCTINRTIUSPGMVZPGWBHPIXC", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT X\nLEFT\nPRINT I\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT B\nLEFT\nPRINT W\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT S\nLEFT\nPRINT U\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT R\nLEFT\nPRINT N\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT C\nLEFT\nPRINT Q\nLEFT\nPRINT E\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT C..." }, { "input": "88 30\n5847857685475132927321580125243001071762130696139249809763381765504146602574972381323476", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT 8\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 7\nRIGHT\nPRINT 6\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 5\nRIGHT\nPRINT 1\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nPRINT 9\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nP..." }, { "input": "100 50\n5B2N,CXCWOIWH71XV!HCFEUCN3U88JDRIFRO2VHY?!N.RGH.?W14X5S.Y00RIY6YA19BPD0T,WECXYI,O2RF1U4NX9,F5AVLPOYK", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT B\nRIGHT\nPRINT 2\nRIGHT\nPRINT N\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT X\nRIGHT\nPRINT C\nRIGHT\nPRINT W\nRIGHT\nPRINT O\nRIGHT\nPRINT I\nRIGHT\nPRINT W\nRIGHT\nPRINT H\nRIGHT\nPRINT 7\n..." }, { "input": "100 51\n!X85PT!WJDNS9KA6D2SJBR,U,G7M914W07EK3EAJ4XG..UHA3KOOFYJ?M0MEFDC6KNCNGKS0A!S,C02H4TSZA1U7NDBTIY?,7XZ4", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT 4\nLEFT\nPRINT Z\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT Y\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT B\nLEFT\nPRINT D\nLEFT\nPRI..." }, { "input": "100 52\n!MLPE.0K72RW9XKHR60QE?69ILFSIKYSK5AG!TA5.02VG5OMY0967G2RI.62CNK9L8G!7IG9F0XNNCGSDOTFD?I,EBP31HRERZSX", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT R\nLEFT\nPRINT H\nLEFT\nPRINT 1\nLEFT\nPRINT 3\nLEFT\nPRINT P\nLEFT\nPRINT B\nLEFT\nPRINT E\nL..." }, { "input": "100 49\n86C0NR7V,BE09,7,ER715OQ3GZ,P014H4BSQ5YS?OFNDD7YWI?S?UMKIWHSBDZ4398?SSDZLTDU1L?G4QVAB53HNDS!4PYW5C!VI", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 8\nRIGHT\nPRINT 6\nRIGHT\nPRINT C\nRIGHT\nPRINT 0\nRIGHT\nPRINT N\nRIGHT\nPRINT R\nRIGHT\nPRINT 7\nRIGHT\nPRINT V\nRIGHT\nPRINT ,\nRIGHT\nPRINT B\nRIGHT\nPRINT E\nRIGHT\nPRINT 0\nRIGHT\nPRINT 9\nRIGHT\nPRINT ,\nRIGHT\n..." }, { "input": "100 48\nFO,IYI4AAV?4?N5PWMZX1AINZLKAUJCKMDWU4CROT?.LYWYLYU5S80,15A6VGP!V0N,O.70CP?GEA52WG59UYWU1MMMU4BERVY.!", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT F\nRIGHT\nPRINT O\nRIGHT\nPRINT ,\nRIGHT\nPRINT I\nRIGHT\nPRINT Y\nRIGHT\nPRINT I\nRIGHT\nPRINT 4\nRIGHT\nPRINT A\nRIGHT\nPRINT A\nRIGHT\nPRINT V\nRIGHT\nPRINT ?\nRIGHT\nPRINT 4\nRIGHT\nPRINT ?\nRIGHT\nPRINT N\nRIGHT\nPRINT..." }, { "input": "100 100\nE?F,W.,,O51!!G13ZWP?YHWRT69?RQPW7,V,EM3336F1YAIKJIME1M45?LJM42?45V7221?P.DIO9FK245LXKMR4ALKPDLA5YI2Y", "output": "PRINT Y\nLEFT\nPRINT 2\nLEFT\nPRINT I\nLEFT\nPRINT Y\nLEFT\nPRINT 5\nLEFT\nPRINT A\nLEFT\nPRINT L\nLEFT\nPRINT D\nLEFT\nPRINT P\nLEFT\nPRINT K\nLEFT\nPRINT L\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT R\nLEFT\nPRINT M\nLEFT\nPRINT K\nLEFT\nPRINT X\nLEFT\nPRINT L\nLEFT\nPRINT 5\nLEFT\nPRINT 4\nLEFT\nPRINT 2\nLEFT\nPRINT K\nLEFT\nPRINT F\nLEFT\nPRINT 9\nLEFT\nPRINT O\nLEFT\nPRINT I\nLEFT\nPRINT D\nLEFT\nPRINT .\nLEFT\nPRINT P\nLEFT\nPRINT ?\nLEFT\nPRINT 1\nLEFT\nPRINT 2\nLEFT\nPRINT 2\nLEFT\nPRINT 7\nLEFT\nP..." }, { "input": "100 1\nJJ0ZOX4CY,SQ9L0K!2C9TM3C6K.6R21717I37VDSXGHBMR2!J820AI75D.O7NYMT6F.AGJ8R0RDETWOACK3P6UZAUYRKMKJ!G3WF", "output": "PRINT J\nRIGHT\nPRINT J\nRIGHT\nPRINT 0\nRIGHT\nPRINT Z\nRIGHT\nPRINT O\nRIGHT\nPRINT X\nRIGHT\nPRINT 4\nRIGHT\nPRINT C\nRIGHT\nPRINT Y\nRIGHT\nPRINT ,\nRIGHT\nPRINT S\nRIGHT\nPRINT Q\nRIGHT\nPRINT 9\nRIGHT\nPRINT L\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT !\nRIGHT\nPRINT 2\nRIGHT\nPRINT C\nRIGHT\nPRINT 9\nRIGHT\nPRINT T\nRIGHT\nPRINT M\nRIGHT\nPRINT 3\nRIGHT\nPRINT C\nRIGHT\nPRINT 6\nRIGHT\nPRINT K\nRIGHT\nPRINT .\nRIGHT\nPRINT 6\nRIGHT\nPRINT R\nRIGHT\nPRINT 2\nRIGHT\nPRINT 1\nRIGHT\nPRINT 7\nRIGHT\n..." }, { "input": "99 50\nLQJ!7GDFJ,SKQ8J2R?I4VA0K2.NDY.AZ?7K275NA81.YK!DO,PCQCJYL6BUU30XQ300FP0,LB!5TYTRSGOB4ELZ8IBKGVDNW8?B", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT B\nLEFT\nPRINT ?\nLEFT\nPRINT 8\nLEFT\nPRINT W\nLEFT\nPRINT N\nLEFT\nPRINT D\nLEFT\nPRINT V\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT B\nLEFT\nPRINT I\nLEFT\nPRI..." }, { "input": "99 51\nD9QHZXG46IWHHLTD2E,AZO0.M40R4B1WU6F,0QNZ37NQ0ACSU6!7Z?H02AD?0?9,5N5RG6PVOWIE6YA9QBCOHVNU??YT6,29SAC", "output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT A\nLEFT\nPRINT S\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT T\nLEFT\nPRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT ?\nLEFT\nPRINT U\nL..." }, { "input": "99 49\nOLUBX0Q3VPNSH,QCAWFVSKZA3NUURJ9PXBS3?72PMJ,27QTA7Z1N?6Q2CSJE,W0YX8XWS.W6B?K?M!PYAD30BX?8.VJCC,P8QL9", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT O\nRIGHT\nPRINT L\nRIGHT\nPRINT U\nRIGHT\nPRINT B\nRIGHT\nPRINT X\nRIGHT\nPRINT 0\nRIGHT\nPRINT Q\nRIGHT\nPRINT 3\nRIGHT\nPRINT V\nRIGHT\nPRINT P\nRIGHT\nPRINT N\nRIGHT\nPRINT S\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\n..." }, { "input": "99 48\nW0GU5MNE5!JVIOO2SR5OO7RWLHDFH.HLCCX89O21SLD9!CU0MFG3RFZUFT!R0LWNVNSS.W54.67N4VAN1Q2J9NMO9Q6.UE8U6B8", "output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT W\nRIGHT\nPRINT 0\nRIGHT\nPRINT G\nRIGHT\nPRINT U\nRIGHT\nPRINT 5\nRIGHT\nPRINT M\nRIGHT\nPRINT N\nRIGHT\nPRINT E\nRIGHT\nPRINT 5\nRIGHT\nPRINT !\nRIGHT\nPRINT J\nRIGHT\nPRINT V\nRIGHT\nPRINT I\nRIGHT\nPRINT O\nRIGHT\nPRINT..." }, { "input": "2 1\nOA", "output": "PRINT O\nRIGHT\nPRINT A" }, { "input": "2 2\nGW", "output": "PRINT W\nLEFT\nPRINT G" }, { "input": "3 1\n.VP", "output": "PRINT .\nRIGHT\nPRINT V\nRIGHT\nPRINT P" }, { "input": "3 2\nUD0", "output": "RIGHT\nPRINT 0\nLEFT\nPRINT D\nLEFT\nPRINT U" }, { "input": "3 3\nMYE", "output": "PRINT E\nLEFT\nPRINT Y\nLEFT\nPRINT M" }, { "input": "4 1\nC5EJ", "output": "PRINT C\nRIGHT\nPRINT 5\nRIGHT\nPRINT E\nRIGHT\nPRINT J" }, { "input": "4 2\n5QSW", "output": "LEFT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT W" }, { "input": "4 3\n!F3D", "output": "RIGHT\nPRINT D\nLEFT\nPRINT 3\nLEFT\nPRINT F\nLEFT\nPRINT !" }, { "input": "4 4\nS!?Y", "output": "PRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT !\nLEFT\nPRINT S" }, { "input": "5 1\nIP4!N", "output": "PRINT I\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT !\nRIGHT\nPRINT N" }, { "input": "5 2\nI7??5", "output": "LEFT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT ?\nRIGHT\nPRINT ?\nRIGHT\nPRINT 5" }, { "input": "5 3\nASNUW", "output": "RIGHT\nRIGHT\nPRINT W\nLEFT\nPRINT U\nLEFT\nPRINT N\nLEFT\nPRINT S\nLEFT\nPRINT A" }, { "input": "5 4\n3?,4L", "output": "RIGHT\nPRINT L\nLEFT\nPRINT 4\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT 3" }, { "input": "5 5\n30COA", "output": "PRINT A\nLEFT\nPRINT O\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT 3" }, { "input": "4 2\nABCD", "output": "LEFT\nPRINT A\nRIGHT\nPRINT B\nRIGHT\nPRINT C\nRIGHT\nPRINT D" } ]
62
0
3
1,500
690
Brain Network (easy)
[]
null
null
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly: 1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false. If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*).
The output consists of one line, containing either yes or no depending on whether the nervous system is valid.
[ "4 4\n1 2\n2 3\n3 1\n4 1\n", "6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n" ]
[ "no\n", "yes\n" ]
none
[ { "input": "4 4\n1 2\n2 3\n3 1\n4 1", "output": "no" }, { "input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "output": "yes" }, { "input": "2 1\n1 2", "output": "yes" }, { "input": "3 3\n2 1\n1 3\n3 2", "output": "no" }, { "input": "3 2\n1 2\n2 3", "output": "yes" }, { "input": "9 8\n1 2\n2 3\n3 4\n4 1\n5 6\n6 7\n7 8\n8 9", "output": "no" }, { "input": "8 7\n6 2\n1 5\n4 8\n4 7\n6 7\n8 3\n8 1", "output": "yes" }, { "input": "200 5\n93 101\n199 164\n14 94\n115 61\n106 156", "output": "no" }, { "input": "10 9\n6 5\n9 2\n4 7\n2 3\n7 3\n3 4\n10 6\n1 2\n5 8", "output": "no" }, { "input": "10 9\n2 3\n6 8\n10 1\n1 8\n6 7\n8 7\n10 5\n7 10\n2 5", "output": "no" }, { "input": "10 9\n3 2\n4 1\n6 1\n7 1\n9 2\n6 9\n5 2\n7 9\n3 7", "output": "no" } ]
109
0
0
1,501
182
Vasya's Calendar
[ "implementation" ]
null
null
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1. Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month. A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one.
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
[ "4\n2\n2 2\n", "5\n3\n3 4 3\n", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n" ]
[ "2\n", "3\n", "7\n" ]
In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing.
[ { "input": "4\n2\n2 2", "output": "2" }, { "input": "5\n3\n3 4 3", "output": "3" }, { "input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n1 1", "output": "0" }, { "input": "2\n2\n1 1", "output": "1" }, { "input": "10\n2\n10 2", "output": "0" }, { "input": "10\n3\n6 3 6", "output": "11" }, { "input": "10\n4\n8 7 1 5", "output": "14" }, { "input": "10\n5\n2 7 8 4 4", "output": "19" }, { "input": "10\n6\n8 3 4 9 6 1", "output": "20" }, { "input": "10\n7\n10 5 3 1 1 9 1", "output": "31" }, { "input": "10\n8\n6 5 10 6 8 1 3 2", "output": "31" }, { "input": "10\n9\n6 2 7 5 5 4 8 6 2", "output": "37" }, { "input": "10\n10\n1 10 1 10 1 1 7 8 6 7", "output": "45" }, { "input": "100\n100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "5099" }, { "input": "101\n100\n19 17 15 16 28 69 41 47 75 42 19 98 16 90 92 47 21 4 98 17 27 31 90 10 14 92 62 73 56 55 6 60 62 22 78 1 3 86 18 59 92 41 21 34 67 9 92 78 77 45 50 92 57 61 11 98 89 72 57 93 100 12 61 48 5 48 38 9 65 64 77 29 18 55 94 42 10 77 43 46 7 89 8 13 5 53 80 59 23 100 30 28 29 24 85 56 10 22 24 16", "output": "5301" }, { "input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32", "output": "5447" }, { "input": "103\n100\n68 38 41 54 37 11 35 26 43 97 70 3 13 11 64 83 3 95 99 16 4 13 22 27 64 20 95 38 40 87 6 17 95 67 31 24 85 33 98 24 89 101 66 38 42 5 95 18 95 13 103 85 72 73 68 93 22 59 48 59 72 46 5 41 54 32 48 69 3 76 2 26 102 44 39 58 55 85 40 16 81 78 92 63 25 97 83 2 54 16 20 63 19 8 84 34 1 22 43 93", "output": "5358" }, { "input": "104\n100\n65 74 94 71 98 38 88 67 71 84 45 79 55 86 55 51 27 89 14 66 29 63 8 103 98 94 87 81 58 68 24 96 60 36 48 95 28 72 95 42 87 7 14 23 99 77 34 14 90 31 8 99 29 30 9 88 42 1 77 61 55 85 17 98 62 78 27 1 58 69 82 62 62 81 56 104 66 8 17 23 7 61 59 70 79 64 78 16 32 11 59 4 24 73 55 2 95 39 62 13", "output": "4773" } ]
404
2,355,200
-1
1,505
266
Queue at the School
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "output": "GBBGBB" }, { "input": "8 3\nBBGBGBGB", "output": "GGBGBBBB" }, { "input": "10 3\nBBGBBBBBBG", "output": "GBBBBBGBBB" }, { "input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "output": "GGGGGGGGBGGBGGBBBBBBBB" }, { "input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB" }, { "input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB" }, { "input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB", "output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB" }, { "input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB", "output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB" }, { "input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB", "output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB" }, { "input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 1\nB", "output": "B" }, { "input": "1 1\nG", "output": "G" }, { "input": "1 50\nB", "output": "B" }, { "input": "1 50\nG", "output": "G" }, { "input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB", "output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB" }, { "input": "6 3\nGGBBBG", "output": "GGGBBB" }, { "input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG", "output": "GGBBBBGBGBGBGGGBGBGGGBGBBB" }, { "input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB", "output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB" }, { "input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB", "output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB", "output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB" }, { "input": "17 42\nBBGBGBGGGGGGBBGGG", "output": "GGGGGGGGGGGBBBBBB" }, { "input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG", "output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB" }, { "input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB", "output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB" }, { "input": "2 2\nBG", "output": "GB" }, { "input": "8 8\nGGGBGGBB", "output": "GGGGGBBB" }, { "input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB", "output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB" }, { "input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG", "output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG", "output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 10\nGGGGGGGGGG", "output": "GGGGGGGGGG" }, { "input": "10 10\nBBBBBBBBBB", "output": "BBBBBBBBBB" }, { "input": "10 10\nBGBGBGBGBG", "output": "GGGGGBBBBB" }, { "input": "1 1\nB", "output": "B" } ]
92
0
3
1,508
1
Spreadsheet
[ "implementation", "math" ]
B. Spreadsheets
10
64
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
[ "2\nR23C55\nBC23\n" ]
[ "BC23\nR23C55\n" ]
none
[ { "input": "2\nR23C55\nBC23", "output": "BC23\nR23C55" }, { "input": "1\nA1", "output": "R1C1" }, { "input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9", "output": "C8\nR1C4\nB7\nI8\nI8" }, { "input": "4\nR4C25\nR90C35\nAP55\nX83", "output": "Y4\nAI90\nR55C42\nR83C24" }, { "input": "10\nR50C12\nR23C47\nY96\nR44C13\nR19C21\nR95C73\nBK12\nR51C74\nAY34\nR63C25", "output": "L50\nAU23\nR96C25\nM44\nU19\nBU95\nR12C63\nBV51\nR34C51\nY63" } ]
92
0
0
1,509
427
Prison Transfer
[ "data structures", "implementation" ]
null
null
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the *c* prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, - The chosen *c* prisoners has to form a contiguous segment of prisoners. - Any of the chosen prisoner's crime level should not be greater then *t*. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the *c* prisoners.
The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Print a single integer — the number of ways you can choose the *c* prisoners.
[ "4 3 3\n2 3 1 1\n", "1 1 1\n2\n", "11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n" ]
[ "2\n", "0\n", "6\n" ]
none
[ { "input": "4 3 3\n2 3 1 1", "output": "2" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "output": "6" }, { "input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6", "output": "0" }, { "input": "2 228885628 1\n90897004 258427916", "output": "1" }, { "input": "3 1 1\n1 2 1", "output": "2" }, { "input": "3 3 3\n3 2 3", "output": "1" }, { "input": "4 2 2\n1 3 3 2", "output": "0" }, { "input": "1 228 1\n1", "output": "1" } ]
139
25,600,000
-1
1,515
225
Barcode
[ "dp", "matrices" ]
null
null
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture. A picture is a barcode if the following conditions are fulfilled: - All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*.
The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*). Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#".
In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.
[ "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n", "2 5 1 1\n#####\n.....\n" ]
[ "11\n", "5\n" ]
In the first test sample the picture after changing some colors can looks as follows: In the second test sample the picture after changing some colors can looks as follows:
[ { "input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..", "output": "11" }, { "input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#", "output": "24" }, { "input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#", "output": "6" }, { "input": "5 10 4 16\n.#####....\n##..#..##.\n.#..##.#..\n##..#####.\n...#.##..#", "output": "21" }, { "input": "5 4 1 4\n####\n..##\n##..\n..#.\n#..#", "output": "8" }, { "input": "1 1 1 2\n.", "output": "0" }, { "input": "3 44 2 18\n####..###.#.##........##...###.####.#.....##\n...#....##.###.###.##.#####.#######.#..#..#.\n#...#.####.#.##.#.#.#.....##.##..###.#....##", "output": "39" }, { "input": "69 1 1 2\n#\n.\n#\n#\n.\n#\n#\n.\n.\n#\n.\n.\n#\n.\n#\n#\n.\n#\n#\n#\n#\n#\n.\n#\n.\n.\n#\n#\n#\n.\n.\n.\n.\n#\n#\n.\n#\n#\n.\n#\n.\n.\n#\n.\n.\n.\n#\n.\n.\n#\n#\n.\n.\n#\n.\n.\n.\n#\n#\n#\n#\n#\n.\n#\n.\n#\n#\n#\n#", "output": "31" }, { "input": "56 2 2 2\n##\n##\n##\n..\n..\n##\n.#\n#.\n..\n##\n##\n..\n..\n#.\n#.\n#.\n#.\n##\n..\n.#\n..\n##\n##\n.#\n#.\n.#\n..\n..\n#.\n..\n##\n..\n#.\n.#\n#.\n#.\n#.\n##\n#.\n##\n##\n.#\n#.\n##\n..\n.#\n#.\n#.\n##\n..\n..\n#.\n##\n..\n..\n##", "output": "55" } ]
154
0
0
1,516
984
Minesweeper
[ "implementation" ]
null
null
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won. Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it? He needs your help to check it. A Minesweeper field is a rectangle $n \times m$, where each cell is either empty, or contains a digit from $1$ to $8$, or a bomb. The field is valid if for each cell: - if there is a digit $k$ in the cell, then exactly $k$ neighboring cells have bombs. - if the cell is empty, then all neighboring cells have no bombs. Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $8$ neighboring cells).
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field. The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive.
Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.
[ "3 3\n111\n1*1\n111\n", "2 4\n*.*.\n1211\n" ]
[ "YES", "NO" ]
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1. You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)).
[ { "input": "3 3\n111\n1*1\n111", "output": "YES" }, { "input": "2 4\n*.*.\n1211", "output": "NO" }, { "input": "1 10\n.....1*1..", "output": "YES" }, { "input": "1 1\n4", "output": "NO" }, { "input": "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542..11\n.13**1..1*\n..2*31..11\n..111..111\n.......1*1\n.......111", "output": "YES" }, { "input": "10 17\n12*2*22123*31....\n2*333*3*4***3211.\n*22*213**4***3*1.\n11111.12224*6*21.\n221..111.14**4311\n**2233*212****2*1\n*55***4*13*544421\n2***54*322*21**31\n13*4*33*221114*4*\n.1122*22*1...2*31", "output": "YES" }, { "input": "10 10\n**********\n**********\n**********\n**********\n**********\n******3***\n**********\n**********\n**********\n***3.5****", "output": "NO" }, { "input": "21 10\n62637783*1\n23*51**531\n35*7*6.**.\n.*3***581*\n2.32*745**\n83*7*6*6*5\n*74.**6**3\n323*6**7*6\n3454*67.*1\n**63265*6*\n3725*4553*\n24****5**4\n23.34****4\n55257*1*4*\n4*3253*456\n**.3*45488\n*7318**4*5\n234.*4557*\n12..21*.*3\n286.225*4*\n834*11*.3*", "output": "NO" }, { "input": "10 10\n**********\n*********6\n*********5\n**********\n**********\n**********\n**********\n**********\n**********\n**********", "output": "NO" }, { "input": "100 1\n.\n.\n.\n.\n1\n*\n2\n*\n1\n.\n.\n.\n.\n.\n.\n1\n*\n1\n1\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n1\n*\n2\n*\n*\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n1\n*\n2\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "output": "YES" }, { "input": "1 100\n*************5****5****************************************************4****************************", "output": "NO" }, { "input": "1 100\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*", "output": "NO" }, { "input": "1 10\n881111882*", "output": "NO" }, { "input": "5 5\n*2221\n24**2\n*3*5*\n3425*\n**12*", "output": "NO" }, { "input": "5 5\n****2\n4***4\n3****\n3*563\n*22**", "output": "NO" }, { "input": "5 5\n***2.\n5**31\n**6**\n***43\n**31*", "output": "NO" }, { "input": "5 5\n*32**\n4*3*4\n**44*\n**45*\n*4***", "output": "NO" }, { "input": "3 3\n***\n*2*\n***", "output": "NO" }, { "input": "1 1\n*", "output": "YES" }, { "input": "1 2\n*1", "output": "YES" }, { "input": "1 2\n*2", "output": "NO" }, { "input": "2 2\n32\n**", "output": "NO" }, { "input": "3 3\n...\n232\n***", "output": "YES" }, { "input": "3 2\n..\n11\n.*", "output": "NO" }, { "input": "2 3\n1*2\n3*2", "output": "NO" }, { "input": "1 3\n.*.", "output": "NO" }, { "input": "3 1\n.\n*\n.", "output": "NO" }, { "input": "3 1\n1\n*\n1", "output": "YES" }, { "input": "3 1\n*\n1\n*", "output": "NO" }, { "input": "1 3\n1**", "output": "YES" }, { "input": "1 1\n8", "output": "NO" }, { "input": "1 1\n.", "output": "YES" }, { "input": "1 2\n2*", "output": "NO" }, { "input": "2 1\n*\n2", "output": "NO" }, { "input": "2 1\n*\n*", "output": "YES" }, { "input": "2 1\n.\n1", "output": "NO" }, { "input": "1 3\n..1", "output": "NO" }, { "input": "3 3\n112\n1*1\n111", "output": "NO" }, { "input": "3 3\n11.\n1*1\n111", "output": "NO" }, { "input": "3 3\n151\n1*1\n111", "output": "NO" }, { "input": "3 3\n1.1\n1*1\n111", "output": "NO" }, { "input": "3 3\n611\n1*1\n111", "output": "NO" }, { "input": "3 3\n.11\n1*1\n111", "output": "NO" }, { "input": "3 3\n111\n2*1\n111", "output": "NO" }, { "input": "3 3\n111\n**1\n111", "output": "NO" }, { "input": "3 3\n111\n5*1\n111", "output": "NO" }, { "input": "3 3\n111\n.*1\n111", "output": "NO" }, { "input": "3 3\n111\n1*1\n411", "output": "NO" }, { "input": "3 3\n111\n1*1\n.11", "output": "NO" }, { "input": "3 3\n111\n1*1\n121", "output": "NO" }, { "input": "3 3\n111\n1*1\n1.1", "output": "NO" }, { "input": "3 3\n111\n1*1\n115", "output": "NO" }, { "input": "3 3\n111\n1*1\n11.", "output": "NO" }, { "input": "3 3\n111\n1*4\n111", "output": "NO" }, { "input": "3 3\n111\n1*.\n111", "output": "NO" }, { "input": "1 4\n*222", "output": "NO" }, { "input": "1 1\n*", "output": "YES" }, { "input": "2 2\n**\n**", "output": "YES" }, { "input": "3 3\n***\n*.*\n***", "output": "NO" }, { "input": "3 3\n***\n***\n***", "output": "YES" }, { "input": "3 3\n***\n*4*\n***", "output": "NO" }, { "input": "2 6\n....1.\n.....*", "output": "NO" }, { "input": "5 5\n*****\n*****\n*****\n*****\n*****", "output": "YES" }, { "input": "4 1\n.\n*\n.\n.", "output": "NO" }, { "input": "2 2\n2*\n11", "output": "NO" }, { "input": "3 3\n888\n888\n888", "output": "NO" }, { "input": "1 4\n*22*", "output": "NO" } ]
31
0
0
1,517
847
Weather Tomorrow
[ "implementation", "math" ]
null
null
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day. Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day.
Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
[ "5\n10 5 0 -5 -10\n", "4\n1 1 1 1\n", "3\n5 1 -5\n", "2\n900 1000\n" ]
[ "-15\n", "1\n", "-5\n", "1100\n" ]
In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 =  - 15. In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1. In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to  - 5. In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100.
[ { "input": "5\n10 5 0 -5 -10", "output": "-15" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "3\n5 1 -5", "output": "-5" }, { "input": "2\n900 1000", "output": "1100" }, { "input": "2\n1 2", "output": "3" }, { "input": "3\n2 5 8", "output": "11" }, { "input": "4\n4 1 -2 -5", "output": "-8" }, { "input": "10\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955", "output": "-950" }, { "input": "11\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000", "output": "1200" }, { "input": "31\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 516 494 472 450 428 406 384 362 340", "output": "318" }, { "input": "5\n1000 544 88 -368 -824", "output": "-1280" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "33\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984", "output": "-1029" }, { "input": "77\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983", "output": "1006" }, { "input": "3\n2 4 8", "output": "8" }, { "input": "4\n4 1 -3 -5", "output": "-5" }, { "input": "10\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955", "output": "-955" }, { "input": "11\n-999 -800 -600 -400 -200 0 200 400 600 800 1000", "output": "1000" }, { "input": "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990", "output": "990" }, { "input": "100\n10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 207", "output": "207" }, { "input": "2\n1000 1000", "output": "1000" }, { "input": "2\n-1000 1000", "output": "3000" }, { "input": "2\n1000 -1000", "output": "-3000" }, { "input": "2\n-1000 -1000", "output": "-1000" }, { "input": "100\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312", "output": "312" }, { "input": "4\n1 2 4 5", "output": "5" } ]
46
0
3
1,527
0
none
[ "none" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "input": "ghbdtn", "output": "Just a legend" }, { "input": "a", "output": "Just a legend" }, { "input": "aa", "output": "Just a legend" }, { "input": "ab", "output": "Just a legend" }, { "input": "aaa", "output": "a" }, { "input": "aba", "output": "Just a legend" }, { "input": "aab", "output": "Just a legend" }, { "input": "abb", "output": "Just a legend" }, { "input": "abc", "output": "Just a legend" }, { "input": "aaabaabaaaaab", "output": "Just a legend" }, { "input": "aabaaabaaaaab", "output": "aab" }, { "input": "aaabaaaabab", "output": "Just a legend" }, { "input": "abcabcabcabcabc", "output": "abcabcabc" }, { "input": "aaaaabaaaa", "output": "aaaa" }, { "input": "aaaabaaaaaaa", "output": "aaaa" }, { "input": "ghghghgxghghghg", "output": "ghghg" }, { "input": "kincenvizh", "output": "Just a legend" }, { "input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "output": "Just a legend" }, { "input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "output": "Just a legend" }, { "input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "output": "nfbdzgdlbjhrlvfryyjb" }, { "input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp" }, { "input": "abcazabca", "output": "a" } ]
124
4,608,000
0
1,529
260
Ancient Prophesy
[ "brute force", "implementation", "strings" ]
null
null
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012"). The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date. A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it. Notice, that any year between 2013 and 2015 is not a leap year.
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
[ "777-444---21-12-2013-12-2013-12-2013---444-777\n" ]
[ "13-12-2013" ]
none
[ { "input": "777-444---21-12-2013-12-2013-12-2013---444-777", "output": "13-12-2013" }, { "input": "30-12-201429-15-208830-12-2014", "output": "30-12-2014" }, { "input": "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013", "output": "14-08-2013" }, { "input": "15-11-201413-02-20147-86-25-298813-02-201413-02-201434615-11-201415-11-201415-11-201415-11-2014", "output": "15-11-2014" }, { "input": "19-07-201419-07-201424-06-201719-07-201419-07-201413-10-201419-07-201468-01-201619-07-20142", "output": "19-07-2014" }, { "input": "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08-20159533-45-00-1212", "output": "01-04-2014" }, { "input": "23-11-201413-07-201412-06-2015124-03-20140-19-201323-11-201424-03-2014537523-11-20143575015-10-2014", "output": "23-11-2014" }, { "input": "15-04-201413-08-201589-09-201013-08-20130-74-28-201620-8497-14-1063713-08-2013813-02-201513-08-2013", "output": "13-08-2013" }, { "input": "13-05-201412-11-2013-12-11-201314-12-201329-05-201306-24-188814-07-201312-11-201312-04-2010", "output": "12-11-2013" }, { "input": "14-01-201402-04-201514-01-201485-26-1443948-14-278314-01-2014615259-09-178413-06-201314-05-2014", "output": "14-01-2014" }, { "input": "31-12-201331-11-201331-11-2013", "output": "31-12-2013" }, { "input": "01-01-2014", "output": "01-01-2014" }, { "input": "32-13-2100-32-13-2100-32-13-2100-12-12-2013", "output": "12-12-2013" }, { "input": "15-1--201315-1--201301-01-2013", "output": "01-01-2013" }, { "input": "00-12-2014-00-12-2014-00-12-2014-12-12-2014", "output": "12-12-2014" }, { "input": "120110201311-10-20151201102013", "output": "11-10-2015" }, { "input": "31-08-2013---31-08-2013---03-03-2013", "output": "31-08-2013" }, { "input": "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013", "output": "12-12-2013" }, { "input": "21-12-201221-12-201221-12-201221-12-201213-12-2013", "output": "13-12-2013" }, { "input": "29-02-2013-02-2013-29-02-2013", "output": "13-02-2013" }, { "input": "20-12-2012----20-12-2012-----01-01-2013", "output": "01-01-2013" }, { "input": "01-2-02013---01-2-02013----13-02-2014", "output": "13-02-2014" }, { "input": "11111111111111111111---21-12-2013", "output": "21-12-2013" }, { "input": "29-02-2014--29-02-2014--28-02-2014", "output": "28-02-2014" }, { "input": "29-02-201329-02-201321-12-2013", "output": "21-12-2013" }, { "input": "01--01--2013-12-2013-01--01--2013", "output": "13-12-2013" }, { "input": "10-10-2023-10-10-2023-10-10-2013", "output": "10-10-2013" } ]
546
1,536,000
-1
1,531
656
Da Vinci Powers
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer.
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
[ "3\n", "10\n" ]
[ "8\n", "1024\n" ]
none
[ { "input": "3", "output": "8" }, { "input": "10", "output": "1024" }, { "input": "35", "output": "33940307968" }, { "input": "0", "output": "1" }, { "input": "1", "output": "2" }, { "input": "2", "output": "4" }, { "input": "4", "output": "16" }, { "input": "5", "output": "32" }, { "input": "6", "output": "64" }, { "input": "7", "output": "128" }, { "input": "8", "output": "256" }, { "input": "9", "output": "512" }, { "input": "11", "output": "2048" }, { "input": "12", "output": "4096" }, { "input": "13", "output": "8092" }, { "input": "14", "output": "16184" }, { "input": "15", "output": "32368" }, { "input": "16", "output": "64736" }, { "input": "17", "output": "129472" }, { "input": "18", "output": "258944" }, { "input": "19", "output": "517888" }, { "input": "20", "output": "1035776" }, { "input": "21", "output": "2071552" }, { "input": "22", "output": "4143104" }, { "input": "23", "output": "8286208" }, { "input": "24", "output": "16572416" }, { "input": "25", "output": "33144832" }, { "input": "26", "output": "66289664" }, { "input": "27", "output": "132579328" }, { "input": "28", "output": "265158656" }, { "input": "29", "output": "530317312" }, { "input": "30", "output": "1060634624" }, { "input": "31", "output": "2121269248" }, { "input": "32", "output": "4242538496" }, { "input": "33", "output": "8485076992" }, { "input": "34", "output": "16970153984" } ]
62
0
3
1,532
757
Gotta Catch Em' All!
[ "implementation" ]
null
null
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur. Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper. Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today? Note: uppercase and lowercase letters are considered different.
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*. The string *s* contains lowercase and uppercase English letters, i.e. .
Output a single integer, the answer to the problem.
[ "Bulbbasaur\n", "F\n", "aBddulbasaurrgndgbualdBdsagaurrgndbb\n" ]
[ "1\n", "0\n", "2\n" ]
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[ { "input": "Bulbbasaur", "output": "1" }, { "input": "F", "output": "0" }, { "input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2" }, { "input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr", "output": "5" }, { "input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr", "output": "0" }, { "input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr", "output": "10" }, { "input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "output": "20" }, { "input": "CeSlSwec", "output": "0" }, { "input": "PnMrWPBGzVcmRcO", "output": "0" }, { "input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM", "output": "0" }, { "input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC", "output": "6" }, { "input": "bulsar", "output": "0" }, { "input": "Bblsar", "output": "0" }, { "input": "Bbusar", "output": "0" }, { "input": "Bbular", "output": "0" }, { "input": "Bbulsr", "output": "0" }, { "input": "Bbulsa", "output": "0" }, { "input": "Bbulsar", "output": "0" }, { "input": "Bbulsar", "output": "0" }, { "input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh", "output": "2" }, { "input": "Bulbasaur", "output": "1" }, { "input": "BulbasaurBulbasaur", "output": "2" }, { "input": "Bulbbasar", "output": "0" }, { "input": "Bulbasur", "output": "0" }, { "input": "Bulbsaur", "output": "0" }, { "input": "BulbsurBulbsurBulbsurBulbsur", "output": "0" }, { "input": "Blbbasar", "output": "0" }, { "input": "Bulbasar", "output": "0" }, { "input": "BBullllbbaassaauurr", "output": "1" }, { "input": "BulbasaurBulbasar", "output": "1" }, { "input": "BulbasaurBulbsaur", "output": "1" }, { "input": "Bubasaur", "output": "0" }, { "input": "ulbasaurulbasaur", "output": "0" }, { "input": "Bulbasr", "output": "0" }, { "input": "BBBuuulllbbbaaasssaaauuurrr", "output": "3" }, { "input": "BBuuuullbbaaaassrr", "output": "2" }, { "input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr", "output": "4" }, { "input": "BBuullbbaassaarr", "output": "1" }, { "input": "Bulbasau", "output": "0" }, { "input": "BBuullbbaassaauurr", "output": "2" }, { "input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau", "output": "0" }, { "input": "Blbasaur", "output": "0" }, { "input": "BulbasaurBulbasaurd", "output": "2" }, { "input": "ulbasaur", "output": "0" }, { "input": "Bulbaaur", "output": "0" }, { "input": "BBuuuullbbbbbbbbbbbbbbbaassrr", "output": "1" }, { "input": "Bulbasua", "output": "0" }, { "input": "Bubbasaur", "output": "0" }, { "input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr", "output": "3" }, { "input": "BulbasaurBubasaur", "output": "1" }, { "input": "Baab", "output": "0" }, { "input": "BulbasaurBulbasau", "output": "1" }, { "input": "Bulbasauu", "output": "0" }, { "input": "BulbasauBulbasau", "output": "0" }, { "input": "BBBBBBBBBBB", "output": "0" }, { "input": "Bulbbasau", "output": "0" }, { "input": "BulbbasaurBulbbasar", "output": "1" }, { "input": "Bulaaaasaur", "output": "0" }, { "input": "BulbasaurBulbasauBulbasauBulbasau", "output": "1" } ]
62
0
0
1,533
918
Radio Station
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server" }, { "input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;", "output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm" }, { "input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;", "output": "zygoumbmx 185.32.99.2; #ervbfot" }, { "input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;", "output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y" }, { "input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;", "output": "zbtjzzue 203.115.124.110; #tdwmshz" }, { "input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;", "output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t" }, { "input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;", "output": "command 11.1.1.1; #get" }, { "input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;", "output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn" }, { "input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;", "output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica" }, { "input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;", "output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica" }, { "input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;", "output": "block 255.255.255.255; #server" }, { "input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;", "output": "block 22.222.30.10; #alp" } ]
46
0
0
1,537
336
Vasily the Bear and Sequence
[ "brute force", "greedy", "implementation", "number theory" ]
null
null
Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers *b*1,<=*b*2,<=...,<=*b**k* is such maximum non-negative integer *v*, that number *b*1 *and* *b*2 *and* ... *and* *b**k* is divisible by number 2*v* without a remainder. If such number *v* doesn't exist (that is, for any non-negative integer *v*, number *b*1 *and* *b*2 *and* ... *and* *b**k* is divisible by 2*v* without a remainder), the beauty of the written out numbers equals -1. Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible. Here expression *x* *and* *y* means applying the bitwise AND operation to numbers *x* and *y*. In programming languages C++ and Java this operation is represented by "&amp;", in Pascal — by "and".
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=109).
In the first line print a single integer *k* (*k*<=&gt;<=0), showing how many numbers to write out. In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the numbers to write out. You are allowed to print numbers *b*1,<=*b*2,<=...,<=*b**k* in any order, but all of them must be distinct. If there are multiple ways to write out the numbers, choose the one with the maximum number of numbers to write out. If there still are multiple ways, you are allowed to print any of them.
[ "5\n1 2 3 4 5\n", "3\n1 2 4\n" ]
[ "2\n4 5\n", "1\n4\n" ]
none
[ { "input": "5\n1 2 3 4 5", "output": "2\n4 5" }, { "input": "3\n1 2 4", "output": "1\n4" }, { "input": "3\n1 20 22", "output": "2\n20 22" }, { "input": "10\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642", "output": "6\n361633800 406156967 452258663 530571268 841023955 967424642" }, { "input": "30\n61 65 67 71 73 75 77 79 129 131 135 137 139 141 267 520 521 522 524 526 1044 1053 6924600 32125372 105667932 109158064 192212084 202506108 214625360 260071380", "output": "8\n520 521 522 524 526 109158064 202506108 260071380" }, { "input": "40\n6 7 10 11 18 19 33 65 129 258 514 515 1026 2049 4741374 8220406 14324390 17172794 17931398 33354714 34796238 38926670 39901570 71292026 72512934 77319030 95372470 102081830 114152702 120215390 133853238 134659386 159128594 165647058 219356350 225884742 236147130 240926050 251729234 263751314", "output": "13\n2049 4741374 8220406 17172794 17931398 38926670 39901570 77319030 134659386 159128594 219356350 225884742 240926050" }, { "input": "1\n536870912", "output": "1\n536870912" }, { "input": "1\n1", "output": "1\n1" }, { "input": "1\n536870911", "output": "1\n536870911" }, { "input": "2\n536870911 536870912", "output": "1\n536870912" }, { "input": "38\n37750369 37750485 37750546 37751012 37751307 37751414 37751958 37751964 37752222 37752448 75497637 75497768 75497771 75498087 75498145 75498177 75498298 75498416 75498457 150994987 150994994 150994999 150995011 150995012 150995015 150995016 150995023 150995040 150995053 805306375 805306377 805306379 805306387 805306389 805306390 805306392 805306396 805306400", "output": "9\n805306375 805306377 805306379 805306387 805306389 805306390 805306392 805306396 805306400" }, { "input": "39\n37749932 37750076 37750391 37750488 37750607 37750812 37750978 37751835 37752173 37752254 75497669 75497829 75497852 75498044 75498061 75498155 75498198 75498341 75498382 75498465 150994988 150994989 150995009 150995019 150995024 150995030 150995031 150995069 150995072 805306369 805306373 805306375 805306379 805306380 805306384 805306387 805306389 805306398 805306400", "output": "10\n805306369 805306373 805306375 805306379 805306380 805306384 805306387 805306389 805306398 805306400" } ]
61
6,963,200
0
1,539
75
Modified GCD
[ "binary search", "number theory" ]
C. Modified GCD
2
256
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range. You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
[ "9 27\n3\n1 5\n10 11\n9 11\n" ]
[ "3\n-1\n9\n" ]
none
[ { "input": "9 27\n3\n1 5\n10 11\n9 11", "output": "3\n-1\n9" }, { "input": "48 72\n2\n8 29\n29 37", "output": "24\n-1" }, { "input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90", "output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1" }, { "input": "84 36\n1\n18 32", "output": "-1" }, { "input": "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36", "output": "-1\n18\n18\n-1\n6\n-1\n9\n9\n18\n-1\n18\n18\n9\n2\n-1\n18" }, { "input": "84 90\n18\n10 75\n2 40\n30 56\n49 62\n19 33\n5 79\n61 83\n13 56\n73 78\n1 18\n23 35\n14 72\n22 33\n1 21\n8 38\n54 82\n6 80\n57 75", "output": "-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n6\n-1" }, { "input": "84 100\n16\n10 64\n3 61\n19 51\n42 67\n51 68\n12 40\n10 47\n52 53\n37 67\n2 26\n23 47\n17 75\n49 52\n3 83\n63 81\n8 43", "output": "-1\n4\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n4\n-1\n-1\n-1\n4\n-1\n-1" }, { "input": "36 60\n2\n17 25\n16 20", "output": "-1\n-1" }, { "input": "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "90 36\n8\n1 19\n10 12\n14 28\n21 24\n8 8\n33 34\n10 26\n15 21", "output": "18\n-1\n18\n-1\n-1\n-1\n18\n18" }, { "input": "48 80\n19\n1 1\n16 16\n1 16\n16 48\n16 80\n16 1000000000\n1000000000 1000000000\n1 1000000000\n500000000 1000000000\n15 17\n17 17\n15 15\n8 8\n8 15\n8 16\n8 17\n7 17\n7 15\n9 15", "output": "1\n16\n16\n16\n16\n16\n-1\n16\n-1\n16\n-1\n-1\n8\n8\n16\n16\n16\n8\n-1" }, { "input": "31607 999002449\n18\n31607 31607\n31606 31608\n31607 31608\n31606 31607\n31606 31606\n31608 31608\n1 31607\n1 31606\n1 31608\n1 1000000000\n31607 1000000000\n31606 1000000000\n31608 1000000000\n1000000000 1000000000\n1 1\n2 31606\n2 31607\n2 31608", "output": "31607\n31607\n31607\n31607\n-1\n-1\n31607\n1\n31607\n31607\n31607\n31607\n-1\n-1\n1\n-1\n31607\n31607" }, { "input": "999999937 999999929\n12\n999999929 999999937\n1 1\n1 1000000000\n2 1000000000\n1 2\n999999937 999999937\n999999929 999999929\n2 2\n3 3\n1 100\n1 999999937\n1 999999929", "output": "-1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1" } ]
592
614,400
3.850856
1,545
839
Arya and Bran
[ "implementation" ]
null
null
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
[ "2 3\n1 2\n", "3 17\n10 10 10\n", "1 9\n10\n" ]
[ "2", "3", "-1" ]
In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
[ { "input": "2 3\n1 2", "output": "2" }, { "input": "3 17\n10 10 10", "output": "3" }, { "input": "1 9\n10", "output": "-1" }, { "input": "10 70\n6 5 2 3 3 2 1 4 3 2", "output": "-1" }, { "input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "output": "18" }, { "input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "output": "30" }, { "input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47", "output": "40" }, { "input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9", "output": "-1" }, { "input": "37 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "30" }, { "input": "100 456\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "57" }, { "input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100", "output": "38" }, { "input": "7 43\n4 3 7 9 3 8 10", "output": "-1" }, { "input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8", "output": "-1" }, { "input": "30 177\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 8", "output": "-1" }, { "input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5", "output": "-1" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69", "output": "13" }, { "input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53", "output": "85" }, { "input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5", "output": "100" }, { "input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6", "output": "98" }, { "input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1", "output": "18" }, { "input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2", "output": "21" }, { "input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1", "output": "-1" }, { "input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91", "output": "45" }, { "input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90", "output": "-1" }, { "input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50", "output": "97" }, { "input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9", "output": "24" }, { "input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42", "output": "21" }, { "input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100", "output": "1" }, { "input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5", "output": "13" }, { "input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92", "output": "14" }, { "input": "2 16\n10 6", "output": "2" }, { "input": "2 8\n7 8", "output": "2" }, { "input": "2 9\n4 8", "output": "2" }, { "input": "3 19\n9 9 1", "output": "3" }, { "input": "4 32\n9 9 9 5", "output": "4" }, { "input": "2 15\n14 1", "output": "2" }, { "input": "2 3\n3 3", "output": "1" }, { "input": "3 10\n10 1 1", "output": "2" }, { "input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4", "output": "4" }, { "input": "4 15\n14 3 3 3", "output": "2" }, { "input": "5 40\n10 10 10 10 1", "output": "5" }, { "input": "4 31\n9 9 8 5", "output": "4" }, { "input": "4 31\n20 7 1 1", "output": "-1" }, { "input": "2 10\n9 1", "output": "2" }, { "input": "10 50\n100 10 1 1 1 1 1 1 1 1", "output": "7" }, { "input": "2 11\n10 2", "output": "2" }, { "input": "3 21\n10 10 1", "output": "3" }, { "input": "2 2\n1 2", "output": "2" }, { "input": "3 2\n1 8 8", "output": "2" }, { "input": "2 11\n10 1", "output": "2" }, { "input": "2 16\n12 4", "output": "2" }, { "input": "3 11\n9 2 2", "output": "2" }, { "input": "3 11\n4 3 4", "output": "3" }, { "input": "2 13\n7 6", "output": "2" }, { "input": "3 24\n14 3 4", "output": "-1" }, { "input": "2 13\n10 3", "output": "2" }, { "input": "3 11\n9 2 1", "output": "2" }, { "input": "2 15\n12 3", "output": "2" }, { "input": "2 14\n11 4", "output": "2" } ]
202
2,355,200
0
1,546
862
Mahmoud and Ehab and the MEX
[ "greedy", "implementation" ]
null
null
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 . Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX. The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
[ "5 3\n0 4 5 6 7\n", "1 0\n0\n", "5 0\n1 2 3 4 5\n" ]
[ "2\n", "1\n", "0\n" ]
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations. For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0. In the third test case the set is already evil.
[ { "input": "5 3\n0 4 5 6 7", "output": "2" }, { "input": "1 0\n0", "output": "1" }, { "input": "5 0\n1 2 3 4 5", "output": "0" }, { "input": "10 5\n57 1 47 9 93 37 76 70 78 15", "output": "4" }, { "input": "10 5\n99 98 93 97 95 100 92 94 91 96", "output": "5" }, { "input": "10 5\n1 2 3 4 59 45 0 58 51 91", "output": "0" }, { "input": "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 43 23 37 95 14 38 83 90 49 56 72 10 20 0 50 71 70 88 19 1 76 81 52 41 82 68 85 47 6 7 35 60 18 64 75 84 27 9 65 91 94 42 53 24 66 26 59 36 51 32 5 58", "output": "0" }, { "input": "100 50\n95 78 46 92 80 18 79 58 30 72 19 89 39 29 44 65 15 100 59 8 96 9 62 67 41 42 82 14 57 32 71 77 40 5 7 51 28 53 85 23 16 35 3 91 6 11 75 61 17 66 13 47 36 56 10 22 83 60 48 24 26 97 4 33 76 86 70 0 34 64 52 43 21 49 55 74 1 73 81 25 54 63 94 84 20 68 87 12 31 88 38 93 37 90 98 69 99 45 27 2", "output": "0" }, { "input": "100 33\n28 11 79 92 88 62 77 72 7 41 96 97 67 84 44 8 81 35 38 1 64 68 46 17 98 83 31 12 74 21 2 22 47 6 36 75 65 61 37 26 25 45 59 48 100 51 93 76 78 49 3 57 16 4 87 29 55 82 70 39 53 0 60 15 24 71 58 20 66 89 95 42 13 43 63 90 85 52 50 30 54 40 56 23 27 34 32 18 10 19 69 9 99 73 91 14 5 80 94 86", "output": "0" }, { "input": "99 33\n25 76 41 95 55 20 47 59 58 84 87 92 16 27 35 65 72 63 93 54 36 96 15 86 5 69 24 46 67 73 48 60 40 6 61 74 97 10 100 8 52 26 77 18 7 62 37 2 14 66 11 56 68 91 0 64 75 99 30 21 53 1 89 81 3 98 12 88 39 38 29 83 22 90 9 28 45 43 78 44 32 57 4 50 70 17 13 51 80 85 71 94 82 19 34 42 23 79 49", "output": "1" }, { "input": "100 100\n65 56 84 46 44 33 99 74 62 72 93 67 43 92 75 88 38 34 66 12 55 76 58 90 78 8 14 45 97 59 48 32 64 18 39 89 31 51 54 81 29 36 70 77 40 22 49 27 3 1 73 13 98 42 87 37 2 57 4 6 50 25 23 79 28 86 68 61 80 17 19 10 15 63 52 11 35 60 21 16 24 85 30 91 7 5 69 20 71 82 53 94 41 95 96 9 26 83 0 47", "output": "0" }, { "input": "100 100\n58 88 12 71 22 1 40 19 73 20 67 48 57 17 69 36 100 35 33 37 72 55 52 8 89 85 47 42 78 70 81 86 11 9 68 99 6 16 21 61 53 98 23 62 32 59 51 0 87 24 50 30 65 10 80 95 7 92 25 74 60 79 91 5 13 31 75 38 90 94 46 66 93 34 14 41 28 2 76 84 43 96 3 56 49 82 27 77 64 63 4 45 18 29 54 39 15 26 83 44", "output": "2" }, { "input": "89 100\n58 96 17 41 86 34 28 84 18 40 8 77 87 89 68 79 33 35 53 49 0 6 22 12 72 90 48 55 21 50 56 62 75 2 37 95 69 74 14 20 44 46 27 32 31 59 63 60 10 85 71 70 38 52 94 30 61 51 80 26 36 23 39 47 76 45 100 57 15 78 97 66 54 13 99 16 93 73 24 4 83 5 98 81 92 25 29 88 65", "output": "13" }, { "input": "100 50\n7 95 24 76 81 78 60 69 83 84 100 1 65 31 48 92 73 39 18 89 38 97 10 42 8 55 98 51 21 90 62 77 16 91 0 94 4 37 19 17 67 35 45 41 56 20 15 85 75 28 59 27 12 54 61 68 36 5 79 93 66 11 70 49 50 34 30 25 96 46 64 14 32 22 47 40 58 23 43 9 87 82 26 53 80 52 3 86 13 99 33 71 6 88 57 74 2 44 72 63", "output": "2" }, { "input": "77 0\n27 8 20 92 21 41 53 98 17 65 67 35 81 11 55 49 61 44 2 66 51 89 40 28 52 62 86 91 64 24 18 5 94 82 96 99 71 6 39 83 26 29 16 30 45 97 80 90 69 12 13 33 76 73 46 19 78 56 88 38 42 34 57 77 47 4 59 58 7 100 95 72 9 74 15 43 54", "output": "0" }, { "input": "100 50\n55 36 0 32 81 6 17 43 24 13 30 19 8 59 71 45 15 74 3 41 99 42 86 47 2 94 35 1 66 95 38 49 4 27 96 89 34 44 92 25 51 39 54 28 80 77 20 14 48 40 68 56 31 63 33 78 69 37 18 26 83 70 23 82 91 65 67 52 61 53 7 22 60 21 12 73 72 87 75 100 90 29 64 79 98 85 5 62 93 84 50 46 97 58 57 16 9 10 76 11", "output": "1" }, { "input": "77 0\n12 8 19 87 9 54 55 86 97 7 27 85 25 48 94 73 26 1 13 57 72 69 76 39 38 91 75 40 42 28 93 21 70 84 65 11 60 90 20 95 66 89 59 47 34 99 6 61 52 100 50 3 77 81 82 53 15 24 0 45 44 14 68 96 58 5 18 35 10 98 29 74 92 49 83 71 17", "output": "1" }, { "input": "100 70\n25 94 66 65 10 99 89 6 70 31 7 40 20 92 64 27 21 72 77 98 17 43 47 44 48 81 38 56 100 39 90 22 88 76 3 83 86 29 33 55 82 79 49 11 2 16 12 78 85 69 32 97 26 15 53 24 23 91 51 67 34 35 52 5 62 50 95 18 71 13 75 8 30 42 93 36 45 60 63 46 57 41 87 0 84 54 74 37 4 58 28 19 96 61 80 9 1 14 73 68", "output": "2" }, { "input": "89 19\n14 77 85 81 79 38 91 45 55 51 50 11 62 67 73 76 2 27 16 23 3 29 65 98 78 17 4 58 22 20 34 66 64 31 72 5 32 44 12 75 80 47 18 25 99 0 61 56 71 84 48 88 10 7 86 8 49 24 43 21 37 28 33 54 46 57 40 89 36 97 6 96 39 95 26 74 1 69 9 100 52 30 83 87 68 60 92 90 35", "output": "2" }, { "input": "89 100\n69 61 56 45 11 41 42 32 28 29 0 76 7 65 13 35 36 82 10 39 26 34 38 40 92 12 17 54 24 46 88 70 66 27 100 52 85 62 22 48 86 68 21 49 53 94 67 20 1 90 77 84 31 87 58 47 95 33 4 72 93 83 8 51 91 80 99 43 71 19 44 59 98 97 64 9 81 16 79 63 25 37 3 75 2 55 50 6 18", "output": "13" }, { "input": "77 0\n38 76 24 74 42 88 29 75 96 46 90 32 59 97 98 60 41 57 80 37 100 49 25 63 95 31 61 68 53 78 27 66 84 48 94 83 30 26 36 99 71 62 45 47 70 28 35 54 34 85 79 43 91 72 86 33 67 92 77 65 69 52 82 55 87 64 56 40 50 44 51 73 89 81 58 93 39", "output": "0" }, { "input": "89 100\n38 90 80 64 35 44 56 11 15 89 23 12 49 70 72 60 63 85 92 10 45 83 8 88 41 33 16 6 61 76 62 71 87 13 25 77 74 0 1 37 96 93 7 94 21 82 34 78 4 73 65 20 81 95 50 32 48 17 69 55 68 5 51 27 53 43 91 67 59 46 86 84 99 24 22 3 97 98 40 36 26 58 57 9 42 30 52 2 47", "output": "11" }, { "input": "77 0\n55 71 78 86 68 35 53 10 59 32 81 19 74 97 62 61 93 87 96 44 25 18 43 82 84 16 34 48 92 39 64 36 49 91 45 76 95 31 57 29 75 79 13 2 14 24 52 23 33 20 47 99 63 15 5 80 58 67 12 3 85 6 1 27 73 90 4 42 37 70 8 11 89 77 9 22 94", "output": "0" }, { "input": "77 0\n12 75 31 71 44 8 3 82 21 77 50 29 57 74 40 10 15 42 84 2 100 9 28 72 92 0 49 11 90 55 17 36 19 54 68 52 4 69 97 91 5 39 59 45 89 62 53 83 16 94 76 60 95 47 30 51 7 48 20 70 67 32 58 78 63 34 56 93 99 88 24 1 66 22 25 14 13", "output": "1" }, { "input": "100 70\n91 82 8 85 26 25 95 97 40 87 81 93 7 73 38 94 64 96 74 18 90 19 65 68 72 61 23 43 36 41 60 88 30 33 71 24 52 39 15 3 16 89 86 79 55 4 9 58 67 44 46 29 6 48 84 69 27 21 78 54 51 57 80 53 76 50 47 77 45 12 34 10 100 0 17 31 56 99 98 11 92 5 2 42 32 59 66 62 37 63 28 75 35 1 22 13 83 49 20 14", "output": "0" }, { "input": "77 0\n51 5 81 62 30 22 11 0 83 16 79 85 52 70 69 10 8 47 58 3 24 34 44 14 82 66 99 17 28 31 64 67 23 49 94 45 4 12 27 15 21 6 43 72 87 2 63 92 35 39 59 9 90 78 93 20 65 36 60 89 50 41 61 84 77 86 76 100 38 68 53 97 96 95 7 19 88", "output": "1" }, { "input": "1 100\n0", "output": "99" }, { "input": "1 0\n100", "output": "0" }, { "input": "1 100\n100", "output": "101" }, { "input": "2 100\n0 100", "output": "100" }, { "input": "5 5\n1 2 3 4 5", "output": "2" }, { "input": "5 3\n0 3 4 5 6", "output": "3" }, { "input": "7 10\n0 1 2 3 4 5 10", "output": "5" }, { "input": "2 2\n0 2", "output": "2" }, { "input": "2 1\n1 2", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "2" }, { "input": "5 2\n1 2 3 4 5", "output": "2" }, { "input": "5 6\n0 1 2 3 4", "output": "1" }, { "input": "3 2\n3 4 5", "output": "2" } ]
30
0
0
1,548
371
Vessels
[ "data structures", "dsu", "implementation", "trees" ]
null
null
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters. Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the *i*-th vessel goes to the (*i*<=+<=1)-th one. The liquid that overflows from the *n*-th vessel spills on the floor. Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries: 1. Add *x**i* liters of water to the *p**i*-th vessel; 1. Print the number of liters of water in the *k**i*-th vessel. When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels.
The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=2·105). Each of the next *m* lines contains the description of one query. The query of the first type is represented as "1 *p**i* *x**i*", the query of the second type is represented as "2 *k**i*" (1<=≤<=*p**i*<=≤<=*n*, 1<=≤<=*x**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=*n*).
For each query, print on a single line the number of liters of water in the corresponding vessel.
[ "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n", "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n" ]
[ "4\n5\n8\n", "7\n10\n5\n" ]
none
[ { "input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2", "output": "4\n5\n8" }, { "input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3", "output": "7\n10\n5" }, { "input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n2 4\n2 7\n1 3 31\n2 4\n1 6 64\n2 2\n2 2\n1 3 54\n2 9\n2 1\n1 6 86", "output": "0\n0\n0\n0\n38\n0\n0\n0\n53\n20" }, { "input": "10\n3 7 10 1 5 4 4 3 3 1\n20\n2 4\n2 4\n1 1 10\n1 1 10\n2 4\n2 3\n1 4 2\n1 4 6\n2 2\n1 8 9\n2 2\n2 5\n2 9\n1 2 1\n1 6 9\n1 1 6\n2 5\n2 2\n2 3\n1 4 10", "output": "0\n0\n0\n10\n7\n7\n5\n3\n5\n7\n10" }, { "input": "50\n57 63 98 44 22 63 5 65 36 69 49 54 61 15 29 79 50 30 43 93 18 94 46 92 72 67 67 51 34 40 50 77 58 53 79 72 72 34 91 75 83 67 71 80 11 51 85 20 6 3\n20\n2 40\n1 14 102\n2 22\n2 15\n2 43\n1 29 532\n2 27\n2 47\n1 24 107\n1 20 720\n1 21 315\n2 20\n1 2 787\n1 27 532\n2 38\n1 32 445\n1 38 17\n1 26 450\n2 40\n1 45 192", "output": "0\n0\n29\n0\n0\n0\n93\n34\n75" }, { "input": "1\n1\n1\n2 1", "output": "0" } ]
529
18,739,200
-1
1,553
568
Primes or Palindromes?
[ "brute force", "implementation", "math", "number theory" ]
null
null
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this! Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one. Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left. One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(*n*) — the number of primes no larger than *n*, *rub*(*n*) — the number of palindromic numbers no larger than *n*. Rikhail wants to prove that there are a lot more primes than palindromic ones. He asked you to solve the following problem: for a given value of the coefficient *A* find the maximum *n*, such that π(*n*)<=≤<=*A*·*rub*(*n*).
The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ).
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
[ "1 1\n", "1 42\n", "6 4\n" ]
[ "40\n", "1\n", "172\n" ]
none
[ { "input": "1 1", "output": "40" }, { "input": "1 42", "output": "1" }, { "input": "6 4", "output": "172" }, { "input": "3 1", "output": "2530" }, { "input": "42 1", "output": "1179858" }, { "input": "10000 239", "output": "1168638" }, { "input": "5 8", "output": "16" }, { "input": "7 11", "output": "16" }, { "input": "16 60", "output": "1" }, { "input": "214 210", "output": "40" }, { "input": "620 35", "output": "251262" }, { "input": "940 480", "output": "1372" }, { "input": "1307 3420", "output": "1" }, { "input": "6811 5416", "output": "66" }, { "input": "7 267", "output": "1" }, { "input": "106 6", "output": "250300" }, { "input": "10000 10000", "output": "40" }, { "input": "10000 9999", "output": "40" }, { "input": "9999 9998", "output": "40" }, { "input": "9999 9999", "output": "40" }, { "input": "4 9", "output": "10" }, { "input": "1000 10000", "output": "1" }, { "input": "238 9996", "output": "1" }, { "input": "999 10000", "output": "1" }, { "input": "241 10000", "output": "1" }, { "input": "239 10000", "output": "1" }, { "input": "5858 674", "output": "71118" } ]
3,000
29,081,600
0
1,555
520
Two Buttons
[ "dfs and similar", "graphs", "greedy", "implementation", "math", "shortest paths" ]
null
null
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*. Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result?
The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space .
Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*.
[ "4 6\n", "10 1\n" ]
[ "2\n", "9\n" ]
In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
[ { "input": "4 6", "output": "2" }, { "input": "10 1", "output": "9" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "1 3", "output": "3" }, { "input": "3 1", "output": "2" }, { "input": "2 10", "output": "5" }, { "input": "100 99", "output": "1" }, { "input": "99 100", "output": "50" }, { "input": "10 17", "output": "3" }, { "input": "666 6666", "output": "255" }, { "input": "6666 666", "output": "6000" }, { "input": "1 8192", "output": "13" }, { "input": "1 8193", "output": "27" }, { "input": "9999 10000", "output": "5000" }, { "input": "10000 9999", "output": "1" }, { "input": "10000 1", "output": "9999" }, { "input": "1234 5678", "output": "528" }, { "input": "9102 9103", "output": "4552" }, { "input": "8192 1", "output": "8191" }, { "input": "9912 1023", "output": "8889" }, { "input": "100 500", "output": "41" }, { "input": "9997 9999", "output": "4999" }, { "input": "5000 10000", "output": "1" }, { "input": "4000 7997", "output": "3" }, { "input": "1 10000", "output": "20" }, { "input": "1 8191", "output": "14" }, { "input": "9999 10000", "output": "5000" }, { "input": "9097 9998", "output": "4099" }, { "input": "886 9383", "output": "305" }, { "input": "1 9", "output": "7" }, { "input": "1918 10000", "output": "671" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "2" }, { "input": "2 10000", "output": "19" }, { "input": "3 10000", "output": "17" }, { "input": "4 10000", "output": "18" }, { "input": "9998 10000", "output": "4999" }, { "input": "5000 10000", "output": "1" }, { "input": "5001 10000", "output": "2" }, { "input": "10000 1", "output": "9999" }, { "input": "1 9999", "output": "21" }, { "input": "7777 9999", "output": "2779" }, { "input": "2 100", "output": "9" }, { "input": "10 8722", "output": "18" }, { "input": "848 4561", "output": "283" }, { "input": "9967 9973", "output": "4982" }, { "input": "5555 10000", "output": "556" }, { "input": "999 10000", "output": "378" }, { "input": "3 6", "output": "1" }, { "input": "9 38", "output": "8" } ]
61
1,228,800
3
1,556
336
Vasily the Bear and Triangle
[ "implementation", "math" ]
null
null
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold: - the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=&lt;<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible. Help the bear, find the required points. It is not so hard to proof that these points are unique.
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
[ "10 5\n", "-10 5\n" ]
[ "0 15 15 0\n", "-15 0 0 15\n" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/> Figure to the first sample
[ { "input": "10 5", "output": "0 15 15 0" }, { "input": "-10 5", "output": "-15 0 0 15" }, { "input": "20 -10", "output": "0 -30 30 0" }, { "input": "-10 -1000000000", "output": "-1000000010 0 0 -1000000010" }, { "input": "-1000000000 -1000000000", "output": "-2000000000 0 0 -2000000000" }, { "input": "1000000000 1000000000", "output": "0 2000000000 2000000000 0" }, { "input": "-123131 3123141", "output": "-3246272 0 0 3246272" }, { "input": "-23423 -243242423", "output": "-243265846 0 0 -243265846" }, { "input": "123112 4560954", "output": "0 4684066 4684066 0" }, { "input": "1321 -23131", "output": "0 -24452 24452 0" }, { "input": "1000000000 999999999", "output": "0 1999999999 1999999999 0" }, { "input": "54543 432423", "output": "0 486966 486966 0" }, { "input": "1 1", "output": "0 2 2 0" }, { "input": "-1 -1", "output": "-2 0 0 -2" }, { "input": "-1 1", "output": "-2 0 0 2" }, { "input": "1 -1", "output": "0 -2 2 0" }, { "input": "42 -2", "output": "0 -44 44 0" }, { "input": "2 -435", "output": "0 -437 437 0" }, { "input": "76 -76", "output": "0 -152 152 0" }, { "input": "1000000000 1", "output": "0 1000000001 1000000001 0" }, { "input": "1000000000 -1", "output": "0 -1000000001 1000000001 0" }, { "input": "-1000000000 1", "output": "-1000000001 0 0 1000000001" }, { "input": "-1000000000 -1", "output": "-1000000001 0 0 -1000000001" }, { "input": "1000000000 -999999999", "output": "0 -1999999999 1999999999 0" }, { "input": "-1000000000 999999999", "output": "-1999999999 0 0 1999999999" }, { "input": "-1000000000 -999999999", "output": "-1999999999 0 0 -1999999999" }, { "input": "999999999 1000000000", "output": "0 1999999999 1999999999 0" }, { "input": "-999999999 1000000000", "output": "-1999999999 0 0 1999999999" }, { "input": "999999999 -1000000000", "output": "0 -1999999999 1999999999 0" }, { "input": "-999999999 -1000000000", "output": "-1999999999 0 0 -1999999999" } ]
186
0
3
1,557
898
Phone Numbers
[ "implementation", "strings" ]
null
null
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record. Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account. The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once. Read the examples to understand statement and format of the output better.
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books. The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books. The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend. Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.
[ "2\nivan 1 00123\nmasha 1 00123\n", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n" ]
[ "2\nmasha 1 00123 \nivan 1 00123 \n", "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n", "2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n" ]
none
[ { "input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123 \nivan 1 00123 " }, { "input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 " }, { "input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 789 23 \nivan 4 2 123 456 789 " }, { "input": "20\nnxj 6 7 6 6 7 7 7\nnxj 10 8 5 1 7 6 1 0 7 0 6\nnxj 2 6 5\nnxj 10 6 7 6 6 5 8 3 6 6 8\nnxj 10 6 1 7 6 7 1 8 7 8 6\nnxj 10 8 5 8 6 5 6 1 9 6 3\nnxj 10 8 1 6 4 8 0 4 6 0 1\nnxj 9 2 6 6 8 1 1 3 6 6\nnxj 10 8 9 0 9 1 3 2 3 2 3\nnxj 6 6 7 0 8 1 2\nnxj 7 7 7 8 1 3 6 9\nnxj 10 2 7 0 1 5 1 9 1 2 6\nnxj 6 9 6 9 6 3 7\nnxj 9 0 1 7 8 2 6 6 5 6\nnxj 4 0 2 3 7\nnxj 10 0 4 0 6 1 1 8 8 4 7\nnxj 8 4 6 2 6 6 1 2 7\nnxj 10 5 3 4 2 1 0 7 0 7 6\nnxj 10 9 6 0 6 1 6 2 1 9 6\nnxj 4 2 9 0 1", "output": "1\nnxj 10 4 1 8 7 5 3 6 9 0 2 " }, { "input": "20\nl 6 02 02 2 02 02 2\nl 8 8 8 8 2 62 13 31 3\ne 9 0 91 0 0 60 91 60 2 44\ne 9 69 2 1 44 2 91 66 1 70\nl 9 7 27 27 3 1 3 7 80 81\nl 9 2 1 13 7 2 10 02 3 92\ne 9 0 15 3 5 5 15 91 09 44\nl 7 2 50 4 5 98 31 98\nl 3 26 7 3\ne 6 7 5 0 62 65 91\nl 8 80 0 4 0 2 2 0 13\nl 9 19 13 02 2 1 4 19 26 02\nl 10 7 39 7 9 22 22 26 2 90 4\ne 7 65 2 36 0 34 57 9\ne 8 13 02 09 91 73 5 36 62\nl 9 75 0 10 8 76 7 82 8 34\nl 7 34 0 19 80 6 4 7\ne 5 4 2 5 7 2\ne 7 4 02 69 7 07 20 2\nl 4 8 2 1 63", "output": "2\ne 18 70 07 62 36 20 69 66 57 02 65 34 44 73 60 91 15 09 13 \nl 21 02 80 27 63 19 50 81 76 34 90 98 92 31 26 22 75 39 13 10 82 62 " }, { "input": "20\no 10 6 6 97 45 6 6 6 6 5 6\nl 8 5 5 5 19 59 5 8 5\nj 9 2 30 58 2 2 1 0 30 4\nc 10 1 1 7 51 7 7 51 1 1 1\no 9 7 97 87 70 2 19 2 14 6\ne 6 26 6 6 6 26 5\ng 9 3 3 3 3 3 78 69 8 9\nl 8 8 01 1 5 8 41 72 3\nz 10 1 2 2 2 9 1 9 1 6 7\ng 8 7 78 05 36 7 3 67 9\no 5 6 9 9 7 7\ne 10 30 2 1 1 2 5 04 0 6 6\ne 9 30 30 2 2 0 26 30 79 8\nt 10 2 2 9 29 7 7 7 9 2 9\nc 7 7 51 1 31 2 7 4\nc 9 83 1 6 78 94 74 54 8 32\ng 8 4 1 01 9 39 28 6 6\nt 7 9 2 01 4 4 9 58\nj 5 0 1 58 02 4\nw 10 80 0 91 91 06 91 9 9 27 7", "output": "9\nw 5 91 06 27 9 80 \nt 6 01 29 4 58 2 7 \ne 8 2 8 30 04 26 5 79 1 \nl 8 8 41 72 01 19 59 3 5 \nj 5 58 02 1 4 30 \nz 5 7 9 6 2 1 \ng 10 39 67 3 01 36 4 05 69 78 28 \no 8 19 2 45 6 87 14 97 70 \nc 10 7 94 32 6 78 74 31 83 51 54 " }, { "input": "1\negew 5 3 123 23 1234 134", "output": "1\negew 3 134 123 1234 " } ]
170
307,200
0
1,558
0
none
[ "none" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines. A position is good if two conditions hold: - there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects. Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction. Therefore, there are 9 good positions in this example.
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 1\n1\n0\n0", "output": "2" }, { "input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0", "output": "25" }, { "input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "4" }, { "input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1", "output": "26" }, { "input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "121" }, { "input": "1 2\n0 1", "output": "1" }, { "input": "1 2\n1 0", "output": "1" }, { "input": "1 2\n1 1", "output": "0" }, { "input": "2 1\n1\n0", "output": "1" }, { "input": "2 1\n0\n1", "output": "1" }, { "input": "2 1\n1\n1", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1", "output": "16" } ]
1,000
5,939,200
0
1,559
4
Registration System
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" }, { "input": "3\nb\nb\nb", "output": "OK\nb1\nb2" }, { "input": "2\nc\ncn", "output": "OK\nOK" }, { "input": "3\nvhn\nvhn\nh", "output": "OK\nvhn1\nOK" }, { "input": "4\nd\nhd\nd\nh", "output": "OK\nOK\nd1\nOK" }, { "input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp", "output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9" }, { "input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh", "output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7" }, { "input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj", "output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4" }, { "input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4" }, { "input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3" } ]
92
0
0
1,564
336
Vasily the Bear and Fly
[ "math" ]
null
null
One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=-<=*R*,<=0), respectively. Circles with numbers from *m*<=+<=1 to 2*m* had centers at points (2*R*<=-<=*R*,<=2*R*), (4*R*<=-<=*R*,<=2*R*), ..., (2*Rm*<=-<=*R*,<=2*R*), respectively. Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continued for *m*2 days. Each day of the experiment got its own unique number from 0 to *m*2<=-<=1, inclusive. On the day number *i* the following things happened: 1. The fly arrived at the coordinate plane at the center of the circle with number ( is the result of dividing number *x* by number *y*, rounded down to an integer). 1. The fly went along the coordinate plane to the center of the circle number ( is the remainder after dividing number *x* by number *y*). The bear noticed that the fly went from the center of circle *v* to the center of circle *u* along the shortest path with all points lying on the border or inside at least one of the 2*m* circles. After the fly reached the center of circle *u*, it flew away in an unknown direction. Help Vasily, count the average distance the fly went along the coordinate plane during each of these *m*2 days.
The first line contains two integers *m*,<=*R* (1<=≤<=*m*<=≤<=105, 1<=≤<=*R*<=≤<=10).
In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "1 1\n", "2 2\n" ]
[ "2.0000000000\n", "5.4142135624\n" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/9fe384073741e20965ddc4bf162afd3a604b6b39.png" style="max-width: 100.0%;max-height: 100.0%;"/> Figure to the second sample
[ { "input": "1 1", "output": "2.0000000000" }, { "input": "2 2", "output": "5.4142135624" }, { "input": "100000 3", "output": "200002.4853316681" }, { "input": "2344 5", "output": "7817.4790439982" }, { "input": "999 10", "output": "6668.3010410807" }, { "input": "6 1", "output": "5.0752966144" }, { "input": "43 4", "output": "118.1337922078" }, { "input": "3333 3", "output": "6668.4867900399" }, { "input": "4444 4", "output": "11853.9818839104" }, { "input": "100000 10", "output": "666674.9511055604" }, { "input": "3134 9", "output": "18811.4606574435" }, { "input": "9 9", "output": "63.0021484426" }, { "input": "32 9", "output": "199.9170568378" }, { "input": "33333 9", "output": "200005.4562967670" }, { "input": "99999 1", "output": "66666.8284438896" }, { "input": "99999 9", "output": "600001.4559950059" }, { "input": "99999 7", "output": "466667.7991072268" }, { "input": "4234 4", "output": "11293.9819587295" }, { "input": "66666 6", "output": "266668.9707136318" }, { "input": "66666 9", "output": "400003.4560704476" }, { "input": "67676 7", "output": "315827.1324966100" }, { "input": "7777 7", "output": "36298.4671653864" }, { "input": "7656 2", "output": "10209.6572921612" }, { "input": "2 8", "output": "21.6568542495" }, { "input": "2 10", "output": "27.0710678119" }, { "input": "2 4", "output": "10.8284271247" }, { "input": "8 1", "output": "6.3530145174" }, { "input": "8 8", "output": "50.8241161391" }, { "input": "92399 1", "output": "61600.1617786019" }, { "input": "1 10", "output": "20.0000000000" }, { "input": "3 1", "output": "3.2570787221" } ]
686
0
3
1,568
468
Hack it!
[ "binary search", "constructive algorithms", "math" ]
null
null
Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code:
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018).
Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=&lt;<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
[ "46\n", "126444381000032\n" ]
[ "1 10\n", "2333333 2333333333333\n" ]
none
[ { "input": "46", "output": "1 10" }, { "input": "126444381000032", "output": "2333333 2333333333333" }, { "input": "69645082595", "output": "613752823618441225798858488535 713259406474207764329704856394" }, { "input": "70602205995", "output": "11 249221334020432074498656960922" }, { "input": "33898130785", "output": "9 558855506346909386939077840182" }, { "input": "58929554039", "output": "22 855783114773435710171914224422" }, { "input": "81696185182", "output": "499118531974994927425925323518 956291458400902769638235161661" }, { "input": "1", "output": "149268802942315027273202513064 277551734280589260570057105889" }, { "input": "2", "output": "119692200833686078608961312319 629363568954685219494592939495" }, { "input": "3", "output": "2 302254410562920936884653943506" }, { "input": "4", "output": "284378053387469023431537894255 317250990020830090421009164911" }, { "input": "5", "output": "2 62668056583245293799710157951" }, { "input": "6", "output": "3 93810188780011787541394067841" }, { "input": "7", "output": "2 834286447477504059026206246185" }, { "input": "8", "output": "3 257583347960907690857477857197" }, { "input": "10", "output": "3 163048811987317819669274448265" }, { "input": "11", "output": "3 919618203693907154039906935669" }, { "input": "12", "output": "448221703341269567451520778454 698029790336105644790102859494" }, { "input": "43", "output": "9 172412961300207091437973214327" }, { "input": "36", "output": "8 619355518777647869838990701242" }, { "input": "65", "output": "6 709024330418134127413755925068" }, { "input": "43", "output": "7 669540448846929747909766131221" }, { "input": "23", "output": "2 104579054315773428039906118259" }, { "input": "100", "output": "15 324437778467489559125023403167" }, { "input": "10000", "output": "2 936791129091842315790163514642" }, { "input": "1000000", "output": "18 369591628030718549289473454545" }, { "input": "100000000", "output": "7 870405265198051697453938746950" }, { "input": "10000000000", "output": "20 972749766921651560604778558599" }, { "input": "1000000000000", "output": "6 68997070398311657294228230677" }, { "input": "100000000000000", "output": "249537318528661282822184562278 397003438246047829818181818181" }, { "input": "10000000000000000", "output": "10 778165727326620883431915444624" }, { "input": "1000000000000000000", "output": "408256298986776744812953390000 824018301451167837914299999999" }, { "input": "450000000000000000", "output": "2 357722688084551093593033993033" }, { "input": "432022", "output": "3 333556238531076799985515487090" }, { "input": "428033", "output": "22 730314748425770554502599499142" }, { "input": "776930", "output": "20 521232359366297130685112811874" }, { "input": "329824", "output": "308969571112207311167474021348 745620588073413831210052337999" }, { "input": "85058261498638", "output": "16 931187081941564769324316582547" }, { "input": "2130909834463", "output": "21 895378349209612431051450316022" }, { "input": "3427089130241", "output": "10 676758114393938690602742889714" }, { "input": "22881472397923", "output": "174523915446146844994793303441 429392837423394397373605399524" }, { "input": "756499070280135900", "output": "17 414254565210363110239866979636" }, { "input": "348919756917359012", "output": "15 148711424846749040017925495268" }, { "input": "789136710974630947", "output": "13 214740524663440316532540770911" }, { "input": "32851678509090784", "output": "15 728787006985867306455350840047" }, { "input": "219760524792138559", "output": "8 51530430692061277616906746431" }, { "input": "1000000007", "output": "19 96093944063249823335491170999" }, { "input": "999999874000003969", "output": "306259936121099507549028331741 983025349899931537481252156006" }, { "input": "999999999999999989", "output": "140766388309929586494194507367 705096656792775954903252198639" }, { "input": "999999999999999983", "output": "4 365946710276937286091309116340" }, { "input": "999999999999999999", "output": "26 983966655749419565978291923474" } ]
62
0
3
1,574
534
Covered Path
[ "dp", "greedy", "math" ]
null
null
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters.
The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that: - the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*.
Print the maximum possible length of the path segment in meters.
[ "5 6\n4 2\n", "10 10\n10 0\n" ]
[ "26", "100" ]
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
[ { "input": "5 6\n4 2", "output": "26" }, { "input": "10 10\n10 0", "output": "100" }, { "input": "87 87\n2 10", "output": "174" }, { "input": "1 11\n6 2", "output": "36" }, { "input": "100 10\n10 10", "output": "550" }, { "input": "1 1\n100 10", "output": "24600" }, { "input": "1 1\n5 1", "output": "9" }, { "input": "1 1\n5 2", "output": "13" }, { "input": "100 100\n100 0", "output": "10000" }, { "input": "100 100\n100 10", "output": "34500" }, { "input": "1 100\n100 1", "output": "5050" }, { "input": "1 100\n100 10", "output": "29305" }, { "input": "100 1\n100 1", "output": "5050" }, { "input": "100 1\n100 10", "output": "29305" }, { "input": "1 10\n2 10", "output": "11" }, { "input": "1 1\n2 1", "output": "2" }, { "input": "1 1\n2 10", "output": "2" }, { "input": "1 2\n2 1", "output": "3" }, { "input": "1 2\n2 10", "output": "3" }, { "input": "1 5\n3 2", "output": "9" }, { "input": "2 1\n2 2", "output": "3" }, { "input": "2 1\n2 10", "output": "3" }, { "input": "1 11\n2 10", "output": "12" }, { "input": "11 1\n2 10", "output": "12" }, { "input": "1 1\n3 5", "output": "8" }, { "input": "1 10\n3 5", "output": "17" }, { "input": "1 21\n3 10", "output": "33" }, { "input": "21 1\n3 10", "output": "33" }, { "input": "100 100\n99 1", "output": "12301" }, { "input": "100 100\n100 1", "output": "12450" }, { "input": "99 99\n99 1", "output": "12202" }, { "input": "99 99\n99 10", "output": "33811" }, { "input": "1 100\n99 10", "output": "28764" }, { "input": "13 31\n7 5", "output": "182" }, { "input": "88 78\n8 5", "output": "719" }, { "input": "34 48\n47 4", "output": "4030" }, { "input": "91 29\n78 3", "output": "8806" }, { "input": "90 81\n21 6", "output": "2391" }, { "input": "95 89\n45 3", "output": "5589" }, { "input": "48 54\n84 2", "output": "7724" }, { "input": "72 31\n59 7", "output": "8865" }, { "input": "51 13\n47 3", "output": "2970" }, { "input": "97 91\n82 2", "output": "10984" }, { "input": "71 71\n9 5", "output": "719" }, { "input": "16 49\n40 3", "output": "2350" }, { "input": "22 41\n68 4", "output": "6608" }, { "input": "13 71\n72 6", "output": "10444" }, { "input": "77 78\n46 3", "output": "5083" }, { "input": "36 60\n54 2", "output": "3924" }, { "input": "55 39\n93 2", "output": "8571" }, { "input": "34 7\n48 6", "output": "4266" }, { "input": "80 88\n79 3", "output": "11193" }, { "input": "34 62\n15 4", "output": "866" }, { "input": "81 40\n73 2", "output": "6798" }, { "input": "13 38\n97 6", "output": "16271" }, { "input": "84 87\n45 2", "output": "4814" }, { "input": "42 65\n76 3", "output": "8240" }, { "input": "55 6\n24 4", "output": "1110" }, { "input": "41 16\n43 2", "output": "2029" }, { "input": "99 93\n78 1", "output": "8961" }, { "input": "10 7\n44 2", "output": "1297" }, { "input": "72 54\n91 3", "output": "11781" }, { "input": "48 34\n80 2", "output": "6376" }, { "input": "92 85\n70 1", "output": "7373" } ]
108
0
0
1,575
962
Equator
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }, { "input": "3\n1 1 3", "output": "3" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "5\n1 2 4 3 5", "output": "4" }, { "input": "5\n2 2 2 4 3", "output": "4" }, { "input": "4\n1 2 3 1", "output": "3" }, { "input": "6\n7 3 10 7 3 11", "output": "4" }, { "input": "2\n3 4", "output": "2" }, { "input": "5\n1 1 1 1 1", "output": "3" }, { "input": "4\n1 3 2 3", "output": "3" }, { "input": "2\n2 3", "output": "2" }, { "input": "3\n32 10 23", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "4" }, { "input": "3\n1 2 4", "output": "3" }, { "input": "6\n3 3 3 2 4 4", "output": "4" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "5\n1 3 3 1 1", "output": "3" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "3\n2 2 1", "output": "2" }, { "input": "4\n2 3 3 3", "output": "3" }, { "input": "4\n3 2 3 3", "output": "3" }, { "input": "4\n2 1 1 1", "output": "2" }, { "input": "3\n2 1 4", "output": "3" }, { "input": "2\n6 7", "output": "2" }, { "input": "4\n3 3 4 3", "output": "3" }, { "input": "4\n1 1 2 5", "output": "4" }, { "input": "4\n1 8 7 3", "output": "3" }, { "input": "6\n2 2 2 2 2 3", "output": "4" }, { "input": "3\n2 2 5", "output": "3" }, { "input": "4\n1 1 2 1", "output": "3" }, { "input": "5\n1 1 2 2 3", "output": "4" }, { "input": "5\n9 5 3 4 8", "output": "3" }, { "input": "3\n3 3 1", "output": "2" }, { "input": "4\n1 2 2 2", "output": "3" }, { "input": "3\n1 3 5", "output": "3" }, { "input": "4\n1 1 3 6", "output": "4" }, { "input": "6\n1 2 1 1 1 1", "output": "3" }, { "input": "3\n3 1 3", "output": "2" }, { "input": "5\n3 4 5 1 2", "output": "3" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "5\n3 1 2 5 2", "output": "4" }, { "input": "4\n1 1 1 4", "output": "4" }, { "input": "4\n2 6 1 10", "output": "4" }, { "input": "4\n2 2 3 2", "output": "3" }, { "input": "4\n4 2 2 1", "output": "2" }, { "input": "6\n1 1 1 1 1 4", "output": "5" }, { "input": "3\n3 2 2", "output": "2" }, { "input": "6\n1 3 5 1 7 4", "output": "5" }, { "input": "5\n1 2 4 8 16", "output": "5" }, { "input": "5\n1 2 4 4 4", "output": "4" }, { "input": "6\n4 2 1 2 3 1", "output": "3" }, { "input": "4\n3 2 1 5", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "3\n2 4 7", "output": "3" }, { "input": "5\n1 1 1 1 3", "output": "4" }, { "input": "3\n3 1 5", "output": "3" }, { "input": "4\n1 2 3 7", "output": "4" }, { "input": "3\n1 4 6", "output": "3" }, { "input": "4\n2 1 2 2", "output": "3" }, { "input": "2\n4 5", "output": "2" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "3\n2 3 6", "output": "3" }, { "input": "6\n1 1 4 1 1 5", "output": "4" }, { "input": "5\n2 2 2 2 1", "output": "3" }, { "input": "2\n5 6", "output": "2" }, { "input": "4\n2 2 1 4", "output": "3" }, { "input": "5\n2 2 3 4 4", "output": "4" }, { "input": "4\n3 1 1 2", "output": "2" }, { "input": "5\n3 4 1 4 5", "output": "4" }, { "input": "4\n1 3 1 6", "output": "4" }, { "input": "5\n1 1 1 2 2", "output": "4" }, { "input": "4\n1 4 2 4", "output": "3" }, { "input": "10\n1 1 1 1 1 1 1 1 1 8", "output": "9" }, { "input": "4\n1 4 5 1", "output": "3" }, { "input": "5\n1 1 1 1 5", "output": "5" }, { "input": "4\n1 3 4 1", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "4\n2 3 2 4", "output": "3" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "3\n4 3 2", "output": "2" }, { "input": "3\n6 5 2", "output": "2" }, { "input": "69\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "35" }, { "input": "6\n1 1 1 1 1 2", "output": "4" }, { "input": "5\n1 2 5 4 5", "output": "4" }, { "input": "2\n9 10", "output": "2" }, { "input": "3\n1 1 5", "output": "3" }, { "input": "4\n3 4 3 5", "output": "3" }, { "input": "4\n1 4 3 3", "output": "3" }, { "input": "4\n7 1 3 4", "output": "2" }, { "input": "3\n100 100 1", "output": "2" }, { "input": "4\n5 2 2 2", "output": "2" } ]
171
20,582,400
3
1,579
1,003
Coins and Queries
[ "greedy" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1. The queries are independent (the answer on the query doesn't affect Polycarp's coins).
The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$).
Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1.
[ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n" ]
[ "1\n-1\n3\n2\n" ]
none
[ { "input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2" }, { "input": "3 3\n1 1 1\n1\n2\n3", "output": "1\n2\n3" }, { "input": "4 1\n2 4 16 32\n14", "output": "-1" }, { "input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\n-1\n-1" }, { "input": "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" } ]
124
2,150,400
-1
1,580
26
Regular Bracket Sequence
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()(((", "output": "6" }, { "input": "()))(()((((()(())", "output": "10" }, { "input": "())))((()())())))))())", "output": "14" }, { "input": ")))((((())(()((()((((()()())((", "output": "16" }, { "input": "))()()((()()))())()(((((((())((((((((())()()((())(", "output": "32" }, { "input": "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))", "output": "48" } ]
92
0
0
1,585
518
Vitaly and Strings
[ "constructive algorithms", "strings" ]
null
null
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*. Let's help Vitaly solve this easy problem!
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*.
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.
[ "a\nc\n", "aaa\nzzz\n", "abcdefg\nabcdefh\n" ]
[ "b\n", "kkk\n", "No such string\n" ]
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> &lt; *t*<sub class="lower-index">*i*</sub>.
[ { "input": "a\nc", "output": "b" }, { "input": "aaa\nzzz", "output": "kkk" }, { "input": "abcdefg\nabcdefh", "output": "No such string" }, { "input": "abcdefg\nabcfefg", "output": "abcdefh" }, { "input": "frt\nfru", "output": "No such string" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzx\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy" }, { "input": "q\nz", "output": "r" }, { "input": "pnzcl\npnzdf", "output": "pnzcm" }, { "input": "vklldrxnfgyorgfpfezvhbouyzzzzz\nvklldrxnfgyorgfpfezvhbouzaaadv", "output": "vklldrxnfgyorgfpfezvhbouzaaaaa" }, { "input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr", "output": "pkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "exoudpymnspkocwszzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nexoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabml", "output": "exoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "anarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubil\nanarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubim", "output": "No such string" }, { "input": "uqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjllzzz\nuqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjlmaaa", "output": "No such string" }, { "input": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdacbzzzzzzzzzzzzzz\nesfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaatf", "output": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaaaa" }, { "input": "oisjtilteipnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\noisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao", "output": "oisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "svpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimgzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nsvpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "No such string" }, { "input": "ddzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\ndeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao", "output": "deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavdzz\nxqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavilj", "output": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdaveaa" }, { "input": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfoq\npoflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawujg", "output": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfor" }, { "input": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nvonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac", "output": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "bqycw\nquhod", "output": "bqycx" }, { "input": "hceslswecf\nnmxshuymaa", "output": "hceslswecg" }, { "input": "awqtzslxowuaefe\nvujscakjpvxviki", "output": "awqtzslxowuaeff" }, { "input": "lerlcnaogdravnogfogcyoxgi\nojrbithvjdqtempegvqxmgmmw", "output": "lerlcnaogdravnogfogcyoxgj" }, { "input": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxv\noevvkhujmhagaholrmsatdjjyfmyblvgetpnxgjcilugjsncjs", "output": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxw" }, { "input": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzww\nspvgaswympzlscnumemgiznngnxqgccbubmxgqmaakbnyngkxlxjjsafricchhpecdjgxw", "output": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzwx" }, { "input": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcf\nohhhhkujfpjbgouebtmmbzizuhuumvrsqfniwpmxdtzhyiaivdyxhywnqzagicydixjtvbqbevhbqttu", "output": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcg" }, { "input": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndl\nuvuqvyrnhtyubpevizhjxdvmpueittksrnosmfuuzbimnqussasdjufrthrgjbyzomauaxbvwferfvtmydmwmjaoxg", "output": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndm" }, { "input": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyay\nqibcfxdfovoejutaeetbbwrgexdrvqywwmhipxgfrvhzovxkfawpfnpjvlhkyahessodqcclangxefcaixysqijnitevwmpalkzd", "output": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyaz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "output": "No such string" }, { "input": "phdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmun\nphdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmuo", "output": "No such string" }, { "input": "hrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzoog\nhrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzooh", "output": "No such string" }, { "input": "kexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywl\nkexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywm", "output": "No such string" }, { "input": "yijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowmk\nyijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowml", "output": "No such string" }, { "input": "a\nb", "output": "No such string" }, { "input": "x\nz", "output": "y" }, { "input": "a\nz", "output": "b" }, { "input": "y\nz", "output": "No such string" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "No such string" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" }, { "input": "yzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyz" }, { "input": "aaa\naac", "output": "aab" }, { "input": "aaa\naab", "output": "No such string" }, { "input": "zzx\nzzz", "output": "zzy" }, { "input": "zzy\nzzz", "output": "No such string" }, { "input": "aba\naca", "output": "abb" }, { "input": "aaa\nbbb", "output": "aab" }, { "input": "azzz\ncaaa", "output": "baaa" } ]
46
0
0
1,589
691
s-palindrome
[ "implementation", "strings" ]
null
null
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. You are given a string *s*. Check if the string is "s-palindrome".
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters.
Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise.
[ "oXoxoXo\n", "bod\n", "ER\n" ]
[ "TAK\n", "TAK\n", "NIE\n" ]
none
[ { "input": "oXoxoXo", "output": "TAK" }, { "input": "bod", "output": "TAK" }, { "input": "ER", "output": "NIE" }, { "input": "o", "output": "TAK" }, { "input": "a", "output": "NIE" }, { "input": "opo", "output": "NIE" }, { "input": "HCMoxkgbNb", "output": "NIE" }, { "input": "vMhhXCMWDe", "output": "NIE" }, { "input": "iIcamjTRFH", "output": "NIE" }, { "input": "WvoWvvWovW", "output": "TAK" }, { "input": "WXxAdbAxXW", "output": "TAK" }, { "input": "vqMTUUTMpv", "output": "TAK" }, { "input": "iii", "output": "NIE" }, { "input": "AAWW", "output": "NIE" }, { "input": "ss", "output": "NIE" }, { "input": "i", "output": "NIE" }, { "input": "ii", "output": "NIE" }, { "input": "mm", "output": "NIE" }, { "input": "LJ", "output": "NIE" }, { "input": "m", "output": "NIE" }, { "input": "ioi", "output": "NIE" }, { "input": "OA", "output": "NIE" }, { "input": "aaaiaaa", "output": "NIE" }, { "input": "SS", "output": "NIE" }, { "input": "iiii", "output": "NIE" }, { "input": "ssops", "output": "NIE" }, { "input": "ssss", "output": "NIE" }, { "input": "ll", "output": "NIE" }, { "input": "s", "output": "NIE" }, { "input": "bb", "output": "NIE" }, { "input": "uu", "output": "NIE" }, { "input": "ZoZ", "output": "NIE" }, { "input": "mom", "output": "NIE" }, { "input": "uou", "output": "NIE" }, { "input": "u", "output": "NIE" }, { "input": "JL", "output": "NIE" }, { "input": "mOm", "output": "NIE" }, { "input": "llll", "output": "NIE" }, { "input": "ouo", "output": "NIE" }, { "input": "aa", "output": "NIE" }, { "input": "olo", "output": "NIE" }, { "input": "S", "output": "NIE" }, { "input": "lAl", "output": "NIE" }, { "input": "nnnn", "output": "NIE" }, { "input": "ZzZ", "output": "NIE" }, { "input": "bNd", "output": "NIE" }, { "input": "ZZ", "output": "NIE" }, { "input": "oNoNo", "output": "NIE" }, { "input": "l", "output": "NIE" }, { "input": "zz", "output": "NIE" }, { "input": "NON", "output": "NIE" }, { "input": "nn", "output": "NIE" }, { "input": "NoN", "output": "NIE" }, { "input": "sos", "output": "NIE" }, { "input": "lol", "output": "NIE" }, { "input": "mmm", "output": "NIE" }, { "input": "YAiAY", "output": "NIE" }, { "input": "ipIqi", "output": "NIE" }, { "input": "AAA", "output": "TAK" }, { "input": "uoOou", "output": "NIE" }, { "input": "SOS", "output": "NIE" }, { "input": "NN", "output": "NIE" }, { "input": "n", "output": "NIE" }, { "input": "h", "output": "NIE" }, { "input": "blld", "output": "NIE" }, { "input": "ipOqi", "output": "NIE" }, { "input": "pop", "output": "NIE" }, { "input": "BB", "output": "NIE" }, { "input": "OuO", "output": "NIE" }, { "input": "lxl", "output": "NIE" }, { "input": "Z", "output": "NIE" }, { "input": "vvivv", "output": "NIE" }, { "input": "nnnnnnnnnnnnn", "output": "NIE" }, { "input": "AA", "output": "TAK" }, { "input": "t", "output": "NIE" }, { "input": "z", "output": "NIE" }, { "input": "mmmAmmm", "output": "NIE" }, { "input": "qlililp", "output": "NIE" }, { "input": "mpOqm", "output": "NIE" }, { "input": "iiiiiiiiii", "output": "NIE" }, { "input": "BAAAB", "output": "NIE" }, { "input": "UA", "output": "NIE" }, { "input": "mmmmmmm", "output": "NIE" }, { "input": "NpOqN", "output": "NIE" }, { "input": "uOu", "output": "NIE" }, { "input": "uuu", "output": "NIE" }, { "input": "NAMAN", "output": "NIE" }, { "input": "lllll", "output": "NIE" }, { "input": "T", "output": "TAK" }, { "input": "mmmmmmmmmmmmmmmm", "output": "NIE" }, { "input": "AiiA", "output": "NIE" }, { "input": "iOi", "output": "NIE" }, { "input": "lll", "output": "NIE" }, { "input": "N", "output": "NIE" }, { "input": "viv", "output": "NIE" }, { "input": "oiio", "output": "NIE" }, { "input": "AiiiA", "output": "NIE" }, { "input": "NNNN", "output": "NIE" }, { "input": "ixi", "output": "NIE" }, { "input": "AuuA", "output": "NIE" }, { "input": "AAAANANAAAA", "output": "NIE" }, { "input": "mmmmm", "output": "NIE" }, { "input": "oYo", "output": "TAK" }, { "input": "dd", "output": "NIE" }, { "input": "A", "output": "TAK" }, { "input": "ioh", "output": "NIE" }, { "input": "mmmm", "output": "NIE" }, { "input": "uuuu", "output": "NIE" }, { "input": "puq", "output": "NIE" }, { "input": "rrrrrr", "output": "NIE" }, { "input": "c", "output": "NIE" }, { "input": "AbpA", "output": "NIE" }, { "input": "qAq", "output": "NIE" }, { "input": "tt", "output": "NIE" }, { "input": "mnmnm", "output": "NIE" }, { "input": "sss", "output": "NIE" }, { "input": "yy", "output": "NIE" }, { "input": "bob", "output": "NIE" }, { "input": "NAN", "output": "NIE" }, { "input": "mAm", "output": "NIE" }, { "input": "tAt", "output": "NIE" }, { "input": "yAy", "output": "NIE" }, { "input": "zAz", "output": "NIE" }, { "input": "aZ", "output": "NIE" }, { "input": "hh", "output": "NIE" }, { "input": "bbbb", "output": "NIE" }, { "input": "ZAZ", "output": "NIE" }, { "input": "Y", "output": "TAK" }, { "input": "AAMM", "output": "NIE" }, { "input": "lml", "output": "NIE" }, { "input": "AZA", "output": "NIE" }, { "input": "mXm", "output": "NIE" }, { "input": "bd", "output": "TAK" }, { "input": "H", "output": "TAK" }, { "input": "uvu", "output": "NIE" }, { "input": "dxxd", "output": "NIE" }, { "input": "dp", "output": "NIE" }, { "input": "vV", "output": "NIE" }, { "input": "vMo", "output": "NIE" }, { "input": "O", "output": "TAK" }, { "input": "vYv", "output": "TAK" }, { "input": "fv", "output": "NIE" }, { "input": "U", "output": "TAK" }, { "input": "iAi", "output": "NIE" }, { "input": "I", "output": "TAK" }, { "input": "VxrV", "output": "NIE" }, { "input": "POP", "output": "NIE" }, { "input": "bid", "output": "NIE" }, { "input": "bmd", "output": "NIE" }, { "input": "AiA", "output": "NIE" }, { "input": "mmmmmm", "output": "NIE" }, { "input": "XHX", "output": "TAK" }, { "input": "llllll", "output": "NIE" }, { "input": "aAa", "output": "NIE" }, { "input": "Db", "output": "NIE" }, { "input": "lOl", "output": "NIE" }, { "input": "bzd", "output": "NIE" } ]
93
0
0
1,590
274
k-Multiple Free Set
[ "binary search", "greedy", "sortings" ]
null
null
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, such that *y*<==<=*x*·*k*. You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). All the numbers in the lines are separated by single spaces.
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
[ "6 2\n2 3 6 5 4 10\n" ]
[ "3\n" ]
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
[ { "input": "6 2\n2 3 6 5 4 10", "output": "3" }, { "input": "10 2\n1 2 3 4 5 6 7 8 9 10", "output": "6" }, { "input": "1 1\n1", "output": "1" }, { "input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 150 158 189 118 75 180 177 176 112 167 140 184 29 166 25 46 169 145 187 123 196 18 115 126 155 100 63 58 159 19 173 113 133 60 130 161 76 157 93 199 50 97 15 67 109 164 99 149 3 137 153 136 56 43 103 170 13 183 194 72 9 181 86 30 91 36", "output": "79" }, { "input": "100 3\n13 38 137 24 46 192 33 8 170 141 118 57 198 133 112 176 40 36 91 130 166 72 123 28 82 180 134 52 64 107 97 79 199 184 158 22 181 163 98 7 88 41 73 87 167 109 15 173 153 70 50 119 139 56 17 152 84 161 11 116 31 187 143 196 27 102 132 126 149 63 146 168 67 48 53 120 20 105 155 10 128 47 23 6 94 3 113 65 44 179 189 99 75 34 111 193 60 145 171 77", "output": "87" }, { "input": "12 400000000\n1 400000000 800000000 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "10 1\n1 100 300 400 500 500000 1000000 10000000 100000000 1000000000", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 1000000000\n1 1000000000", "output": "1" }, { "input": "4 1000\n1 1000 1000000 1000000000", "output": "2" }, { "input": "2 2\n1 3", "output": "2" }, { "input": "2 2\n16 8", "output": "1" }, { "input": "3 2\n8 4 2", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "5" }, { "input": "2 2\n500000000 1000000000", "output": "1" }, { "input": "2 2\n4 2", "output": "1" }, { "input": "10 100000000\n1 2 3 4 5 6 7 8 82000 907431936", "output": "10" }, { "input": "8 65538\n65535 65536 65537 65538 65539 131072 262144 196608", "output": "8" }, { "input": "5 2\n10 8 6 4 2", "output": "4" }, { "input": "2 1000000000\n276447232 100000", "output": "2" } ]
2,000
8,294,400
0
1,592
676
Vasya and String
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { "input": "10 10\nbbbbbbbbbb", "output": "10" }, { "input": "10 2\nbbbbbbbbbb", "output": "10" }, { "input": "10 1\nbbabbabbba", "output": "6" }, { "input": "10 10\nbbabbbaabb", "output": "10" }, { "input": "10 9\nbabababbba", "output": "10" }, { "input": "10 4\nbababbaaab", "output": "9" }, { "input": "10 10\naabaaabaaa", "output": "10" }, { "input": "10 10\naaaabbbaaa", "output": "10" }, { "input": "10 1\nbaaaaaaaab", "output": "9" }, { "input": "10 5\naaaaabaaaa", "output": "10" }, { "input": "10 4\naaaaaaaaaa", "output": "10" }, { "input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab", "output": "93" }, { "input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba", "output": "100" }, { "input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb", "output": "34" }, { "input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab", "output": "100" }, { "input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba", "output": "17" }, { "input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa", "output": "80" }, { "input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa", "output": "61" }, { "input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa", "output": "76" }, { "input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa", "output": "100" }, { "input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" }, { "input": "10 0\nbbbbbbbbbb", "output": "10" }, { "input": "10 0\nbbbbabbbbb", "output": "5" }, { "input": "10 0\nbbabbbabba", "output": "3" }, { "input": "10 0\nbaabbbbaba", "output": "4" }, { "input": "10 0\naababbbbaa", "output": "4" }, { "input": "10 2\nabbbbbaaba", "output": "8" }, { "input": "10 0\nabbaaabaaa", "output": "3" }, { "input": "10 0\naabbaaabaa", "output": "3" }, { "input": "10 1\naaaaaababa", "output": "8" }, { "input": "10 0\nbaaaaaaaaa", "output": "9" }, { "input": "10 0\naaaaaaaaaa", "output": "10" }, { "input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab", "output": "40" }, { "input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb", "output": "65" }, { "input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb", "output": "33" }, { "input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab", "output": "65" }, { "input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb", "output": "26" }, { "input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba", "output": "22" }, { "input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa", "output": "49" }, { "input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa", "output": "56" }, { "input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba", "output": "86" }, { "input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" } ]
31
0
0
1,594
505
Mr. Kitayuta's Gift
[ "brute force", "implementation", "strings" ]
null
null
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not. You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome. If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
[ "revive\n", "ee\n", "kitayuta\n" ]
[ "reviver\n", "eye", "NA\n" ]
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
[ { "input": "revive", "output": "reviver" }, { "input": "ee", "output": "eee" }, { "input": "kitayuta", "output": "NA" }, { "input": "evima", "output": "NA" }, { "input": "a", "output": "aa" }, { "input": "yutampo", "output": "NA" }, { "input": "fft", "output": "tfft" }, { "input": "shuseki", "output": "NA" }, { "input": "lsdijfjisl", "output": "lsdijfjidsl" }, { "input": "ewcdcwerp", "output": "NA" }, { "input": "noon", "output": "nooon" }, { "input": "add", "output": "adda" }, { "input": "iq", "output": "qiq" }, { "input": "hogloid", "output": "NA" }, { "input": "yosupo", "output": "NA" }, { "input": "stat", "output": "stats" }, { "input": "level", "output": "levvel" }, { "input": "iwiwi", "output": "iwiiwi" }, { "input": "racecar", "output": "raceecar" }, { "input": "dog", "output": "NA" }, { "input": "squirrel", "output": "NA" }, { "input": "slime", "output": "NA" }, { "input": "palindrome", "output": "NA" }, { "input": "nqwcvcwqn", "output": "nqwcvvcwqn" }, { "input": "lsdijfjisl", "output": "lsdijfjidsl" }, { "input": "jewiiwefj", "output": "jfewiiwefj" }, { "input": "vnwmvvmonv", "output": "NA" }, { "input": "zennyuu", "output": "NA" }, { "input": "mrtoudai", "output": "NA" }, { "input": "z", "output": "zz" }, { "input": "babccba", "output": "babccbab" }, { "input": "battaba", "output": "abattaba" }, { "input": "bbb", "output": "bbbb" }, { "input": "zaa", "output": "zaaz" }, { "input": "abbabab", "output": "NA" }, { "input": "racecar", "output": "raceecar" }, { "input": "zzz", "output": "zzzz" }, { "input": "eviver", "output": "reviver" }, { "input": "aaaaa", "output": "aaaaaa" }, { "input": "eee", "output": "eeee" } ]
93
0
0
1,598
111
Petya and Inequiations
[ "greedy" ]
A. Petya and Inequiations
2
256
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y*
The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.
Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
[ "5 15 15\n", "2 3 2\n", "1 99 11\n" ]
[ "4\n4\n1\n1\n2\n", "-1\n", "11\n" ]
none
[ { "input": "5 15 15", "output": "11\n1\n1\n1\n1" }, { "input": "2 3 2", "output": "-1" }, { "input": "1 99 11", "output": "11" }, { "input": "100000 810000099998 1000000", "output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "3 254 18", "output": "16\n1\n1" }, { "input": "4 324 77", "output": "74\n1\n1\n1" }, { "input": "5 315 90", "output": "86\n1\n1\n1\n1" }, { "input": "6 225 59", "output": "54\n1\n1\n1\n1\n1" }, { "input": "7 351 29", "output": "23\n1\n1\n1\n1\n1\n1" }, { "input": "100 913723780421 955988", "output": "-1" }, { "input": "200 894176381082 945808", "output": "-1" }, { "input": "300 923251939897 961159", "output": "960860\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "1000 824905348050 909242", "output": "-1" }, { "input": "10000 795416053320 901860", "output": "891861\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "31000 819461299082 936240", "output": "-1" }, { "input": "44000 772772899626 923074", "output": "-1" }, { "input": "45678 783917268558 931068", "output": "885391\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99999 681508136225 925533", "output": "-1" }, { "input": "99999 688345771552 929664", "output": "829666\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99976 664640815001 915230", "output": "-1" }, { "input": "100000 729199960625 953931", "output": "-1" }, { "input": "50 890543266647 943735", "output": "-1" }, { "input": "60 817630084499 904288", "output": "904229\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "99999 716046078026 946193", "output": "-1" }, { "input": "99998 729652614803 954194", "output": "854197\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "10000 950051796437 984705", "output": "-1" }, { "input": "999 992972391401 997478", "output": "-1" }, { "input": "99999 667887855532 917242", "output": "817244\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "12313 955817132591 989971", "output": "977659\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "1 983300308227 991615", "output": "-1" }, { "input": "2 912219830404 955103", "output": "955102\n1" }, { "input": "3 934371623645 966631", "output": "-1" }, { "input": "4 857839030421 926199", "output": "-1" }, { "input": "7 897398130730 947317", "output": "-1" }, { "input": "60 833021290059 912759", "output": "912700\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "99999 715837929182 946070", "output": "846072\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99998 714958284701 945549", "output": "845552\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "100000 730132752483 954477", "output": "854478\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "9999 850451005599 932197", "output": "922199\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99999 741078317879 960857", "output": "860859\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "12313 873989408188 947186", "output": "934874\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "1 860113420929 927423", "output": "927423" }, { "input": "2 933669982757 966267", "output": "966266\n1" }, { "input": "3 933157932003 966003", "output": "966001\n1\n1" }, { "input": "4 944626542564 971922", "output": "971919\n1\n1\n1" }, { "input": "7 937519681542 968262", "output": "968256\n1\n1\n1\n1\n1\n1" }, { "input": "100000 1000000000000 1000000", "output": "-1" }, { "input": "99999 999999999999 999999", "output": "-1" }, { "input": "100 1 1", "output": "-1" }, { "input": "2 1 1", "output": "-1" }, { "input": "11 10 10", "output": "-1" }, { "input": "1 5 10", "output": "10" }, { "input": "10 3 8", "output": "-1" }, { "input": "5 37 10", "output": "6\n1\n1\n1\n1" }, { "input": "5 1 4", "output": "-1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000000 1", "output": "-1" }, { "input": "1 1 1000000", "output": "1000000" }, { "input": "100000 1 1", "output": "-1" }, { "input": "100000 1 1000000", "output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "100000 1000000000000 1", "output": "-1" }, { "input": "1 1000000000000 1000000", "output": "1000000" } ]
436
8,089,600
3.875932
1,603
175
Robot Bicorn Attack
[ "brute force", "implementation" ]
null
null
Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string *s*. Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.
The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.
Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.
[ "1234\n", "9000\n", "0009\n" ]
[ "37\n", "90\n", "-1\n" ]
In the first example the string must be split into numbers 1, 2 and 34. In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes.
[ { "input": "1234", "output": "37" }, { "input": "9000", "output": "90" }, { "input": "0009", "output": "-1" }, { "input": "100000010000001000000", "output": "3000000" }, { "input": "1000000011", "output": "1000011" }, { "input": "9991", "output": "109" }, { "input": "1000001999", "output": "101000" }, { "input": "100000010000011000000", "output": "-1" }, { "input": "100000010000001000001", "output": "-1" }, { "input": "102", "output": "3" }, { "input": "100", "output": "1" }, { "input": "000", "output": "0" }, { "input": "001", "output": "1" }, { "input": "090", "output": "9" }, { "input": "999999999999999999999999999999", "output": "-1" }, { "input": "12345678901234567", "output": "947035" }, { "input": "12635000000127683", "output": "-1" }, { "input": "428595000000042345353", "output": "-1" }, { "input": "48726340000000", "output": "-1" }, { "input": "93246310000000", "output": "1932463" }, { "input": "00123456", "output": "123456" }, { "input": "001234567", "output": "-1" }, { "input": "0891249843934", "output": "1735183" }, { "input": "04234581000000", "output": "1423458" }, { "input": "10000000999999", "output": "1999999" }, { "input": "69284626624", "output": "935092" }, { "input": "6061357", "output": "61363" }, { "input": "1215", "output": "27" }, { "input": "5305167573651040691", "output": "-1" }, { "input": "948245431759126577", "output": "1506581" }, { "input": "3699951264723380749", "output": "-1" }, { "input": "97862382", "output": "978633" }, { "input": "4073734152", "output": "737433" }, { "input": "9123396793", "output": "913138" }, { "input": "52027725398636318", "output": "1413743" }, { "input": "03990796938958", "output": "-1" }, { "input": "460657644093588", "output": "1105338" }, { "input": "8793853284967905230", "output": "-1" }, { "input": "298036933890712", "output": "1232638" }, { "input": "80796461750373352", "output": "1498819" }, { "input": "2376843019069559343", "output": "-1" }, { "input": "7464340065209674219", "output": "-1" }, { "input": "1551627800131899383", "output": "-1" }, { "input": "20973541540356666047", "output": "-1" }, { "input": "31587335978612", "output": "1565978" }, { "input": "744503034", "output": "744537" }, { "input": "15533274860535679", "output": "939616" }, { "input": "58308242321837", "output": "1006337" }, { "input": "9929120076123816", "output": "323868" }, { "input": "623650711335", "output": "773700" }, { "input": "1066168753173", "output": "981936" }, { "input": "5353645507305053", "output": "1091147" }, { "input": "111111111111111111111111111111", "output": "-1" }, { "input": "1000000999888777666", "output": "2777554" }, { "input": "1000001999888777666", "output": "-1" }, { "input": "9998881000001777666", "output": "-1" }, { "input": "9999991000000999999", "output": "2999998" }, { "input": "9999999999991000000", "output": "2999998" }, { "input": "1000000999999999999", "output": "2999998" }, { "input": "123", "output": "6" }, { "input": "132", "output": "6" }, { "input": "213", "output": "6" }, { "input": "231", "output": "6" }, { "input": "312", "output": "6" }, { "input": "321", "output": "6" }, { "input": "666", "output": "18" }, { "input": "012894600", "output": "894612" }, { "input": "01289400", "output": "289401" }, { "input": "429496729742949672974294967297", "output": "-1" }, { "input": "429496729700", "output": "959414" }, { "input": "429496729701", "output": "959415" }, { "input": "1", "output": "-1" }, { "input": "55", "output": "-1" }, { "input": "99", "output": "-1" }, { "input": "9991999999999999", "output": "2009989" }, { "input": "999199999999099", "output": "1999297" }, { "input": "9991990199999999", "output": "2000189" }, { "input": "99999900999999", "output": "1999998" }, { "input": "4444440044444", "output": "488888" }, { "input": "0089", "output": "89" }, { "input": "00243", "output": "243" }, { "input": "008743", "output": "8743" }, { "input": "0042764", "output": "42764" }, { "input": "00912838", "output": "912838" }, { "input": "001000000", "output": "1000000" }, { "input": "001000001", "output": "-1" }, { "input": "12435900", "output": "435903" }, { "input": "28492300", "output": "849232" }, { "input": "99999900", "output": "999999" }, { "input": "931863000", "output": "863094" }, { "input": "23566000", "output": "566005" }, { "input": "100000000", "output": "1000000" }, { "input": "100000100", "output": "100010" }, { "input": "3246870032", "output": "870362" }, { "input": "04354640947", "output": "645301" }, { "input": "0734620342343", "output": "1076963" }, { "input": "09999990", "output": "999999" }, { "input": "010000000", "output": "1000000" }, { "input": "010000001", "output": "1000001" }, { "input": "01000001000000", "output": "1100000" }, { "input": "1844674407370955161600", "output": "-1" }, { "input": "184467440737105516141111", "output": "-1" }, { "input": "1844674407371055161600", "output": "-1" }, { "input": "1111111111111111111111111", "output": "-1" }, { "input": "999999999999999999999", "output": "-1" }, { "input": "100000110000011000001", "output": "-1" }, { "input": "0018446744073709551616", "output": "-1" }, { "input": "429596729610000001000", "output": "-1" }, { "input": "123456789123456789123456789123", "output": "-1" }, { "input": "011", "output": "2" }, { "input": "10000100001000", "output": "21000" }, { "input": "091", "output": "10" }, { "input": "1234567891012131416123222443", "output": "-1" }, { "input": "429496729642949672964294967296", "output": "-1" }, { "input": "214748364821474836482147483648", "output": "-1" }, { "input": "10000001073741824001000000", "output": "-1" }, { "input": "5000000000", "output": "-1" }, { "input": "999955555555555555555555", "output": "-1" }, { "input": "1844674407371055161699", "output": "-1" }, { "input": "99999999999999999999999999999", "output": "-1" }, { "input": "009", "output": "9" }, { "input": "1844674407370955161611", "output": "-1" }, { "input": "000000999", "output": "-1" }, { "input": "003", "output": "3" }, { "input": "0000000009000000000", "output": "-1" }, { "input": "010", "output": "1" }, { "input": "0", "output": "-1" }, { "input": "000009000000", "output": "-1" }, { "input": "21371283283242384239423423123", "output": "-1" }, { "input": "100000010004294967300", "output": "-1" }, { "input": "429596729600", "output": "969314" }, { "input": "429496729510000001000000", "output": "-1" }, { "input": "2147483648010000010000", "output": "-1" }, { "input": "349967407479541078587181768161", "output": "-1" } ]
61
5,529,600
0
1,608
598
Igor In the Museum
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2", "output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10" }, { "input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6", "output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4" }, { "input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9", "output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6" }, { "input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2", "output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4" } ]
1,000
27,852,800
0
1,609
938
Word Correction
[ "implementation" ]
null
null
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word *s*. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n" ]
[ "werd\n", "word\n", "a\n" ]
Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
[ { "input": "5\nweird", "output": "werd" }, { "input": "4\nword", "output": "word" }, { "input": "5\naaeaa", "output": "a" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw" }, { "input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "12\nmmmmmmmmmmmm", "output": "mmmmmmmmmmmm" }, { "input": "18\nyaywptqwuyiqypwoyw", "output": "ywptqwuqypwow" }, { "input": "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "13\nmmmmmmmmmmmmm", "output": "mmmmmmmmmmmmm" }, { "input": "10\nmmmmmmmmmm", "output": "mmmmmmmmmm" }, { "input": "11\nmmmmmmmmmmm", "output": "mmmmmmmmmmm" }, { "input": "15\nmmmmmmmmmmmmmmm", "output": "mmmmmmmmmmmmmmm" }, { "input": "1\na", "output": "a" }, { "input": "14\nmmmmmmmmmmmmmm", "output": "mmmmmmmmmmmmmm" }, { "input": "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" }, { "input": "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "2\naa", "output": "a" }, { "input": "18\niuiuqpyyaoaetiwliu", "output": "iqpytiwli" }, { "input": "5\nxxxxx", "output": "xxxxx" }, { "input": "6\nxxxahg", "output": "xxxahg" }, { "input": "3\nzcv", "output": "zcv" }, { "input": "4\naepo", "output": "apo" }, { "input": "5\nqqqqq", "output": "qqqqq" }, { "input": "6\naaaaaa", "output": "a" }, { "input": "4\naeta", "output": "ata" }, { "input": "20\nttyttlwaoieulyiluuri", "output": "ttyttlwalyluri" }, { "input": "1\nb", "output": "b" }, { "input": "3\nanc", "output": "anc" }, { "input": "1\ne", "output": "e" }, { "input": "3\naie", "output": "a" }, { "input": "3\nvio", "output": "vi" }, { "input": "2\nea", "output": "e" }, { "input": "3\nuas", "output": "us" }, { "input": "2\nba", "output": "ba" }, { "input": "2\naq", "output": "aq" }, { "input": "2\nya", "output": "y" }, { "input": "2\nou", "output": "o" }, { "input": "2\nbb", "output": "bb" }, { "input": "7\nayylmao", "output": "alma" }, { "input": "2\nab", "output": "ab" }, { "input": "19\nyuouiyaoiiweqrryqqp", "output": "yweqrryqqp" }, { "input": "25\niqypwqpriiioetiuqqqttouei", "output": "iqypwqpritiqqqtto" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz", "output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz" }, { "input": "17\naccccccccccccccca", "output": "accccccccccccccca" }, { "input": "5\nababa", "output": "ababa" }, { "input": "10\naaaaaaaaaa", "output": "a" }, { "input": "22\naaaaabbbbboyoyoyoyoyac", "output": "abbbbboc" }, { "input": "7\nmahmoud", "output": "mahmod" } ]
140
0
3
1,610
245
Queries for Number of Palindromes
[ "dp", "hashing", "strings" ]
null
null
You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which are palindromes. String *s*[*l*... *r*]<==<=*s**l**s**l*<=+<=1... *s**r* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) is a substring of string *s*<==<=*s*1*s*2... *s*|*s*|. String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t*<==<=*t*1*t*2... *t*|*t*|<==<=*t*|*t*|*t*|*t*|<=-<=1... *t*1.
The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). The second line contains a single integer *q* (1<=≤<=*q*<=≤<=106) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|) — the description of the *i*-th query. It is guaranteed that the given string consists only of lowercase English letters.
Print *q* integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
[ "caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5\n" ]
[ "1\n7\n3\n4\n2\n" ]
Consider the fourth query in the first test case. String *s*[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba».
[ { "input": "caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5", "output": "1\n7\n3\n4\n2" }, { "input": "a\n100\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "ab\n100\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 2\n2 2\n1 1\n1 1\n2 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 2\n2 2\n2 2\n1 2\n2 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 2\n2 2\n1 1\n2 2\n1 1\n1 1\n1 2\n1 1\n2 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n2 2\n1 1\n2 2\n2 2\n2 2\n2 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 1\n1 2\n2 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n1 2\n1 1\n1 2\n2 2", "output": "2\n2\n1\n1\n1\n1\n2\n2\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n2\n1\n1\n2\n1\n1\n1\n1\n1\n2\n1\n2\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n1\n2\n2\n2\n1\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n1\n1\n1\n2\n1\n2\n1\n1\n2\n1\n1\n2\n1\n2\n1" }, { "input": "caa\n100\n2 3\n2 3\n1 3\n2 3\n2 2\n2 3\n1 1\n1 3\n1 3\n1 2\n3 3\n1 3\n1 3\n3 3\n1 2\n1 3\n1 3\n2 2\n2 2\n1 2\n1 3\n1 3\n1 3\n1 2\n3 3\n1 1\n2 3\n2 3\n1 2\n2 3\n1 3\n1 2\n1 3\n2 3\n3 3\n1 2\n2 3\n1 2\n1 3\n1 1\n2 2\n2 2\n2 3\n2 2\n2 3\n1 3\n1 1\n1 2\n1 3\n1 3\n2 3\n1 2\n1 3\n1 2\n1 3\n1 2\n1 1\n1 1\n1 2\n2 3\n1 1\n2 3\n3 3\n2 2\n1 2\n1 3\n1 2\n1 2\n1 2\n2 3\n1 2\n1 2\n1 3\n3 3\n1 2\n2 2\n1 2\n2 2\n1 1\n2 3\n1 2\n1 2\n1 2\n1 2\n2 2\n1 1\n1 2\n3 3\n2 3\n1 2\n1 2\n2 3\n1 2\n1 2\n1 3\n2 3\n1 3\n1 1\n2 2\n1 2", "output": "3\n3\n4\n3\n1\n3\n1\n4\n4\n2\n1\n4\n4\n1\n2\n4\n4\n1\n1\n2\n4\n4\n4\n2\n1\n1\n3\n3\n2\n3\n4\n2\n4\n3\n1\n2\n3\n2\n4\n1\n1\n1\n3\n1\n3\n4\n1\n2\n4\n4\n3\n2\n4\n2\n4\n2\n1\n1\n2\n3\n1\n3\n1\n1\n2\n4\n2\n2\n2\n3\n2\n2\n4\n1\n2\n1\n2\n1\n1\n3\n2\n2\n2\n2\n1\n1\n2\n1\n3\n2\n2\n3\n2\n2\n4\n3\n4\n1\n1\n2" }, { "input": "ccca\n100\n2 4\n1 2\n1 1\n2 3\n3 4\n3 4\n2 2\n3 3\n1 2\n1 4\n2 2\n1 3\n1 4\n4 4\n1 2\n2 3\n3 4\n1 3\n3 4\n2 3\n1 1\n2 4\n1 4\n1 2\n2 2\n2 2\n1 1\n3 3\n1 2\n2 3\n2 3\n1 2\n1 4\n4 4\n2 2\n2 2\n4 4\n1 4\n1 1\n1 2\n4 4\n2 3\n2 4\n3 3\n1 4\n2 4\n2 3\n4 4\n4 4\n3 4\n2 2\n1 2\n1 1\n1 2\n3 3\n2 4\n1 3\n2 4\n1 1\n3 3\n3 4\n2 4\n1 4\n2 4\n1 2\n3 3\n1 4\n2 2\n2 4\n1 4\n1 4\n1 3\n3 4\n1 2\n2 3\n2 3\n3 4\n1 4\n4 4\n3 3\n2 4\n2 2\n1 2\n2 3\n1 2\n1 4\n1 3\n2 3\n4 4\n3 3\n1 2\n4 4\n2 4\n1 2\n2 4\n2 2\n3 4\n2 3\n2 3\n2 3", "output": "4\n3\n1\n3\n2\n2\n1\n1\n3\n7\n1\n6\n7\n1\n3\n3\n2\n6\n2\n3\n1\n4\n7\n3\n1\n1\n1\n1\n3\n3\n3\n3\n7\n1\n1\n1\n1\n7\n1\n3\n1\n3\n4\n1\n7\n4\n3\n1\n1\n2\n1\n3\n1\n3\n1\n4\n6\n4\n1\n1\n2\n4\n7\n4\n3\n1\n7\n1\n4\n7\n7\n6\n2\n3\n3\n3\n2\n7\n1\n1\n4\n1\n3\n3\n3\n7\n6\n3\n1\n1\n3\n1\n4\n3\n4\n1\n2\n3\n3\n3" } ]
5,000
34,918,400
0
1,616
221
Little Elephant and Function
[ "implementation", "math" ]
null
null
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists.
[ "1\n", "2\n" ]
[ "1 ", "2 1 " ]
none
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "2 1 " }, { "input": "3", "output": "3 1 2 " }, { "input": "4", "output": "4 1 2 3 " }, { "input": "5", "output": "5 1 2 3 4 " }, { "input": "6", "output": "6 1 2 3 4 5 " }, { "input": "7", "output": "7 1 2 3 4 5 6 " }, { "input": "1000", "output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "999", "output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "998", "output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "997", "output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "900", "output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "101", "output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "3", "output": "3 1 2 " }, { "input": "67", "output": "67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 " }, { "input": "779", "output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "195", "output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "907", "output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "971", "output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "683", "output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "99", "output": "99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 " }, { "input": "811", "output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "875", "output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "291", "output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3", "output": "3 1 2 " }, { "input": "419", "output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "779", "output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "195", "output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "907", "output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "21", "output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 " }, { "input": "22", "output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 " }, { "input": "23", "output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 " }, { "input": "24", "output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 " }, { "input": "25", "output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 " } ]
248
0
0
1,624
712
Memory and Crow
[ "implementation", "math" ]
null
null
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
[ "5\n6 -4 8 -2 3\n", "5\n3 -2 -1 5 6\n" ]
[ "2 4 6 1 3 \n", "1 -3 4 11 6 \n" ]
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
[ { "input": "5\n6 -4 8 -2 3", "output": "2 4 6 1 3 " }, { "input": "5\n3 -2 -1 5 6", "output": "1 -3 4 11 6 " }, { "input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10", "output": "11 530 469 -86 -86 -127 -87 -11 22 10 " }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0 0 0 0 0 0 0 0 0 0 " }, { "input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1", "output": "0 0 0 0 0 0 0 0 0 -1 " }, { "input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "0 0 0 0 0 0 0 0 0 1000000000 " }, { "input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12", "output": "656 -110 5840 6358 828 717 7359 7628 22 -12 " }, { "input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240", "output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 " } ]
405
8,396,800
3
1,625
808
Lucky Year
[ "implementation" ]
null
null
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
[ "4\n", "201\n", "4000\n" ]
[ "1\n", "99\n", "1000\n" ]
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
[ { "input": "4", "output": "1" }, { "input": "201", "output": "99" }, { "input": "4000", "output": "1000" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "1", "output": "1" }, { "input": "100000000", "output": "100000000" }, { "input": "900000000", "output": "100000000" }, { "input": "999999999", "output": "1" }, { "input": "1000000000", "output": "1000000000" }, { "input": "9999999", "output": "1" }, { "input": "100000001", "output": "99999999" }, { "input": "3660", "output": "340" }, { "input": "21", "output": "9" }, { "input": "900000001", "output": "99999999" }, { "input": "62911", "output": "7089" }, { "input": "11", "output": "9" }, { "input": "940302010", "output": "59697990" }, { "input": "91", "output": "9" }, { "input": "101", "output": "99" }, { "input": "1090", "output": "910" }, { "input": "987654321", "output": "12345679" }, { "input": "703450474", "output": "96549526" }, { "input": "1091", "output": "909" }, { "input": "89", "output": "1" }, { "input": "109", "output": "91" }, { "input": "190", "output": "10" }, { "input": "19", "output": "1" }, { "input": "8", "output": "1" }, { "input": "482", "output": "18" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "6", "output": "1" }, { "input": "7", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "11", "output": "9" }, { "input": "12", "output": "8" }, { "input": "13", "output": "7" }, { "input": "14", "output": "6" }, { "input": "15", "output": "5" }, { "input": "16", "output": "4" }, { "input": "17", "output": "3" }, { "input": "18", "output": "2" }, { "input": "19", "output": "1" }, { "input": "20", "output": "10" }, { "input": "21", "output": "9" }, { "input": "22", "output": "8" }, { "input": "23", "output": "7" }, { "input": "24", "output": "6" }, { "input": "25", "output": "5" }, { "input": "26", "output": "4" }, { "input": "27", "output": "3" }, { "input": "28", "output": "2" }, { "input": "29", "output": "1" }, { "input": "30", "output": "10" }, { "input": "31", "output": "9" }, { "input": "32", "output": "8" }, { "input": "33", "output": "7" }, { "input": "34", "output": "6" }, { "input": "35", "output": "5" }, { "input": "36", "output": "4" }, { "input": "37", "output": "3" }, { "input": "38", "output": "2" }, { "input": "39", "output": "1" }, { "input": "40", "output": "10" }, { "input": "41", "output": "9" }, { "input": "42", "output": "8" }, { "input": "43", "output": "7" }, { "input": "44", "output": "6" }, { "input": "45", "output": "5" }, { "input": "46", "output": "4" }, { "input": "47", "output": "3" }, { "input": "48", "output": "2" }, { "input": "49", "output": "1" }, { "input": "50", "output": "10" }, { "input": "51", "output": "9" }, { "input": "52", "output": "8" }, { "input": "53", "output": "7" }, { "input": "54", "output": "6" }, { "input": "55", "output": "5" }, { "input": "56", "output": "4" }, { "input": "57", "output": "3" }, { "input": "58", "output": "2" }, { "input": "59", "output": "1" }, { "input": "60", "output": "10" }, { "input": "61", "output": "9" }, { "input": "62", "output": "8" }, { "input": "63", "output": "7" }, { "input": "64", "output": "6" }, { "input": "65", "output": "5" }, { "input": "66", "output": "4" }, { "input": "67", "output": "3" }, { "input": "68", "output": "2" }, { "input": "69", "output": "1" }, { "input": "70", "output": "10" }, { "input": "71", "output": "9" }, { "input": "72", "output": "8" }, { "input": "73", "output": "7" }, { "input": "74", "output": "6" }, { "input": "75", "output": "5" }, { "input": "76", "output": "4" }, { "input": "77", "output": "3" }, { "input": "78", "output": "2" }, { "input": "79", "output": "1" }, { "input": "80", "output": "10" }, { "input": "81", "output": "9" }, { "input": "82", "output": "8" }, { "input": "83", "output": "7" }, { "input": "84", "output": "6" }, { "input": "85", "output": "5" }, { "input": "86", "output": "4" }, { "input": "87", "output": "3" }, { "input": "88", "output": "2" }, { "input": "89", "output": "1" }, { "input": "90", "output": "10" }, { "input": "91", "output": "9" }, { "input": "92", "output": "8" }, { "input": "93", "output": "7" }, { "input": "94", "output": "6" }, { "input": "95", "output": "5" }, { "input": "96", "output": "4" }, { "input": "97", "output": "3" }, { "input": "98", "output": "2" }, { "input": "99", "output": "1" }, { "input": "100", "output": "100" }, { "input": "100", "output": "100" }, { "input": "100", "output": "100" }, { "input": "1000", "output": "1000" }, { "input": "1000", "output": "1000" }, { "input": "1000", "output": "1000" }, { "input": "10000", "output": "10000" }, { "input": "10000", "output": "10000" }, { "input": "101", "output": "99" }, { "input": "110", "output": "90" }, { "input": "1001", "output": "999" }, { "input": "1100", "output": "900" }, { "input": "1010", "output": "990" }, { "input": "10010", "output": "9990" }, { "input": "10100", "output": "9900" }, { "input": "102", "output": "98" }, { "input": "120", "output": "80" }, { "input": "1002", "output": "998" }, { "input": "1200", "output": "800" }, { "input": "1020", "output": "980" }, { "input": "10020", "output": "9980" }, { "input": "10200", "output": "9800" }, { "input": "108", "output": "92" }, { "input": "180", "output": "20" }, { "input": "1008", "output": "992" }, { "input": "1800", "output": "200" }, { "input": "1080", "output": "920" }, { "input": "10080", "output": "9920" }, { "input": "10800", "output": "9200" }, { "input": "109", "output": "91" }, { "input": "190", "output": "10" }, { "input": "1009", "output": "991" }, { "input": "1900", "output": "100" }, { "input": "1090", "output": "910" }, { "input": "10090", "output": "9910" }, { "input": "10900", "output": "9100" }, { "input": "200", "output": "100" }, { "input": "200", "output": "100" }, { "input": "2000", "output": "1000" }, { "input": "2000", "output": "1000" }, { "input": "2000", "output": "1000" }, { "input": "20000", "output": "10000" }, { "input": "20000", "output": "10000" }, { "input": "201", "output": "99" }, { "input": "210", "output": "90" }, { "input": "2001", "output": "999" }, { "input": "2100", "output": "900" }, { "input": "2010", "output": "990" }, { "input": "20010", "output": "9990" }, { "input": "20100", "output": "9900" }, { "input": "202", "output": "98" }, { "input": "220", "output": "80" }, { "input": "2002", "output": "998" }, { "input": "2200", "output": "800" }, { "input": "2020", "output": "980" }, { "input": "20020", "output": "9980" }, { "input": "20200", "output": "9800" }, { "input": "208", "output": "92" }, { "input": "280", "output": "20" }, { "input": "2008", "output": "992" }, { "input": "2800", "output": "200" }, { "input": "2080", "output": "920" }, { "input": "20080", "output": "9920" }, { "input": "20800", "output": "9200" }, { "input": "209", "output": "91" }, { "input": "290", "output": "10" }, { "input": "2009", "output": "991" }, { "input": "2900", "output": "100" }, { "input": "2090", "output": "910" }, { "input": "20090", "output": "9910" }, { "input": "20900", "output": "9100" }, { "input": "800", "output": "100" }, { "input": "800", "output": "100" }, { "input": "8000", "output": "1000" }, { "input": "8000", "output": "1000" }, { "input": "8000", "output": "1000" }, { "input": "80000", "output": "10000" }, { "input": "80000", "output": "10000" }, { "input": "801", "output": "99" }, { "input": "810", "output": "90" }, { "input": "8001", "output": "999" }, { "input": "8100", "output": "900" }, { "input": "8010", "output": "990" }, { "input": "80010", "output": "9990" }, { "input": "80100", "output": "9900" }, { "input": "802", "output": "98" }, { "input": "820", "output": "80" }, { "input": "8002", "output": "998" }, { "input": "8200", "output": "800" }, { "input": "8020", "output": "980" }, { "input": "80020", "output": "9980" }, { "input": "80200", "output": "9800" }, { "input": "808", "output": "92" }, { "input": "880", "output": "20" }, { "input": "8008", "output": "992" }, { "input": "8800", "output": "200" }, { "input": "8080", "output": "920" }, { "input": "80080", "output": "9920" }, { "input": "80800", "output": "9200" }, { "input": "809", "output": "91" }, { "input": "890", "output": "10" }, { "input": "8009", "output": "991" }, { "input": "8900", "output": "100" }, { "input": "8090", "output": "910" }, { "input": "80090", "output": "9910" }, { "input": "80900", "output": "9100" }, { "input": "900", "output": "100" }, { "input": "900", "output": "100" }, { "input": "9000", "output": "1000" }, { "input": "9000", "output": "1000" }, { "input": "9000", "output": "1000" }, { "input": "90000", "output": "10000" }, { "input": "90000", "output": "10000" }, { "input": "901", "output": "99" }, { "input": "910", "output": "90" }, { "input": "9001", "output": "999" }, { "input": "9100", "output": "900" }, { "input": "9010", "output": "990" }, { "input": "90010", "output": "9990" }, { "input": "90100", "output": "9900" }, { "input": "902", "output": "98" }, { "input": "920", "output": "80" }, { "input": "9002", "output": "998" }, { "input": "9200", "output": "800" }, { "input": "9020", "output": "980" }, { "input": "90020", "output": "9980" }, { "input": "90200", "output": "9800" }, { "input": "908", "output": "92" }, { "input": "980", "output": "20" }, { "input": "9008", "output": "992" }, { "input": "9800", "output": "200" }, { "input": "9080", "output": "920" }, { "input": "90080", "output": "9920" }, { "input": "90800", "output": "9200" }, { "input": "909", "output": "91" }, { "input": "990", "output": "10" }, { "input": "9009", "output": "991" }, { "input": "9900", "output": "100" }, { "input": "9090", "output": "910" }, { "input": "90090", "output": "9910" }, { "input": "90900", "output": "9100" }, { "input": "92651241", "output": "7348759" } ]
155
0
3
1,628
761
Dasha and Stairs
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
[ "2 3\n", "3 1\n" ]
[ "YES\n", "NO\n" ]
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
[ { "input": "2 3", "output": "YES" }, { "input": "3 1", "output": "NO" }, { "input": "5 4", "output": "YES" }, { "input": "9 9", "output": "YES" }, { "input": "85 95", "output": "NO" }, { "input": "0 1", "output": "YES" }, { "input": "89 25", "output": "NO" }, { "input": "74 73", "output": "YES" }, { "input": "62 39", "output": "NO" }, { "input": "57 57", "output": "YES" }, { "input": "100 99", "output": "YES" }, { "input": "0 0", "output": "NO" }, { "input": "98 100", "output": "NO" }, { "input": "99 100", "output": "YES" }, { "input": "1 0", "output": "YES" }, { "input": "100 0", "output": "NO" }, { "input": "0 100", "output": "NO" }, { "input": "100 98", "output": "NO" }, { "input": "100 100", "output": "YES" }, { "input": "0 5", "output": "NO" }, { "input": "2 2", "output": "YES" } ]
109
0
3
1,629
20
BerOS file system
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "/a//aa/a//", "output": "/a/aa/a" }, { "input": "/aa//b/aa", "output": "/aa/b/aa" }, { "input": "////////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/" }, { "input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb" }, { "input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt" }, { "input": "///a//a////a/a//a//a//a/////", "output": "/a/a/a/a/a/a/a" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a" }, { "input": "///////////////////////////////////////////////////////////////////////////////////////////////////z", "output": "/z" }, { "input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/z" } ]
186
0
3.9535
1,631
452
Eevee
[ "brute force", "implementation", "strings" ]
null
null
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
[ "7\nj......\n", "7\n...feon\n", "7\n.l.r.o.\n" ]
[ "jolteon\n", "leafeon\n", "flareon\n" ]
Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
[ { "input": "7\n...feon", "output": "leafeon" }, { "input": "7\n.l.r.o.", "output": "flareon" }, { "input": "6\n.s..o.", "output": "espeon" }, { "input": "7\nglaceon", "output": "glaceon" }, { "input": "8\n.a.o.e.n", "output": "vaporeon" }, { "input": "7\n.laceon", "output": "glaceon" }, { "input": "7\n..lveon", "output": "sylveon" }, { "input": "7\n.l.ceon", "output": "glaceon" }, { "input": "7\n..areon", "output": "flareon" } ]
61
0
0
1,633
570
Tree Requests
[ "binary search", "bitmasks", "constructive algorithms", "dfs and similar", "graphs", "trees" ]
null
null
Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always less than the index of the vertex (i.e., *p**i*<=&lt;<=*i*). The depth of the vertex is the number of nodes on the path from the root to *v* along the edges. In particular, the depth of the root is equal to 1. We say that vertex *u* is in the subtree of vertex *v*, if we can get from *u* to *v*, moving from the vertex to the parent. In particular, vertex *v* is in its subtree. Roma gives you *m* queries, the *i*-th of which consists of two numbers *v**i*, *h**i*. Let's consider the vertices in the subtree *v**i* located at depth *h**i*. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=500<=000) — the number of nodes in the tree and queries, respectively. The following line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* — the parents of vertices from the second to the *n*-th (1<=≤<=*p**i*<=&lt;<=*i*). The next line contains *n* lowercase English letters, the *i*-th of these letters is written on vertex *i*. Next *m* lines describe the queries, the *i*-th line contains two numbers *v**i*, *h**i* (1<=≤<=*v**i*,<=*h**i*<=≤<=*n*) — the vertex and the depth that appear in the *i*-th query.
Print *m* lines. In the *i*-th line print "Yes" (without the quotes), if in the *i*-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).
[ "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2\n" ]
[ "Yes\nNo\nYes\nYes\nYes\n" ]
String *s* is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome. Clarification for the sample test. In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z". In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them. In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome. In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome. In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac".
[ { "input": "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2", "output": "Yes\nNo\nYes\nYes\nYes" }, { "input": "5 6\n1 1 2 3\ncbcab\n3 1\n5 2\n1 3\n4 1\n4 2\n1 1", "output": "Yes\nYes\nNo\nYes\nYes\nYes" }, { "input": "5 6\n1 2 2 1\nbaabb\n1 1\n1 2\n5 1\n4 1\n4 2\n3 2", "output": "Yes\nNo\nYes\nYes\nYes\nYes" }, { "input": "5 9\n1 1 1 2\nedbcb\n1 3\n2 1\n1 3\n2 1\n2 2\n2 2\n1 1\n1 3\n2 1", "output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes" }, { "input": "8 12\n1 1 1 2 1 1 4\ncbecdcce\n1 2\n1 2\n2 1\n1 1\n2 1\n1 3\n1 3\n1 3\n1 2\n2 3\n1 3\n1 1", "output": "No\nNo\nYes\nYes\nYes\nNo\nNo\nNo\nNo\nYes\nNo\nYes" }, { "input": "1 1\n\np\n1 1", "output": "Yes" }, { "input": "1 1\n\na\n1 1", "output": "Yes" } ]
2,000
217,907,200
0
1,634
979
Kuro and Walking Route
[ "dfs and similar", "trees" ]
null
null
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
[ "3 1 3\n1 2\n2 3\n", "3 1 3\n1 2\n1 3\n" ]
[ "5", "4" ]
On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
[ { "input": "3 1 3\n1 2\n2 3", "output": "5" }, { "input": "3 1 3\n1 2\n1 3", "output": "4" }, { "input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 52\n1 39\n35 19\n39 50\n27 6\n26 3\n26 55\n35 31\n1 61\n1 23\n27 45\n39 7\n1 35\n39 29\n27 5\n39 32\n27 48\n35 49\n29 54\n1 46\n35 36\n31 33", "output": "3657" }, { "input": "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2", "output": "40" }, { "input": "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19", "output": "872" }, { "input": "8 6 4\n1 2\n1 4\n1 8\n1 3\n1 7\n2 6\n2 5", "output": "55" }, { "input": "7 7 3\n3 2\n3 5\n3 7\n1 3\n1 4\n5 6", "output": "36" }, { "input": "70 42 32\n25 50\n51 7\n39 61\n1 33\n20 5\n1 70\n1 63\n42 35\n64 16\n1 11\n39 42\n20 54\n11 14\n57 44\n1 59\n55 40\n25 3\n31 18\n38 68\n57 23\n39 57\n28 10\n39 20\n42 26\n58 6\n20 56\n57 2\n13 21\n15 69\n39 64\n1 39\n62 53\n39 13\n1 41\n22 12\n13 30\n68 67\n20 31\n51 15\n57 32\n59 34\n39 4\n31 65\n58 24\n20 55\n15 27\n25 46\n20 22\n57 49\n68 52\n39 8\n54 58\n39 28\n13 48\n15 43\n25 66\n1 29\n15 37\n31 60\n1 19\n62 38\n39 17\n64 36\n59 25\n57 45\n57 9\n11 62\n20 51\n54 47", "output": "4827" }, { "input": "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1 13\n13 11\n13 4\n10 6\n10 12\n7 9\n1 10", "output": "146" }, { "input": "72 16 5\n1 20\n8 4\n23 19\n16 63\n45 65\n27 67\n58 21\n36 17\n20 52\n1 71\n8 59\n20 26\n28 16\n23 3\n45 42\n61 51\n6 31\n1 15\n1 11\n6 62\n43 60\n20 27\n20 32\n1 8\n68 25\n1 57\n20 70\n1 64\n1 13\n8 18\n8 46\n28 49\n8 39\n64 58\n28 47\n27 14\n8 10\n11 53\n1 24\n28 2\n72 30\n36 29\n1 45\n24 23\n1 72\n46 61\n45 56\n72 35\n11 50\n8 55\n8 28\n1 38\n61 41\n1 44\n61 40\n27 33\n72 69\n46 36\n43 66\n61 22\n45 5\n27 43\n46 12\n1 7\n16 68\n1 6\n1 9\n45 37\n27 34\n8 54\n20 48", "output": "5108" }, { "input": "2 1 2\n1 2", "output": "1" }, { "input": "2 1 2\n2 1", "output": "1" } ]
109
1,024,000
0
1,637
630
Again Twenty Five!
[ "number theory" ]
null
null
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City?
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output the last two digits of 5*n* without spaces between them.
[ "2\n" ]
[ "25" ]
none
[ { "input": "2", "output": "25" }, { "input": "7", "output": "25" }, { "input": "1000000000000000000", "output": "25" }, { "input": "2000000000000000000", "output": "25" }, { "input": "987654321012345678", "output": "25" } ]
46
0
0
1,638
429
Xor-tree
[ "dfs and similar", "trees" ]
null
null
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
[ "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n" ]
[ "2\n4\n7\n" ]
none
[ { "input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "output": "2\n4\n7" }, { "input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "output": "7\n1\n4\n7\n8\n9\n11\n13" }, { "input": "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13 2\n14 12\n15 14\n16 8\n17 9\n18 13\n19 2\n20 17\n1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0\n1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1", "output": "8\n11\n15\n17\n20\n10\n18\n19\n7" }, { "input": "30\n2 1\n3 2\n4 3\n5 3\n6 5\n7 3\n8 3\n9 2\n10 3\n11 2\n12 11\n13 6\n14 4\n15 5\n16 11\n17 9\n18 14\n19 6\n20 2\n21 19\n22 9\n23 19\n24 20\n25 14\n26 22\n27 1\n28 6\n29 13\n30 27\n1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0\n0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0", "output": "15\n1\n2\n4\n5\n6\n13\n29\n19\n21\n23\n28\n7\n22\n26\n30" }, { "input": "15\n2 1\n3 1\n4 1\n5 1\n6 3\n7 1\n8 1\n9 1\n10 5\n11 9\n12 3\n13 5\n14 5\n15 4\n1 1 0 0 0 0 1 1 1 0 1 1 1 0 0\n1 0 1 1 0 1 1 1 1 1 1 1 1 1 0", "output": "6\n2\n3\n6\n4\n10\n14" }, { "input": "20\n2 1\n3 1\n4 2\n5 2\n6 3\n7 1\n8 6\n9 2\n10 3\n11 6\n12 2\n13 3\n14 2\n15 1\n16 8\n17 15\n18 2\n19 14\n20 14\n0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1\n0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0", "output": "10\n2\n4\n19\n18\n8\n16\n11\n10\n13\n7" }, { "input": "23\n2 1\n3 2\n4 1\n5 1\n6 5\n7 3\n8 2\n9 8\n10 5\n11 6\n12 9\n13 3\n14 11\n15 5\n16 2\n17 3\n18 10\n19 16\n20 14\n21 19\n22 17\n23 7\n0 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1", "output": "8\n2\n23\n13\n17\n9\n4\n11\n20" }, { "input": "1\n0\n0", "output": "0" }, { "input": "10\n1 10\n1 9\n10 2\n10 3\n3 7\n3 8\n9 4\n9 5\n5 6\n1 0 1 1 0 1 0 1 0 1\n0 0 0 0 0 0 0 0 0 0", "output": "6\n1\n10\n2\n7\n5\n6" } ]
1,000
20,582,400
0
1,641
845
Chess Tourney
[ "implementation", "sortings" ]
null
null
Berland annual chess tournament is coming! Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins. Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000).
If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
[ "2\n1 3 2 4\n", "1\n3 3\n" ]
[ "YES\n", "NO\n" ]
none
[ { "input": "2\n1 3 2 4", "output": "YES" }, { "input": "1\n3 3", "output": "NO" }, { "input": "5\n1 1 1 1 2 2 3 3 3 3", "output": "NO" }, { "input": "5\n1 1 1 1 1 2 2 2 2 2", "output": "YES" }, { "input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "1\n2 3", "output": "YES" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "35\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884", "output": "YES" }, { "input": "5\n1 2 3 4 10 10 6 7 8 9", "output": "YES" }, { "input": "2\n1 1 1 2", "output": "NO" }, { "input": "2\n10 4 4 4", "output": "NO" }, { "input": "2\n2 3 3 3", "output": "NO" }, { "input": "4\n1 2 3 4 5 4 6 7", "output": "NO" }, { "input": "4\n2 5 4 5 8 3 1 5", "output": "YES" }, { "input": "4\n8 2 2 4 1 4 10 9", "output": "NO" }, { "input": "2\n3 8 10 2", "output": "YES" }, { "input": "3\n1 3 4 4 5 6", "output": "NO" }, { "input": "2\n3 3 3 4", "output": "NO" }, { "input": "2\n1 1 2 2", "output": "YES" }, { "input": "2\n1 1 3 3", "output": "YES" }, { "input": "2\n1 2 3 2", "output": "NO" }, { "input": "10\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4", "output": "NO" }, { "input": "3\n1 2 3 3 4 5", "output": "NO" }, { "input": "2\n2 2 1 1", "output": "YES" }, { "input": "7\n1 2 3 4 5 6 7 7 8 9 10 11 12 19", "output": "NO" }, { "input": "5\n1 2 3 4 5 3 3 5 6 7", "output": "YES" }, { "input": "4\n1 1 2 2 3 3 3 3", "output": "YES" }, { "input": "51\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224", "output": "YES" }, { "input": "3\n3 3 3 2 3 2", "output": "NO" }, { "input": "2\n5 3 3 6", "output": "YES" }, { "input": "2\n1 2 2 3", "output": "NO" }, { "input": "2\n1 3 2 2", "output": "NO" }, { "input": "2\n1 3 3 4", "output": "NO" }, { "input": "2\n1 2 2 2", "output": "NO" }, { "input": "3\n1 2 7 19 19 7", "output": "NO" }, { "input": "3\n1 2 3 3 5 6", "output": "NO" }, { "input": "2\n1 2 2 4", "output": "NO" }, { "input": "2\n6 6 5 5", "output": "YES" }, { "input": "2\n3 1 3 1", "output": "YES" }, { "input": "3\n1 2 3 3 1 1", "output": "YES" }, { "input": "3\n3 2 1 3 4 5", "output": "NO" }, { "input": "3\n4 5 6 4 2 1", "output": "NO" }, { "input": "3\n1 1 2 3 2 4", "output": "NO" }, { "input": "3\n100 99 1 1 1 1", "output": "NO" }, { "input": "3\n1 2 3 6 5 3", "output": "NO" }, { "input": "2\n2 2 1 2", "output": "NO" }, { "input": "4\n1 2 3 4 5 6 7 4", "output": "NO" }, { "input": "3\n1 2 3 1 1 1", "output": "NO" }, { "input": "3\n6 5 3 3 1 3", "output": "NO" }, { "input": "2\n1 2 1 2", "output": "YES" }, { "input": "3\n1 2 5 6 8 6", "output": "YES" }, { "input": "5\n1 2 3 4 5 3 3 3 3 3", "output": "NO" }, { "input": "2\n1 2 4 2", "output": "NO" }, { "input": "3\n7 7 4 5 319 19", "output": "NO" }, { "input": "3\n1 2 4 4 3 5", "output": "YES" }, { "input": "3\n3 2 3 4 5 2", "output": "NO" }, { "input": "5\n1 2 3 4 4 5 3 6 7 8", "output": "NO" }, { "input": "3\n3 3 4 4 5 1", "output": "YES" }, { "input": "2\n3 4 3 3", "output": "NO" }, { "input": "2\n2 5 4 4", "output": "NO" }, { "input": "5\n1 2 3 3 4 5 6 7 8 4", "output": "NO" }, { "input": "3\n1 2 3 3 5 5", "output": "NO" }, { "input": "2\n3 4 4 4", "output": "NO" }, { "input": "2\n1 4 5 4", "output": "NO" }, { "input": "2\n1 2 3 3", "output": "YES" }, { "input": "2\n1 1 2 1", "output": "NO" }, { "input": "4\n1 1 1 1 2 2 2 2", "output": "YES" }, { "input": "4\n1 2 3 5 6 7 8 5", "output": "NO" }, { "input": "2\n4 3 3 1", "output": "NO" }, { "input": "3\n3 1 2 4 3 5", "output": "NO" }, { "input": "3\n1 2 3 3 4 6", "output": "NO" }, { "input": "4\n2 2 2 4 5 5 5 5", "output": "YES" }, { "input": "2\n1 3 4 3", "output": "NO" }, { "input": "2\n3 3 2 3", "output": "NO" }, { "input": "2\n1 2 1 1", "output": "NO" }, { "input": "3\n1 3 4 4 2 5", "output": "YES" }, { "input": "4\n4 7 1 2 3 5 6 4", "output": "NO" }, { "input": "2\n3 2 2 2", "output": "NO" }, { "input": "1\n2 1", "output": "YES" }, { "input": "2\n3 3 1 2", "output": "YES" }, { "input": "1\n8 6", "output": "YES" }, { "input": "7\n6 7 6 7 3 1 9 4 6 10 8 2 5 7", "output": "NO" }, { "input": "2\n3 9 2 1", "output": "YES" }, { "input": "2\n3 3 3 3", "output": "NO" } ]
109
0
3
1,644
844
Rectangles
[ "combinatorics", "math" ]
null
null
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly. The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
Output single integer  — the number of non-empty sets from the problem description.
[ "1 1\n0\n", "2 3\n1 0 1\n0 1 0\n" ]
[ "1\n", "8\n" ]
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
[ { "input": "1 1\n0", "output": "1" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "8" }, { "input": "2 2\n1 1\n1 1", "output": "8" }, { "input": "1 10\n0 0 0 0 0 0 0 0 0 0", "output": "1023" }, { "input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "2047" }, { "input": "10 11\n1 1 0 1 1 0 0 0 1 0 0\n1 0 0 1 1 1 0 0 1 1 0\n0 0 1 0 1 1 0 1 0 1 1\n0 1 1 1 0 1 0 1 0 0 0\n1 1 1 1 1 1 1 0 1 0 0\n1 1 0 1 1 1 1 0 0 1 1\n1 0 1 0 1 0 0 1 1 1 0\n1 1 0 0 0 0 0 1 0 1 1\n1 1 0 1 1 1 0 0 1 1 0\n1 0 1 1 0 0 1 0 0 1 1", "output": "2444" }, { "input": "50 1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n1", "output": "142606334" }, { "input": "1 50\n0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1", "output": "142606334" }, { "input": "2 20\n0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0", "output": "589853" }, { "input": "5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "285" }, { "input": "6 6\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1", "output": "720" }, { "input": "21 2\n0 1\n1 1\n0 1\n0 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1310745" }, { "input": "3 15\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 1 0 0 0 0 0 1 0\n1 0 0 1 0 0 0 0 0 0 0 0 1 0 1", "output": "22587" }, { "input": "10 11\n0 1 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 1 0\n0 0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 1 1 0 0 0\n0 0 0 0 0 0 0 0 1 0 0\n0 0 1 0 1 0 0 0 0 1 1", "output": "12047" }, { "input": "14 15\n0 1 0 0 0 0 0 0 1 0 0 0 1 0 1\n0 0 0 1 1 1 1 0 1 0 0 1 1 0 0\n1 0 0 0 0 1 1 0 0 0 0 0 0 0 0\n0 1 0 0 0 1 0 1 1 0 0 1 0 0 0\n0 0 1 1 0 1 0 1 0 1 1 0 1 0 0\n0 0 0 1 1 0 0 0 0 0 1 1 0 1 0\n0 0 1 0 0 0 0 0 0 1 0 0 1 1 0\n1 1 0 0 0 1 0 0 0 0 0 0 1 1 0\n0 0 0 0 1 0 1 1 1 0 0 0 1 0 1\n1 0 1 1 0 1 0 0 1 0 0 1 1 1 0\n1 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n0 0 0 1 0 1 0 0 0 0 1 0 0 0 1\n0 0 1 0 1 0 0 0 1 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0", "output": "53166" }, { "input": "1 50\n0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0", "output": "1099511628798" }, { "input": "50 1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1", "output": "35184372088862" }, { "input": "1 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1125899906842623" }, { "input": "5 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5629499534214415" }, { "input": "32 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "8589934622" }, { "input": "1 50\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "562949953421312" }, { "input": "50 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "1125899906842623" }, { "input": "1 49\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "562949953421311" }, { "input": "2 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2251799813685296" }, { "input": "3 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "3377699720528069" }, { "input": "1 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1125899906842623" }, { "input": "1 40\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1099511627775" }, { "input": "1 33\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "8589934591" }, { "input": "2 40\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2199023255590" }, { "input": "1 35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "34359738367" }, { "input": "50 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "1125899906842623" } ]
46
0
0
1,646
239
Two Bags of Potatoes
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..." }, { "input": "84817 1 33457", "output": "-1" }, { "input": "21 37 99", "output": "16 53 " }, { "input": "78 7 15", "output": "-1" }, { "input": "74 17 27", "output": "-1" }, { "input": "79 23 43", "output": "-1" }, { "input": "32 33 3", "output": "-1" }, { "input": "55 49 44", "output": "-1" }, { "input": "64 59 404", "output": "54 113 172 231 290 " }, { "input": "61 69 820", "output": "8 77 146 215 284 353 422 491 560 629 698 " }, { "input": "17 28 532", "output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 " }, { "input": "46592 52 232", "output": "-1" }, { "input": "1541 58 648", "output": "-1" }, { "input": "15946 76 360", "output": "-1" }, { "input": "30351 86 424", "output": "-1" }, { "input": "1 2 37493", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "1 3 27764", "output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..." }, { "input": "10 4 9174", "output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..." }, { "input": "33 7 4971", "output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..." }, { "input": "981 1 3387", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "386 1 2747", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "123 2 50000", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "3123 100 10000000", "output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..." }, { "input": "2 10000 1000000000", "output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..." }, { "input": "3 10000 1000000000", "output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..." }, { "input": "12312223 10000 1000000000", "output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..." }, { "input": "500000000 1000000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 1000000000", "output": "999999999 " }, { "input": "10 6 11", "output": "-1" }, { "input": "2 100 10", "output": "-1" }, { "input": "1 100000007 1000000000", "output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 " }, { "input": "1 999999999 1000000000", "output": "999999998 " }, { "input": "100000000 1000000000 1000000000", "output": "900000000 " }, { "input": "11 2 12", "output": "1 " }, { "input": "31 10 39", "output": "-1" }, { "input": "48 6 50", "output": "-1" }, { "input": "500000000 500000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 999999999", "output": "-1" }, { "input": "4 2 10", "output": "2 4 6 " }, { "input": "1000000000 1 1", "output": "-1" }, { "input": "1000000000 1 100000", "output": "-1" }, { "input": "1000000000 1 10", "output": "-1" }, { "input": "10 5 14", "output": "-1" }, { "input": "500000000 499999999 1000000000", "output": "499999998 " }, { "input": "1 999999997 1000000000", "output": "999999996 " } ]
1,000
24,268,800
0
1,651
540
Combination Lock
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { "input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "output": "245" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "3\n607\n684", "output": "5" }, { "input": "4\n0809\n0636", "output": "8" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762280548\n9519431339078678836940020", "output": "72" }, { "input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "output": "305" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762285484\n9519431339078678836940202", "output": "74" }, { "input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "output": "357" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8378525987476228048406972\n9194339078883694020217816", "output": "55" }, { "input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "output": "274" }, { "input": "1\n0\n0", "output": "0" }, { "input": "1\n7\n7", "output": "0" }, { "input": "1\n0\n5", "output": "5" }, { "input": "1\n2\n7", "output": "5" }, { "input": "1\n7\n9", "output": "2" }, { "input": "1\n9\n7", "output": "2" }, { "input": "1\n2\n9", "output": "3" }, { "input": "1\n9\n2", "output": "3" }, { "input": "25\n3164978461316464614169874\n9413979197249127496597357", "output": "66" }, { "input": "4\n9999\n9999", "output": "0" }, { "input": "2\n11\n11", "output": "0" } ]
77
1,433,600
3
1,657
453
Little Pony and Lord Tirek
[ "data structures" ]
null
null
Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger. The core skill of Tirek is called Absorb Mana. It takes all mana from a magic creature and gives them to the caster. Now to simplify the problem, assume you have *n* ponies (numbered from 1 to *n*). Each pony has three attributes: - *s**i* : amount of mana that the pony has at time 0; - *m**i* : maximum mana that the pony can have; - *r**i* : mana regeneration per unit time. Lord Tirek will do *m* instructions, each of them can be described with three integers: *t**i*,<=*l**i*,<=*r**i*. The instruction means that at time *t**i*, Tirek will use Absorb Mana on ponies with numbers from *l**i* to *r**i* (both borders inclusive). We'll give you all the *m* instructions in order, count how much mana Tirek absorbs for each instruction.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of ponies. Each of the next *n* lines contains three integers *s**i*,<=*m**i*,<=*r**i* (0<=≤<=*s**i*<=≤<=*m**i*<=≤<=105; 0<=≤<=*r**i*<=≤<=105), describing a pony. The next line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of instructions. Each of the next *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (0<=≤<=*t**i*<=≤<=109; 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), describing an instruction of Lord Tirek. The instructions are given in strictly increasing order of *t**i* (all *t**i* are distinct).
For each instruction, output a single line which contains a single integer, the total mana absorbed in this instruction.
[ "5\n0 10 1\n0 12 1\n0 20 1\n0 12 1\n0 10 1\n2\n5 1 5\n19 1 5\n" ]
[ "25\n58\n" ]
Every pony starts with zero mana. For the first instruction, each pony has 5 mana, so you get 25 mana in total and each pony has 0 mana after the first instruction. For the second instruction, pony 3 has 14 mana and other ponies have mana equal to their *m*<sub class="lower-index">*i*</sub>.
[]
93
307,200
-1
1,663