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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
994 | Knights of a Polygonal Table | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight. | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ β the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ β powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ β the number of coins each knight has. | Print $n$ integers β the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input": "7 2\n2 4 6 7 8 9 10\n10 8 4 8 4 5 9",
"output": "10 18 22 26 22 23 27 "
},
{
"input": "11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000 2000000000 3000000000 4000000000 5000000000 6000000000 7000000000 8000000000 9000000000 10000000000 11000000000 "
},
{
"input": "2 0\n2 3\n3 3",
"output": "3 3 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 4 5 6 7",
"output": "3 6 9 13 15 18 22 "
},
{
"input": "3 0\n3 2 1\n1 2 3",
"output": "1 2 3 "
},
{
"input": "5 3\n4 5 7 9 11\n10 10 10 10 10",
"output": "10 20 30 40 40 "
},
{
"input": "4 0\n4 5 9 7\n1 2 11 33",
"output": "1 2 11 33 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 8 8 8 8",
"output": "3 6 9 17 22 27 32 "
},
{
"input": "3 0\n1 2 3\n5 5 5",
"output": "5 5 5 "
},
{
"input": "4 2\n4 5 9 7\n2 2 11 33",
"output": "2 4 46 37 "
},
{
"input": "6 3\n1 2 3 4 5 6\n1 1 1 1 1 1",
"output": "1 2 3 4 4 4 "
},
{
"input": "10 5\n1 2 3 4 5 6 7 8 9 10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 2 3 4 5 6 6 6 6 6 "
},
{
"input": "3 2\n1 2 3\n1 1 1",
"output": "1 2 3 "
},
{
"input": "3 0\n1 2 3\n10 20 30",
"output": "10 20 30 "
},
{
"input": "4 0\n4 5 9 7\n1 2 3 4",
"output": "1 2 3 4 "
},
{
"input": "5 4\n1 2 3 4 5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "4 3\n1 2 3 4\n5 5 5 5",
"output": "5 10 15 20 "
},
{
"input": "5 3\n1 2 3 4 5\n7 7 7 7 7",
"output": "7 14 21 28 28 "
}
] | 1,000 | 22,016,000 | 0 | 384 |
|
218 | Airport | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency).
The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer?
The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1000) β the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=β€<=*a**i*<=β€<=1000) β *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets.
The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. | Print two integers β the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person β to the 2-nd plane, the 3-rd person β to the 3-rd plane, the 4-th person β to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person β to the 1-st plane, the 3-rd person β to the 2-nd plane, the 4-th person β to the 2-nd plane. | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7",
"output": "37 37"
},
{
"input": "40 10\n1 2 3 4 5 6 7 10 10 10",
"output": "223 158"
},
{
"input": "1 1\n6",
"output": "6 6"
},
{
"input": "1 2\n10 9",
"output": "10 9"
},
{
"input": "2 1\n7",
"output": "13 13"
},
{
"input": "2 2\n7 2",
"output": "13 3"
},
{
"input": "3 2\n4 7",
"output": "18 9"
},
{
"input": "3 3\n2 1 1",
"output": "4 4"
},
{
"input": "3 3\n2 1 1",
"output": "4 4"
},
{
"input": "10 10\n3 1 2 2 1 1 2 1 2 3",
"output": "20 13"
},
{
"input": "10 2\n7 3",
"output": "34 34"
},
{
"input": "10 1\n19",
"output": "145 145"
},
{
"input": "100 3\n29 36 35",
"output": "1731 1731"
},
{
"input": "100 5\n3 38 36 35 2",
"output": "2019 1941"
},
{
"input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62",
"output": "50279 5479"
},
{
"input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4",
"output": "1501 1501"
},
{
"input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2",
"output": "12204 8871"
}
] | 62 | 0 | -1 | 385 |
|
508 | Pasha and Pixels | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=Γ<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=Γ<=2 square consisting of black pixels is formed. | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=β€<=*n*,<=*m*<=β€<=1000, 1<=β€<=*k*<=β€<=105)Β β the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=β€<=*i*<=β€<=*n*, 1<=β€<=*j*<=β€<=*m*), representing the row number and column number of the pixel that was painted during a move. | If Pasha loses, print the number of the move when the 2<=Γ<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=Γ<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
"output": "9"
},
{
"input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2",
"output": "5"
},
{
"input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352",
"output": "0"
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5",
"output": "0"
},
{
"input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "0"
},
{
"input": "1 1 1\n1 1",
"output": "0"
},
{
"input": "10 10 4\n5 9\n6 9\n6 10\n5 10",
"output": "4"
},
{
"input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000",
"output": "4"
},
{
"input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2",
"output": "5"
},
{
"input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000",
"output": "4"
}
] | 2,000 | 4,915,200 | 0 | 386 |
|
1,011 | Stages | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the stringΒ β concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z'Β β $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. | The first line of input contains two integersΒ β $n$ and $k$ ($1 \le k \le n \le 50$)Β β the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. | Print a single integerΒ β the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "169"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "13 13\nuwgmkyqeiaocs",
"output": "169"
},
{
"input": "13 13\nhzdxpbfvrltnj",
"output": "182"
},
{
"input": "1 1\nn",
"output": "14"
},
{
"input": "10 8\nsmzeblyjqw",
"output": "113"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh",
"output": "-1"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav",
"output": "-1"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv",
"output": "-1"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz",
"output": "-1"
},
{
"input": "10 7\niuiukrxcml",
"output": "99"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa",
"output": "5"
},
{
"input": "12 6\nfwseyrarkwcd",
"output": "61"
},
{
"input": "2 2\nac",
"output": "4"
},
{
"input": "1 1\nc",
"output": "3"
},
{
"input": "2 2\nad",
"output": "5"
},
{
"input": "2 1\nac",
"output": "1"
},
{
"input": "4 3\nadjz",
"output": "15"
},
{
"input": "3 3\naoz",
"output": "42"
},
{
"input": "3 1\nzzz",
"output": "26"
},
{
"input": "2 1\nxz",
"output": "24"
},
{
"input": "5 1\naaddd",
"output": "1"
}
] | 140 | 0 | 3 | 388 |
|
740 | Alyona and copybooks | [
"brute force",
"implementation"
] | null | null | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks.
What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. | The only line contains 4 integers *n*, *a*, *b*, *c* (1<=β€<=*n*,<=*a*,<=*b*,<=*c*<=β€<=109). | Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. | [
"1 1 3 4\n",
"6 2 1 1\n",
"4 4 4 4\n",
"999999999 1000000000 1000000000 1000000000\n"
] | [
"3\n",
"1\n",
"0\n",
"1000000000\n"
] | In the first example Alyona can buy 3 packs of 1 copybook for 3*a*β=β3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for *b*β=β1 ruble. She will have 8 copybooks in total.
In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
In the fourth example Alyona should buy one pack of one copybook. | [
{
"input": "1 1 3 4",
"output": "3"
},
{
"input": "6 2 1 1",
"output": "1"
},
{
"input": "4 4 4 4",
"output": "0"
},
{
"input": "999999999 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1016 3 2 1",
"output": "0"
},
{
"input": "17 100 100 1",
"output": "1"
},
{
"input": "17 2 3 100",
"output": "5"
},
{
"input": "18 1 3 3",
"output": "2"
},
{
"input": "19 1 1 1",
"output": "1"
},
{
"input": "999999997 999999990 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "999999998 1000000000 999999990 1000000000",
"output": "999999990"
},
{
"input": "634074578 336470888 481199252 167959139",
"output": "335918278"
},
{
"input": "999999999 1000000000 1000000000 999999990",
"output": "1000000000"
},
{
"input": "804928248 75475634 54748096 641009859",
"output": "0"
},
{
"input": "535590429 374288891 923264237 524125987",
"output": "524125987"
},
{
"input": "561219907 673102149 496813081 702209411",
"output": "673102149"
},
{
"input": "291882089 412106895 365329221 585325539",
"output": "585325539"
},
{
"input": "757703054 5887448 643910770 58376259",
"output": "11774896"
},
{
"input": "783332532 449924898 72235422 941492387",
"output": "0"
},
{
"input": "513994713 43705451 940751563 824608515",
"output": "131116353"
},
{
"input": "539624191 782710197 514300407 2691939",
"output": "8075817"
},
{
"input": "983359971 640274071 598196518 802030518",
"output": "640274071"
},
{
"input": "8989449 379278816 26521171 685146646",
"output": "405799987"
},
{
"input": "34618927 678092074 895037311 863230070",
"output": "678092074"
},
{
"input": "205472596 417096820 468586155 41313494",
"output": "0"
},
{
"input": "19 5 1 2",
"output": "3"
},
{
"input": "17 1 2 2",
"output": "2"
},
{
"input": "18 3 3 1",
"output": "2"
},
{
"input": "19 4 3 1",
"output": "3"
},
{
"input": "936134778 715910077 747167704 219396918",
"output": "438793836"
},
{
"input": "961764255 454914823 615683844 102513046",
"output": "307539138"
},
{
"input": "692426437 48695377 189232688 985629174",
"output": "146086131"
},
{
"input": "863280107 347508634 912524637 458679894",
"output": "347508634"
},
{
"input": "593942288 86513380 486073481 341796022",
"output": "0"
},
{
"input": "914539062 680293934 764655030 519879446",
"output": "764655030"
},
{
"input": "552472140 509061481 586588704 452405440",
"output": "0"
},
{
"input": "723325809 807874739 160137548 335521569",
"output": "335521569"
},
{
"input": "748955287 546879484 733686393 808572289",
"output": "546879484"
},
{
"input": "774584765 845692742 162011045 691688417",
"output": "691688417"
},
{
"input": "505246946 439473295 30527185 869771841",
"output": "30527185"
},
{
"input": "676100616 178478041 604076030 752887969",
"output": "0"
},
{
"input": "701730093 477291299 177624874 930971393",
"output": "654916173"
},
{
"input": "432392275 216296044 751173719 109054817",
"output": "216296044"
},
{
"input": "458021753 810076598 324722563 992170945",
"output": "992170945"
},
{
"input": "188683934 254114048 48014511 170254369",
"output": "48014511"
},
{
"input": "561775796 937657403 280013594 248004555",
"output": "0"
},
{
"input": "1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 10000 10000 3",
"output": "9"
},
{
"input": "3 12 3 4",
"output": "7"
},
{
"input": "3 10000 10000 1",
"output": "3"
},
{
"input": "3 1000 1000 1",
"output": "3"
},
{
"input": "3 10 10 1",
"output": "3"
},
{
"input": "3 100 100 1",
"output": "3"
},
{
"input": "3 100000 10000 1",
"output": "3"
},
{
"input": "7 10 2 3",
"output": "5"
},
{
"input": "3 1000 1000 2",
"output": "6"
},
{
"input": "1 100000 1 100000",
"output": "100000"
},
{
"input": "7 4 3 1",
"output": "3"
},
{
"input": "3 1000 1000 3",
"output": "9"
},
{
"input": "3 1000 1 1",
"output": "2"
},
{
"input": "3 10 1 1",
"output": "2"
},
{
"input": "3 100000 1 1",
"output": "2"
},
{
"input": "3 100 1 1",
"output": "2"
},
{
"input": "3 100000 100000 1",
"output": "3"
},
{
"input": "3 1000 1 100",
"output": "101"
},
{
"input": "3 1000000000 1 1000000000",
"output": "1000000000"
},
{
"input": "3 1000 1 10",
"output": "11"
},
{
"input": "3 200 1 100",
"output": "101"
},
{
"input": "7 4 1 1",
"output": "2"
},
{
"input": "7 4 12 1",
"output": "3"
},
{
"input": "3 9 1 1",
"output": "2"
},
{
"input": "3 10000000 1000000 1",
"output": "3"
},
{
"input": "7 1000 1000 1",
"output": "3"
},
{
"input": "3 10000 1 30",
"output": "31"
},
{
"input": "3 1000 1 2",
"output": "3"
},
{
"input": "7 12 6 1",
"output": "3"
},
{
"input": "3 100000 1 1000",
"output": "1001"
},
{
"input": "7 1000 1000 3",
"output": "9"
},
{
"input": "3 4 3 1",
"output": "3"
},
{
"input": "3 3000000 1 100000",
"output": "100001"
},
{
"input": "3 3 1 1",
"output": "2"
},
{
"input": "3 10 1 5",
"output": "6"
},
{
"input": "3 2000 2000 1",
"output": "3"
},
{
"input": "3 10000000 10000000 1",
"output": "3"
},
{
"input": "3 5 1 1",
"output": "2"
},
{
"input": "3 100 1 33",
"output": "34"
},
{
"input": "7 9 2 7",
"output": "9"
},
{
"input": "4448 2 3 6",
"output": "0"
},
{
"input": "2228 1 6 3",
"output": "0"
}
] | 46 | 0 | 0 | 389 |
|
127 | Wasted Time | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers. | The first line contains two integers *n* and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*k*<=β€<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* β integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. | Print one real number β the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8",
"output": "429.309294877"
},
{
"input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10",
"output": "13629.282573522"
},
{
"input": "2 1\n-20 -10\n-10 -6",
"output": "0.215406592"
},
{
"input": "2 13\n13 -10\n-3 -2",
"output": "4.651021393"
},
{
"input": "2 21\n13 8\n14 10",
"output": "0.939148551"
},
{
"input": "2 75\n-3 12\n1 12",
"output": "6.000000000"
},
{
"input": "2 466\n10 16\n-6 -3",
"output": "231.503997374"
},
{
"input": "2 999\n6 16\n-17 -14",
"output": "755.286284531"
},
{
"input": "2 1000\n-17 -14\n-14 -8",
"output": "134.164078650"
},
{
"input": "3 384\n-4 -19\n-17 -2\n3 4",
"output": "324.722285390"
},
{
"input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5",
"output": "668.956254495"
},
{
"input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15",
"output": "789.212495576"
},
{
"input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18",
"output": "3415.618464093"
},
{
"input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5",
"output": "2113.552527680"
},
{
"input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6",
"output": "2999.497312668"
},
{
"input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4",
"output": "2797.756635934"
},
{
"input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5",
"output": "12766.080247922"
},
{
"input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3",
"output": "36.467924851"
},
{
"input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4",
"output": "9495.010556306"
},
{
"input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14",
"output": "6087.366930474"
},
{
"input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11",
"output": "8929.162822862"
},
{
"input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13",
"output": "16314.207721932"
},
{
"input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11",
"output": "22153.369189802"
}
] | 92 | 0 | 3 | 390 |
|
811 | Vladik and Complicated Book | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladikβs mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x*Β β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | First line contains two space-separated integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=β€<=*p**i*<=β€<=*n*)Β β permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=β€<=*l**i*<=β€<=*x**i*<=β€<=*r**i*<=β€<=*n*)Β β left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik. | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". 1. [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". 1. [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". 1. [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". 1. [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo"
},
{
"input": "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11 10\n2 8 6\n12 18 16\n4 8 8\n2 2 2\n5 11 11\n4 9 9\n5 6 6\n3 20 12\n8 8 8\n6 16 11\n9 18 18\n8 18 17\n1 1 1\n2 6 5\n1 4 3",
"output": "No\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "5 10\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo\nYes\nNo\nYes\nYes\nNo"
}
] | 997 | 11,776,000 | 3 | 391 |
|
939 | Love Triangle | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=β€<=*f**i*<=β€<=*n* and *f**i*<=β <=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=5000)Β β the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=β€<=*f**i*<=β€<=*n*, *f**i*<=β <=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output Β«YESΒ» if there is a love triangle consisting of planes on Earth. Otherwise, output Β«NOΒ».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 62 | 2,048,000 | 3 | 393 |
|
612 | The Text Splitting | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=β€<=*p*,<=*q*<=β€<=*n*<=β€<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* β the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* β from left to right.
If there are several solutions print any of them. | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"output": "1\n1"
},
{
"input": "10 8 1\nuTl9w4lcdo",
"output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no"
},
{
"input": "20 6 4\nfmFRpk2NrzSvnQC9gB61",
"output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61"
},
{
"input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6",
"output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6"
},
{
"input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde",
"output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde"
},
{
"input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu",
"output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu"
},
{
"input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj",
"output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj"
},
{
"input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY",
"output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY"
},
{
"input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc",
"output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc"
},
{
"input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE",
"output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE"
},
{
"input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB",
"output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB"
},
{
"input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ",
"output": "-1"
},
{
"input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn",
"output": "-1"
},
{
"input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT",
"output": "-1"
},
{
"input": "10 3 1\nXQ2vXLPShy",
"output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny"
},
{
"input": "4 2 3\naaaa",
"output": "2\naa\naa"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb"
},
{
"input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 2 3\nhavanahavan",
"output": "4\nha\nvan\naha\nvan"
},
{
"input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa"
},
{
"input": "17 3 5\ngopstopmipodoshli",
"output": "5\ngop\nsto\npmi\npod\noshli"
},
{
"input": "5 4 3\nfoyku",
"output": "-1"
},
{
"input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"output": "-1"
},
{
"input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit",
"output": "-1"
},
{
"input": "11 2 3\nqibwnnvqqgo",
"output": "4\nqi\nbwn\nnvq\nqgo"
},
{
"input": "4 4 3\nhhhh",
"output": "1\nhhhh"
},
{
"input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh"
},
{
"input": "10 5 9\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "10 5 9\naaaaaaaaaa",
"output": "2\naaaaa\naaaaa"
},
{
"input": "11 3 2\nmlmqpohwtsf",
"output": "5\nmlm\nqp\noh\nwt\nsf"
},
{
"input": "3 3 2\nzyx",
"output": "1\nzyx"
},
{
"input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "4 2 3\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "3 2 3\nejt",
"output": "1\nejt"
},
{
"input": "5 2 4\nzyxwv",
"output": "-1"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na"
},
{
"input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa"
},
{
"input": "3 2 2\nzyx",
"output": "-1"
},
{
"input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "-1"
},
{
"input": "26 8 9\nabcabcabcabcabcabcabcabcab",
"output": "3\nabcabcab\ncabcabcab\ncabcabcab"
},
{
"input": "6 3 5\naaaaaa",
"output": "2\naaa\naaa"
},
{
"input": "3 2 3\nzyx",
"output": "1\nzyx"
},
{
"input": "5 5 2\naaaaa",
"output": "1\naaaaa"
},
{
"input": "4 3 2\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "5 4 3\nzyxwv",
"output": "-1"
},
{
"input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab"
},
{
"input": "3 2 2\naaa",
"output": "-1"
},
{
"input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj",
"output": "-1"
},
{
"input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
"output": "-1"
},
{
"input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab"
},
{
"input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca",
"output": "-1"
},
{
"input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb",
"output": "-1"
},
{
"input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy",
"output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy"
},
{
"input": "16 3 7\naaaaaaaaaaaaaaaa",
"output": "4\naaa\naaa\naaa\naaaaaaa"
},
{
"input": "11 10 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 8 8\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 7 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab"
},
{
"input": "11 3 2\naaaaaaaaaaa",
"output": "5\naaa\naa\naa\naa\naa"
},
{
"input": "14 9 4\nabcdefghijklmn",
"output": "-1"
},
{
"input": "9 9 5\n123456789",
"output": "1\n123456789"
},
{
"input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw",
"output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw"
},
{
"input": "17 16 3\ndxyhgtsxtuyljmclj",
"output": "-1"
},
{
"input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd",
"output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd"
},
{
"input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor",
"output": "-1"
},
{
"input": "7 5 3\nzyxwvut",
"output": "-1"
},
{
"input": "17 16 4\nctvfhkiakagcilrdw",
"output": "-1"
}
] | 62 | 0 | 0 | 394 |
|
932 | Recursive Queries | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=β€<=*Q*<=β€<=2<=Γ<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=β€<=*l*<=β€<=*r*<=β€<=106,<=1<=β€<=*k*<=β€<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33)β=β9 as *g*(33)β=β*g*(3βΓβ3)β=β*g*(9)β=β9 - *g*(47)β=β*g*(48)β=β*g*(60)β=β*g*(61)β=β6 - There are no such integers between 47 and 55. - *g*(4)β=β*g*(14)β=β*g*(22)β=β*g*(27)β=β*g*(39)β=β*g*(40)β=β*g*(41)β=β*g*(58)β=β4 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 93 | 5,632,000 | 0 | 395 |
|
493 | Vasya and Wrestling | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. | The first line contains number *n* β the number of techniques that the wrestlers have used (1<=β€<=*n*<=β€<=2Β·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=β€<=109, *a**i*<=β <=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order. | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x*ββ=ββ*x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*ββ=ββ*y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|ββ>ββ|*y*| and *x*<sub class="lower-index">1</sub>ββ=ββ*y*<sub class="lower-index">1</sub>,ββ*x*<sub class="lower-index">2</sub>ββ=ββ*y*<sub class="lower-index">2</sub>,β... ,ββ*x*<sub class="lower-index">|*y*|</sub>ββ=ββ*y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*ββ<ββ|*x*|,β*r*ββ<ββ|*y*|), that *x*<sub class="lower-index">1</sub>ββ=ββ*y*<sub class="lower-index">1</sub>,ββ*x*<sub class="lower-index">2</sub>ββ=ββ*y*<sub class="lower-index">2</sub>,ββ... ,ββ*x*<sub class="lower-index">*r*</sub>ββ=ββ*y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*ββ+ββ1</sub>ββ>ββ*y*<sub class="lower-index">*r*ββ+ββ1</sub>.
We use notation |*a*| to denote length of sequence *a*. | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 0 | 0 | -1 | 396 |
|
38 | Army | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible.
Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | The first input line contains an integer *n* (2<=β€<=*n*<=β€<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=β€<=*d**i*<=β€<=100). The third input line contains two integers *a* and *b* (1<=β€<=*a*<=<<=*b*<=β€<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n2 5",
"output": "181"
},
{
"input": "6\n22 9 87 89 57\n1 6",
"output": "264"
},
{
"input": "7\n52 36 31 23 74 78\n2 7",
"output": "242"
},
{
"input": "8\n82 14 24 5 91 49 94\n3 8",
"output": "263"
},
{
"input": "9\n12 40 69 39 59 21 59 5\n4 6",
"output": "98"
},
{
"input": "10\n95 81 32 59 71 30 50 61 100\n1 6",
"output": "338"
},
{
"input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14",
"output": "617"
},
{
"input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17",
"output": "399"
},
{
"input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23",
"output": "846"
},
{
"input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16",
"output": "730"
},
{
"input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35",
"output": "1663"
},
{
"input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26",
"output": "862"
},
{
"input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40",
"output": "1061"
},
{
"input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28",
"output": "344"
},
{
"input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60",
"output": "1502"
},
{
"input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41",
"output": "1767"
},
{
"input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24",
"output": "219"
},
{
"input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44",
"output": "1713"
},
{
"input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15",
"output": "570"
},
{
"input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26",
"output": "328"
},
{
"input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68",
"output": "3385"
},
{
"input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77",
"output": "3319"
},
{
"input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36",
"output": "514"
},
{
"input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92",
"output": "2599"
},
{
"input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27",
"output": "618"
},
{
"input": "2\n3\n1 2",
"output": "3"
},
{
"input": "5\n6 8 22 22\n2 3",
"output": "8"
},
{
"input": "6\n3 12 27 28 28\n3 4",
"output": "27"
},
{
"input": "9\n1 2 2 2 2 3 3 5\n3 7",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1\n6 8",
"output": "2"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17",
"output": "23"
},
{
"input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8",
"output": "23"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31",
"output": "2"
},
{
"input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45",
"output": "30"
},
{
"input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17",
"output": "285"
},
{
"input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58",
"output": "173"
},
{
"input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65",
"output": "126"
},
{
"input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65",
"output": "326"
},
{
"input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48",
"output": "784"
},
{
"input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93",
"output": "1636"
},
{
"input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96",
"output": "898"
},
{
"input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90",
"output": "3016"
},
{
"input": "99\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\n66 95",
"output": "29"
},
{
"input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52",
"output": "82"
},
{
"input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44",
"output": "2268"
}
] | 92 | 0 | 3.977 | 399 |
469 | I Wanna Be the Guy | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=β€<=<=*n*<=β€<=100).
The next line contains an integer *p* (0<=β€<=*p*<=β€<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=β€<=*a**i*<=β€<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 62 | 0 | 3 | 401 |
|
960 | Minimize the error | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed. | The first line contains three space-separated integers *n* (1<=β€<=*n*<=β€<=103), *k*1 and *k*2 (0<=β€<=*k*1<=+<=*k*2<=β€<=103, *k*1 and *k*2 are non-negative) β size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=β€<=*a**i*<=β€<=106) β array *A*.
Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=β€<=*b**i*<=β€<=106)β array *B*. | Output a single integer β the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E*β=β(1β-β2)<sup class="upper-index">2</sup>β+β(2β-β3)<sup class="upper-index">2</sup>β=β2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A*β=β[2,β2]. The error is now *E*β=β(2β-β2)<sup class="upper-index">2</sup>β+β(2β-β2)<sup class="upper-index">2</sup>β=β0. This is the minimum possible error obtainable.
In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A*β=β[8,β4] and *B*β=β[8,β4]. The error is now *E*β=β(8β-β8)<sup class="upper-index">2</sup>β+β(4β-β4)<sup class="upper-index">2</sup>β=β0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B*β=β[8,β5] and *E*β=β(8β-β8)<sup class="upper-index">2</sup>β+β(4β-β5)<sup class="upper-index">2</sup>β=β1. | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 5\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "3 4 5\n1 2 3\n3 2 1",
"output": "1"
},
{
"input": "3 1000 0\n1 2 3\n-1000 -1000 -1000",
"output": "1341346"
},
{
"input": "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3",
"output": "1"
},
{
"input": "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 21 25 2 -3 45 -7 -98 -56",
"output": "0"
},
{
"input": "10 10 580\n302 -553 -281 -299 -270 -890 -989 -749 -418 486\n735 330 6 725 -984 209 -855 -786 -502 967",
"output": "2983082"
},
{
"input": "10 403 187\n9691 -3200 3016 3540 -9475 8840 -4705 7940 6293 -2631\n-2288 9129 4067 696 -6754 9869 -5747 701 3344 -3426",
"output": "361744892"
},
{
"input": "10 561 439\n76639 67839 10670 -23 -18393 65114 46538 67596 86615 90480\n50690 620 -33631 -75857 75634 91321 -81662 -93668 -98557 -43621",
"output": "116776723778"
},
{
"input": "10 765 62\n-929885 -995154 254071 -370672 -435272 584846 -301610 -234118 -82557 743536\n-36327 439149 -977780 -821019 -585558 953598 -151943 140715 -311253 -383103",
"output": "6216649853365"
},
{
"input": "22 334 246\n-462653 -618002 4973 -348485 366658 192390 274752 200590 138367 779540 -661269 642587 113645 -110388 -604418 -491231 -933401 -219332 -603140 836439 167007 210226\n357638 -646669 -558432 -434313 -285851 -119233 323088 -512237 -729293 215256 39316 -984201 -209814 715016 -271932 796550 988227 -89577 67202 462973 -942079 -823339",
"output": "15389604923763"
},
{
"input": "1 1000 0\n1000000\n-1000000",
"output": "3996001000000"
},
{
"input": "1 1000 0\n1000000\n1000000",
"output": "0"
},
{
"input": "1 0 1000\n-1000000\n1000000",
"output": "3996001000000"
},
{
"input": "1 0 1000\n1000000\n1000000",
"output": "0"
},
{
"input": "1 5 7\n1\n2",
"output": "1"
},
{
"input": "2 1 3\n2 2\n2 2",
"output": "0"
},
{
"input": "3 3 0\n1 1 1\n1 1 1",
"output": "1"
},
{
"input": "1 0 6\n0\n0",
"output": "0"
},
{
"input": "2 1 1\n2 2\n0 0",
"output": "2"
},
{
"input": "3 1 4\n0 0 0\n1 5 6",
"output": "19"
},
{
"input": "1 1 2\n0\n8",
"output": "25"
},
{
"input": "2 2 0\n3 3\n3 3",
"output": "0"
}
] | 77 | 7,065,600 | 0 | 402 |
|
208 | Dubstep | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" β between them Vasya added two "WUB". | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 184 | 0 | 3 | 403 |
|
224 | Array | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=β€<=*l*<=β€<=*r*<=β€<=*n*) such, that among numbers *a**l*,<=Β *a**l*<=+<=1,<=Β ...,<=Β *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=β€<=*l*<=β€<=*r*<=β€<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=β€<=*l*<=β€<=*x*<=β€<=*y*<=β€<=*r*<=β€<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. | The first line contains two space-separated integers: *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*Β β elements of the array *a* (1<=β€<=*a**i*<=β€<=105). | Print a space-separated pair of integers *l* and *r* (1<=β€<=*l*<=β€<=*r*<=β€<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2,β5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"input": "1 1\n5",
"output": "1 1"
},
{
"input": "10 4\n1 1 2 2 3 3 4 4 4 4",
"output": "2 7"
},
{
"input": "4 2\n3 3 4 3",
"output": "2 3"
},
{
"input": "4 3\n4 4 4 2",
"output": "-1 -1"
},
{
"input": "10 5\n15 17 2 13 3 16 4 5 9 12",
"output": "1 5"
},
{
"input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148",
"output": "1 13"
},
{
"input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796",
"output": "-1 -1"
},
{
"input": "8 5\n1 2 1 1 2 3 4 5",
"output": "4 8"
},
{
"input": "7 3\n2 1 2 2 1 2 3",
"output": "5 7"
},
{
"input": "6 3\n1 3 1 1 4 5",
"output": "2 5"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2 5"
},
{
"input": "9 3\n1 2 1 2 1 2 2 3 1",
"output": "5 8"
},
{
"input": "4 3\n1 2 1 3",
"output": "2 4"
},
{
"input": "5 3\n1 3 1 3 4",
"output": "3 5"
},
{
"input": "6 3\n1 3 3 1 4 4",
"output": "3 5"
},
{
"input": "5 3\n1 2 1 2 3",
"output": "3 5"
},
{
"input": "8 4\n1 2 3 2 1 2 3 4",
"output": "5 8"
},
{
"input": "10 4\n1 2 3 1 2 3 4 3 2 1",
"output": "4 7"
},
{
"input": "10 3\n1 1 1 2 1 2 3 3 3 4",
"output": "5 7"
},
{
"input": "10 3\n1 1 2 1 2 2 3 4 5 6",
"output": "4 7"
}
] | 342 | 19,251,200 | 3 | 404 |
|
742 | Arpaβs hard exam and Mehrdadβs naive cheat | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. | The single line of input contains one integer *n* (0<=<=β€<=<=*n*<=<=β€<=<=109). | Print single integerΒ β the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup>β=β1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup>β=β1378Β·1378β=β1898884 is 4. | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": "8"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "2"
},
{
"input": "1378",
"output": "4"
},
{
"input": "13781378",
"output": "4"
},
{
"input": "51202278",
"output": "4"
},
{
"input": "999999998",
"output": "4"
},
{
"input": "999999997",
"output": "8"
},
{
"input": "12193721",
"output": "8"
},
{
"input": "0",
"output": "1"
},
{
"input": "989898989",
"output": "8"
},
{
"input": "7",
"output": "2"
},
{
"input": "8",
"output": "6"
},
{
"input": "9",
"output": "8"
},
{
"input": "10",
"output": "4"
},
{
"input": "11",
"output": "2"
},
{
"input": "12",
"output": "6"
},
{
"input": "13",
"output": "8"
},
{
"input": "14",
"output": "4"
},
{
"input": "15",
"output": "2"
},
{
"input": "16",
"output": "6"
},
{
"input": "999999996",
"output": "6"
},
{
"input": "999999995",
"output": "2"
},
{
"input": "999999994",
"output": "4"
}
] | 1,000 | 24,985,600 | 0 | 406 |
|
440 | Forgotten Episode | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=100000)Β β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*n*)Β β the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct. | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
{
"input": "3\n2 3",
"output": "1"
},
{
"input": "3\n2 1",
"output": "3"
},
{
"input": "3\n3 1",
"output": "2"
},
{
"input": "3\n3 2",
"output": "1"
},
{
"input": "5\n2 3 4 5",
"output": "1"
},
{
"input": "5\n5 4 3 2",
"output": "1"
},
{
"input": "5\n5 2 4 3",
"output": "1"
},
{
"input": "5\n1 2 3 4",
"output": "5"
},
{
"input": "5\n2 1 3 4",
"output": "5"
},
{
"input": "5\n1 5 3 4",
"output": "2"
},
{
"input": "5\n1 4 5 2",
"output": "3"
},
{
"input": "5\n2 1 5 3",
"output": "4"
},
{
"input": "5\n2 3 4 5",
"output": "1"
}
] | 92 | 10,547,200 | 3 | 408 |
|
810 | Summer sell-off | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem. | The first line contains two integers *n* and *f* (1<=β€<=*n*<=β€<=105,<=0<=β€<=*f*<=β€<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=β€<=*k**i*,<=*l**i*<=β€<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day. | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2,β6,β2,β2] respectively. So on the first day shop will sell 1 product, on the secondΒ β 5, on the thirdΒ β 2, on the fourthΒ β 2. In total 1β+β5β+β2β+β2β=β10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"input": "2 1\n5 7\n6 7",
"output": "13"
},
{
"input": "2 1\n7 8\n3 6",
"output": "13"
},
{
"input": "2 1\n9 10\n5 8",
"output": "17"
},
{
"input": "2 1\n3 6\n7 8",
"output": "13"
},
{
"input": "1 0\n10 20",
"output": "10"
},
{
"input": "2 1\n99 100\n3 6",
"output": "105"
},
{
"input": "4 2\n2 10\n3 10\n9 9\n5 10",
"output": "27"
},
{
"input": "2 1\n3 4\n2 8",
"output": "7"
},
{
"input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2",
"output": "1889"
},
{
"input": "2 1\n10 5\n2 4",
"output": "9"
},
{
"input": "2 1\n50 51\n30 40",
"output": "90"
},
{
"input": "3 2\n5 10\n5 10\n7 9",
"output": "27"
},
{
"input": "3 1\n1000 1000\n50 100\n2 2",
"output": "1102"
},
{
"input": "2 1\n2 4\n12 12",
"output": "16"
},
{
"input": "2 1\n4 4\n1 2",
"output": "6"
},
{
"input": "2 1\n4000 4000\n1 2",
"output": "4002"
},
{
"input": "2 1\n5 6\n2 4",
"output": "9"
},
{
"input": "3 2\n10 10\n10 10\n1 2",
"output": "22"
},
{
"input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4",
"output": "25"
},
{
"input": "2 1\n30 30\n10 20",
"output": "50"
},
{
"input": "1 1\n1 1",
"output": "1"
},
{
"input": "2 1\n10 2\n2 10",
"output": "6"
},
{
"input": "2 1\n4 5\n3 9",
"output": "10"
},
{
"input": "2 1\n100 100\n5 10",
"output": "110"
},
{
"input": "2 1\n14 28\n15 28",
"output": "43"
},
{
"input": "2 1\n100 1\n20 40",
"output": "41"
},
{
"input": "2 1\n5 10\n6 10",
"output": "16"
},
{
"input": "2 1\n29 30\n10 20",
"output": "49"
},
{
"input": "1 0\n12 12",
"output": "12"
},
{
"input": "2 1\n7 8\n4 7",
"output": "14"
},
{
"input": "2 1\n5 5\n2 4",
"output": "9"
},
{
"input": "2 1\n1 2\n228 2",
"output": "4"
},
{
"input": "2 1\n5 10\n100 20",
"output": "30"
},
{
"input": "2 1\n1000 1001\n2 4",
"output": "1004"
},
{
"input": "2 1\n3 9\n7 7",
"output": "13"
},
{
"input": "2 0\n1 1\n1 1",
"output": "2"
},
{
"input": "4 1\n10 10\n10 10\n10 10\n4 6",
"output": "36"
},
{
"input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64",
"output": "772"
},
{
"input": "2 1\n10 18\n17 19",
"output": "35"
},
{
"input": "3 0\n1 1\n1 1\n1 1",
"output": "3"
},
{
"input": "2 1\n4 7\n8 9",
"output": "15"
},
{
"input": "4 2\n2 10\n3 10\n9 10\n5 10",
"output": "27"
},
{
"input": "2 1\n5 7\n3 6",
"output": "11"
},
{
"input": "2 1\n3 4\n12 12",
"output": "16"
},
{
"input": "2 1\n10 11\n9 20",
"output": "28"
},
{
"input": "2 1\n7 8\n2 4",
"output": "11"
},
{
"input": "2 1\n5 10\n7 10",
"output": "17"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 10",
"output": "27"
},
{
"input": "2 1\n99 100\n5 10",
"output": "109"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 9",
"output": "27"
},
{
"input": "2 1\n3 7\n5 7",
"output": "11"
},
{
"input": "2 1\n10 10\n3 6",
"output": "16"
},
{
"input": "2 1\n100 1\n2 4",
"output": "5"
},
{
"input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "5"
},
{
"input": "3 1\n3 7\n4 5\n2 3",
"output": "12"
},
{
"input": "2 1\n3 9\n7 8",
"output": "13"
},
{
"input": "2 1\n10 2\n3 4",
"output": "6"
},
{
"input": "2 1\n40 40\n3 5",
"output": "45"
},
{
"input": "2 1\n5 3\n1 2",
"output": "5"
},
{
"input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4",
"output": "45"
},
{
"input": "3 1\n1 5\n1 5\n4 4",
"output": "7"
},
{
"input": "4 0\n1 1\n1 1\n1 1\n1 1",
"output": "4"
},
{
"input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2",
"output": "2005"
},
{
"input": "2 1\n15 30\n50 59",
"output": "80"
},
{
"input": "2 1\n8 8\n3 5",
"output": "13"
},
{
"input": "2 1\n4 5\n2 5",
"output": "8"
},
{
"input": "3 2\n3 3\n1 2\n1 2",
"output": "7"
},
{
"input": "3 1\n2 5\n2 5\n4 4",
"output": "10"
},
{
"input": "2 1\n3 10\n50 51",
"output": "56"
},
{
"input": "4 2\n2 4\n2 4\n9 10\n9 10",
"output": "26"
},
{
"input": "2 1\n3 5\n8 8",
"output": "13"
},
{
"input": "2 1\n100 150\n70 150",
"output": "240"
},
{
"input": "2 1\n4 5\n3 6",
"output": "10"
},
{
"input": "2 1\n20 10\n3 5",
"output": "15"
},
{
"input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533",
"output": "435467000"
},
{
"input": "2 1\n8 7\n3 6",
"output": "13"
},
{
"input": "2 1\n7 8\n3 5",
"output": "12"
},
{
"input": "2 1\n10 10\n1 3",
"output": "12"
},
{
"input": "2 1\n9 10\n2 4",
"output": "13"
},
{
"input": "3 1\n10 11\n12 13\n8 10",
"output": "32"
},
{
"input": "2 1\n5 10\n7 7",
"output": "17"
},
{
"input": "4 2\n90 91\n2 10\n2 10\n2 10",
"output": "100"
},
{
"input": "2 1\n2 4\n4 4",
"output": "8"
},
{
"input": "2 1\n2 3\n4 3",
"output": "6"
},
{
"input": "2 1\n40 45\n50 52",
"output": "95"
},
{
"input": "3 1\n1 4\n2 4\n3 4",
"output": "8"
},
{
"input": "2 1\n1 2\n1000 1000",
"output": "1002"
},
{
"input": "2 1\n80 100\n70 95",
"output": "175"
}
] | 30 | 0 | -1 | 410 |
|
466 | Number of Ways | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=β€<=*i*<=β€<=*j*<=β€<=*n*<=-<=1), that . | The first line contains integer *n* (1<=β€<=*n*<=β€<=5Β·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=β€<=<=109) β the elements of array *a*. | Print a single integer β the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "100\n1 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "2030"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "10\n1 0 0 0 1 1 1 0 1 1",
"output": "2"
},
{
"input": "10\n-2 2 -2 0 -2 -1 1 -1 2 0",
"output": "0"
},
{
"input": "4\n0 2 -1 2",
"output": "0"
},
{
"input": "5\n3 3 -3 3 3",
"output": "3"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "8\n-1 -1 -1 -1 -1 -1 -1 -1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "4\n1 -1 0 0",
"output": "1"
},
{
"input": "3\n6 -3 6",
"output": "0"
}
] | 46 | 0 | 0 | 411 |
|
554 | Ohana Cleans Up | [
"brute force",
"greedy",
"strings"
] | null | null | Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean. | The first line of input will be a single integer *n* (1<=β€<=*n*<=β€<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty. | The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. | [
"4\n0101\n1000\n1111\n0101\n",
"3\n111\n111\n111\n"
] | [
"2\n",
"3\n"
] | In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything. | [
{
"input": "4\n0101\n1000\n1111\n0101",
"output": "2"
},
{
"input": "3\n111\n111\n111",
"output": "3"
},
{
"input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "9"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011",
"output": "6"
},
{
"input": "20\n10101011101000011010\n11111010001100110101\n01011100010000001111\n10110100000101010011\n11010001110111101101\n00100110011011101010\n01000110101011001100\n01101100111101101101\n10111010010100111100\n00010010110001101110\n10111110010000101010\n10010111110100100100\n11010111001111110100\n11110111101100000001\n00011010100111011000\n11110001011000011010\n10001101010000011011\n01010101110010000111\n11100110111101101111\n11011111110010001111",
"output": "1"
},
{
"input": "10\n1001000000\n0111101111\n1111001011\n1000010100\n0111101111\n0101100110\n1001000000\n1000010100\n0111101111\n1001000000",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "10"
},
{
"input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111",
"output": "10"
},
{
"input": "10\n1000000000\n0100000000\n0010000000\n0001000000\n0000100000\n0000010000\n0000001000\n0000000100\n0000000010\n0000000001",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "4\n0000\n0000\n1111\n1111",
"output": "2"
},
{
"input": "11\n10000000001\n10000000001\n10000000001\n10000000001\n10001000001\n10001000000\n10001000001\n10001000001\n10001000000\n10001000000\n10001000100",
"output": "4"
}
] | 483 | 0 | 3 | 413 |
|
43 | Football | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of lines in the description. Then follow *n* lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 218 | 0 | 3.9455 | 414 |
499 | Lecture | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. | The first line contains two integers, *n* and *m* (1<=β€<=*n*<=β€<=3000, 1<=β€<=*m*<=β€<=3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* β the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 0 | 0 | -1 | 415 |
|
743 | Vladik and flights | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*.
Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad. | The first line contains three integers *n*, *a*, and *b* (1<=β€<=*n*<=β€<=105, 1<=β€<=*a*,<=*b*<=β€<=*n*)Β β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second. | Print single integerΒ β the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1β-β2|β=β1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company. | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n1001011011",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "10 5 8\n1000001110",
"output": "1"
},
{
"input": "10 1 10\n0000011111",
"output": "1"
},
{
"input": "4 1 4\n0011",
"output": "1"
},
{
"input": "10 3 7\n0000011111",
"output": "1"
},
{
"input": "5 1 5\n11010",
"output": "1"
},
{
"input": "6 1 6\n111000",
"output": "1"
},
{
"input": "2 1 2\n01",
"output": "1"
},
{
"input": "10 10 1\n0000011111",
"output": "1"
},
{
"input": "6 1 6\n000111",
"output": "1"
},
{
"input": "10 2 10\n0000011111",
"output": "1"
},
{
"input": "8 1 8\n11110000",
"output": "1"
},
{
"input": "6 1 5\n100000",
"output": "1"
},
{
"input": "16 4 12\n0000000011111111",
"output": "1"
},
{
"input": "6 1 5\n111000",
"output": "1"
},
{
"input": "8 2 7\n11110000",
"output": "1"
},
{
"input": "6 2 5\n111000",
"output": "1"
},
{
"input": "9 9 1\n111000000",
"output": "1"
},
{
"input": "2 2 1\n01",
"output": "1"
},
{
"input": "5 2 5\n00001",
"output": "1"
},
{
"input": "5 1 5\n10000",
"output": "1"
},
{
"input": "6 1 6\n011111",
"output": "1"
},
{
"input": "5 5 1\n11110",
"output": "1"
},
{
"input": "2 1 2\n10",
"output": "1"
},
{
"input": "4 2 4\n0001",
"output": "1"
},
{
"input": "10 1 10\n1111100000",
"output": "1"
},
{
"input": "8 4 5\n00001111",
"output": "1"
},
{
"input": "4 4 1\n0111",
"output": "1"
},
{
"input": "8 1 8\n00101001",
"output": "1"
}
] | 61 | 5,324,800 | 0 | 416 |
|
300 | Array | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array. | The first line of the input contains integer *n* (3<=β€<=*n*<=β€<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=β€<=103) β the array elements. | In the first line print integer *n*1 (*n*1<=><=0) β the number of elements in the first set. Then print *n*1 numbers β the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) β the number of elements in the second set. Then print *n*2 numbers β the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) β the number of elements in the third set. Then print *n*3 numbers β the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82",
"output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0"
},
{
"input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46",
"output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0"
},
{
"input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38",
"output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0"
},
{
"input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37",
"output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37"
},
{
"input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61",
"output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61"
},
{
"input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66",
"output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0"
},
{
"input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82",
"output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0"
},
{
"input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22",
"output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20"
},
{
"input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41",
"output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0"
},
{
"input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935",
"output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0"
},
{
"input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952",
"output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961"
},
{
"input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0",
"output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673"
},
{
"input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0",
"output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182"
},
{
"input": "5\n-1 -2 -3 -4 0",
"output": "1 -1\n2 -4 -3\n2 0 -2"
},
{
"input": "3\n-101 101 0",
"output": "1 -101\n1 101\n1 0"
},
{
"input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000",
"output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000"
},
{
"input": "4\n0 -1 -2 -3",
"output": "1 -1\n2 -3 -2\n1 0"
}
] | 92 | 0 | 0 | 422 |
|
515 | Drazil and Date | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? | You are given three integers *a*, *b*, and *s* (<=-<=109<=β€<=*a*,<=*b*<=β€<=109, 1<=β€<=*s*<=β€<=2Β·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 998320124 820674098",
"output": "No"
},
{
"input": "948253616 -83299062 1031552680",
"output": "Yes"
},
{
"input": "711980199 216568284 928548487",
"output": "Yes"
},
{
"input": "-453961301 271150176 725111473",
"output": "No"
},
{
"input": "0 0 2000000000",
"output": "Yes"
},
{
"input": "0 0 1999999999",
"output": "No"
},
{
"input": "1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 1000000000",
"output": "No"
},
{
"input": "-1 -1 3",
"output": "No"
},
{
"input": "919785634 216774719 129321944",
"output": "No"
},
{
"input": "-467780354 -721273539 1369030008",
"output": "No"
},
{
"input": "-232833910 -880680184 1774549792",
"output": "Yes"
},
{
"input": "45535578 402686155 1011249824",
"output": "No"
},
{
"input": "-203250176 -30379840 233630015",
"output": "No"
},
{
"input": "-814516648 -75830576 890347222",
"output": "No"
},
{
"input": "869184175 -511854751 1381038923",
"output": "No"
},
{
"input": "552884998 -262338193 815223187",
"output": "No"
},
{
"input": "-133874494 857573117 991447611",
"output": "Yes"
},
{
"input": "169406792 786701289 956108082",
"output": "No"
},
{
"input": "30237137 -989203246 1019440385",
"output": "Yes"
},
{
"input": "576608216 -617624133 1194232352",
"output": "No"
},
{
"input": "-662360368 97618995 759979367",
"output": "Yes"
},
{
"input": "-115989290 321714461 437703756",
"output": "No"
},
{
"input": "-1 -3 2",
"output": "No"
},
{
"input": "-2 -2 2",
"output": "No"
},
{
"input": "0 0 1",
"output": "No"
},
{
"input": "0 -1 7",
"output": "Yes"
},
{
"input": "1 2 7",
"output": "Yes"
},
{
"input": "0 5 6",
"output": "No"
},
{
"input": "0 -4 2",
"output": "No"
},
{
"input": "-5 5 2",
"output": "No"
},
{
"input": "-5 -2 7",
"output": "Yes"
},
{
"input": "5 -5 2",
"output": "No"
}
] | 62 | 0 | 3 | 423 |
|
1,008 | Romaji | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese. | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"input": "n",
"output": "YES"
},
{
"input": "necnei",
"output": "NO"
},
{
"input": "nternn",
"output": "NO"
},
{
"input": "aucunuohja",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "b",
"output": "NO"
},
{
"input": "nn",
"output": "YES"
},
{
"input": "nnnzaaa",
"output": "YES"
},
{
"input": "zn",
"output": "NO"
},
{
"input": "ab",
"output": "NO"
},
{
"input": "aaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaab",
"output": "NO"
},
{
"input": "aaaaaaaaan",
"output": "YES"
},
{
"input": "baaaaaaaaa",
"output": "YES"
},
{
"input": "naaaaaaaaa",
"output": "YES"
},
{
"input": "nbaaaaaaaa",
"output": "YES"
},
{
"input": "bbaaaaaaaa",
"output": "NO"
},
{
"input": "bnaaaaaaaa",
"output": "NO"
},
{
"input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu",
"output": "YES"
},
{
"input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino",
"output": "NO"
},
{
"input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul",
"output": "NO"
},
{
"input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu",
"output": "YES"
},
{
"input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo",
"output": "NO"
},
{
"input": "y",
"output": "NO"
},
{
"input": "by",
"output": "NO"
},
{
"input": "yy",
"output": "NO"
},
{
"input": "nbn",
"output": "NO"
},
{
"input": "nz",
"output": "NO"
},
{
"input": "king",
"output": "NO"
},
{
"input": "g",
"output": "NO"
},
{
"input": "az",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "yn",
"output": "NO"
},
{
"input": "aeo",
"output": "YES"
},
{
"input": "nb",
"output": "NO"
},
{
"input": "npn",
"output": "NO"
},
{
"input": "kini",
"output": "YES"
},
{
"input": "pya",
"output": "NO"
},
{
"input": "m",
"output": "NO"
},
{
"input": "p",
"output": "NO"
},
{
"input": "aaaaaaaak",
"output": "NO"
},
{
"input": "aab",
"output": "NO"
},
{
"input": "d",
"output": "NO"
},
{
"input": "at",
"output": "NO"
},
{
"input": "aaaaaak",
"output": "NO"
},
{
"input": "aaz",
"output": "NO"
},
{
"input": "aaab",
"output": "NO"
},
{
"input": "s",
"output": "NO"
},
{
"input": "nzzen",
"output": "NO"
},
{
"input": "aeionnhhhn",
"output": "NO"
},
{
"input": "h",
"output": "NO"
},
{
"input": "ny",
"output": "NO"
}
] | 46 | 0 | 3 | 424 |
|
295 | Greg and Array | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=β€<=*x**i*<=β€<=*y**i*<=β€<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg. | The first line contains integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*,<=*k*<=β€<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=105) β the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*), (0<=β€<=*d**i*<=β€<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=β€<=*x**i*<=β€<=*y**i*<=β€<=*m*).
The numbers in the lines are separated by single spaces. | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1",
"output": "0"
}
] | 1,500 | 3,379,200 | 0 | 426 |
|
255 | Greg's Workout | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. | The first line contains integer *n* (1<=β€<=*n*<=β€<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=25) β the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 154 | 6,758,400 | 3 | 428 |
|
983 | Finite or not? | [
"implementation",
"math"
] | null | null | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. | The first line contains a single integer $n$ ($1 \le n \le 10^5$)Β β the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. | For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] | $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | [
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite"
},
{
"input": "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10",
"output": "Infinite\nFinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4",
"output": "Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\nFinite"
},
{
"input": "10\n5 8 2\n0 5 8\n5 9 7\n0 7 2\n6 7 2\n10 3 7\n8 1 10\n9 1 8\n0 7 10\n9 1 4",
"output": "Finite\nFinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite"
},
{
"input": "1\n1 864691128455135232 2",
"output": "Infinite"
},
{
"input": "11\n1 1000000000000000000 10000000\n2 999 9\n2 999 333111\n0 9 7\n17 128 2\n13 311992186885373952 18\n1971402979058461 750473176484995605 75\n14 19 23\n3 21914624432020321 23\n3 21914624432020321 46\n3 21914624432020321 47",
"output": "Finite\nInfinite\nFinite\nFinite\nFinite\nFinite\nFinite\nInfinite\nFinite\nFinite\nInfinite"
},
{
"input": "1\n1 100000000000000000 10000000000000000",
"output": "Finite"
},
{
"input": "1\n1 4294967297 4294967296",
"output": "Infinite"
},
{
"input": "1\n1 5244319080000 30030",
"output": "Finite"
}
] | 77 | 0 | 0 | 430 |
|
664 | Complicated GCD | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100Β β such number do not fit even in 64-bit integer type! | The only line of the input contains two integers *a* and *b* (1<=β€<=*a*<=β€<=*b*<=β€<=10100). | Output one integerΒ β greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000",
"output": "1"
},
{
"input": "12345 67890123456789123457",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158",
"output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158"
},
{
"input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751",
"output": "1"
},
{
"input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794",
"output": "1"
},
{
"input": "10000 1000000000",
"output": "1"
},
{
"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "11210171722243 65715435710585778347",
"output": "1"
},
{
"input": "2921881079263974825226940825843 767693191032295360887755303860323261471",
"output": "1"
},
{
"input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085",
"output": "1"
},
{
"input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424",
"output": "1"
},
{
"input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614",
"output": "1"
},
{
"input": "15943150466658398903 15943150466658398903",
"output": "15943150466658398903"
},
{
"input": "410470228200245407491525399055972 410470228200245407491525399055972",
"output": "410470228200245407491525399055972"
},
{
"input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307",
"output": "51894705655711504622197349350106792045098781545973899451307"
},
{
"input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410",
"output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410"
},
{
"input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535",
"output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535"
},
{
"input": "1 2000000000",
"output": "1"
},
{
"input": "13 1928834874",
"output": "1"
},
{
"input": "87 2938984237482934238",
"output": "1"
},
{
"input": "213 413",
"output": "1"
},
{
"input": "3 4",
"output": "1"
}
] | 77 | 6,758,400 | 3 | 431 |
|
753 | Santa Claus and Candies | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=β€<=*n*<=β€<=1000) β number of candies Santa Claus has. | Print to the first line integer number *k* β maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 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 54 "
},
{
"input": "4",
"output": "2\n1 3 "
},
{
"input": "6",
"output": "3\n1 2 3 "
},
{
"input": "7",
"output": "3\n1 2 4 "
},
{
"input": "8",
"output": "3\n1 2 5 "
},
{
"input": "10",
"output": "4\n1 2 3 4 "
},
{
"input": "11",
"output": "4\n1 2 3 5 "
},
{
"input": "12",
"output": "4\n1 2 3 6 "
},
{
"input": "13",
"output": "4\n1 2 3 7 "
},
{
"input": "14",
"output": "4\n1 2 3 8 "
},
{
"input": "15",
"output": "5\n1 2 3 4 5 "
},
{
"input": "16",
"output": "5\n1 2 3 4 6 "
},
{
"input": "20",
"output": "5\n1 2 3 4 10 "
},
{
"input": "21",
"output": "6\n1 2 3 4 5 6 "
},
{
"input": "22",
"output": "6\n1 2 3 4 5 7 "
},
{
"input": "27",
"output": "6\n1 2 3 4 5 12 "
},
{
"input": "28",
"output": "7\n1 2 3 4 5 6 7 "
},
{
"input": "29",
"output": "7\n1 2 3 4 5 6 8 "
},
{
"input": "35",
"output": "7\n1 2 3 4 5 6 14 "
},
{
"input": "36",
"output": "8\n1 2 3 4 5 6 7 8 "
},
{
"input": "37",
"output": "8\n1 2 3 4 5 6 7 9 "
},
{
"input": "44",
"output": "8\n1 2 3 4 5 6 7 16 "
},
{
"input": "45",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "46",
"output": "9\n1 2 3 4 5 6 7 8 10 "
},
{
"input": "230",
"output": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40 "
},
{
"input": "231",
"output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "232",
"output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 "
},
{
"input": "239",
"output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 29 "
},
{
"input": "629",
"output": "34\n1 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 68 "
},
{
"input": "630",
"output": "35\n1 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 "
},
{
"input": "631",
"output": "35\n1 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 36 "
},
{
"input": "945",
"output": "42\n1 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 84 "
},
{
"input": "946",
"output": "43\n1 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 "
},
{
"input": "947",
"output": "43\n1 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 44 "
},
{
"input": "989",
"output": "43\n1 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 86 "
},
{
"input": "990",
"output": "44\n1 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 "
},
{
"input": "991",
"output": "44\n1 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 45 "
},
{
"input": "956",
"output": "43\n1 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 53 "
},
{
"input": "981",
"output": "43\n1 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 78 "
},
{
"input": "867",
"output": "41\n1 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 47 "
},
{
"input": "906",
"output": "42\n1 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 45 "
},
{
"input": "999",
"output": "44\n1 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 53 "
},
{
"input": "100",
"output": "13\n1 2 3 4 5 6 7 8 9 10 11 12 22 "
},
{
"input": "126",
"output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 21 "
}
] | 93 | 307,200 | 0 | 433 |
|
842 | Kirill And The Game | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integersΒ β amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers *a* and *b* such that *l*<=β€<=*a*<=β€<=*r* and *x*<=β€<=*b*<=β€<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)Β·(*y*<=-<=*x*<=+<=1) potions).
Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=β€<=*l*<=β€<=*r*<=β€<=107, 1<=β€<=*x*<=β€<=*y*<=β€<=107, 1<=β€<=*k*<=β€<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 1 100000 100001",
"output": "NO"
},
{
"input": "25 10000 200 10000 5",
"output": "YES"
},
{
"input": "1 100000 10 100000 50000",
"output": "NO"
},
{
"input": "91939 94921 10197 89487 1",
"output": "NO"
},
{
"input": "30518 58228 74071 77671 1",
"output": "NO"
},
{
"input": "46646 79126 78816 91164 5",
"output": "NO"
},
{
"input": "30070 83417 92074 99337 2",
"output": "NO"
},
{
"input": "13494 17544 96820 99660 6",
"output": "NO"
},
{
"input": "96918 97018 10077 86510 9",
"output": "YES"
},
{
"input": "13046 45594 14823 52475 1",
"output": "YES"
},
{
"input": "29174 40572 95377 97669 4",
"output": "NO"
},
{
"input": "79894 92433 8634 86398 4",
"output": "YES"
},
{
"input": "96022 98362 13380 94100 6",
"output": "YES"
},
{
"input": "79446 95675 93934 96272 3",
"output": "NO"
},
{
"input": "5440 46549 61481 99500 10",
"output": "NO"
},
{
"input": "21569 53580 74739 87749 3",
"output": "NO"
},
{
"input": "72289 78297 79484 98991 7",
"output": "NO"
},
{
"input": "88417 96645 92742 98450 5",
"output": "NO"
},
{
"input": "71841 96625 73295 77648 8",
"output": "NO"
},
{
"input": "87969 99230 78041 94736 4",
"output": "NO"
},
{
"input": "4 4 1 2 3",
"output": "NO"
},
{
"input": "150 150 1 2 100",
"output": "NO"
},
{
"input": "99 100 1 100 50",
"output": "YES"
},
{
"input": "7 7 3 6 2",
"output": "NO"
},
{
"input": "10 10 1 10 1",
"output": "YES"
},
{
"input": "36 36 5 7 6",
"output": "YES"
},
{
"input": "73 96 1 51 51",
"output": "NO"
},
{
"input": "3 3 1 3 2",
"output": "NO"
},
{
"input": "10000000 10000000 1 100000 10000000",
"output": "YES"
},
{
"input": "9222174 9829060 9418763 9955619 9092468",
"output": "NO"
},
{
"input": "70 70 1 2 50",
"output": "NO"
},
{
"input": "100 200 1 20 5",
"output": "YES"
},
{
"input": "1 200000 65536 65536 65537",
"output": "NO"
},
{
"input": "15 15 1 100 1",
"output": "YES"
},
{
"input": "10000000 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "10 10 2 5 4",
"output": "NO"
},
{
"input": "67 69 7 7 9",
"output": "NO"
},
{
"input": "100000 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "9 12 1 2 7",
"output": "NO"
},
{
"input": "5426234 6375745 2636512 8492816 4409404",
"output": "NO"
},
{
"input": "6134912 6134912 10000000 10000000 999869",
"output": "NO"
},
{
"input": "3 3 1 100 1",
"output": "YES"
},
{
"input": "10000000 10000000 10 10000000 100000",
"output": "YES"
},
{
"input": "4 4 1 100 2",
"output": "YES"
},
{
"input": "8 13 1 4 7",
"output": "NO"
},
{
"input": "10 10 100000 10000000 10000000",
"output": "NO"
},
{
"input": "5 6 1 4 2",
"output": "YES"
},
{
"input": "1002 1003 1 2 1000",
"output": "NO"
},
{
"input": "4 5 1 2 2",
"output": "YES"
},
{
"input": "5 6 1 5 1",
"output": "YES"
},
{
"input": "15 21 2 4 7",
"output": "YES"
},
{
"input": "4 5 3 7 1",
"output": "YES"
},
{
"input": "15 15 3 4 4",
"output": "NO"
},
{
"input": "3 6 1 2 2",
"output": "YES"
},
{
"input": "2 10 3 6 3",
"output": "YES"
},
{
"input": "1 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "8 13 1 2 7",
"output": "NO"
},
{
"input": "98112 98112 100000 100000 128850",
"output": "NO"
},
{
"input": "2 2 1 2 1",
"output": "YES"
},
{
"input": "8 8 3 4 2",
"output": "YES"
},
{
"input": "60 60 2 3 25",
"output": "NO"
},
{
"input": "16 17 2 5 5",
"output": "NO"
},
{
"input": "2 4 1 3 1",
"output": "YES"
},
{
"input": "4 5 1 2 3",
"output": "NO"
},
{
"input": "10 10 3 4 3",
"output": "NO"
},
{
"input": "10 10000000 999999 10000000 300",
"output": "NO"
},
{
"input": "100 120 9 11 10",
"output": "YES"
},
{
"input": "8 20 1 3 4",
"output": "YES"
},
{
"input": "10 14 2 3 4",
"output": "YES"
},
{
"input": "2000 2001 1 3 1000",
"output": "YES"
},
{
"input": "12 13 2 3 5",
"output": "NO"
},
{
"input": "7 7 2 3 3",
"output": "NO"
},
{
"input": "5 8 1 10000000 4",
"output": "YES"
},
{
"input": "5 5 1 1 4",
"output": "NO"
},
{
"input": "5 5 1 6 2",
"output": "NO"
},
{
"input": "200 300 4000381 4000382 4000381",
"output": "NO"
},
{
"input": "11 17 2 5 2",
"output": "NO"
},
{
"input": "9999999 10000000 1 10000000 999997",
"output": "NO"
},
{
"input": "7 8 2 3 3",
"output": "NO"
},
{
"input": "7 7 3 3 2",
"output": "NO"
},
{
"input": "15 15 2 3 7",
"output": "NO"
},
{
"input": "65408 65408 859 859 10000000",
"output": "NO"
},
{
"input": "1000000 10000000 1 100000 1",
"output": "NO"
},
{
"input": "6 12 2 3 2",
"output": "YES"
},
{
"input": "7 8 1 3 3",
"output": "NO"
},
{
"input": "4 4 1 2 2",
"output": "YES"
},
{
"input": "2 3 1 2 2",
"output": "YES"
},
{
"input": "11 14 2 3 5",
"output": "NO"
},
{
"input": "7 7 1 10 3",
"output": "NO"
},
{
"input": "49 50 1 2 27",
"output": "NO"
},
{
"input": "1 10000000 1 10000000 123456",
"output": "YES"
},
{
"input": "100000 10000000 100 10000000 100000",
"output": "YES"
},
{
"input": "17 19 2 3 8",
"output": "NO"
},
{
"input": "4 6 3 9 1",
"output": "YES"
},
{
"input": "19 20 6 7 3",
"output": "NO"
},
{
"input": "5000000 10000000 1 4999999 1",
"output": "NO"
}
] | 62 | 0 | 0 | 434 |
|
139 | Petr and Book | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. | The first input line contains the single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 β those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. | Print a single number β the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "20\n5 3 7 2 1 6 4",
"output": "6"
},
{
"input": "10\n5 1 1 1 1 1 5",
"output": "6"
},
{
"input": "50\n10 1 10 1 10 1 10",
"output": "1"
},
{
"input": "77\n11 11 11 11 11 11 10",
"output": "1"
},
{
"input": "1\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n100 100 100 100 100 100 100",
"output": "3"
},
{
"input": "999\n10 20 10 20 30 20 10",
"output": "3"
},
{
"input": "433\n109 58 77 10 39 125 15",
"output": "7"
},
{
"input": "1\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n1 0 1 0 1 0 1",
"output": "1"
},
{
"input": "997\n1 1 0 0 1 0 1",
"output": "1"
},
{
"input": "1000\n1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1000\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "1000\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "1000\n1 0 0 1 0 0 1",
"output": "1"
},
{
"input": "509\n105 23 98 0 7 0 155",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2\n1 1 0 0 0 0 0",
"output": "2"
},
{
"input": "1\n0 0 0 0 0 1 0",
"output": "6"
},
{
"input": "10\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 6 0",
"output": "6"
},
{
"input": "3\n0 1 0 0 0 0 0",
"output": "2"
},
{
"input": "10\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "28\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "100\n5 5 5 5 5 5 5",
"output": "6"
},
{
"input": "4\n1 0 0 0 0 0 1",
"output": "7"
},
{
"input": "2\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "7\n0 0 0 0 0 0 7",
"output": "7"
},
{
"input": "7\n2 1 1 1 1 1 0",
"output": "6"
},
{
"input": "2\n0 0 1 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1 0",
"output": "6"
},
{
"input": "5\n1 1 1 0 0 1 1",
"output": "7"
},
{
"input": "100\n10 20 30 10 10 10 10",
"output": "7"
},
{
"input": "1\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "70\n10 10 10 10 10 10 10",
"output": "7"
},
{
"input": "22\n1 2 3 4 5 6 10",
"output": "7"
},
{
"input": "5\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "2\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 0 0 0 0 0 2",
"output": "7"
},
{
"input": "10\n1 2 2 1 2 1 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "4\n0 1 1 0 0 0 0",
"output": "3"
},
{
"input": "100\n0 0 0 0 0 1 0",
"output": "6"
}
] | 62 | 0 | -1 | 436 |
|
13 | Numbers | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. | Input contains one integer number *A* (3<=β€<=*A*<=β€<=1000). | Output should contain required average value in format Β«X/YΒ», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
"input": "386",
"output": "857/12"
},
{
"input": "277",
"output": "2864/55"
},
{
"input": "766",
"output": "53217/382"
},
{
"input": "28",
"output": "85/13"
},
{
"input": "406",
"output": "7560/101"
},
{
"input": "757",
"output": "103847/755"
},
{
"input": "6",
"output": "9/4"
},
{
"input": "239",
"output": "10885/237"
},
{
"input": "322",
"output": "2399/40"
},
{
"input": "98",
"output": "317/16"
},
{
"input": "208",
"output": "4063/103"
},
{
"input": "786",
"output": "55777/392"
},
{
"input": "879",
"output": "140290/877"
},
{
"input": "702",
"output": "89217/700"
},
{
"input": "948",
"output": "7369/43"
},
{
"input": "537",
"output": "52753/535"
},
{
"input": "984",
"output": "174589/982"
},
{
"input": "934",
"output": "157951/932"
},
{
"input": "726",
"output": "95491/724"
},
{
"input": "127",
"output": "3154/125"
},
{
"input": "504",
"output": "23086/251"
},
{
"input": "125",
"output": "3080/123"
},
{
"input": "604",
"output": "33178/301"
},
{
"input": "115",
"output": "2600/113"
},
{
"input": "27",
"output": "167/25"
},
{
"input": "687",
"output": "85854/685"
},
{
"input": "880",
"output": "69915/439"
},
{
"input": "173",
"output": "640/19"
},
{
"input": "264",
"output": "6438/131"
},
{
"input": "785",
"output": "111560/783"
},
{
"input": "399",
"output": "29399/397"
},
{
"input": "514",
"output": "6031/64"
},
{
"input": "381",
"output": "26717/379"
},
{
"input": "592",
"output": "63769/590"
},
{
"input": "417",
"output": "32002/415"
},
{
"input": "588",
"output": "62723/586"
},
{
"input": "852",
"output": "131069/850"
},
{
"input": "959",
"output": "5059/29"
},
{
"input": "841",
"output": "127737/839"
},
{
"input": "733",
"output": "97598/731"
},
{
"input": "692",
"output": "87017/690"
},
{
"input": "69",
"output": "983/67"
},
{
"input": "223",
"output": "556/13"
},
{
"input": "93",
"output": "246/13"
},
{
"input": "643",
"output": "75503/641"
},
{
"input": "119",
"output": "2833/117"
},
{
"input": "498",
"output": "1459/16"
},
{
"input": "155",
"output": "4637/153"
},
{
"input": "305",
"output": "17350/303"
},
{
"input": "454",
"output": "37893/452"
},
{
"input": "88",
"output": "1529/86"
},
{
"input": "850",
"output": "32645/212"
},
{
"input": "474",
"output": "20581/236"
},
{
"input": "309",
"output": "17731/307"
},
{
"input": "762",
"output": "105083/760"
},
{
"input": "591",
"output": "63761/589"
},
{
"input": "457",
"output": "38317/455"
},
{
"input": "141",
"output": "3832/139"
},
{
"input": "385",
"output": "27232/383"
},
{
"input": "387",
"output": "27628/385"
},
{
"input": "469",
"output": "40306/467"
},
{
"input": "624",
"output": "35285/311"
},
{
"input": "330",
"output": "487/8"
},
{
"input": "31",
"output": "222/29"
},
{
"input": "975",
"output": "171679/973"
},
{
"input": "584",
"output": "62183/582"
},
{
"input": "668",
"output": "81127/666"
},
{
"input": "331",
"output": "20297/329"
},
{
"input": "189",
"output": "6789/187"
},
{
"input": "251",
"output": "11939/249"
},
{
"input": "876",
"output": "69196/437"
},
{
"input": "615",
"output": "68987/613"
},
{
"input": "451",
"output": "37258/449"
},
{
"input": "499",
"output": "45727/497"
},
{
"input": "699",
"output": "89117/697"
},
{
"input": "619",
"output": "70019/617"
},
{
"input": "413",
"output": "10515/137"
},
{
"input": "197",
"output": "7399/195"
},
{
"input": "794",
"output": "14281/99"
},
{
"input": "659",
"output": "79403/657"
},
{
"input": "653",
"output": "77695/651"
},
{
"input": "23",
"output": "45/7"
},
{
"input": "430",
"output": "16985/214"
},
{
"input": "249",
"output": "11659/247"
},
{
"input": "837",
"output": "126869/835"
},
{
"input": "258",
"output": "12373/256"
},
{
"input": "995",
"output": "59665/331"
},
{
"input": "102",
"output": "504/25"
},
{
"input": "989",
"output": "177124/987"
},
{
"input": "376",
"output": "13008/187"
},
{
"input": "657",
"output": "15715/131"
},
{
"input": "746",
"output": "50509/372"
},
{
"input": "602",
"output": "13177/120"
}
] | 60 | 0 | -1 | 437 |
18 | Seller Bob | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. | The first input line contains number *n* (1<=β€<=*n*<=β€<=5000) β amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=β€<=*x*<=β€<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=β€<=*x*<=β€<=2000). | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsell 18\nwin 17\nsell 17\nwin 16\nsell 16\nwin 15\nsell 15\nwin 14\nsell 14\nwin 13\nsell 13\nwin 12\nsell 12\nwin 11\nsell 11\nwin 10\nsell 10\nwin 9\nsell 9\nwin 8\nsell 8\nwin 7\nsell 7\nwin 6\nsell 6\nwin 5\nsell 5\nwin 4\nsell 4\nwin 3\nsell 3\nwin 2\nsell 2\nwin 1\nsell 1",
"output": "2147483646"
},
{
"input": "10\nsell 179\nwin 1278\nsell 1278\nwin 179\nwin 788\nsell 788\nwin 1819\nwin 1278\nsell 1454\nsell 1819",
"output": "3745951177859672748085876072016755224158263650470541376602416977749506433342393741012551962469399005106980957564747771946546075632634156222832360666586993197712597743102870994304893421406288896658113922358079050393796282759740479830789771109056742931607432542704338811780614109483471170758503563410473205320757445249359340913055427891395101189449739249593088482768598397566812797391842205760535689034164783939977837838115215972505331175064745799973957898910533590618104893265678599370512439216359131269814745054..."
},
{
"input": "10\nsell 573\nwin 1304\nsell 278\nwin 1631\nsell 1225\nsell 1631\nsell 177\nwin 1631\nwin 177\nsell 1304",
"output": "95482312335125227379668481690754940528280513838693267460502082967052005332103697568042408703168913727303170456338425853153094403747135188778307041838920404959089576368946137708987138986696495077466398994298434148881715073638178666201165545650953479735059082316661443204882826188032944866093372620219104327689636641547141835841165681118172603993695103043804276669836594061369229043451067647935298287687852302215923887110435577776767805943668204998410716005202198549540411238299513630278811648"
},
{
"input": "10\nwin 1257\nwin 1934\nsell 1934\nsell 1257\nwin 1934\nwin 1257\nsell 495\nwin 495\nwin 495\nwin 1257",
"output": "1556007242642049292787218246793379348327505438878680952714050868520307364441227819009733220897932984584977593931988662671459594674963394056587723382487766303981362587048873128400436836690128983570130687310221668877557121158055843621982630476422478413285775826498536883275291967793661985813155062733063913176306327509625594121241472451054995889483447103432414676059872469910105149496451402271546454282618581884282152530090816240540173251729211604658704990425330422792556824836640431985211146197816770068601144273..."
},
{
"input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell 434\nsell 1236\nsell 14\nwin 29\nsell 1165",
"output": "0"
},
{
"input": "50\nwin 1591\nwin 312\nwin 1591\nwin 1277\nwin 1732\nwin 1277\nwin 312\nwin 1591\nwin 210\nwin 1591\nwin 210\nsell 1732\nwin 312\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 210\nwin 1732\nwin 1732\nwin 1591\nwin 1732\nwin 312\nwin 1732\nsell 1277\nwin 1732\nwin 210\nwin 1277\nwin 1277\nwin 312\nwin 1732\nsell 312\nsell 1591\nwin 312\nsell 210\nwin 1732\nwin 312\nwin 210\nwin 1591\nwin 1591\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 1277\nwin 1591\nwin 210\nwin 1277\nwin 1732\nwin 312",
"output": "2420764210856015331214801822295882718446835865177072936070024961324113887299407742968459201784200628346247573017634417460105466317641563795817074771860850712020768123310899251645626280515264270127874292153603360689565451372953171008749749476807656127914801962353129980445541683621172887240439496869443980760905844921588668701053404581445092887732985786593080332302468009347364906506742888063949158794894756704243685813947581549214136427388148927087858952333440295415050590550479915766637705353193400817849524933..."
},
{
"input": "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\nwin 728\nwin 1462\nwin 596\nwin 728\nsell 1462\nsell 731\nsell 723\nsell 596\nsell 1799\nwin 715\nsell 329\nsell 715\nwin 731\nwin 596\nwin 596\nwin 1799\nsell 838",
"output": "3572417428836510418020130226151232933195365572424451233484665849446779664366143933308174097508811001879673917355296871134325099594720989439804421106898301313126179907518635998806895566124222305730664245219198882158809677890894851351153171006242601699481340338225456896495739360268670655803862712132671163869311331357956008411198419420320449558787147867731519734760711196755523479867536729489438488681378976579126837971468043235641314636566999618274861697304906262004280314028540891222536060126170572182168995779..."
},
{
"input": "50\nwin 879\nwin 1153\nwin 1469\nwin 157\nwin 827\nwin 679\nsell 1229\nwin 454\nsell 879\nsell 1222\nwin 924\nwin 827\nsell 1366\nwin 879\nsell 754\nwin 1153\nwin 679\nwin 1185\nsell 1469\nsell 454\nsell 679\nsell 1153\nwin 1469\nwin 827\nwin 1469\nwin 1024\nwin 1222\nsell 157\nsell 1185\nsell 827\nwin 1469\nsell 1569\nwin 754\nsell 1024\nwin 924\nwin 924\nsell 1876\nsell 479\nsell 435\nwin 754\nwin 174\nsell 174\nsell 147\nsell 924\nwin 1469\nwin 1876\nwin 1229\nwin 1469\nwin 1222\nwin 157",
"output": "16332912310228701097717316802721870128775022868221080314403305773060286348016616983179506327297989866534783694332203603069900790667846028602603898749788769867206327097934433881603593880774778104853105937620753202513845830781396468839434689035327911539335925798473899153215505268301939672678983012311225261177070282290958328569587449928340374890197297462448526671963786572758011646874155763250281850311510811863346015732742889066278088442118144"
},
{
"input": "50\nsell 1549\nwin 1168\nsell 1120\nwin 741\nsell 633\nwin 274\nsell 1936\nwin 1168\nsell 614\nwin 33\nsell 1778\nwin 127\nsell 1168\nwin 33\nwin 633\nsell 1474\nwin 518\nwin 1685\nsell 1796\nsell 741\nsell 485\nwin 747\nsell 588\nsell 1048\nwin 1580\nwin 60\nsell 1685\nsell 1580\nsell 1535\nwin 485\nsell 31\nsell 747\nsell 1473\nsell 518\nwin 633\nsell 1313\nwin 1580\nsell 1560\nsell 127\nsell 274\nwin 123\nwin 31\nsell 123\nsell 33\nwin 1778\nsell 1834\nsell 60\nsell 1751\nsell 1287\nwin 1549",
"output": "1720056425011773151265118871077591733216276990085092619030835675616738576936900493041118761959770055340668032173576279597675976622004777210845027112875371906527379337573212312341811682481516081119925150514042583039122963732518350292624889782510925425243478590699982487521431988980734651291693696303059520879874887472437061826782122289965998009474317347011699360401227487786089319043200666474560882786695043543699741809763479940250459103751744852630592882730442346682844070898735881280272505893611419620868096"
},
{
"input": "1\nsell 2000",
"output": "0"
},
{
"input": "1\nwin 2000",
"output": "0"
},
{
"input": "2\nwin 2000\nsell 2000",
"output": "1148130695274254524232833201177681984022317702088695200477642736825766261392370313856659486316506269918445964638987462773447118960863055331425931356166653185391299891453122800006887791482400448714289269900634862447816154636463883639473170260404663539709049965581623988089446296056233116495361642219703326813441689089844585056023794848079140589009347765004290027167066258305220081322362812917612678833172065989953964181270217798584040421598531832515408894339020919205549577835896720391600819572166305827553804255..."
}
] | 312 | 614,400 | 3.919711 | 438 |
978 | Remove Duplicates | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) β the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) β the Petya's array. | In the first line print integer $x$ β the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space β Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
"output": "2\n99 100 "
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 "
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421",
"output": "8\n117 151 183 227 954 222 909 421 "
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2",
"output": "4\n62 726 903 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2",
"output": "6\n5 33 375 37 3 2 "
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6",
"output": "6\n4 3 2 5 1 6 "
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n233 1 "
},
{
"input": "47\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",
"output": "1\n1 "
},
{
"input": "2\n964 964",
"output": "1\n964 "
},
{
"input": "2\n1000 1000",
"output": "1\n1000 "
},
{
"input": "1\n1000",
"output": "1\n1000 "
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993",
"output": "10\n996 1000 999 992 997 991 995 998 994 993 "
},
{
"input": "6\n994 993 1000 998 991 994",
"output": "5\n993 1000 998 991 994 "
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999",
"output": "10\n993 996 995 991 994 997 998 992 1000 999 "
},
{
"input": "3\n6 6 3",
"output": "2\n6 3 "
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997",
"output": "9\n1000 995 994 993 999 996 998 991 997 "
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996",
"output": "10\n998 995 999 992 1000 993 994 997 991 996 "
},
{
"input": "2\n1000 999",
"output": "2\n1000 999 "
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000",
"output": "10\n996 999 993 994 997 995 991 992 998 1000 "
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992",
"output": "8\n993 997 998 994 1000 991 995 992 "
},
{
"input": "6\n1000 1 1000 2 1000 1",
"output": "3\n2 1000 1 "
},
{
"input": "6\n1000 1 1000 2 1 1000",
"output": "3\n2 1 1000 "
},
{
"input": "7\n1 1000 1 999 1000 1 2",
"output": "4\n999 1000 1 2 "
}
] | 46 | 0 | 0 | 440 |
|
254 | Cards with Numbers | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that. | The first line contains integer *n* (1<=β€<=*n*<=β€<=3Β·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=β€<=*a**i*<=β€<=5000) β the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line β the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them. | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"input": "5\n1 2 2 2 1 2 2 1 2 1",
"output": "3 2\n1 5\n6 4\n7 9\n10 8"
},
{
"input": "5\n3 3 1 1 1 3 2 3 1 2",
"output": "2 1\n3 4\n8 6\n5 9\n10 7"
},
{
"input": "5\n1 1 3 1 3 3 3 1 1 1",
"output": "2 1\n3 5\n7 6\n4 8\n10 9"
},
{
"input": "5\n3 1 1 1 2 3 3 3 2 1",
"output": "3 2\n1 6\n8 7\n5 9\n10 4"
},
{
"input": "5\n3 3 2 2 3 3 1 3 1 3",
"output": "2 1\n3 4\n6 5\n7 9\n10 8"
},
{
"input": "5\n4 1 3 1 4 1 2 2 3 1",
"output": "4 2\n1 5\n8 7\n3 9\n10 6"
},
{
"input": "100\n8 6 7 8 7 9 1 7 3 3 5 8 7 8 5 4 8 4 8 1 2 8 3 7 8 7 6 5 7 9 6 10 7 6 7 8 6 8 9 5 1 5 6 1 4 8 4 8 7 2 6 2 6 6 2 8 2 8 7 1 5 4 4 6 4 9 7 5 1 8 1 3 9 2 3 2 4 7 6 10 5 3 4 10 8 9 6 7 2 7 10 1 8 10 4 1 1 1 2 7 5 4 9 10 6 8 3 1 10 9 9 6 1 5 8 6 6 3 3 4 10 10 8 9 7 10 9 3 7 6 3 2 10 8 5 8 5 5 5 10 8 5 7 6 10 7 7 9 10 10 9 9 3 6 5 6 8 1 9 8 2 4 8 8 6 8 10 2 3 5 2 6 8 4 8 6 4 5 10 8 1 10 5 2 5 6 8 2 6 8 1 3 4 5 7 5 6 9 2 8",
"output": "4 1\n3 5\n10 9\n8 13\n14 12\n11 15\n18 16\n17 19\n20 7\n22 25\n26 24\n2 27\n30 6\n29 33\n34 31\n36 38\n40 28\n37 43\n44 41\n45 47\n48 46\n35 49\n50 21\n51 53\n55 52\n56 58\n61 42\n62 63\n64 54\n39 66\n67 59\n60 69\n72 23\n57 74\n77 65\n32 80\n81 68\n75 82\n85 70\n73 86\n87 79\n78 88\n89 76\n84 91\n92 71\n83 95\n97 96\n90 100\n104 94\n93 106\n108 98\n103 110\n112 105\n101 114\n117 116\n107 118\n120 102\n109 121\n123 115\n111 124\n126 122\n119 128\n129 125\n99 132\n136 134\n135 137\n139 138\n133 140\n144 130..."
},
{
"input": "100\n7 3 8 8 1 9 6 6 3 3 8 2 7 9 9 10 2 10 4 4 9 3 6 5 2 6 3 6 3 5 2 3 8 2 5 10 3 9 7 2 1 6 7 4 8 3 9 10 9 4 3 3 7 1 4 2 2 5 6 6 1 7 9 1 8 1 2 2 5 9 7 7 6 4 6 10 1 1 8 1 5 6 4 9 5 4 4 10 6 4 5 1 9 1 7 8 6 10 3 2 4 7 10 4 8 10 6 7 8 4 1 3 8 3 2 1 9 4 2 4 3 1 6 8 6 2 2 5 6 8 6 10 1 6 4 2 7 3 6 10 6 5 6 6 3 9 4 6 4 1 5 4 4 2 8 4 10 3 7 6 6 10 2 5 5 6 1 6 1 9 9 1 10 5 10 1 1 5 7 5 2 1 4 2 3 3 3 5 1 8 10 3 3 5 9 6 3 6 8 1",
"output": "4 3\n7 8\n9 2\n1 13\n14 6\n12 17\n18 16\n19 20\n21 15\n10 22\n26 23\n27 29\n30 24\n25 31\n33 11\n32 37\n40 34\n5 41\n42 28\n39 43\n47 38\n36 48\n50 44\n46 51\n57 56\n35 58\n60 59\n54 61\n62 53\n49 63\n65 45\n64 66\n68 67\n71 72\n74 55\n73 75\n78 77\n69 81\n84 70\n83 86\n88 76\n82 89\n90 87\n85 91\n92 80\n79 96\n99 52\n95 102\n103 98\n101 104\n107 97\n105 109\n111 94\n112 114\n115 100\n93 117\n118 110\n116 122\n124 113\n123 125\n126 119\n129 131\n132 106\n120 135\n136 127\n108 137\n138 121\n134 139\n142 128..."
},
{
"input": "100\n6 3 6 8 8 4 3 7 10 3 1 3 9 5 10 10 6 7 6 6 2 3 8 8 7 6 4 9 6 7 4 4 10 4 7 3 2 7 10 8 6 7 9 1 3 5 3 7 9 1 1 7 1 1 7 7 8 3 2 7 4 8 7 8 10 3 1 7 2 7 9 8 8 8 5 2 8 1 2 7 8 7 8 8 5 10 10 4 9 10 8 7 8 8 7 7 3 6 4 3 4 8 10 8 6 3 7 1 8 6 3 3 7 10 3 9 3 5 10 9 9 2 8 7 2 3 2 1 10 9 6 2 8 7 2 2 5 3 10 6 7 2 1 1 5 10 7 5 4 9 7 7 8 1 1 3 3 7 10 5 9 8 6 8 2 2 1 7 8 9 6 2 2 6 2 9 10 2 10 9 6 3 3 10 6 5 3 6 6 3 6 10 8 7 4 8 6 3 4 7",
"output": "-1"
},
{
"input": "1\n2 2",
"output": "2 1"
},
{
"input": "2\n1 2 4 7",
"output": "-1"
}
] | 577 | 36,147,200 | 3 | 441 |
|
77 | Falling Anvils | [
"math",
"probabilities"
] | B. Falling Anvils | 2 | 256 | For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height *p* of the potential victim vary in the range [0;*a*] and the direction of the wind *q* vary in the range [<=-<=*b*;*b*]. *p* and *q* could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the *p* and *q* coefficients are chosen equiprobably and independently in their ranges. | The first line contains integer *t* (1<=β€<=*t*<=β€<=10000) β amount of testcases.
Each of the following *t* lines contain two space-separated integers *a* and *b* (0<=β€<=*a*,<=*b*<=β€<=106).
Pretests contain all the tests with 0<=<<=*a*<=<<=10,<=0<=β€<=*b*<=<<=10. | Print *t* lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10<=-<=6. | [
"2\n4 2\n1 2\n"
] | [
"0.6250000000\n0.5312500000\n"
] | none | [
{
"input": "2\n4 2\n1 2",
"output": "0.6250000000\n0.5312500000"
},
{
"input": "90\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n1 2\n2 2\n3 2\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n1 3\n2 3\n3 3\n4 3\n5 3\n6 3\n7 3\n8 3\n9 3\n1 4\n2 4\n3 4\n4 4\n5 4\n6 4\n7 4\n8 4\n9 4\n1 5\n2 5\n3 5\n4 5\n5 5\n6 5\n7 5\n8 5\n9 5\n1 6\n2 6\n3 6\n4 6\n5 6\n6 6\n7 6\n8 6\n9 6\n1 7\n2 7\n3 7\n4 7\n5 7\n6 7\n7 7\n8 7\n9 7\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n8 8\n9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n7 9\n8 9\n9 9\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0",
"output": "0.5625000000\n0.6250000000\n0.6875000000\n0.7500000000\n0.8000000000\n0.8333333333\n0.8571428571\n0.8750000000\n0.8888888889\n0.5312500000\n0.5625000000\n0.5937500000\n0.6250000000\n0.6562500000\n0.6875000000\n0.7187500000\n0.7500000000\n0.7777777778\n0.5208333333\n0.5416666667\n0.5625000000\n0.5833333333\n0.6041666667\n0.6250000000\n0.6458333333\n0.6666666667\n0.6875000000\n0.5156250000\n0.5312500000\n0.5468750000\n0.5625000000\n0.5781250000\n0.5937500000\n0.6093750000\n0.6250000000\n0.6406250000\n0.5125000000\n0.5250000000\n0.5375000000\n0.55..."
},
{
"input": "10\n4 6\n4 2\n10 3\n6 3\n7 8\n2 5\n0 3\n6 1\n4 1\n10 9",
"output": "0.5416666667\n0.6250000000\n0.7083333333\n0.6250000000\n0.5546875000\n0.5250000000\n0.5\n0.8333333333\n0.7500000000\n0.5694444444"
}
] | 216 | 0 | 3.946 | 442 |
784 | BF Calculator | [
"*special"
] | null | null | In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
- 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem. | The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries). | Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps. | [
"2+3\n",
"9-7\n"
] | [
"++>\n+++>\n<[<+>-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n",
"+++++++++>\n+++++++>\n<[<->-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n"
] | You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs. | [
{
"input": "2+3",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "9-7",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+1+1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+11+111",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "111-11-1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+1-1+1-1+1-1+1-1+1",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "9+1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "10-1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "31+49+49+71-51-61+59-111+51",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "255+255+255+255+255-255-255-255-255-255",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "100+100+10+10+10+10+10+5",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "255-255+255-255+255-255+255-255+255",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "0-255-255-255-255+255+255+255+255+255",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "34+45+29-49+52-111-4+4+2+9",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "0+0+0+0+0+0+0+0+0+0",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "193+235+47+150+222-3-90-248-187-100",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "66-165-34+209+76",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "36+90+6+102",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "255-12-34-56-69-78",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "243-173+90-56+78-53+53-21",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>"
}
] | 124 | 0 | 3 | 443 |
|
0 | none | [
"none"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*. | The first line of the input contains two integers *n* and *k* (1<=β€<=*n*,<= *k*<=β€<=1<=000<=000)Β β the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
"output": "Yes"
},
{
"input": "11 95\n31 49 8 139 169 121 71 17 43 29 125",
"output": "No"
},
{
"input": "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17",
"output": "No"
},
{
"input": "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71",
"output": "No"
},
{
"input": "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 37 29 71",
"output": "Yes"
},
{
"input": "2 4\n2 2",
"output": "No"
},
{
"input": "14 87\n1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619",
"output": "No"
},
{
"input": "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766",
"output": "No"
},
{
"input": "1 994619\n216000",
"output": "No"
},
{
"input": "1 651040\n911250",
"output": "No"
},
{
"input": "1 620622\n60060",
"output": "No"
},
{
"input": "1 1\n559872",
"output": "Yes"
},
{
"input": "88 935089\n967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967",
"output": "No"
},
{
"input": "93 181476\n426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426",
"output": "No"
},
{
"input": "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630 70 630 70 630 70 630 630 70 910 630 630 630 770 630 630 630 70 910 70 630 70 630 770 630 630 70 630 770 70 630 70 70 630 630 70 70 70 70 630 70 70 770 910 630 70 630 770 70 910 70 630 910 630 70 770 70 70 630 770 630 70 630 70 70 630 70 630 770 630 70 630 630 70 910 630",
"output": "No"
},
{
"input": "61 531012\n698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 698043 966694 698043 698043 698043 698043 698043 698043 636247 698043 963349 698043 698043 698043 698043 697838 698043 963349 698043 698043 966694 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 963349 698043 698043 698043 698043 963349 698043",
"output": "No"
},
{
"input": "1 216000\n648000",
"output": "Yes"
},
{
"input": "2 8\n4 4",
"output": "No"
},
{
"input": "3 8\n4 4 4",
"output": "No"
},
{
"input": "2 8\n2 4",
"output": "No"
},
{
"input": "3 12\n2 2 3",
"output": "No"
},
{
"input": "10 4\n2 2 2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "10 1024\n1 2 4 8 16 32 64 128 256 512",
"output": "No"
},
{
"input": "3 24\n2 2 3",
"output": "No"
},
{
"input": "1 8\n2",
"output": "No"
},
{
"input": "2 9\n3 3",
"output": "No"
},
{
"input": "3 4\n2 2 2",
"output": "No"
},
{
"input": "3 4\n1 2 2",
"output": "No"
},
{
"input": "1 4\n2",
"output": "No"
},
{
"input": "1 100003\n2",
"output": "No"
},
{
"input": "1 2\n12",
"output": "Yes"
},
{
"input": "2 988027\n989018 995006",
"output": "Yes"
},
{
"input": "3 9\n3 3 3",
"output": "No"
},
{
"input": "1 49\n7",
"output": "No"
},
{
"input": "2 600000\n200000 300000",
"output": "Yes"
},
{
"input": "3 8\n2 2 2",
"output": "No"
},
{
"input": "7 510510\n524288 531441 390625 823543 161051 371293 83521",
"output": "Yes"
},
{
"input": "2 30\n6 10",
"output": "Yes"
},
{
"input": "2 27000\n5400 4500",
"output": "Yes"
},
{
"input": "3 8\n1 2 4",
"output": "No"
},
{
"input": "4 16\n2 2 2 2",
"output": "No"
},
{
"input": "2 16\n4 8",
"output": "No"
},
{
"input": "2 8\n4 2",
"output": "No"
},
{
"input": "3 4\n2 2 3",
"output": "No"
},
{
"input": "1 8\n4",
"output": "No"
},
{
"input": "1 999983\n2",
"output": "No"
},
{
"input": "3 16\n2 4 8",
"output": "No"
},
{
"input": "2 216\n12 18",
"output": "No"
},
{
"input": "2 16\n8 8",
"output": "No"
},
{
"input": "2 36\n18 12",
"output": "Yes"
},
{
"input": "2 36\n12 18",
"output": "Yes"
},
{
"input": "2 1000000\n1000000 1000000",
"output": "Yes"
},
{
"input": "3 20\n2 2 5",
"output": "No"
},
{
"input": "1 2\n6",
"output": "Yes"
},
{
"input": "4 4\n2 3 6 5",
"output": "No"
},
{
"input": "1 2\n1",
"output": "No"
},
{
"input": "1 6\n6",
"output": "Yes"
},
{
"input": "2 16\n4 4",
"output": "No"
},
{
"input": "2 3779\n1 2",
"output": "No"
},
{
"input": "2 8\n4 12",
"output": "No"
},
{
"input": "2 24\n4 6",
"output": "No"
},
{
"input": "1 1\n5",
"output": "Yes"
},
{
"input": "10 255255\n1000000 700000 300000 110000 130000 170000 190000 230000 290000 310000",
"output": "Yes"
},
{
"input": "2 1000\n500 2",
"output": "No"
},
{
"input": "4 8\n2 2 2 2",
"output": "No"
},
{
"input": "1 666013\n1",
"output": "No"
},
{
"input": "1 999983\n1",
"output": "No"
},
{
"input": "1 125\n5",
"output": "No"
},
{
"input": "2 32\n4 8",
"output": "No"
},
{
"input": "3 32\n2 4 8",
"output": "No"
},
{
"input": "3 8\n2 4 11",
"output": "No"
},
{
"input": "1 32\n2",
"output": "No"
},
{
"input": "4 4\n2 2 2 2",
"output": "No"
},
{
"input": "8 32\n2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "3 24\n2 4 3",
"output": "No"
},
{
"input": "2 4\n2 6",
"output": "No"
},
{
"input": "2 24\n6 4",
"output": "No"
},
{
"input": "1 20998\n2",
"output": "No"
},
{
"input": "1 1\n1",
"output": "Yes"
},
{
"input": "2 20998\n2 10499",
"output": "Yes"
},
{
"input": "1 5\n1",
"output": "No"
},
{
"input": "2 25\n5 5",
"output": "No"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "Yes"
},
{
"input": "3 12\n2 3 6",
"output": "No"
},
{
"input": "1 1\n3",
"output": "Yes"
},
{
"input": "2 16\n8 4",
"output": "No"
},
{
"input": "40 10\n2 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 2 2 2 2 2 2 2 2 2",
"output": "No"
}
] | 61 | 3,379,200 | -1 | 446 |
|
282 | Bit++ | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=150) β the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter Β«XΒ»). Thus, there are no empty statements. The operation and the variable can be written in any order. | Print a single integer β the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++",
"output": "4"
},
{
"input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++",
"output": "-10"
},
{
"input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X",
"output": "-14"
},
{
"input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X",
"output": "3"
},
{
"input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X",
"output": "-5"
},
{
"input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X",
"output": "1"
},
{
"input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--",
"output": "1"
},
{
"input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++",
"output": "-3"
},
{
"input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X",
"output": "1"
},
{
"input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++",
"output": "8"
},
{
"input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++",
"output": "-1"
},
{
"input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--",
"output": "-5"
},
{
"input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--",
"output": "1"
},
{
"input": "1\nX--",
"output": "-1"
}
] | 46 | 0 | 3 | 448 |
|
900 | Position in Fraction | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=β€<=*a*<=<<=*b*<=β€<=105, 0<=β€<=*c*<=β€<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction. | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
},
{
"input": "7 31 3",
"output": "15"
},
{
"input": "8880 81608 9",
"output": "161"
},
{
"input": "4942 62768 5",
"output": "122"
},
{
"input": "69168 84860 4",
"output": "107"
},
{
"input": "971 1883 3",
"output": "130"
},
{
"input": "1636 3269 6",
"output": "150"
},
{
"input": "6873 7769 3",
"output": "163"
},
{
"input": "13805 15538 3",
"output": "164"
},
{
"input": "10958 21926 3",
"output": "117"
},
{
"input": "8 51 0",
"output": "10"
},
{
"input": "1 10 1",
"output": "1"
},
{
"input": "1 9 0",
"output": "-1"
},
{
"input": "53 101 6",
"output": "-1"
},
{
"input": "1 10001 9",
"output": "5"
},
{
"input": "25102 31579 2",
"output": "174"
},
{
"input": "38790 39359 0",
"output": "212"
},
{
"input": "47117 78718 0",
"output": "213"
},
{
"input": "1 57 0",
"output": "1"
},
{
"input": "1 3 0",
"output": "-1"
},
{
"input": "1 100 0",
"output": "1"
},
{
"input": "2 3 0",
"output": "-1"
},
{
"input": "99971 99989 0",
"output": "9"
},
{
"input": "567 1580 0",
"output": "6"
},
{
"input": "45 97 0",
"output": "39"
},
{
"input": "35 111 4",
"output": "-1"
},
{
"input": "1 2 5",
"output": "1"
},
{
"input": "1 7 0",
"output": "-1"
}
] | 171 | 1,638,400 | 0 | 450 |
|
507 | Amr and Music | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. | The first line contains two numbers *n*, *k* (1<=β€<=*n*<=β€<=100, 0<=β€<=*k*<=β€<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying. | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2,β3,β5} or {3,β4,β5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"input": "4 0\n100 100 100 100",
"output": "0"
},
{
"input": "100 7567\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": "75\n1 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"
},
{
"input": "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50",
"output": "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68"
},
{
"input": "100 10000\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": "100\n1 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": "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93",
"output": "25\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25"
},
{
"input": "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76",
"output": "98\n1 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": "5 249\n96 13 7 2 81",
"output": "5\n1 2 3 4 5"
},
{
"input": "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44",
"output": "61\n1 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"
},
{
"input": "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80",
"output": "99\n1 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"
},
{
"input": "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97",
"output": "89\n1 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"
},
{
"input": "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8",
"output": "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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"
},
{
"input": "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12",
"output": "27\n1 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"
},
{
"input": "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93",
"output": "55\n1 2 3 4 5 6 7 8 9 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"
},
{
"input": "6 41\n6 8 9 8 9 8",
"output": "5\n1 2 3 4 6"
},
{
"input": "9 95\n9 11 12 11 12 11 8 11 10",
"output": "9\n1 2 3 4 5 6 7 8 9"
},
{
"input": "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52",
"output": "89\n1 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"
},
{
"input": "5 29\n6 3 7 2 1",
"output": "5\n1 2 3 4 5"
},
{
"input": "5 49\n16 13 7 2 1",
"output": "5\n1 2 3 4 5"
},
{
"input": "6 84\n16 21 25 6 17 16",
"output": "5\n1 2 4 5 6"
},
{
"input": "4 9\n7 4 2 1",
"output": "3\n2 3 4"
},
{
"input": "50 2500\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50\n1 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"
},
{
"input": "100 10000\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\n1 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": "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\n1 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": "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6",
"output": "96\n1 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"
},
{
"input": "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3",
"output": "47\n1 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"
},
{
"input": "100 200\n2 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 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 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 2 2 2 2 2 2 2 2 2",
"output": "100\n1 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": "2 10000\n1 1",
"output": "2\n1 2"
},
{
"input": "1 2\n1",
"output": "1\n1"
},
{
"input": "1 3\n2",
"output": "1\n1"
},
{
"input": "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71",
"output": "34\n1 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"
},
{
"input": "2 2\n1 10",
"output": "1\n1"
},
{
"input": "2 5\n1 1",
"output": "2\n1 2"
},
{
"input": "1 4\n3",
"output": "1\n1"
},
{
"input": "4 384\n1 2 3 4",
"output": "4\n1 2 3 4"
}
] | 109 | 512,000 | 3 | 451 |
|
901 | Hashing Trees | [
"constructive algorithms",
"trees"
] | null | null | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence *a*0,<=*a*1,<=...,<=*a**h*, where *h* is the height of the tree, and *a**i* equals to the number of vertices that are at distance of *i* edges from root.
Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence *a**i*, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree.
Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal.
The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex. | The first line contains a single integer *h* (2<=β€<=*h*<=β€<=105)Β β the height of the tree.
The second line contains *h*<=+<=1 integersΒ β the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=β€<=*a**i*<=β€<=2Β·105). The sum of all *a**i* does not exceed 2Β·105. It is guaranteed that there is at least one tree matching this sequence. | If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *k*-th vertex is the root.
These treese should be non-isomorphic and should match the given sequence. | [
"2\n1 1 1\n",
"2\n1 2 2\n"
] | [
"perfect\n",
"ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"
] | The only tree in the first example and the two printed trees from the second example are shown on the picture:
<img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "2\n1 1 1",
"output": "perfect"
},
{
"input": "2\n1 2 2",
"output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 1 2 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 2 2 1 1 1 1 1",
"output": "ambiguous\n0 1 2 3 4 4 6 6 8 9 10 11 12\n0 1 2 3 4 4 6 5 8 9 10 11 12"
},
{
"input": "10\n1 1 1 1 1 1 1 2 1 1 2",
"output": "perfect"
},
{
"input": "10\n1 1 1 3 2 1 2 4 1 3 1",
"output": "ambiguous\n0 1 2 3 3 3 6 6 8 9 9 11 11 11 11 15 16 16 16 19\n0 1 2 3 3 3 6 5 8 9 9 11 10 10 10 15 16 16 16 19"
},
{
"input": "10\n1 1 1 4 1 1 2 1 5 1 2",
"output": "perfect"
},
{
"input": "10\n1 1 11 12 12 11 15 13 8 8 8",
"output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 13 13 13 13 13 13 13 13 13 13 13 13 25 25 25 25 25 25 25 25 25 25 25 25 37 37 37 37 37 37 37 37 37 37 37 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 63 63 63 63 63 63 63 63 63 63 63 63 63 76 76 76 76 76 76 76 76 84 84 84 84 84 84 84 84 92 92 92 92 92 92 92 92\n0 1 2 2 2 2 2 2 2 2 2 2 2 13 12 12 12 12 12 12 12 12 12 12 12 25 24 24 24 24 24 24 24 24 24 24 24 37 36 36 36 36 36 36 36 36 36 36 48 47 47 47 47 47 47 47 47 47 47 47 47 47 47 63 62 62 62 62 62 62 62 62 62 62 62 ..."
},
{
"input": "10\n1 1 21 1 20 1 14 1 19 1 20",
"output": "perfect"
},
{
"input": "10\n1 1 93 121 112 103 114 112 112 122 109",
"output": "ambiguous\n0 1 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 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 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 2 2 2 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 9..."
},
{
"input": "10\n1 1 262 1 232 1 245 1 1 254 1",
"output": "perfect"
},
{
"input": "2\n1 1 199998",
"output": "perfect"
},
{
"input": "3\n1 1 199997 1",
"output": "perfect"
},
{
"input": "3\n1 1 100009 99989",
"output": "ambiguous\n0 1 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 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 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 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 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 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 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 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 2 2 2 2 2 2 2 2 ..."
},
{
"input": "123\n1 1 1 3714 1 3739 1 3720 1 1 3741 1 1 3726 1 3836 1 3777 1 1 3727 1 1 3866 1 3799 1 3785 1 3693 1 1 3667 1 3930 1 3849 1 1 3767 1 3792 1 3792 1 3808 1 3680 1 3798 1 3817 1 3636 1 3833 1 1 3765 1 3774 1 3747 1 1 3897 1 3773 1 3814 1 3739 1 1 3852 1 3759 1 3783 1 1 3836 1 3787 1 3752 1 1 3818 1 3794 1 3745 1 3785 1 3784 1 1 3765 1 3750 1 3690 1 1 3806 1 3781 1 3680 1 1 3748 1 3709 1 3793 1 3618 1 1 3893 1",
"output": "perfect"
},
{
"input": "13\n1 1 16677 16757 16710 16596 16512 16762 16859 16750 16658 16489 16594 16634",
"output": "ambiguous\n0 1 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 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 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 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 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 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 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 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 2 2 2 2 2 2 2 2 ..."
},
{
"input": "13\n1 1 40049 1 1 39777 1 1 40008 1 40060 1 40097 1",
"output": "perfect"
},
{
"input": "4\n1 2 1 2 2",
"output": "ambiguous\n0 1 1 3 4 4 6 6\n0 1 1 3 4 4 6 5"
},
{
"input": "16\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536",
"output": "ambiguous\n0 1 1 3 3 3 3 7 7 7 7 7 7 7 7 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 12..."
},
{
"input": "4\n1 2 1 2 3",
"output": "ambiguous\n0 1 1 3 4 4 6 6 6\n0 1 1 3 4 4 6 5 5"
},
{
"input": "2\n1 3 199969",
"output": "ambiguous\n0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ..."
},
{
"input": "2\n1 99999 99999",
"output": "ambiguous\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "2\n1 3 2",
"output": "ambiguous\n0 1 1 1 4 4\n0 1 1 1 4 3"
}
] | 109 | 0 | 0 | 452 |
|
513 | Permutations | [
"brute force"
] | null | null | You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum:
Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*). | The single line of input contains two integers *n* and *m* (1<=β€<=*m*<=β€<=*cnt**n*), where *cnt**n* is the number of permutations of length *n* with maximum possible value of *f*(*p*).
The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
- In subproblem B1 (3 points), the constraint 1<=β€<=*n*<=β€<=8 will hold. - In subproblem B2 (4 points), the constraint 1<=β€<=*n*<=β€<=50 will hold. | Output *n* number forming the required permutation. | [
"2 2\n",
"3 2\n"
] | [
"2 1 \n",
"1 3 2 \n"
] | In the first example, both permutations of numbers {1, 2} yield maximum possible *f*(*p*) which is equal to 4. Among them, (2,β1) comes second in lexicographical order. | [
{
"input": "2 2",
"output": "2 1 "
},
{
"input": "3 2",
"output": "1 3 2 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "3 1",
"output": "1 2 3 "
},
{
"input": "3 3",
"output": "2 3 1 "
},
{
"input": "3 4",
"output": "3 2 1 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "4 3",
"output": "1 3 4 2 "
},
{
"input": "4 4",
"output": "1 4 3 2 "
},
{
"input": "4 8",
"output": "4 3 2 1 "
},
{
"input": "5 2",
"output": "1 2 3 5 4 "
},
{
"input": "5 7",
"output": "1 4 5 3 2 "
},
{
"input": "5 15",
"output": "4 5 3 2 1 "
},
{
"input": "6 23",
"output": "2 5 6 4 3 1 "
},
{
"input": "7 7",
"output": "1 2 3 6 7 5 4 "
},
{
"input": "7 44",
"output": "2 4 7 6 5 3 1 "
},
{
"input": "8 1",
"output": "1 2 3 4 5 6 7 8 "
},
{
"input": "8 127",
"output": "7 8 6 5 4 3 2 1 "
},
{
"input": "8 128",
"output": "8 7 6 5 4 3 2 1 "
}
] | 61 | 0 | 0 | 453 |
|
703 | Mishka and Game | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=β€<=*n*<=β€<=100)Β β the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=β€<=*m**i*,<=<=*c**i*<=β€<=6)Β β values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4",
"output": "Chris"
},
{
"input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4",
"output": "Friendship is magic!^^"
},
{
"input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3",
"output": "Mishka"
},
{
"input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6",
"output": "Friendship is magic!^^"
},
{
"input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2",
"output": "Mishka"
},
{
"input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4",
"output": "Chris"
},
{
"input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1",
"output": "Mishka"
},
{
"input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4",
"output": "Chris"
},
{
"input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6",
"output": "Chris"
},
{
"input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1",
"output": "Mishka"
},
{
"input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4",
"output": "Friendship is magic!^^"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4",
"output": "Chris"
},
{
"input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4",
"output": "Mishka"
},
{
"input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3",
"output": "Mishka"
},
{
"input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5",
"output": "Chris"
},
{
"input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3",
"output": "Chris"
},
{
"input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6",
"output": "Mishka"
},
{
"input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2",
"output": "Mishka"
},
{
"input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1",
"output": "Chris"
},
{
"input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2",
"output": "Chris"
},
{
"input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 61 | 0 | 3 | 454 |
|
863 | Kayaking | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2Β·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking β if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability! | The first line contains one number *n* (2<=β€<=*n*<=β€<=50).
The second line contains 2Β·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=β€<=*w**i*<=β€<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
"output": "35"
},
{
"input": "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3 2 1 3 3 2 2 1 3 1 3 1 2 2 1 2 3 2",
"output": "0"
},
{
"input": "50\n5 5 5 5 4 2 2 3 2 2 4 1 5 5 1 2 4 2 4 2 5 2 2 2 2 3 2 4 2 5 5 4 3 1 2 3 3 5 4 2 2 5 2 4 5 5 4 4 1 5 5 3 2 2 5 1 3 3 2 4 4 5 1 2 3 4 4 1 3 3 3 5 1 2 4 4 4 4 2 5 2 5 3 2 4 5 5 2 1 1 2 4 5 3 2 1 2 4 4 4",
"output": "1"
},
{
"input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319 382 651 594 411 845 746 18 232 6 289 889 81 174 175 805 1000 799 950 475 713 951 685 729 925 262 447 139 217 788 514 658 572 784 185 112 636 10 251 621 218 210 89 597 553 430 532 264 11 160 476",
"output": "368"
},
{
"input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393 955 540 896 241 362 146 74 680 734 767 851 337 751 860 542 735 444 793 340 259 495 903 743 961 964 966 87 275 22 776 368 701 835 732 810 735 267 988 352 647 924 183 1 924 217 944 322 252 758 597",
"output": "393"
},
{
"input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52 69 591 181 573 258 381 665 301 589 379 362 146 790 842 765 100 229 916 938 97 340 793 758 177 736 396 247 562 571 92 923 861 165 748 345 703 431 930 101 761 862 595 505 393 126 846 431 103 596 21",
"output": "387"
},
{
"input": "50\n721 631 587 746 692 406 583 90 388 16 161 948 921 70 387 426 39 398 517 724 879 377 906 502 359 950 798 408 846 718 911 845 57 886 9 668 537 632 344 762 19 193 658 447 870 173 98 156 592 519 183 539 274 393 962 615 551 626 148 183 769 763 829 120 796 761 14 744 537 231 696 284 581 688 611 826 703 145 224 600 965 613 791 275 984 375 402 281 851 580 992 8 816 454 35 532 347 250 242 637",
"output": "376"
},
{
"input": "50\n849 475 37 120 754 183 758 374 543 198 896 691 11 607 198 343 761 660 239 669 628 259 223 182 216 158 20 565 454 884 137 923 156 22 310 77 267 707 582 169 120 308 439 309 59 152 206 696 210 177 296 887 559 22 154 553 142 247 491 692 473 572 461 206 532 319 503 164 328 365 541 366 300 392 486 257 863 432 877 404 520 69 418 99 519 239 374 927 601 103 226 316 423 219 240 26 455 101 184 61",
"output": "351"
},
{
"input": "3\n1 2 10 11 100 100",
"output": "1"
},
{
"input": "17\n814 744 145 886 751 1000 272 914 270 529 467 164 410 369 123 424 991 12 702 582 561 858 746 950 598 393 606 498 648 686 455 873 728 858",
"output": "318"
},
{
"input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 990 714 662 572 467 949 799 648 581 545 828 508 636",
"output": "355"
},
{
"input": "2\n55 5 25 51",
"output": "4"
},
{
"input": "25\n89 50 640 463 858 301 522 241 923 378 892 822 550 17 42 66 706 779 657 840 273 222 444 459 94 925 437 159 182 727 92 851 742 215 653 891 782 533 29 128 133 883 317 475 165 994 802 434 744 973",
"output": "348"
},
{
"input": "4\n35 48 71 44 78 79 57 48",
"output": "10"
},
{
"input": "3\n58 89 73 15 5 47",
"output": "21"
},
{
"input": "2\n1 20 99 100",
"output": "1"
}
] | 62 | 3,788,800 | 3 | 455 |
|
810 | Straight <<A>> | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in schoolΒ β she is going to study in university next year. However, she has to get an Β«AΒ» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784Β β to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with Β«AΒ» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*k*<=β€<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integerΒ β minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marksΒ β 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10,β10,β10,β10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5,β5,β5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate. | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12",
"output": "712"
},
{
"input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6",
"output": "482"
},
{
"input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28",
"output": "6469"
},
{
"input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31",
"output": "1340"
},
{
"input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61",
"output": "329"
},
{
"input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16",
"output": "5753"
},
{
"input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29",
"output": "0"
},
{
"input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25",
"output": "851"
},
{
"input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4",
"output": "5884"
},
{
"input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1",
"output": "14170"
},
{
"input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30",
"output": "6650"
},
{
"input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20",
"output": "11786"
},
{
"input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28",
"output": "3182"
},
{
"input": "1 26\n26",
"output": "0"
},
{
"input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26",
"output": "1807"
},
{
"input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4",
"output": "946"
},
{
"input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2",
"output": "3164"
},
{
"input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16",
"output": "1262"
},
{
"input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18",
"output": "2024"
},
{
"input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15",
"output": "1984"
},
{
"input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55",
"output": "740"
},
{
"input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4",
"output": "14888"
},
{
"input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40",
"output": "13118"
},
{
"input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76",
"output": "3030"
},
{
"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": "19700"
},
{
"input": "100 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": "0"
},
{
"input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "19696"
},
{
"input": "100 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 99",
"output": "0"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 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": "0"
},
{
"input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100",
"output": "2"
},
{
"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": "0"
},
{
"input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1",
"output": "16"
},
{
"input": "3 5\n5 5 5",
"output": "0"
},
{
"input": "7 7\n1 1 1 1 1 1 1",
"output": "77"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"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": "19700"
},
{
"input": "4 10\n10 10 10 10",
"output": "0"
},
{
"input": "1 10\n10",
"output": "0"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3 10\n10 10 10",
"output": "0"
},
{
"input": "2 4\n3 4",
"output": "0"
},
{
"input": "1 2\n2",
"output": "0"
},
{
"input": "3 4\n4 4 4",
"output": "0"
},
{
"input": "3 2\n2 2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "0"
},
{
"input": "3 3\n3 3 3",
"output": "0"
},
{
"input": "2 9\n8 9",
"output": "0"
},
{
"input": "3 10\n9 10 10",
"output": "0"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "0"
},
{
"input": "2 10\n10 10",
"output": "0"
},
{
"input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14",
"output": "0"
},
{
"input": "2 10\n9 10",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 4",
"output": "0"
},
{
"input": "3 5\n4 5 5",
"output": "0"
},
{
"input": "5 4\n4 4 4 4 4",
"output": "0"
},
{
"input": "2 10\n10 9",
"output": "0"
},
{
"input": "4 5\n3 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "3 10\n10 10 9",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "4 10\n9 10 10 10",
"output": "0"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "2 5\n4 5",
"output": "0"
},
{
"input": "5 10\n10 10 10 10 10",
"output": "0"
},
{
"input": "2 6\n6 6",
"output": "0"
},
{
"input": "2 9\n9 9",
"output": "0"
},
{
"input": "3 10\n10 9 10",
"output": "0"
},
{
"input": "4 40\n39 40 40 40",
"output": "0"
},
{
"input": "3 4\n3 4 4",
"output": "0"
},
{
"input": "9 9\n9 9 9 9 9 9 9 9 9",
"output": "0"
},
{
"input": "1 4\n4",
"output": "0"
},
{
"input": "4 7\n1 1 1 1",
"output": "44"
},
{
"input": "1 5\n5",
"output": "0"
},
{
"input": "3 1\n1 1 1",
"output": "0"
},
{
"input": "1 100\n100",
"output": "0"
},
{
"input": "2 7\n3 5",
"output": "10"
},
{
"input": "3 6\n6 6 6",
"output": "0"
},
{
"input": "4 2\n1 2 2 2",
"output": "0"
},
{
"input": "4 5\n4 5 5 5",
"output": "0"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "35"
},
{
"input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1",
"output": "0"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 4 5",
"output": "0"
},
{
"input": "3 7\n1 1 1",
"output": "33"
},
{
"input": "2 5\n5 5",
"output": "0"
},
{
"input": "1 7\n1",
"output": "11"
},
{
"input": "6 7\n1 1 1 1 1 1",
"output": "66"
},
{
"input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64",
"output": "10077"
},
{
"input": "8 7\n1 1 1 1 1 1 1 1",
"output": "88"
},
{
"input": "3 2\n2 2 2",
"output": "0"
},
{
"input": "6 5\n5 5 5 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 4 1 1",
"output": "8"
},
{
"input": "1 5\n1",
"output": "7"
},
{
"input": "10 10\n10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "2 3\n2 3",
"output": "0"
},
{
"input": "1 9\n9",
"output": "0"
},
{
"input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 4",
"output": "0"
}
] | 62 | 0 | 3 | 457 |
|
588 | Duff and Meat | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days. | The first line of input contains integer *n* (1<=β€<=*n*<=β€<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=β€<=*a**i*,<=*p**i*<=β€<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
},
{
"input": "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88",
"output": "6742"
},
{
"input": "2\n100 68\n38 80",
"output": "9384"
}
] | 577 | 6,348,800 | 3 | 458 |
|
814 | An abandoned sentiment from past | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. | The first line of input contains two space-separated positive integers *n* (2<=β€<=*n*<=β€<=100) and *k* (1<=β€<=*k*<=β€<=*n*) β the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=200) β Hitagi's broken sequence with exactly *k* zero elements.
The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=β€<=*b**i*<=β€<=200) β the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11,β0,β0,β14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11,β5,β4,β14 and 11,β4,β5,β14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2,β3,β5,β8,β9,β10, which is an increasing sequence and therefore invalid. | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80",
"output": "No"
},
{
"input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58",
"output": "Yes"
},
{
"input": "4 1\n2 1 0 4\n3",
"output": "Yes"
},
{
"input": "2 1\n199 0\n200",
"output": "No"
},
{
"input": "3 2\n115 0 0\n145 191",
"output": "Yes"
},
{
"input": "5 1\n196 197 198 0 200\n199",
"output": "No"
},
{
"input": "5 1\n92 0 97 99 100\n93",
"output": "No"
},
{
"input": "3 1\n3 87 0\n81",
"output": "Yes"
},
{
"input": "3 1\n0 92 192\n118",
"output": "Yes"
},
{
"input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22",
"output": "Yes"
},
{
"input": "100 1\n14 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 0 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\n67",
"output": "No"
},
{
"input": "100 5\n1 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 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 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 0 99 100\n98 64 55 52 29",
"output": "Yes"
},
{
"input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27",
"output": "Yes"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 0 10 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\n11",
"output": "Yes"
},
{
"input": "100 1\n0 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\n1",
"output": "No"
},
{
"input": "100 1\n1 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 0\n100",
"output": "No"
},
{
"input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65",
"output": "Yes"
},
{
"input": "100 2\n0 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 0 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\n48 1",
"output": "Yes"
},
{
"input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69",
"output": "Yes"
},
{
"input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129",
"output": "No"
},
{
"input": "5 2\n0 2 7 0 10\n1 8",
"output": "Yes"
},
{
"input": "3 1\n5 4 0\n1",
"output": "Yes"
},
{
"input": "3 1\n1 0 3\n4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n1",
"output": "No"
},
{
"input": "2 1\n0 5\n7",
"output": "Yes"
},
{
"input": "5 1\n10 11 0 12 13\n1",
"output": "Yes"
},
{
"input": "5 1\n0 2 3 4 5\n6",
"output": "Yes"
},
{
"input": "6 2\n1 0 3 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "7 2\n1 2 3 0 0 6 7\n4 5",
"output": "Yes"
},
{
"input": "4 1\n1 2 3 0\n4",
"output": "No"
},
{
"input": "2 2\n0 0\n1 2",
"output": "Yes"
},
{
"input": "3 2\n1 0 0\n2 3",
"output": "Yes"
},
{
"input": "4 2\n1 0 4 0\n5 2",
"output": "Yes"
},
{
"input": "2 1\n0 1\n2",
"output": "Yes"
},
{
"input": "5 2\n1 0 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 4 5\n1",
"output": "Yes"
},
{
"input": "3 1\n0 2 3\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 5 0\n6",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n5 0 2\n7",
"output": "Yes"
},
{
"input": "4 1\n4 5 0 8\n3",
"output": "Yes"
},
{
"input": "5 1\n10 11 12 0 14\n13",
"output": "No"
},
{
"input": "4 1\n1 2 0 4\n5",
"output": "Yes"
},
{
"input": "3 1\n0 11 14\n12",
"output": "Yes"
},
{
"input": "4 1\n1 3 0 4\n2",
"output": "Yes"
},
{
"input": "2 1\n0 5\n1",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 7\n5",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n1",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 5 4\n6",
"output": "Yes"
},
{
"input": "4 2\n11 0 0 14\n13 12",
"output": "Yes"
},
{
"input": "2 1\n1 0\n2",
"output": "No"
},
{
"input": "3 1\n1 2 0\n3",
"output": "No"
},
{
"input": "4 1\n1 0 3 2\n4",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n5",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n3",
"output": "Yes"
},
{
"input": "4 1\n0 2 3 4\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n1 2 0\n5",
"output": "No"
},
{
"input": "4 2\n1 0 0 4\n3 2",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 5 7\n6",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n4",
"output": "No"
},
{
"input": "3 1\n1 0 11\n5",
"output": "No"
},
{
"input": "4 1\n7 9 5 0\n8",
"output": "Yes"
},
{
"input": "6 2\n1 2 3 0 5 0\n6 4",
"output": "Yes"
},
{
"input": "3 2\n0 1 0\n3 2",
"output": "Yes"
},
{
"input": "4 1\n6 9 5 0\n8",
"output": "Yes"
},
{
"input": "2 1\n0 3\n6",
"output": "Yes"
},
{
"input": "5 2\n1 2 0 0 5\n4 3",
"output": "Yes"
},
{
"input": "4 2\n2 0 0 8\n3 4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n3",
"output": "Yes"
},
{
"input": "3 1\n0 4 5\n6",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 0 5\n6",
"output": "Yes"
},
{
"input": "2 1\n2 0\n3",
"output": "No"
},
{
"input": "4 2\n11 0 0 200\n100 199",
"output": "Yes"
},
{
"input": "2 1\n5 0\n4",
"output": "Yes"
},
{
"input": "3 1\n1 0 5\n10",
"output": "Yes"
},
{
"input": "6 2\n1 2 0 0 5 6\n3 4",
"output": "Yes"
},
{
"input": "5 2\n1 0 3 0 5\n2 4",
"output": "Yes"
},
{
"input": "4 1\n1 4 0 8\n3",
"output": "Yes"
},
{
"input": "4 1\n5 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 7\n3 2",
"output": "Yes"
},
{
"input": "3 3\n0 0 0\n1 4 3",
"output": "Yes"
},
{
"input": "5 5\n0 0 0 0 0\n5 4 3 2 1",
"output": "Yes"
},
{
"input": "4 1\n3 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 4\n2 3",
"output": "Yes"
},
{
"input": "6 1\n2 4 0 8 9 10\n3",
"output": "Yes"
},
{
"input": "4 1\n0 3 5 6\n9",
"output": "Yes"
},
{
"input": "4 2\n1 2 0 0\n3 4",
"output": "Yes"
},
{
"input": "5 1\n2 3 4 5 0\n1",
"output": "Yes"
},
{
"input": "3 1\n2 0 4\n5",
"output": "Yes"
}
] | 62 | 0 | 3 | 460 |
|
231 | Team | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer β the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 92 | 0 | 3 | 461 |
|
768 | Code For 1 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.
Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=><=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.
Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test? | The first line contains three integers *n*, *l*, *r* (0<=β€<=*n*<=<<=250, 0<=β€<=*r*<=-<=*l*<=β€<=105, *r*<=β₯<=1, *l*<=β₯<=1) β initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1,β1,β1,β1]. The number of ones is 4.
For the second example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 3-rd to 10-th in list is [1,β1,β1,β0,β1,β0,β1,β0]. The number of ones is 5. | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "33534354842198 32529564319236 32529564342569",
"output": "22239"
},
{
"input": "62518534961045 50734311240112 50734311287877",
"output": "42439"
},
{
"input": "95173251245550 106288351347530 106288351372022",
"output": "16565"
},
{
"input": "542 321 956",
"output": "336"
},
{
"input": "3621 237 2637",
"output": "2124"
},
{
"input": "9056 336 896",
"output": "311"
},
{
"input": "36007 368 24490",
"output": "13253"
},
{
"input": "244269 149154 244246",
"output": "88609"
},
{
"input": "880234 669493 757150",
"output": "73585"
},
{
"input": "3740160 1031384 1104236",
"output": "64965"
},
{
"input": "11586121 15337246 15397874",
"output": "41868"
},
{
"input": "38658997 35923164 35985664",
"output": "36004"
},
{
"input": "192308932 207804787 207866400",
"output": "44142"
},
{
"input": "950099012 175922161 176000556",
"output": "69369"
},
{
"input": "2787326787 3799676481 3799680514",
"output": "2618"
},
{
"input": "14417262581 8527979363 8528075536",
"output": "80707"
},
{
"input": "39889373539 7747197212 7747278363",
"output": "47105"
},
{
"input": "251772781087 70597428577 70597479816",
"output": "46933"
},
{
"input": "0 1 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "3 2 3",
"output": "2"
},
{
"input": "14 7 12",
"output": "5"
},
{
"input": "1125899906842623 1 100001",
"output": "100001"
},
{
"input": "1125899906842623 1125899906742623 1125899906842623",
"output": "100001"
},
{
"input": "1000 1 1023",
"output": "1000"
},
{
"input": "281474976710656 17179869184 17179869186",
"output": "1"
},
{
"input": "2 2 2",
"output": "0"
},
{
"input": "3 2 2",
"output": "1"
}
] | 1,996 | 268,390,400 | 0 | 463 |
|
757 | Felicity's Big Secret Revealed | [
"bitmasks",
"dp"
] | null | null | The gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon.
The organizers of the camp gave the gym leaders a PokeBlock, a sequence of *n* ingredients. Each ingredient can be of type 0 or 1. Now the organizers told the gym leaders that to evolve a Pokemon of type *k* (*k*<=β₯<=2), they need to make a valid set of *k* cuts on the PokeBlock to get smaller blocks.
Suppose the given PokeBlock sequence is *b*0*b*1*b*2... *b**n*<=-<=1. You have a choice of making cuts at *n*<=+<=1 places, i.e., Before *b*0, between *b*0 and *b*1, between *b*1 and *b*2, ..., between *b**n*<=-<=2 and *b**n*<=-<=1, and after *b**n*<=-<=1.
The *n*<=+<=1 choices of making cuts are as follows (where a | denotes a possible cut):
Consider a sequence of *k* cuts. Now each pair of consecutive cuts will contain a binary string between them, formed from the ingredient types. The ingredients before the first cut and after the last cut are wasted, which is to say they are not considered. So there will be exactly *k*<=-<=1 such binary substrings. Every substring can be read as a binary number. Let *m* be the maximum number out of the obtained numbers. If all the obtained numbers are positive and the set of the obtained numbers contains all integers from 1 to *m*, then this set of cuts is said to be a valid set of cuts.
For example, suppose the given PokeBlock sequence is 101101001110 and we made 5 cuts in the following way:
So the 4 binary substrings obtained are: 11, 010, 01 and 1, which correspond to the numbers 3, 2, 1 and 1 respectively. Here *m*<==<=3, as it is the maximum value among the obtained numbers. And all the obtained numbers are positive and we have obtained all integers from 1 to *m*. Hence this set of cuts is a valid set of 5 cuts.
A Pokemon of type *k* will evolve only if the PokeBlock is cut using a valid set of *k* cuts. There can be many valid sets of the same size. Two valid sets of *k* cuts are considered different if there is a cut in one set which is not there in the other set.
Let *f*(*k*) denote the number of valid sets of *k* cuts. Find the value of . Since the value of *s* can be very large, output *s* modulo 109<=+<=7. | The input consists of two lines. The first line consists an integer *n* (1<=β€<=*n*<=β€<=75)Β β the length of the PokeBlock. The next line contains the PokeBlock, a binary string of length *n*. | Output a single integer, containing the answer to the problem, i.e., the value of *s* modulo 109<=+<=7. | [
"4\n1011\n",
"2\n10\n"
] | [
"10\n",
"1\n"
] | In the first sample, the sets of valid cuts are:
Size 2: |1|011, 1|01|1, 10|1|1, 101|1|.
Size 3: |1|01|1, |10|1|1, 10|1|1|, 1|01|1|.
Size 4: |10|1|1|, |1|01|1|.
Hence, *f*(2)β=β4, *f*(3)β=β4 and *f*(4)β=β2. So, the value of *s*β=β10.
In the second sample, the set of valid cuts is:
Size 2: |1|0.
Hence, *f*(2)β=β1 and *f*(3)β=β0. So, the value of *s*β=β1. | [
{
"input": "4\n1011",
"output": "10"
},
{
"input": "2\n10",
"output": "1"
},
{
"input": "7\n0110011",
"output": "28"
},
{
"input": "10\n0100011101",
"output": "80"
},
{
"input": "12\n010010101011",
"output": "298"
},
{
"input": "31\n1000000010111001111000111001110",
"output": "129377"
},
{
"input": "62\n00010011000110010011110110011001110110010011110110111100100010",
"output": "996654969"
},
{
"input": "51\n100010110000000110000101100110111110001001011000000",
"output": "26730714"
},
{
"input": "75\n011001100010010010100010011010001000110010011010100111110110100000010111111",
"output": "928344407"
},
{
"input": "75\n010110111011010010011101000010001010011111100101000101001100110010001010100",
"output": "375282145"
},
{
"input": "75\n101111111101000110000001001101011101100010010001011010010100001001111111110",
"output": "623731146"
},
{
"input": "75\n110100001001110011011011101010001001101000111110010001111110101001011111110",
"output": "601716747"
},
{
"input": "9\n110101010",
"output": "97"
},
{
"input": "17\n11110101001000001",
"output": "614"
},
{
"input": "17\n10110100110101010",
"output": "2026"
},
{
"input": "25\n0000001101010011111101101",
"output": "29992"
},
{
"input": "25\n1001101000101001111011100",
"output": "44856"
},
{
"input": "25\n0110000000100001011010110",
"output": "3455"
},
{
"input": "33\n010001101110010000001001100001000",
"output": "30402"
},
{
"input": "33\n111111000000010010010010101000101",
"output": "155739"
},
{
"input": "41\n00111110100100100001101110011100011010010",
"output": "15011055"
},
{
"input": "41\n00101001111010010011011101000100100000100",
"output": "6654256"
},
{
"input": "49\n0100000110110101000011101100011000111010110100110",
"output": "284760197"
},
{
"input": "49\n1110001011001111000000101011111111010111101101010",
"output": "113840431"
},
{
"input": "49\n1001001011010111000101011111101000100101101110110",
"output": "123145241"
},
{
"input": "57\n001101010001001110011001100011100111101010100000100100111",
"output": "313846708"
},
{
"input": "57\n101011110010100010010001111101111001011110101000001111100",
"output": "565909910"
},
{
"input": "57\n010000101010000000000010101010110111010110001110101111001",
"output": "317648452"
},
{
"input": "65\n01100100011001001010011011011001101010111011010101101011111001000",
"output": "223299317"
},
{
"input": "65\n00111101000100110101110000101000101001011101110110100100000011101",
"output": "911430600"
},
{
"input": "73\n1001100010010111111000001100100011111011110100000101110101001001010100011",
"output": "933309680"
},
{
"input": "73\n0000101011101101110110000010000100010010010011100011101010010110010001110",
"output": "216844366"
},
{
"input": "73\n0101010100110101110101000111110001110110000011001011000100110000111010011",
"output": "887992377"
},
{
"input": "73\n1110011000101111111111111010010110011001111111100111110110100101011111110",
"output": "688351754"
},
{
"input": "73\n1111100101110101011111110111110011100100111000000001101000110011111010011",
"output": "588026128"
},
{
"input": "44\n11000011111110110100110110010101001000111011",
"output": "299589727"
},
{
"input": "2\n11",
"output": "3"
},
{
"input": "32\n10011100101110110101100111001010",
"output": "2055033"
},
{
"input": "16\n1110101011100001",
"output": "822"
},
{
"input": "56\n10010100101100101000110110001001110101011111100100111101",
"output": "724204481"
},
{
"input": "68\n11100010101100000101101100010111100111001110010010101011111100111110",
"output": "924337491"
},
{
"input": "62\n00000100010110001100000101000001011001000111101011100110000101",
"output": "42655630"
},
{
"input": "21\n110001101110001001100",
"output": "3389"
},
{
"input": "23\n11100111010100011110000",
"output": "9071"
},
{
"input": "60\n001100010011100010101011000011101010111101011101111101001001",
"output": "67025753"
},
{
"input": "59\n10110000010101101101110000000001010010011111001111000110110",
"output": "77661632"
},
{
"input": "42\n100001010001111100000010101101110100001001",
"output": "3715362"
},
{
"input": "23\n01111101010011011011001",
"output": "34033"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "15\n101000111100010",
"output": "406"
},
{
"input": "31\n1010100111110001001010101000001",
"output": "164173"
},
{
"input": "75\n011101011001000010000010001001010100101001111110110111101000101101111010101",
"output": "864150441"
},
{
"input": "75\n100101111101111010001000111011001010101001011110111111101110010011011111110",
"output": "388576952"
},
{
"input": "75\n111011001000011110100101001011111010101001101010000100001100111001011101111",
"output": "47586061"
},
{
"input": "75\n111100100001011010000101101000010100110110011110100110101011111101101110100",
"output": "457624439"
},
{
"input": "75\n111100101001010010011000100100011101111000101100101110100100001111101001011",
"output": "271125629"
},
{
"input": "75\n001010011010111110010011100100000101101010001110010011100100100011101000111",
"output": "517784773"
},
{
"input": "75\n111000100000010001101110100100111010000111110010101010110100111101101110010",
"output": "689673388"
},
{
"input": "75\n010101100111100101010010011001000000110010100110100101110011111101111010010",
"output": "236468305"
},
{
"input": "75\n110100001100101001001001001000010000011101011100000100011111011011000111110",
"output": "65671604"
},
{
"input": "75\n010001001010001101000100100000101111111010010100110100111111101000111011010",
"output": "200661894"
},
{
"input": "75\n111001001011110001010100000011110010010100011011110101001001100101100010001",
"output": "224259484"
},
{
"input": "75\n010010111010010011100001010011010001010011010011110010111110010000101100001",
"output": "782231136"
},
{
"input": "75\n111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "2850"
},
{
"input": "75\n111111111111111111111111111111111111111111111111111111111111111111111111110",
"output": "598994266"
},
{
"input": "75\n111111110111111011111111011111110011111110100011111111111000011111111111110",
"output": "303998985"
},
{
"input": "75\n010101000010101111110011110010001010100101010001110110111110000111100010111",
"output": "817830931"
},
{
"input": "75\n111010111011001000011100001101010001111001110010101001110011001010110001000",
"output": "678777685"
},
{
"input": "75\n110111000100001111000101101100110010100011110101110100110111111100011000101",
"output": "856496502"
},
{
"input": "75\n111000011010111110100101101000000001101010100010111001101010010110011011000",
"output": "132632533"
},
{
"input": "75\n101100111111100100000011101001110100111101100010100101110101100111101110011",
"output": "662817629"
},
{
"input": "75\n111010011111111000010100111011100101001001001111010010110001111011011100011",
"output": "122189821"
},
{
"input": "75\n000000000000100000000000011000010000101010100000000000000000000000000000100",
"output": "32314"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "75\n100000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "77"
},
{
"input": "75\n100000000000000000000000001111000000000000000000000000010000000000000001000",
"output": "2388"
},
{
"input": "75\n101110000111010110110011001111111100100111010000001000111100001110100110011",
"output": "706235237"
},
{
"input": "75\n010010011001101111001011110001000011010010110001100101010110011100001100111",
"output": "83382495"
},
{
"input": "75\n110001100110100011000010111100101101111100101000110111000110100110001010010",
"output": "531446727"
},
{
"input": "75\n100101101110001111111110110010100001111010010110101001010011011111001100111",
"output": "158490657"
},
{
"input": "75\n000101000100010101111100101111011001100100101111010000011100011110110100100",
"output": "650849043"
},
{
"input": "75\n010101000110111001011110011011010000100100111011110000011110011010000110111",
"output": "523584169"
},
{
"input": "75\n111111111111111111111111111011001111111111111111111111111111111111011111111",
"output": "763088827"
},
{
"input": "75\n000000000010001000000000000000000000001000001000000000000000000000000000000",
"output": "432"
},
{
"input": "75\n011111101111111111111111111111111110111101111111111111111111111111111111111",
"output": "69182016"
},
{
"input": "75\n101111101111111111111111111111111111101111110111111111111111111111111111111",
"output": "57141715"
},
{
"input": "75\n111111111110011111111111111101111111111111111111111111111111111111110111111",
"output": "820494757"
},
{
"input": "75\n111111101111011101101111111111111111111100111111111101111111111110111111111",
"output": "65685547"
},
{
"input": "75\n111111111111011011111111111111111110011111111011111111011111111110111011111",
"output": "57316598"
},
{
"input": "75\n100000000000000000000000000000011000100001000000000000000100001000000001000",
"output": "13285"
},
{
"input": "75\n001000000000000000010000000000000000101000000010000100000000100010000000000",
"output": "8162"
},
{
"input": "75\n000000000100000000000000001000000101000000000000000000000000000000000000000",
"output": "477"
},
{
"input": "75\n101001100001001000010001000110010000101001000010010010100110000101010101000",
"output": "377044625"
},
{
"input": "75\n100001000100010000111100100101001001000010100001000100100100011000010001010",
"output": "401069803"
},
{
"input": "75\n110000100001001010001000100010001010100010001011000100010000100010100011001",
"output": "952955634"
},
{
"input": "75\n100101000010111000101001000100001000010010100100101000010010000100001000010",
"output": "454813411"
},
{
"input": "75\n100001001000100010110100001010000100001001000110000100010000110100010100111",
"output": "852034934"
},
{
"input": "75\n110000101100001010000100110001001000010110100001101010100010010001000010000",
"output": "953764512"
},
{
"input": "75\n100010100110000100100001000110100100100010000100010100010010000101000100001",
"output": "37562460"
},
{
"input": "75\n100100011011000010000101101001010001011100001100001100110000100001000101001",
"output": "292478450"
},
{
"input": "75\n101001010010110000100100001000010110010100110001000010000100001000111000101",
"output": "174101396"
},
{
"input": "75\n110001001100001010100010110001010000100100010000110000110010000100100100011",
"output": "186593444"
},
{
"input": "75\n000000000000000000000000000000000000000000000000000000000000000000000001011",
"output": "365"
}
] | 1,809 | 56,115,200 | 3 | 464 |
|
848 | Days of Floral Colours | [
"combinatorics",
"divide and conquer",
"dp",
"fft",
"math"
] | null | null | The Floral Clock has been standing by the side of Mirror Lake for years. Though unable to keep time, it reminds people of the passage of time and the good old days.
On the rim of the Floral Clock are 2*n* flowers, numbered from 1 to 2*n* clockwise, each of which has a colour among all *n* possible ones. For each colour, there are exactly two flowers with it, the distance between which either is less than or equal to 2, or equals *n*. Additionally, if flowers *u* and *v* are of the same colour, then flowers opposite to *u* and opposite to *v* should be of the same colour as well β symmetry is beautiful!
Formally, the distance between two flowers is 1 plus the number of flowers on the minor arc (or semicircle) between them. Below is a possible arrangement with *n*<==<=6 that cover all possibilities.
The beauty of an arrangement is defined to be the product of the lengths of flower segments separated by all opposite flowers of the same colour. In other words, in order to compute the beauty, we remove from the circle all flowers that have the same colour as flowers opposite to them. Then, the beauty is the product of lengths of all remaining segments. Note that we include segments of length 0 in this product. If there are no flowers that have the same colour as flower opposite to them, the beauty equals 0. For instance, the beauty of the above arrangement equals 1<=Γ<=3<=Γ<=1<=Γ<=3<==<=9 β the segments are {2}, {4,<=5,<=6}, {8} and {10,<=11,<=12}.
While keeping the constraints satisfied, there may be lots of different arrangements. Find out the sum of beauty over all possible arrangements, modulo 998<=244<=353. Two arrangements are considered different, if a pair (*u*,<=*v*) (1<=β€<=*u*,<=*v*<=β€<=2*n*) exists such that flowers *u* and *v* are of the same colour in one of them, but not in the other. | The first and only line of input contains a lonely positive integer *n* (3<=β€<=*n*<=β€<=50<=000)Β β the number of colours present on the Floral Clock. | Output one integer β the sum of beauty over all possible arrangements of flowers, modulo 998<=244<=353. | [
"3\n",
"4\n",
"7\n",
"15\n"
] | [
"24\n",
"4\n",
"1316\n",
"3436404\n"
] | With *n*β=β3, the following six arrangements each have a beauty of 2βΓβ2β=β4.
While many others, such as the left one in the figure below, have a beauty of 0. The right one is invalid, since it's asymmetric. | [
{
"input": "3",
"output": "24"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "1316"
},
{
"input": "15",
"output": "3436404"
},
{
"input": "10",
"output": "26200"
},
{
"input": "99",
"output": "620067986"
},
{
"input": "1317",
"output": "414025"
},
{
"input": "50000",
"output": "475800099"
},
{
"input": "5",
"output": "240"
},
{
"input": "6",
"output": "204"
},
{
"input": "8",
"output": "2988"
},
{
"input": "9",
"output": "6720"
},
{
"input": "11",
"output": "50248"
},
{
"input": "12",
"output": "174280"
},
{
"input": "13",
"output": "436904"
},
{
"input": "14",
"output": "1140888"
},
{
"input": "16",
"output": "8348748"
},
{
"input": "17",
"output": "24631232"
},
{
"input": "18",
"output": "64575924"
},
{
"input": "19",
"output": "174658944"
},
{
"input": "20",
"output": "488230244"
},
{
"input": "33",
"output": "823529776"
},
{
"input": "39",
"output": "302870971"
},
{
"input": "89",
"output": "530141864"
},
{
"input": "144",
"output": "395837543"
},
{
"input": "233",
"output": "422271260"
},
{
"input": "396",
"output": "994574954"
},
{
"input": "418",
"output": "57956054"
},
{
"input": "431",
"output": "767293469"
},
{
"input": "831",
"output": "418821250"
},
{
"input": "985",
"output": "574051668"
},
{
"input": "998",
"output": "452930999"
},
{
"input": "1000",
"output": "945359814"
},
{
"input": "2017",
"output": "222633425"
},
{
"input": "3939",
"output": "582943734"
},
{
"input": "5000",
"output": "148029988"
},
{
"input": "8081",
"output": "473740780"
},
{
"input": "10000",
"output": "938538566"
},
{
"input": "10001",
"output": "552705744"
},
{
"input": "10492",
"output": "914991759"
},
{
"input": "20178",
"output": "207394683"
},
{
"input": "23333",
"output": "259575428"
},
{
"input": "25252",
"output": "306102706"
},
{
"input": "30000",
"output": "583465411"
},
{
"input": "35000",
"output": "520751787"
},
{
"input": "39393",
"output": "929692433"
},
{
"input": "40404",
"output": "618777849"
},
{
"input": "45000",
"output": "672059275"
},
{
"input": "49997",
"output": "645043850"
},
{
"input": "49999",
"output": "791828238"
}
] | 30 | 0 | 0 | 468 |
|
33 | Knights | [
"geometry",
"graphs",
"shortest paths",
"sortings"
] | D. Knights | 2 | 256 | Berland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came *n* knights. After long discussions it became clear that the kingdom has exactly *n* control points (if the enemy conquers at least one of these points, the war is lost) and each knight will occupy one of these points.
Berland is divided into *m*<=+<=1 regions with *m* fences, and the only way to get from one region to another is to climb over the fence. Each fence is a circle on a plane, no two fences have common points, and no control point is on the fence. You are given *k* pairs of numbers *a**i*, *b**i*. For each pair you have to find out: how many fences a knight from control point with index *a**i* has to climb over to reach control point *b**i* (in case when Van de Mart attacks control point *b**i* first). As each knight rides a horse (it is very difficult to throw a horse over a fence), you are to find out for each pair the minimum amount of fences to climb over. | The first input line contains three integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*<=β€<=1000, 0<=β€<=*k*<=β€<=100000). Then follow *n* lines, each containing two integers *Kx**i*, *Ky**i* (<=-<=109<=β€<=*Kx**i*,<=*Ky**i*<=β€<=109) β coordinates of control point with index *i*. Control points can coincide.
Each of the following *m* lines describes fence with index *i* with three integers *r**i*, *Cx**i*, *Cy**i* (1<=β€<=*r**i*<=β€<=109, <=-<=109<=β€<=*Cx**i*,<=*Cy**i*<=β€<=109) β radius and center of the circle where the corresponding fence is situated.
Then follow *k* pairs of integers *a**i*, *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*), each in a separate line β requests that you have to answer. *a**i* and *b**i* can coincide. | Output exactly *k* lines, each containing one integer β the answer to the corresponding request. | [
"2 1 1\n0 0\n3 3\n2 0 0\n1 2\n",
"2 3 1\n0 0\n4 4\n1 0 0\n2 0 0\n3 0 0\n1 2\n"
] | [
"1\n",
"3\n"
] | none | [] | 62 | 0 | 0 | 471 |
708 | Letters Cyclic Shift | [
"constructive algorithms",
"greedy",
"implementation",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once? | The only line of the input contains the string *s* (1<=β€<=|*s*|<=β€<=100<=000) consisting of lowercase English letters. | Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. | [
"codeforces\n",
"abacaba\n"
] | [
"bncdenqbdr\n",
"aaacaba\n"
] | String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1ββ€β*i*ββ€β|*s*|, such 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>, and *s*<sub class="lower-index">*i*</sub>β<β*t*<sub class="lower-index">*i*</sub>. | [
{
"input": "codeforces",
"output": "bncdenqbdr"
},
{
"input": "abacaba",
"output": "aaacaba"
},
{
"input": "babbbabaababbaa",
"output": "aabbbabaababbaa"
},
{
"input": "bcbacaabcababaccccaaaabacbbcbbaa",
"output": "abaacaabcababaccccaaaabacbbcbbaa"
},
{
"input": "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda",
"output": "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda"
},
{
"input": "a",
"output": "z"
},
{
"input": "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec",
"output": "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec"
},
{
"input": "fddfbabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe",
"output": "ecceaabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaz"
},
{
"input": "abbabaaaaa",
"output": "aaaabaaaaa"
},
{
"input": "bbbbbbbbbbbb",
"output": "aaaaaaaaaaaa"
},
{
"input": "aabaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaz"
},
{
"input": "abaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa",
"output": "aaaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa"
},
{
"input": "abbbbbbbabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb",
"output": "aaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb"
},
{
"input": "aaaaa",
"output": "aaaaz"
},
{
"input": "aaa",
"output": "aaz"
},
{
"input": "aa",
"output": "az"
}
] | 31 | 409,600 | -1 | 472 |
|
35 | Shell Game | [
"implementation"
] | A. Shell Game | 2 | 64 | Today the Β«ZΒ» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | The first input line contains an integer from 1 to 3 β index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 β indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle β index 2 and the one on the right β index 3. | In the first line output an integer from 1 to 3 β index of the cup which will have the ball after all the shuffles. | [
"1\n1 2\n2 1\n2 1\n",
"1\n2 1\n3 1\n1 3\n"
] | [
"2\n",
"2\n"
] | none | [
{
"input": "1\n1 2\n2 1\n2 1",
"output": "2"
},
{
"input": "1\n2 1\n3 1\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 1\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 2\n2 3",
"output": "2"
},
{
"input": "3\n3 2\n3 1\n3 1",
"output": "2"
},
{
"input": "1\n2 1\n1 3\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 3\n3 2",
"output": "1"
},
{
"input": "2\n1 3\n1 2\n2 1",
"output": "2"
},
{
"input": "1\n1 3\n3 2\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 3\n2 3",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n2 1",
"output": "2"
},
{
"input": "3\n1 3\n3 2\n2 1",
"output": "2"
},
{
"input": "1\n1 2\n2 1\n2 3",
"output": "1"
},
{
"input": "1\n2 3\n1 3\n1 2",
"output": "3"
},
{
"input": "2\n3 1\n3 2\n2 3",
"output": "2"
},
{
"input": "2\n1 3\n3 1\n3 1",
"output": "2"
},
{
"input": "1\n3 2\n1 3\n3 1",
"output": "1"
},
{
"input": "3\n1 3\n1 2\n1 3",
"output": "2"
},
{
"input": "1\n3 2\n3 1\n1 2",
"output": "3"
},
{
"input": "2\n2 3\n1 3\n1 3",
"output": "3"
}
] | 30 | 0 | -1 | 473 |
496 | Minimum Difficulty | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=β€<=*n*<=β€<=100)Β β the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=β€<=*a**i*<=β€<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number β the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1,β6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1,β3,β7,β8), (1,β2,β7,β8), (1,β2,β3,β8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer β 4. | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"input": "100\n1 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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 31 | 0 | 0 | 474 |
|
910 | The Way to Home | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. | The first line contains two integers *n* and *d* (2<=β€<=*n*<=β€<=100, 1<=β€<=*d*<=β€<=*n*<=-<=1) β the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
"output": "1"
},
{
"input": "10 7\n1101111011",
"output": "2"
},
{
"input": "10 9\n1110000101",
"output": "1"
},
{
"input": "10 9\n1100000001",
"output": "1"
},
{
"input": "20 5\n11111111110111101001",
"output": "4"
},
{
"input": "20 11\n11100000111000011011",
"output": "2"
},
{
"input": "20 19\n10100000000000000001",
"output": "1"
},
{
"input": "50 13\n10011010100010100111010000010000000000010100000101",
"output": "5"
},
{
"input": "50 8\n11010100000011001100001100010001110000101100110011",
"output": "8"
},
{
"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111",
"output": "25"
},
{
"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "20"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111",
"output": "25"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111",
"output": "25"
},
{
"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111",
"output": "34"
},
{
"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111",
"output": "13"
},
{
"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111",
"output": "15"
},
{
"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111",
"output": "12"
},
{
"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111",
"output": "18"
},
{
"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001",
"output": "16"
},
{
"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101",
"output": "10"
},
{
"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111",
"output": "13"
},
{
"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001",
"output": "18"
},
{
"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011",
"output": "12"
},
{
"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001",
"output": "9"
},
{
"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101",
"output": "12"
},
{
"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001",
"output": "7"
},
{
"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001",
"output": "3"
},
{
"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001",
"output": "3"
},
{
"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001",
"output": "3"
},
{
"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "99"
},
{
"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111",
"output": "-1"
},
{
"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111",
"output": "33"
},
{
"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111",
"output": "-1"
},
{
"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111",
"output": "17"
},
{
"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111",
"output": "-1"
},
{
"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011",
"output": "14"
},
{
"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101",
"output": "11"
},
{
"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001",
"output": "-1"
},
{
"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111",
"output": "-1"
},
{
"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101",
"output": "13"
},
{
"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101",
"output": "9"
},
{
"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001",
"output": "-1"
},
{
"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001",
"output": "-1"
},
{
"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001",
"output": "-1"
},
{
"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001",
"output": "3"
},
{
"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "-1"
},
{
"input": "43 30\n1001000001111111010100100100110101011101101",
"output": "2"
},
{
"input": "7 1\n1111111",
"output": "6"
},
{
"input": "9 3\n101000001",
"output": "-1"
},
{
"input": "10 3\n1100000001",
"output": "-1"
},
{
"input": "8 2\n10000101",
"output": "-1"
},
{
"input": "2 1\n11",
"output": "1"
}
] | 62 | 5,529,600 | 3 | 477 |
|
330 | Road Construction | [
"constructive algorithms",
"graphs"
] | null | null | A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given *m* pairs of cities β roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible. | The first line consists of two integers *n* and *m* .
Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*.
It is guaranteed that every pair of cities will appear at most once in the input. | You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=*a**i*<=β <=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*.
If there are several solutions, you may print any of them. | [
"4 1\n1 3\n"
] | [
"3\n1 2\n4 2\n2 3\n"
] | This is one possible solution of the example:
These are examples of wrong solutions: | [
{
"input": "4 1\n1 3",
"output": "3\n1 2\n4 2\n2 3"
},
{
"input": "1000 0",
"output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "484 11\n414 97\n414 224\n444 414\n414 483\n414 399\n414 484\n414 189\n414 246\n414 115\n89 414\n14 414",
"output": "483\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "150 3\n112 30\n61 45\n37 135",
"output": "149\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26",
"output": "33\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34"
},
{
"input": "1000 48\n816 885\n576 357\n878 659\n610 647\n37 670\n192 184\n393 407\n598 160\n547 995\n177 276\n788 44\n14 184\n604 281\n176 97\n176 293\n10 57\n852 579\n223 669\n313 260\n476 691\n667 22\n851 792\n411 489\n526 66\n233 566\n35 396\n964 815\n672 123\n148 210\n163 339\n379 598\n382 675\n132 955\n221 441\n253 490\n856 532\n135 119\n276 319\n525 835\n996 270\n92 778\n434 369\n351 927\n758 983\n798 267\n272 830\n539 728\n166 26",
"output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "534 0",
"output": "533\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "226 54\n80 165\n2 53\n191 141\n107 207\n95 196\n61 82\n42 168\n118 94\n205 182\n172 160\n84 224\n113 143\n122 93\n37 209\n176 32\n56 83\n151 81\n70 190\n99 171\n68 204\n212 48\n4 67\n116 7\n206 199\n105 62\n158 51\n178 147\n17 129\n22 47\n72 162\n188 77\n24 111\n184 26\n175 128\n110 89\n139 120\n127 92\n121 39\n217 75\n145 69\n20 161\n30 220\n222 154\n54 46\n21 87\n144 185\n164 115\n73 202\n173 35\n9 132\n74 180\n137 5\n157 117\n31 177",
"output": "225\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "84 3\n39 19\n55 73\n42 43",
"output": "83\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84"
},
{
"input": "207 35\n34 116\n184 5\n90 203\n12 195\n138 101\n40 150\n189 109\n115 91\n93 201\n106 18\n51 187\n139 197\n168 130\n182 64\n31 42\n86 107\n158 111\n159 132\n119 191\n53 127\n81 13\n153 112\n38 2\n87 84\n121 82\n120 22\n21 177\n151 202\n23 58\n68 192\n29 46\n105 70\n8 167\n56 54\n149 15",
"output": "206\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "91 37\n50 90\n26 82\n61 1\n50 17\n51 73\n45 9\n39 53\n78 35\n12 45\n43 47\n83 20\n9 59\n18 48\n68 31\n47 33\n10 25\n15 78\n5 3\n73 65\n77 4\n62 31\n73 3\n53 7\n29 58\n52 14\n56 20\n6 87\n71 16\n17 19\n77 86\n1 50\n74 79\n15 54\n55 80\n13 77\n4 69\n24 69",
"output": "90\n2 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..."
},
{
"input": "226 54\n197 107\n181 146\n218 115\n36 169\n199 196\n116 93\n152 75\n213 164\n156 95\n165 58\n90 42\n141 58\n203 221\n179 204\n186 69\n27 127\n76 189\n40 195\n111 29\n85 189\n45 88\n84 135\n82 186\n185 17\n156 217\n8 123\n179 112\n92 137\n114 89\n10 152\n132 24\n135 36\n61 218\n10 120\n155 102\n222 79\n150 92\n184 34\n102 180\n154 196\n171 9\n217 105\n84 207\n56 189\n152 179\n43 165\n115 209\n208 167\n52 14\n92 47\n197 95\n13 78\n222 138\n75 36",
"output": "225\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "207 35\n154 79\n174 101\n189 86\n137 56\n66 23\n199 69\n18 28\n32 53\n13 179\n182 170\n199 12\n24 158\n105 133\n25 10\n40 162\n64 72\n108 9\n172 125\n43 190\n15 39\n128 150\n102 129\n90 97\n64 196\n70 123\n163 41\n12 126\n127 186\n107 23\n182 51\n29 46\n46 123\n89 35\n59 80\n206 171",
"output": "206\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "84 0",
"output": "83\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84"
},
{
"input": "226 54\n5 29\n130 29\n55 29\n19 29\n29 92\n29 38\n185 29\n29 150\n29 202\n29 25\n29 66\n184 29\n29 189\n177 29\n50 29\n87 29\n138 29\n29 48\n151 29\n125 29\n16 29\n42 29\n29 157\n90 29\n21 29\n29 45\n29 80\n29 67\n29 26\n29 173\n74 29\n29 193\n29 40\n172 29\n29 85\n29 102\n88 29\n29 182\n116 29\n180 29\n161 29\n10 29\n171 29\n144 29\n29 218\n190 29\n213 29\n29 71\n29 191\n29 160\n29 137\n29 58\n29 135\n127 29",
"output": "225\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "207 35\n25 61\n188 61\n170 61\n113 61\n35 61\n61 177\n77 61\n61 39\n61 141\n116 61\n61 163\n30 61\n192 61\n19 61\n61 162\n61 133\n185 61\n8 61\n118 61\n61 115\n7 61\n61 105\n107 61\n61 11\n161 61\n61 149\n136 61\n82 61\n20 61\n151 61\n156 61\n12 61\n87 61\n61 205\n61 108",
"output": "206\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "34 7\n11 32\n33 29\n17 16\n15 5\n13 25\n8 19\n20 4",
"output": "33\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34"
},
{
"input": "43 21\n38 19\n43 8\n40 31\n3 14\n24 21\n12 17\n1 9\n5 27\n25 37\n11 6\n13 26\n16 22\n10 32\n36 7\n30 29\n42 35\n20 33\n4 23\n18 15\n41 34\n2 28",
"output": "42\n39 1\n39 2\n39 3\n39 4\n39 5\n39 6\n39 7\n39 8\n39 9\n39 10\n39 11\n39 12\n39 13\n39 14\n39 15\n39 16\n39 17\n39 18\n39 19\n39 20\n39 21\n39 22\n39 23\n39 24\n39 25\n39 26\n39 27\n39 28\n39 29\n39 30\n39 31\n39 32\n39 33\n39 34\n39 35\n39 36\n39 37\n39 38\n39 40\n39 41\n39 42\n39 43"
},
{
"input": "34 7\n22 4\n5 25\n15 7\n5 9\n27 7\n34 21\n3 13",
"output": "33\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34"
},
{
"input": "50 7\n19 37\n30 32\n43 20\n48 14\n30 29\n18 36\n9 46",
"output": "49\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50"
},
{
"input": "41 12\n41 12\n29 13\n3 37\n2 20\n4 24\n27 6\n39 20\n28 41\n30 1\n35 9\n5 39\n12 31",
"output": "40\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 8\n7 9\n7 10\n7 11\n7 12\n7 13\n7 14\n7 15\n7 16\n7 17\n7 18\n7 19\n7 20\n7 21\n7 22\n7 23\n7 24\n7 25\n7 26\n7 27\n7 28\n7 29\n7 30\n7 31\n7 32\n7 33\n7 34\n7 35\n7 36\n7 37\n7 38\n7 39\n7 40\n7 41"
},
{
"input": "26 2\n22 1\n14 10",
"output": "25\n2 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26"
},
{
"input": "7 3\n4 7\n4 6\n6 5",
"output": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7"
},
{
"input": "484 11\n459 166\n12 217\n14 231\n477 111\n365 225\n62 412\n221 223\n258 184\n266 404\n425 236\n83 269",
"output": "483\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..."
},
{
"input": "50 24\n18 36\n11 18\n22 18\n18 47\n18 10\n45 18\n18 29\n13 18\n8 18\n18 30\n26 18\n18 6\n5 18\n18 7\n46 18\n50 18\n18 3\n18 32\n4 18\n18 24\n18 19\n23 18\n35 18\n31 18",
"output": "49\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50"
},
{
"input": "7 3\n3 4\n7 3\n3 2",
"output": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 0",
"output": "1\n1 2"
},
{
"input": "4 1\n1 2",
"output": "3\n3 1\n3 2\n3 4"
},
{
"input": "3 1\n1 2",
"output": "2\n3 1\n3 2"
},
{
"input": "5 1\n1 5",
"output": "4\n2 1\n2 3\n2 4\n2 5"
}
] | 62 | 0 | -1 | 478 |
|
803 | Maximal Binary Matrix | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1. | The first line consists of two numbers *n* and *k* (1<=β€<=*n*<=β€<=100, 0<=β€<=*k*<=β€<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "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 \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 \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..."
},
{
"input": "20 401",
"output": "-1"
},
{
"input": "100 3574",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1..."
},
{
"input": "100 10001",
"output": "-1"
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "1 1000000",
"output": "-1"
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "-1"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "1 6",
"output": "-1"
},
{
"input": "1 7",
"output": "-1"
},
{
"input": "1 8",
"output": "-1"
},
{
"input": "1 9",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "1 11",
"output": "-1"
},
{
"input": "1 12",
"output": "-1"
},
{
"input": "1 13",
"output": "-1"
},
{
"input": "1 14",
"output": "-1"
},
{
"input": "1 15",
"output": "-1"
},
{
"input": "1 16",
"output": "-1"
},
{
"input": "1 17",
"output": "-1"
},
{
"input": "1 18",
"output": "-1"
},
{
"input": "1 19",
"output": "-1"
},
{
"input": "1 20",
"output": "-1"
},
{
"input": "1 21",
"output": "-1"
},
{
"input": "1 22",
"output": "-1"
},
{
"input": "1 23",
"output": "-1"
},
{
"input": "1 24",
"output": "-1"
},
{
"input": "1 25",
"output": "-1"
},
{
"input": "1 26",
"output": "-1"
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "2 2",
"output": "1 0 \n0 1 "
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "2 4",
"output": "1 1 \n1 1 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "2 7",
"output": "-1"
},
{
"input": "2 8",
"output": "-1"
},
{
"input": "2 9",
"output": "-1"
},
{
"input": "2 10",
"output": "-1"
},
{
"input": "2 11",
"output": "-1"
},
{
"input": "2 12",
"output": "-1"
},
{
"input": "2 13",
"output": "-1"
},
{
"input": "2 14",
"output": "-1"
},
{
"input": "2 15",
"output": "-1"
},
{
"input": "2 16",
"output": "-1"
},
{
"input": "2 17",
"output": "-1"
},
{
"input": "2 18",
"output": "-1"
},
{
"input": "2 19",
"output": "-1"
},
{
"input": "2 20",
"output": "-1"
},
{
"input": "2 21",
"output": "-1"
},
{
"input": "2 22",
"output": "-1"
},
{
"input": "2 23",
"output": "-1"
},
{
"input": "2 24",
"output": "-1"
},
{
"input": "2 25",
"output": "-1"
},
{
"input": "2 26",
"output": "-1"
},
{
"input": "3 0",
"output": "0 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 1",
"output": "1 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "3 7",
"output": "1 1 1 \n1 1 0 \n1 0 1 "
},
{
"input": "3 8",
"output": "1 1 1 \n1 1 1 \n1 1 0 "
},
{
"input": "3 9",
"output": "1 1 1 \n1 1 1 \n1 1 1 "
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "3 11",
"output": "-1"
},
{
"input": "3 12",
"output": "-1"
},
{
"input": "3 13",
"output": "-1"
},
{
"input": "3 14",
"output": "-1"
},
{
"input": "3 15",
"output": "-1"
},
{
"input": "3 16",
"output": "-1"
},
{
"input": "3 17",
"output": "-1"
},
{
"input": "3 18",
"output": "-1"
},
{
"input": "3 19",
"output": "-1"
},
{
"input": "3 20",
"output": "-1"
},
{
"input": "3 21",
"output": "-1"
},
{
"input": "3 22",
"output": "-1"
},
{
"input": "3 23",
"output": "-1"
},
{
"input": "3 24",
"output": "-1"
},
{
"input": "3 25",
"output": "-1"
},
{
"input": "3 26",
"output": "-1"
},
{
"input": "4 0",
"output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 1",
"output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 2",
"output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 4",
"output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 6",
"output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 7",
"output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 8",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 9",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 "
},
{
"input": "4 10",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 "
},
{
"input": "4 11",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 "
},
{
"input": "4 12",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 "
},
{
"input": "4 13",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 "
},
{
"input": "4 14",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 "
},
{
"input": "4 15",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 "
},
{
"input": "4 16",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 "
},
{
"input": "4 17",
"output": "-1"
},
{
"input": "4 18",
"output": "-1"
},
{
"input": "4 19",
"output": "-1"
},
{
"input": "4 20",
"output": "-1"
},
{
"input": "4 21",
"output": "-1"
},
{
"input": "4 22",
"output": "-1"
},
{
"input": "4 23",
"output": "-1"
},
{
"input": "4 24",
"output": "-1"
},
{
"input": "4 25",
"output": "-1"
},
{
"input": "4 26",
"output": "-1"
},
{
"input": "5 0",
"output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 1",
"output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 2",
"output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 3",
"output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 4",
"output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 5",
"output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 7",
"output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 8",
"output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 9",
"output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 11",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 12",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 13",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 14",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 15",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 16",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 17",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 18",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 "
},
{
"input": "5 19",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 "
},
{
"input": "5 20",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 "
},
{
"input": "5 21",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 "
},
{
"input": "5 22",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 "
},
{
"input": "5 23",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "5 25",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 "
},
{
"input": "5 26",
"output": "-1"
},
{
"input": "100 0",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0..."
},
{
"input": "100 1",
"output": "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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0..."
},
{
"input": "100 2",
"output": "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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0..."
},
{
"input": "100 3",
"output": "1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0..."
},
{
"input": "100 99",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 101",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 9999",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1..."
},
{
"input": "100 10001",
"output": "-1"
}
] | 31 | 614,400 | 0 | 480 |
|
862 | Mahmoud and Ehab and the bipartiteness | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.
Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?
A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | The first line of input contains an integer *n*Β β the number of nodes in the tree (1<=β€<=*n*<=β€<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=β€<=*u*,<=*v*<=β€<=*n*, *u*<=β <=*v*)Β β the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integerΒ β the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2,β3), but adding this edge will make the graph non-bipartite so the answer is 0.
In the second test case Mahmoud and Ehab can add edges (1,β4) and (2,β5). | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8",
"output": "16"
},
{
"input": "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
}
] | 46 | 409,600 | 0 | 482 |
|
82 | Double Cola | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=β€<=*n*<=β€<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line β the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 62 | 0 | 3.969 | 485 |
498 | Array and Operations | [
"flows",
"graph matchings",
"number theory"
] | null | null | You have written on a piece of paper an array of *n* positive integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] and *m* good pairs of integers (*i*1,<=*j*1),<=(*i*2,<=*j*2),<=...,<=(*i**m*,<=*j**m*). Each good pair (*i**k*,<=*j**k*) meets the following conditions: *i**k*<=+<=*j**k* is an odd number and 1<=β€<=*i**k*<=<<=*j**k*<=β€<=*n*.
In one operation you can perform a sequence of actions:
- take one of the good pairs (*i**k*,<=*j**k*) and some integer *v* (*v*<=><=1), which divides both numbers *a*[*i**k*] and *a*[*j**k*]; - divide both numbers by *v*, i. e. perform the assignments: and .
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations. | The first line contains two space-separated integers *n*, *m* (2<=β€<=*n*<=β€<=100, 1<=β€<=*m*<=β€<=100).
The second line contains *n* space-separated integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=β€<=*a*[*i*]<=β€<=109) β the description of the array.
The following *m* lines contain the description of good pairs. The *k*-th line contains two space-separated integers *i**k*, *j**k* (1<=β€<=*i**k*<=<<=*j**k*<=β€<=*n*, *i**k*<=+<=*j**k* is an odd number).
It is guaranteed that all the good pairs are distinct. | Output the answer for the problem. | [
"3 2\n8 3 8\n1 2\n2 3\n",
"3 2\n8 12 8\n1 2\n2 3\n"
] | [
"0\n",
"2\n"
] | none | [
{
"input": "3 2\n8 3 8\n1 2\n2 3",
"output": "0"
},
{
"input": "3 2\n8 12 8\n1 2\n2 3",
"output": "2"
},
{
"input": "6 4\n35 33 46 58 7 61\n4 5\n3 6\n5 6\n1 6",
"output": "0"
},
{
"input": "10 25\n262144 262144 64 64 16 134217728 32 512 32 8192\n1 2\n3 10\n5 8\n9 10\n2 5\n5 10\n3 6\n3 8\n2 9\n4 5\n8 9\n1 4\n4 9\n3 4\n1 6\n4 7\n7 8\n5 6\n2 3\n1 10\n1 8\n6 9\n6 7\n2 7\n7 10",
"output": "38"
},
{
"input": "10 9\n67108864 8 2 131072 268435456 256 16384 128 8 128\n4 9\n5 10\n6 9\n9 10\n1 4\n3 8\n8 9\n1 2\n4 5",
"output": "31"
},
{
"input": "20 10\n512 64 536870912 256 1 262144 8 2097152 8192 524288 32 2 16 16777216 524288 64 268435456 256 67108864 131072\n17 20\n2 13\n11 12\n18 19\n4 7\n4 13\n8 9\n14 17\n8 19\n7 10",
"output": "65"
},
{
"input": "20 19\n512 524288 268435456 2048 16384 8192 524288 16777216 128 536870912 256 1 32768 2097152 131072 268435456 262144 134217728 8388608 16\n3 20\n5 12\n19 20\n10 15\n3 18\n3 4\n6 19\n3 14\n3 16\n5 10\n3 12\n5 20\n12 17\n6 9\n13 18\n2 11\n7 12\n6 11\n2 15",
"output": "99"
},
{
"input": "20 19\n4 65536 2097152 512 16777216 262144 4096 4096 64 32 268435456 2 2048 128 512 1048576 524288 1024 512 536870912\n10 15\n16 17\n15 18\n19 20\n9 12\n2 9\n12 19\n8 19\n2 11\n4 17\n2 5\n7 18\n7 10\n17 20\n9 10\n4 15\n10 19\n5 18\n1 16",
"output": "71"
},
{
"input": "22 2\n2097152 2048 1024 134217728 536870912 2097152 32768 2 16777216 67108864 4194304 4194304 512 16 1048576 8 16384 131072 8388608 8192 2097152 4\n9 10\n14 21",
"output": "28"
},
{
"input": "10 25\n2048 536870912 64 65536 524288 2048 4194304 131072 8 128\n7 10\n3 6\n8 9\n9 10\n1 2\n1 8\n2 9\n2 3\n4 7\n5 6\n5 8\n6 9\n1 4\n3 10\n4 5\n3 8\n5 10\n6 7\n2 7\n1 10\n4 9\n1 6\n3 4\n2 5\n7 8",
"output": "61"
},
{
"input": "2 1\n1020407 1020407\n1 2",
"output": "1"
},
{
"input": "8 6\n1020407 1020407 1020407 1020407 1020407 1020407 1020407 1020407\n1 2\n1 4\n2 3\n5 6\n6 7\n7 8",
"output": "4"
},
{
"input": "2 1\n9999991 9999991\n1 2",
"output": "1"
},
{
"input": "2 1\n19961993 19961993\n1 2",
"output": "1"
},
{
"input": "5 3\n1 2 2 2 2\n2 3\n3 4\n2 5",
"output": "2"
},
{
"input": "2 1\n10 10\n1 2",
"output": "2"
},
{
"input": "5 3\n1 1000003 1000003 1000003 1000003\n2 3\n3 4\n2 5",
"output": "2"
},
{
"input": "6 3\n12 7 8 12 7 8\n1 4\n1 6\n3 4",
"output": "5"
},
{
"input": "4 3\n2 2 2 2\n1 2\n1 4\n2 3",
"output": "2"
},
{
"input": "6 3\n12 3 4 12 8 8\n1 4\n4 5\n1 6",
"output": "5"
}
] | 140 | 5,836,800 | 0 | 486 |
|
161 | Distance in Tree | [
"dfs and similar",
"dp",
"trees"
] | null | null | A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of exactly *k* between them. Note that pairs (*v*, *u*) and (*u*, *v*) are considered to be the same pair. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=50000, 1<=β€<=*k*<=β€<=500) β the number of vertices and the required distance between the vertices.
Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*), where *a**i* and *b**i* are the vertices connected by the *i*-th edge. All given edges are different. | Print a single integer β the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5 2\n1 2\n2 3\n3 4\n2 5\n",
"5 3\n1 2\n2 3\n3 4\n4 5\n"
] | [
"4\n",
"2\n"
] | In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | [
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "4"
},
{
"input": "5 3\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "9"
},
{
"input": "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "10"
},
{
"input": "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "8"
},
{
"input": "50 3\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\n16 15\n17 16\n18 17\n19 18\n20 19\n21 20\n22 21\n23 22\n24 23\n25 24\n26 25\n27 26\n28 27\n29 28\n30 29\n31 30\n32 31\n33 32\n34 33\n35 34\n36 35\n37 36\n38 37\n39 38\n40 39\n41 40\n42 41\n43 42\n44 43\n45 44\n46 45\n47 46\n48 47\n49 48\n50 49",
"output": "47"
},
{
"input": "50 4\n2 1\n3 1\n4 2\n5 2\n6 3\n7 3\n8 4\n9 4\n10 5\n11 5\n12 6\n13 6\n14 7\n15 7\n16 8\n17 8\n18 9\n19 9\n20 10\n21 10\n22 11\n23 11\n24 12\n25 12\n26 13\n27 13\n28 14\n29 14\n30 15\n31 15\n32 16\n33 16\n34 17\n35 17\n36 18\n37 18\n38 19\n39 19\n40 20\n41 20\n42 21\n43 21\n44 22\n45 22\n46 23\n47 23\n48 24\n49 24\n50 25",
"output": "124"
},
{
"input": "50 5\n2 1\n3 1\n4 2\n5 2\n6 4\n7 4\n8 6\n9 6\n10 8\n11 8\n12 10\n13 10\n14 12\n15 12\n16 14\n17 14\n18 16\n19 16\n20 18\n21 18\n22 20\n23 20\n24 22\n25 22\n26 24\n27 24\n28 26\n29 26\n30 28\n31 28\n32 30\n33 30\n34 32\n35 32\n36 34\n37 34\n38 36\n39 36\n40 38\n41 38\n42 40\n43 40\n44 42\n45 42\n46 44\n47 44\n48 46\n49 46\n50 48",
"output": "84"
},
{
"input": "10 20\n2 1\n3 2\n4 1\n5 3\n6 4\n7 1\n8 2\n9 7\n10 2",
"output": "0"
}
] | 3,000 | 109,772,800 | 0 | 488 |
|
607 | Chain Reaction | [
"binary search",
"dp"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.
Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. | The first line of input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000) β the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=β€<=*a**i*<=β€<=1<=000<=000, 1<=β€<=*b**i*<=β€<=1<=000<=000)Β β the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=β <=*a**j* if *i*<=β <=*j*. | Print a single integerΒ β the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7",
"output": "4"
},
{
"input": "5\n1 1\n3 1\n5 1\n7 10\n8 10",
"output": "2"
},
{
"input": "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1",
"output": "4"
}
] | 530 | 16,588,800 | 0 | 491 |
|
876 | Divisiblity of Differences | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. | First line contains three integers *n*, *k* and *m* (2<=β€<=*k*<=β€<=*n*<=β€<=100<=000, 1<=β€<=*m*<=β€<=100<=000)Β β number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=109)Β β the numbers in the multiset. | If it is not possible to select *k* numbers in the desired way, output Β«NoΒ» (without the quotes).
Otherwise, in the first line of output print Β«YesΒ» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k*Β β the selected numbers. If there are multiple possible solutions, print any of them. | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 "
},
{
"input": "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455",
"output": "Yes\n216175135 15241965 987180005 533996295 875331635 46172555 604086315 350146655 "
},
{
"input": "2 2 100000\n0 1",
"output": "No"
},
{
"input": "101 25 64\n451 230 14 53 7 520 709 102 678 358 166 870 807 230 230 279 166 230 765 176 742 358 924 976 647 806 870 473 976 994 750 146 802 224 503 801 105 614 882 203 390 338 29 587 214 213 405 806 102 102 621 358 521 742 678 205 309 871 796 326 162 693 268 486 68 627 304 829 806 623 748 934 714 672 712 614 587 589 846 260 593 85 839 257 711 395 336 358 472 133 324 527 599 5 845 920 989 494 358 70 882",
"output": "Yes\n230 102 678 358 166 870 230 230 166 230 742 358 806 870 614 806 102 102 358 742 678 486 806 934 614 "
},
{
"input": "108 29 72\n738 619 711 235 288 288 679 36 785 233 706 71 216 144 216 781 338 583 495 648 144 432 72 720 541 288 158 328 154 202 10 533 635 176 707 216 314 397 440 142 326 458 568 701 745 144 61 634 520 720 744 144 409 127 526 476 101 469 72 432 738 432 235 641 695 276 144 144 231 555 630 9 109 319 437 288 288 317 453 432 601 0 449 576 743 352 333 504 504 369 228 288 381 142 500 72 297 359 230 773 216 576 144 244 437 772 483 51",
"output": "Yes\n288 288 216 144 216 648 144 432 72 720 288 216 144 720 144 72 432 432 144 144 288 288 432 0 576 504 504 288 72 "
},
{
"input": "8 2 6\n750462183 165947982 770714338 368445737 363145692 966611485 376672869 678687947",
"output": "Yes\n165947982 363145692 "
},
{
"input": "12 2 1\n512497388 499105388 575265677 864726520 678272195 667107176 809432109 439696443 770034376 873126825 690514828 541499950",
"output": "Yes\n512497388 499105388 "
},
{
"input": "9 3 1\n506004039 471451660 614118177 518013571 43210072 454727076 285905913 543002174 298515615",
"output": "Yes\n506004039 471451660 614118177 "
},
{
"input": "8 4 6\n344417267 377591123 938158786 682031413 804153975 89006697 275945670 735510539",
"output": "No"
},
{
"input": "8 8 1\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253",
"output": "Yes\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253 "
},
{
"input": "7 7 1\n0 0 0 0 0 0 0",
"output": "Yes\n0 0 0 0 0 0 0 "
},
{
"input": "11 4 3\n0 1 0 1 1 0 0 0 0 0 0",
"output": "Yes\n0 0 0 0 "
},
{
"input": "13 4 4\n1 1 0 3 2 4 1 0 3 4 2 4 3",
"output": "Yes\n0 4 0 4 "
},
{
"input": "5 5 1\n6 4 6 0 4",
"output": "Yes\n6 4 6 0 4 "
},
{
"input": "3 2 3\n1 2 3",
"output": "No"
},
{
"input": "6 3 4\n5 9 10 6 7 8",
"output": "No"
},
{
"input": "4 4 3\n4 7 2 5",
"output": "No"
},
{
"input": "4 2 6\n5 5 5 5",
"output": "Yes\n5 5 "
},
{
"input": "4 3 3\n5 1 4 7",
"output": "Yes\n1 4 7 "
},
{
"input": "4 3 10\n0 1 11 11",
"output": "Yes\n1 11 11 "
},
{
"input": "5 2 4\n1 2 2 2 2",
"output": "Yes\n2 2 "
},
{
"input": "5 5 9\n8 17 26 35 44",
"output": "Yes\n8 17 26 35 44 "
},
{
"input": "3 2 2\n1 2 4",
"output": "Yes\n2 4 "
},
{
"input": "5 4 2\n1 3 6 10 12",
"output": "No"
},
{
"input": "3 2 4\n1 2 3",
"output": "No"
},
{
"input": "8 3 5\n1 2 3 4 1 2 3 4",
"output": "No"
},
{
"input": "5 2 9\n8 8 8 8 8",
"output": "Yes\n8 8 "
},
{
"input": "3 3 3\n1 3 6",
"output": "No"
},
{
"input": "5 2 10\n4 5 6 19 29",
"output": "Yes\n19 29 "
},
{
"input": "5 3 3\n3 6 4 7 10",
"output": "Yes\n4 7 10 "
}
] | 233 | 13,619,200 | 3 | 494 |
|
91 | Newspaper Headline | [
"greedy",
"strings"
] | A. Newspaper Headline | 2 | 256 | A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new word *s*2. It is considered that when Fangy erases some letter, there's no whitespace formed instead of the letter. That is, the string remains unbroken and it still only consists of lowercase Latin letters.
For example, the heading is "abc". If we take two such headings and glue them one to the other one, we get "abcabc". If we erase the letters on positions 1 and 5, we get a word "bcac".
Which least number of newspaper headings *s*1 will Fangy need to glue them, erase several letters and get word *s*2? | The input data contain two lines. The first line contain the heading *s*1, the second line contains the word *s*2. The lines only consist of lowercase Latin letters (1<=β€<=|*s*1|<=β€<=104,<=1<=β€<=|*s*2|<=β€<=106). | If it is impossible to get the word *s*2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings *s*1, which Fangy will need to receive the word *s*2. | [
"abc\nxyz\n",
"abcd\ndabc\n"
] | [
"-1\n",
"2\n"
] | none | [
{
"input": "abc\nxyz",
"output": "-1"
},
{
"input": "abcd\ndabc",
"output": "2"
},
{
"input": "ab\nbabaaab",
"output": "5"
},
{
"input": "ab\nbaaabba",
"output": "6"
},
{
"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb",
"output": "-1"
},
{
"input": "ibifgcfdbfdhihbifageaaadegbfbhgeebgdgiafgedchdg\ndedfebcfdigdefdediigcfcafbhhiacgfbeccfchd",
"output": "7"
},
{
"input": "fcagdciidcedeaicgfffgjefaefaachfbfj\naiecchjehdgbjfcdjdefgfhiddjajeddiigidaibejabd",
"output": "11"
},
{
"input": "ehfjaabjfedhddejjfcfijagefhjeahjcddhchahjbagi\nfbfdjbjhibjgjgaaajgdbcfdbhjcajcbbieijhcjgajhgaa",
"output": "10"
},
{
"input": "ifjcedhjhdjhbiaededfefagigggcebfaebf\ngeibbffgeefbaghdbfidbbhabdbdgej",
"output": "9"
},
{
"input": "eidfdfbbgjigghaddbjhcbdechecgghjgfjjcajjhaghdhd\nfcgecaefhgjjegbhjeaffcabifihhcadaibhi",
"output": "11"
}
] | 62 | 0 | 0 | 496 |
701 | They Are Everywhere | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. | The first line contains the integer *n* (1<=β€<=*n*<=β€<=100<=000) β the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "52"
},
{
"input": "2\nAA",
"output": "1"
},
{
"input": "4\nqqqE",
"output": "2"
},
{
"input": "10\nrrrrroooro",
"output": "2"
},
{
"input": "15\nOCOCCCCiCOCCCOi",
"output": "3"
},
{
"input": "20\nVEVnVVnWnVEVVnEVBEWn",
"output": "5"
},
{
"input": "25\ncpcyPPjPPcPPPPcppPcPpppcP",
"output": "6"
},
{
"input": "30\nsssssAsesssssssssssssessssssss",
"output": "3"
},
{
"input": "35\ngdXdddgddddddddggggXdbgdggdgddddddb",
"output": "4"
},
{
"input": "40\nIgsggIiIggzgigIIiiIIIiIgIggIzgIiiiggggIi",
"output": "9"
},
{
"input": "45\neteeeeeteaattaeetaetteeettoetettteyeteeeotaae",
"output": "9"
},
{
"input": "50\nlUlUllUlUllllUllllUllllUlUlllUlllUlllllUUlllUUlkUl",
"output": "3"
},
{
"input": "55\nAAAAASAAAASAASAAAAAAAAAAAAASAAAAAAAAAAAAAAAASAAAAAAAAAA",
"output": "2"
},
{
"input": "60\nRRRrSRRRRRRRRRSSRRRSRRRRRRRRrRSRRRRRRRRRRRRRRSRRRRRSSRSRrRRR",
"output": "3"
},
{
"input": "65\nhhMhMhhhhhhhhhhhMhhMMMhhhhBhhhhMhhhhMhhhhhMhhhBhhhhhhhhhhBhhhhhhh",
"output": "5"
},
{
"input": "70\nwAwwwAwwwwwwwwwwwwwwAwAAwwAwwwwwwwwAwAAAwAAwwwwwwwwwAwwwwwwwwwwwwAAwww",
"output": "2"
},
{
"input": "75\niiiXXiiyiiiXyXiiyXiiXiiiiiiXXyiiiiXXiiXiiXifiXiXXiifiiiiiiXfXiyiXXiXiiiiXiX",
"output": "4"
},
{
"input": "80\nSrSrrrrrrrrrrrrrrSSSrrrrrrSrrrrSrrrrrrrrrrSSrrrrrrrrrrrSrrrSrrrrSrrrrSrrrrSSrSSr",
"output": "2"
},
{
"input": "85\nwkMMMwMMkMMMMMMMkkkkMMMMzkkMMwMMkkwMkMwkMMkMMwwMzMMMkkMwwMMMMMMkMMkMzMMMkMMkwMkMMMkMM",
"output": "6"
},
{
"input": "90\nZllZZZyZlZlllZlylllZlllZZllllllllZZllllllllllyylZZyvZvZlllZZlZllZlZlllZyllZyZlllZlllllllZl",
"output": "5"
},
{
"input": "95\nEmuBuEBmmEBBElBlElmmBEmmmEmmEuBEEmummmEmBBBBEWBBBmEEBmmummBBmmlluBBmElmEBEmBmBBmBmuLmEBBmlEBmBu",
"output": "39"
},
{
"input": "100\nfAfhfNNNhfffAfNffNANhffNffffffNfffffhNfffNfffNfffNfNNNffNfffNfhNNNffffNfNfffAffNffNffNNfhfffNhNffNNN",
"output": "4"
},
{
"input": "7\nabcbbab",
"output": "3"
},
{
"input": "65\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjkkkkkkkkkkkkkkkkkkkllllllljk",
"output": "3"
},
{
"input": "9\nbcdddbddc",
"output": "3"
},
{
"input": "71\nlqcrdopdpfagcilpcmheqhjbmnciqmeoabflrenbkrsaabaanpehdmpqcdqnljcrsplnlco",
"output": "36"
},
{
"input": "8\nabbbbbbc",
"output": "8"
}
] | 77 | 0 | 0 | 497 |
|
302 | Eugeny and Play List | [
"binary search",
"implementation",
"two pointers"
] | null | null | Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then song number 2 plays *c*2 times, ..., in the end the song number *n* plays *c**n* times.
Eugeny took a piece of paper and wrote out *m* moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment *x* means that Eugeny wants to know which song was playing during the *x*-th minute of his listening to the play list.
Help Eugeny and calculate the required numbers of songs. | The first line contains two integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=105). The next *n* lines contain pairs of integers. The *i*-th line contains integers *c**i*,<=*t**i* (1<=β€<=*c**i*,<=*t**i*<=β€<=109) β the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 .
The next line contains *m* positive integers *v*1,<=*v*2,<=...,<=*v**m*, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time *v**i*, when the music doesn't play any longer. It is guaranteed that *v**i*<=<<=*v**i*<=+<=1 (*i*<=<<=*m*).
The moment of time *v**i* means that Eugeny wants to know which song was playing during the *v**i*-th munite from the start of listening to the playlist. | Print *m* integers β the *i*-th number must equal the number of the song that was playing during the *v**i*-th minute after Eugeny started listening to the play list. | [
"1 2\n2 8\n1 16\n",
"4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9\n"
] | [
"1\n1\n",
"1\n1\n2\n2\n3\n4\n4\n4\n4\n"
] | none | [
{
"input": "1 2\n2 8\n1 16",
"output": "1\n1"
},
{
"input": "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9",
"output": "1\n1\n2\n2\n3\n4\n4\n4\n4"
},
{
"input": "3 3\n2 8\n5 1\n10 5\n13 16 62",
"output": "1\n1\n3"
},
{
"input": "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85",
"output": "1\n3\n3\n4"
},
{
"input": "5 5\n9 6\n8 7\n2 9\n10 3\n8 10\n69 95 146 162 177",
"output": "2\n2\n4\n5\n5"
},
{
"input": "6 6\n4 9\n8 5\n3 8\n8 10\n4 2\n10 9\n15 45 97 197 231 265",
"output": "1\n2\n3\n6\n6\n6"
},
{
"input": "7 7\n1 10\n1 1\n7 2\n4 9\n10 4\n5 5\n7 1\n48 71 86 87 110 113 127",
"output": "4\n5\n5\n5\n6\n6\n7"
},
{
"input": "8 8\n4 6\n10 9\n5 1\n8 7\n4 7\n2 6\n5 3\n1 10\n21 91 93 142 145 157 181 206",
"output": "1\n2\n2\n4\n4\n4\n5\n6"
},
{
"input": "9 9\n2 5\n7 1\n8 2\n8 8\n8 8\n4 4\n6 10\n10 9\n2 9\n1 10 36 48 76 151 229 276 310",
"output": "1\n1\n4\n4\n4\n5\n7\n8\n8"
},
{
"input": "10 10\n3 1\n2 7\n5 1\n7 2\n9 10\n9 5\n2 5\n4 10\n9 9\n1 9\n26 34 37 141 146 201 239 245 296 299",
"output": "4\n4\n5\n6\n6\n8\n9\n9\n9\n9"
},
{
"input": "2 3\n1 500000000\n1 500000000\n499999999 500000000 500000001",
"output": "1\n1\n2"
},
{
"input": "2 3\n500000000 1\n1 500000000\n499999999 500000000 500000001",
"output": "1\n1\n2"
},
{
"input": "2 3\n500000000 1\n500000000 1\n499999999 500000000 500000001",
"output": "1\n1\n2"
},
{
"input": "3 1\n2 50\n1 50\n1 50\n160",
"output": "3"
}
] | 498 | 268,390,400 | 0 | 499 |
|
459 | Pashmak and Garden | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=β€<=*x*1,<=*y*1,<=*x*2,<=*y*2<=β€<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=β€<=*x*3,<=*y*3,<=*x*4,<=*y*4<=β€<=1000). | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input": "0 -100 0 100",
"output": "200 -100 200 100"
},
{
"input": "27 -74 27 74",
"output": "175 -74 175 74"
},
{
"input": "0 1 2 3",
"output": "0 3 2 1"
},
{
"input": "-100 100 100 -100",
"output": "-100 -100 100 100"
},
{
"input": "-100 -100 -100 100",
"output": "100 -100 100 100"
},
{
"input": "100 100 100 -100",
"output": "300 100 300 -100"
},
{
"input": "100 -100 -100 -100",
"output": "100 100 -100 100"
},
{
"input": "-100 100 100 100",
"output": "-100 300 100 300"
},
{
"input": "0 1 0 0",
"output": "1 1 1 0"
},
{
"input": "1 1 0 0",
"output": "1 0 0 1"
},
{
"input": "0 0 1 0",
"output": "0 1 1 1"
},
{
"input": "1 0 0 1",
"output": "1 1 0 0"
},
{
"input": "1 0 1 1",
"output": "2 0 2 1"
},
{
"input": "1 1 0 1",
"output": "1 2 0 2"
},
{
"input": "15 -9 80 -9",
"output": "15 56 80 56"
},
{
"input": "51 -36 18 83",
"output": "-1"
},
{
"input": "69 -22 60 16",
"output": "-1"
},
{
"input": "-68 -78 -45 -55",
"output": "-68 -55 -45 -78"
},
{
"input": "68 -92 8 -32",
"output": "68 -32 8 -92"
},
{
"input": "95 -83 -39 -6",
"output": "-1"
},
{
"input": "54 94 53 -65",
"output": "-1"
},
{
"input": "-92 15 84 15",
"output": "-92 191 84 191"
},
{
"input": "67 77 -11 -1",
"output": "67 -1 -11 77"
},
{
"input": "91 -40 30 21",
"output": "91 21 30 -40"
},
{
"input": "66 -64 -25 -64",
"output": "66 27 -25 27"
},
{
"input": "-42 84 -67 59",
"output": "-42 59 -67 84"
},
{
"input": "73 47 -5 -77",
"output": "-1"
},
{
"input": "6 85 -54 -84",
"output": "-1"
},
{
"input": "-58 -55 40 43",
"output": "-58 43 40 -55"
},
{
"input": "56 22 48 70",
"output": "-1"
},
{
"input": "-17 -32 76 -32",
"output": "-17 61 76 61"
},
{
"input": "0 2 2 0",
"output": "0 0 2 2"
},
{
"input": "0 0 -1 1",
"output": "0 1 -1 0"
},
{
"input": "0 2 1 1",
"output": "0 1 1 2"
},
{
"input": "0 0 1 -1",
"output": "0 -1 1 0"
},
{
"input": "-1 2 -2 3",
"output": "-1 3 -2 2"
},
{
"input": "0 1 1 0",
"output": "0 0 1 1"
},
{
"input": "1 2 2 1",
"output": "1 1 2 2"
},
{
"input": "4 1 2 1",
"output": "4 3 2 3"
},
{
"input": "70 0 0 10",
"output": "-1"
},
{
"input": "2 3 4 1",
"output": "2 1 4 3"
},
{
"input": "1 3 3 1",
"output": "1 1 3 3"
},
{
"input": "-3 3 0 0",
"output": "-3 0 0 3"
},
{
"input": "2 8 7 3",
"output": "2 3 7 8"
},
{
"input": "1 2 2 3",
"output": "1 3 2 2"
},
{
"input": "0 3 3 0",
"output": "0 0 3 3"
},
{
"input": "0 0 -3 3",
"output": "0 3 -3 0"
},
{
"input": "0 2 1 2",
"output": "0 3 1 3"
},
{
"input": "1 1 2 0",
"output": "1 0 2 1"
},
{
"input": "0 0 5 0",
"output": "0 5 5 5"
},
{
"input": "3 4 7 8",
"output": "3 8 7 4"
},
{
"input": "0 5 5 0",
"output": "0 0 5 5"
},
{
"input": "5 6 8 3",
"output": "5 3 8 6"
},
{
"input": "2 2 1 1",
"output": "2 1 1 2"
},
{
"input": "0 1 3 1",
"output": "0 4 3 4"
},
{
"input": "2 4 5 4",
"output": "2 7 5 7"
},
{
"input": "0 5 1 5",
"output": "0 6 1 6"
},
{
"input": "4 0 0 4",
"output": "4 4 0 0"
},
{
"input": "0 1 1 8",
"output": "-1"
},
{
"input": "2 3 3 4",
"output": "2 4 3 3"
},
{
"input": "1 0 2 1",
"output": "1 1 2 0"
},
{
"input": "0 0 2 14",
"output": "-1"
},
{
"input": "0 0 4 3",
"output": "-1"
},
{
"input": "3 5 5 3",
"output": "3 3 5 5"
},
{
"input": "-1 1 1 -1",
"output": "-1 -1 1 1"
},
{
"input": "0 0 2 0",
"output": "0 2 2 2"
},
{
"input": "0 0 1 7",
"output": "-1"
},
{
"input": "1 2 3 2",
"output": "1 4 3 4"
},
{
"input": "1 12 3 10",
"output": "1 10 3 12"
}
] | 31 | 0 | 0 | 501 |
|
513 | Game | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally. | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"output": "Second"
},
{
"input": "1 1 1 1",
"output": "Second"
},
{
"input": "50 50 50 50",
"output": "Second"
},
{
"input": "50 49 1 2",
"output": "First"
},
{
"input": "50 48 3 1",
"output": "First"
},
{
"input": "48 50 12 11",
"output": "Second"
},
{
"input": "49 50 11 12",
"output": "Second"
},
{
"input": "49 49 4 1",
"output": "Second"
},
{
"input": "49 49 3 3",
"output": "Second"
},
{
"input": "1 50 1 50",
"output": "Second"
},
{
"input": "1 50 50 50",
"output": "Second"
},
{
"input": "50 1 1 1",
"output": "First"
},
{
"input": "50 1 1 50",
"output": "First"
},
{
"input": "32 31 10 9",
"output": "First"
},
{
"input": "32 4 17 3",
"output": "First"
}
] | 30 | 0 | -1 | 504 |
|
704 | Thor | [
"brute force",
"data structures",
"implementation"
] | null | null | Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
*q* events are about to happen (in chronological order). They are of three types:
1. Application *x* generates a notification (this new notification is unread). 1. Thor reads all notifications generated so far by application *x* (he may re-read some notifications). 1. Thor reads the first *t* notifications generated by phone applications (notifications generated in first *t* events of the first type). It's guaranteed that there were at least *t* events of the first type before this event. Please note that he doesn't read first *t* unread notifications, he just reads the very first *t* notifications generated on his phone and he may re-read some of them in this operation.
Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone. | The first line of input contains two integers *n* and *q* (1<=β€<=*n*,<=*q*<=β€<=300<=000)Β β the number of applications and the number of events to happen.
The next *q* lines contain the events. The *i*-th of these lines starts with an integer *type**i*Β β type of the *i*-th event. If *type**i*<==<=1 or *type**i*<==<=2 then it is followed by an integer *x**i*. Otherwise it is followed by an integer *t**i* (1<=β€<=*type**i*<=β€<=3,<=1<=β€<=*x**i*<=β€<=*n*,<=1<=β€<=*t**i*<=β€<=*q*). | Print the number of unread notifications after each event. | [
"3 4\n1 3\n1 1\n1 2\n2 3\n",
"4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n"
] | [
"1\n2\n3\n2\n",
"1\n2\n3\n0\n1\n2\n"
] | In the first sample:
1. Application 3 generates a notification (there is 1 unread notification). 1. Application 1 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads the notification generated by application 3, there are 2 unread notifications left.
In the second sample test:
1. Application 2 generates a notification (there is 1 unread notification). 1. Application 4 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left. 1. Application 3 generates a notification (there is 1 unread notification). 1. Application 3 generates a notification (there are 2 unread notifications). | [
{
"input": "3 4\n1 3\n1 1\n1 2\n2 3",
"output": "1\n2\n3\n2"
},
{
"input": "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3",
"output": "1\n2\n3\n0\n1\n2"
},
{
"input": "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5\n1 5\n2 2\n2 4\n1 7\n1 1\n2 4\n1 9\n1 1\n1 7\n1 8\n3 33\n1 10\n2 2\n1 3\n1 10\n1 6\n3 32\n2 3\n1 5\n2 10\n2 2\n2 4\n2 3\n3 16\n1 3\n2 2\n1 1\n3 18\n2 2\n2 5\n1 5\n1 9\n2 4\n1 3\n1 4\n1 3\n1 6\n1 10\n2 2\n1 7\n1 7\n2 8\n1 1\n3 1\n1 8\n1 10\n1 7\n1 8",
"output": "0\n1\n2\n2\n3\n4\n5\n4\n5\n3\n4\n5\n6\n7\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n9\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n17\n16\n17\n18\n18\n19\n20\n21\n22\n3\n4\n4\n5\n6\n7\n7\n6\n7\n5\n5\n5\n5\n5\n6\n6\n7\n7\n7\n6\n7\n8\n8\n9\n10\n11\n12\n13\n13\n14\n15\n14\n15\n15\n16\n17\n18\n19"
},
{
"input": "300000 1\n1 300000",
"output": "1"
}
] | 46 | 0 | 0 | 505 |
|
715 | Complete The Graph | [
"binary search",
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices *s* and *t* in the resulting graph is exactly *L*. Can you help him? | The first line contains five integers *n*,<=*m*,<=*L*,<=*s*,<=*t* (2<=β€<=*n*<=β€<=1000,<=<=1<=β€<=*m*<=β€<=10<=000,<=<=1<=β€<=*L*<=β€<=109,<=<=0<=β€<=*s*,<=*t*<=β€<=*n*<=-<=1,<=<=*s*<=β <=*t*)Β β the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, *m* lines describing the edges of the graph follow. *i*-th of them contains three integers, *u**i*,<=*v**i*,<=*w**i* (0<=β€<=*u**i*,<=*v**i*<=β€<=*n*<=-<=1,<=<=*u**i*<=β <=*v**i*,<=<=0<=β€<=*w**i*<=β€<=109). *u**i* and *v**i* denote the endpoints of the edge and *w**i* denotes its weight. If *w**i* is equal to 0 then the weight of the corresponding edge was erased.
It is guaranteed that there is at most one edge between any pair of vertices. | Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next *m* lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. *i*-th of them should contain three integers *u**i*, *v**i* and *w**i*, denoting an edge between vertices *u**i* and *v**i* of weight *w**i*. The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 1018.
The order of the edges in the output doesn't matter. The length of the shortest path between *s* and *t* must be equal to *L*.
If there are multiple solutions, print any of them. | [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n"
] | [
"YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n",
"YES\n0 1 123456789\n",
"NO\n"
] | Here's how the graph in the first sample case looks like :
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456789.
In the last sample case, there is no weights to assign but the length of the shortest path doesn't match the required value, so the answer is "NO". | [
{
"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4",
"output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"
},
{
"input": "2 1 123456789 0 1\n0 1 0",
"output": "YES\n0 1 123456789"
},
{
"input": "2 1 999999999 1 0\n0 1 1000000000",
"output": "NO"
},
{
"input": "4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6",
"output": "NO"
},
{
"input": "100 1 123456 99 0\n0 99 123456",
"output": "YES\n0 99 123456"
},
{
"input": "1000 1 5 999 0\n0 999 0",
"output": "YES\n0 999 5"
},
{
"input": "1000 1 1000000000 998 0\n0 999 0",
"output": "NO"
},
{
"input": "4 4 14 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12",
"output": "NO"
},
{
"input": "4 4 13 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12",
"output": "YES\n1 3 13\n2 3 1000000000000000000\n2 0 1000000000000000000\n1 0 12"
},
{
"input": "4 4 2 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 0",
"output": "NO"
},
{
"input": "4 4 8 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 6",
"output": "YES\n1 3 13\n2 3 1\n2 0 1\n1 0 6"
},
{
"input": "5 6 1000000000 0 4\n0 1 1\n2 0 2\n3 0 3\n4 1 0\n4 2 0\n3 4 0",
"output": "YES\n0 1 1\n2 0 2\n3 0 3\n4 1 999999999\n4 2 1000000000000000000\n3 4 1000000000000000000"
},
{
"input": "7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61",
"output": "YES\n0 1 1\n1 2 199\n2 3 318\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61"
},
{
"input": "7 9 319 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61",
"output": "YES\n0 1 1\n1 2 198\n2 3 317\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61"
},
{
"input": "7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1",
"output": "YES\n0 1 1\n1 2 999999996\n2 3 999999997\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1"
},
{
"input": "5 5 2 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0",
"output": "YES\n0 1 1\n1 2 1\n0 4 1000000000000000000\n4 3 1000000000000000000\n3 2 1000000000000000000"
},
{
"input": "5 5 1 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0",
"output": "NO"
},
{
"input": "5 5 3 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0",
"output": "NO"
},
{
"input": "8 9 10 1 0\n1 2 1\n2 4 1\n1 3 0\n3 4 0\n4 5 0\n5 6 1\n6 0 1\n5 7 0\n7 0 0",
"output": "YES\n1 2 1\n2 4 1\n1 3 1000000000000000000\n3 4 1000000000000000000\n4 5 6\n5 6 1\n6 0 1\n5 7 1000000000000000000\n7 0 1000000000000000000"
},
{
"input": "4 5 7 0 3\n0 1 0\n1 2 3\n2 3 0\n0 2 5\n1 3 5",
"output": "YES\n0 1 2\n1 2 3\n2 3 3\n0 2 5\n1 3 5"
}
] | 280 | 13,824,000 | 3 | 506 |
|
455 | Boredom | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105). | Print a single integer β the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2,β2,β2,β2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 31 | 0 | 0 | 507 |
|
667 | Pouring Rain | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter. | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=β€<=*d*,<=*h*,<=*v*,<=*e*<=β€<=104), where:
- *d* β the diameter of your cylindrical cup, - *h* β the initial level of water in the cup, - *v* β the speed of drinking process from the cup in milliliters per second, - *e* β the growth of water because of rain if you do not drink from the cup. | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input": "20 287 3845 5",
"output": "YES\n39.646277165210"
},
{
"input": "48 6428 9807 83",
"output": "NO"
},
{
"input": "72 5272 4552 64",
"output": "NO"
},
{
"input": "100 4117 5106 34",
"output": "NO"
},
{
"input": "20 2961 9852 15",
"output": "YES\n180.991437129723"
},
{
"input": "48 1805 3109 93",
"output": "NO"
},
{
"input": "72 8534 7042 65",
"output": "NO"
},
{
"input": "1 47 80 68",
"output": "YES\n1.388102806810"
},
{
"input": "4 495 8813 1",
"output": "YES\n0.706823517575"
},
{
"input": "5 2797 5925 9",
"output": "YES\n9.553973511669"
},
{
"input": "1 8324 4362 23",
"output": "YES\n1.505007106354"
},
{
"input": "6 1976 8455 3",
"output": "YES\n6.674898722265"
},
{
"input": "7 2644 8080 5",
"output": "YES\n12.900417790197"
},
{
"input": "3 4183 5491 98",
"output": "YES\n6.162185601824"
},
{
"input": "2 8591 320 101",
"output": "YES\n9999.259991757254"
},
{
"input": "10000 10000 10000 10000",
"output": "NO"
},
{
"input": "2 5000 12 3",
"output": "YES\n6099.653943875812"
},
{
"input": "10 1000 100 1",
"output": "YES\n3659.792366325487"
}
] | 140 | 0 | 3 | 509 |
|
0 | none | [
"none"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100)Β β the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input": "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo",
"output": "gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo"
},
{
"input": "10\nogooggoggo",
"output": "***oggoggo"
},
{
"input": "20\nooggooogooogooogooog",
"output": "ooggoo***o***o***oog"
},
{
"input": "30\ngoggogoooggooggggoggoggoogoggo",
"output": "gogg***ooggooggggoggoggo***ggo"
},
{
"input": "40\nogggogooggoogoogggogooogogggoogggooggooo",
"output": "oggg***oggo***oggg***o***gggoogggooggooo"
},
{
"input": "50\noggggogoogggggggoogogggoooggooogoggogooogogggogooo",
"output": "ogggg***ogggggggo***gggoooggoo***gg***o***ggg***oo"
},
{
"input": "60\nggoooogoggogooogogooggoogggggogogogggggogggogooogogogggogooo",
"output": "ggooo***gg***o***oggooggggg***gggggoggg***o***ggg***oo"
},
{
"input": "70\ngogoooggggoggoggggggoggggoogooogogggggooogggogoogoogoggogggoggogoooooo",
"output": "g***ooggggoggoggggggoggggo***o***gggggoooggg*********ggogggogg***ooooo"
},
{
"input": "80\nooogoggoooggogogoggooooogoogogooogoggggogggggogoogggooogooooooggoggoggoggogoooog",
"output": "oo***ggooogg***ggoooo******o***ggggoggggg***ogggoo***oooooggoggoggogg***ooog"
},
{
"input": "90\nooogoggggooogoggggoooogggggooggoggoggooooooogggoggogggooggggoooooogoooogooggoooogggggooooo",
"output": "oo***ggggoo***ggggoooogggggooggoggoggooooooogggoggogggooggggooooo***oo***oggoooogggggooooo"
},
{
"input": "100\ngooogoggooggggoggoggooooggogoogggoogogggoogogoggogogogoggogggggogggggoogggooogogoggoooggogoooooogogg",
"output": "goo***ggooggggoggoggoooogg***ogggo***gggo***gg***ggogggggogggggoogggoo***ggooogg***oooo***gg"
},
{
"input": "100\ngoogoogggogoooooggoogooogoogoogogoooooogooogooggggoogoggogooogogogoogogooooggoggogoooogooooooggogogo",
"output": "go***oggg***ooooggo***o*********oooo***o***oggggo***gg***o******oooggogg***oo***ooooogg***"
},
{
"input": "100\ngoogoggggogggoooggoogoogogooggoggooggggggogogggogogggoogogggoogoggoggogooogogoooogooggggogggogggoooo",
"output": "go***ggggogggoooggo******oggoggoogggggg***ggg***gggo***gggo***ggogg***o***oo***oggggogggogggoooo"
},
{
"input": "100\nogogogogogoggogogogogogogoggogogogoogoggoggooggoggogoogoooogogoogggogogogogogoggogogogogogogogogogoe",
"output": "***gg***gg******ggoggooggogg******oo***oggg***gg***e"
},
{
"input": "5\nogoga",
"output": "***ga"
},
{
"input": "1\no",
"output": "o"
},
{
"input": "100\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogog",
"output": "***g"
},
{
"input": "99\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo",
"output": "***"
},
{
"input": "5\nggggg",
"output": "ggggg"
},
{
"input": "6\ngoogoo",
"output": "go***o"
},
{
"input": "7\nooogooo",
"output": "oo***oo"
},
{
"input": "8\ngggggggg",
"output": "gggggggg"
},
{
"input": "9\nogggogggg",
"output": "ogggogggg"
},
{
"input": "10\nogogoggogo",
"output": "***gg***"
},
{
"input": "11\noooggooggog",
"output": "oooggooggog"
},
{
"input": "12\nogggooooggog",
"output": "ogggooooggog"
},
{
"input": "13\nogoggogogooog",
"output": "***gg***oog"
},
{
"input": "15\nggooogoooggoggg",
"output": "ggoo***ooggoggg"
},
{
"input": "14\noogooooggooggo",
"output": "o***oooggooggo"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "1\ng",
"output": "g"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "46\nsdfkogogogogergergogogergerogogogogoergoegogog",
"output": "sdfk***gergerg***gerger***ergoeg***g"
},
{
"input": "86\ngdfggogogodfogogdofgoodfogodgodgfogoogdodhbofgobgbgfogoogdfogogogogogoogggsgfosogodgon",
"output": "gdfgg***df***gdofgoodf***dgodgf***ogdodhbofgobgbgf***ogdf***ogggsgfos***dgon"
},
{
"input": "83\nergegergoogogogerogoerorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgtogooggsdgogoog",
"output": "ergegergo***ger***erorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgt***oggsdg***og"
},
{
"input": "2\nog",
"output": "og"
},
{
"input": "4\nogog",
"output": "***g"
},
{
"input": "4\nogoo",
"output": "***o"
},
{
"input": "29\naaaogogogogogogogogogogogobbb",
"output": "aaa***bbb"
},
{
"input": "11\nogogogogogo",
"output": "***"
},
{
"input": "9\nogogogogo",
"output": "***"
},
{
"input": "3\nogo",
"output": "***"
},
{
"input": "15\nogogogogogogogo",
"output": "***"
},
{
"input": "25\nogogogogogogogogogogogogo",
"output": "***"
}
] | 93 | 819,200 | 3 | 510 |
|
869 | The Eternal Immortality | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessorΒ β as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=Γ<=2<=Γ<=...<=Γ<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=β₯<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. | The first and only line of input contains two space-separated integers *a* and *b* (0<=β€<=*a*<=β€<=*b*<=β€<=1018). | Output one line containing a single decimal digitΒ β the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
"output": "0"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 15",
"output": "0"
},
{
"input": "24 26",
"output": "0"
},
{
"input": "14 60",
"output": "0"
},
{
"input": "11 79",
"output": "0"
},
{
"input": "1230 1232",
"output": "2"
},
{
"input": "2633 2634",
"output": "4"
},
{
"input": "535 536",
"output": "6"
},
{
"input": "344319135 396746843",
"output": "0"
},
{
"input": "696667767 696667767",
"output": "1"
},
{
"input": "419530302 610096911",
"output": "0"
},
{
"input": "238965115 821731161",
"output": "0"
},
{
"input": "414626436 728903812",
"output": "0"
},
{
"input": "274410639 293308324",
"output": "0"
},
{
"input": "650636673091305697 650636673091305702",
"output": "0"
},
{
"input": "651240548333620923 651240548333620924",
"output": "4"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "0 4",
"output": "4"
},
{
"input": "50000000062000007 50000000062000011",
"output": "0"
},
{
"input": "0 0",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "0 2",
"output": "2"
},
{
"input": "10000000000012 10000000000015",
"output": "0"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "12 23",
"output": "0"
},
{
"input": "0 11",
"output": "0"
},
{
"input": "11111234567890 11111234567898",
"output": "0"
},
{
"input": "0 3",
"output": "6"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999999999999999997 999999999999999999",
"output": "2"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "0 1",
"output": "1"
},
{
"input": "101 1002",
"output": "0"
},
{
"input": "0 100000000000000001",
"output": "0"
},
{
"input": "99999999999999997 99999999999999999",
"output": "2"
},
{
"input": "14 15",
"output": "5"
},
{
"input": "8 19",
"output": "0"
},
{
"input": "12 22",
"output": "0"
},
{
"input": "999999999999996 999999999999999",
"output": "4"
},
{
"input": "1 3",
"output": "6"
},
{
"input": "124 125",
"output": "5"
},
{
"input": "11 32",
"output": "0"
},
{
"input": "0 5",
"output": "0"
},
{
"input": "0 999999",
"output": "0"
},
{
"input": "151151151515 151151151526",
"output": "0"
},
{
"input": "6 107",
"output": "0"
},
{
"input": "5 16",
"output": "0"
},
{
"input": "7 16",
"output": "0"
},
{
"input": "6 19",
"output": "0"
},
{
"input": "11113111111111 13111111111111",
"output": "0"
},
{
"input": "1 1000",
"output": "0"
},
{
"input": "24 25",
"output": "5"
},
{
"input": "0 100000000000",
"output": "0"
},
{
"input": "1 22",
"output": "0"
},
{
"input": "999999999999999996 999999999999999999",
"output": "4"
}
] | 31 | 0 | -1 | 512 |
|
389 | Fox and Number Game | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum. | The first line contains an integer *n* (2<=β€<=*n*<=β€<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=β€<=*x**i*<=β€<=100). | Output a single integer β the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"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": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 62 | 0 | 0 | 514 |
|
991 | Getting an A | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically Β β he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the studentΒ β $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help VasyaΒ β calculate the minimum amount of lab works Vasya has to redo. | The first line contains a single integer $n$Β β the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$Β β Vasya's grades for his lab works. | Output a single integerΒ β the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
{
"input": "8\n5 4 2 5 5 2 5 5",
"output": "1"
},
{
"input": "5\n5 5 2 5 5",
"output": "1"
},
{
"input": "6\n5 5 5 5 5 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "5"
},
{
"input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4",
"output": "40"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "4\n3 2 5 5",
"output": "1"
},
{
"input": "6\n4 3 3 3 3 4",
"output": "4"
},
{
"input": "8\n3 3 5 3 3 3 5 5",
"output": "3"
},
{
"input": "10\n2 4 5 5 5 5 2 3 3 2",
"output": "3"
},
{
"input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2",
"output": "10"
},
{
"input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4",
"output": "13"
},
{
"input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2",
"output": "15"
},
{
"input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5",
"output": "14"
},
{
"input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2",
"output": "33"
},
{
"input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4",
"output": "34"
},
{
"input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5",
"output": "16"
},
{
"input": "99\n2 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 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 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 2 2 2 2 2 2 2 2",
"output": "83"
},
{
"input": "100\n2 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 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 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 2 2 2 2 2 2 2 2 2",
"output": "84"
},
{
"input": "99\n3 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 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 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 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "75"
},
{
"input": "100\n3 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 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 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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "75"
},
{
"input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3",
"output": "75"
},
{
"input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2",
"output": "75"
},
{
"input": "99\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "50"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "50"
},
{
"input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4",
"output": "54"
},
{
"input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4",
"output": "50"
},
{
"input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3",
"output": "51"
},
{
"input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4",
"output": "51"
},
{
"input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3",
"output": "58"
},
{
"input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3",
"output": "61"
},
{
"input": "99\n5 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 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 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 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "100\n5 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 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 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 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5",
"output": "48"
},
{
"input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5",
"output": "38"
},
{
"input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3",
"output": "32"
},
{
"input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5",
"output": "32"
},
{
"input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3",
"output": "39"
},
{
"input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2",
"output": "42"
},
{
"input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4",
"output": "0"
},
{
"input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4",
"output": "1"
},
{
"input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4",
"output": "37"
},
{
"input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2",
"output": "31"
},
{
"input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3",
"output": "24"
},
{
"input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5",
"output": "19"
},
{
"input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4",
"output": "37"
},
{
"input": "2\n5 2",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "5"
},
{
"input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2",
"output": "61"
},
{
"input": "100\n5 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 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "1"
},
{
"input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5",
"output": "35"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5",
"output": "1"
}
] | 77 | 6,963,200 | 3 | 516 |
|
30 | Accounting | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative β it means that there was a loss in the correspondent year).
King wants to show financial stability. To do this, he needs to find common coefficient *X* β the coefficient of income growth during one year. This coefficient should satisfy the equation:
Surely, the king is not going to do this job by himself, and demands you to find such number *X*.
It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=β€<=1000, 1<=β€<=*n*<=β€<=10). | Output the required integer coefficient *X*, or Β«No solutionΒ», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "4 972 1",
"output": "243"
},
{
"input": "-1 -1 5",
"output": "1"
},
{
"input": "-1 0 4",
"output": "0"
},
{
"input": "-7 0 1",
"output": "0"
},
{
"input": "-5 -5 3",
"output": "1"
},
{
"input": "-5 -5 9",
"output": "1"
},
{
"input": "-5 -5 6",
"output": "1"
},
{
"input": "-4 0 1",
"output": "0"
},
{
"input": "-5 0 3",
"output": "0"
},
{
"input": "-4 4 9",
"output": "-1"
},
{
"input": "10 0 6",
"output": "0"
},
{
"input": "-5 3 4",
"output": "No solution"
},
{
"input": "0 3 6",
"output": "No solution"
},
{
"input": "3 6 10",
"output": "No solution"
},
{
"input": "-3 7 5",
"output": "No solution"
},
{
"input": "-526 526 1",
"output": "-1"
},
{
"input": "-373 373 3",
"output": "-1"
},
{
"input": "-141 0 8",
"output": "0"
},
{
"input": "7 175 1",
"output": "25"
},
{
"input": "-5 -560 1",
"output": "112"
},
{
"input": "-1 -512 10",
"output": "No solution"
},
{
"input": "-3 -768 8",
"output": "2"
},
{
"input": "-3 -768 7",
"output": "No solution"
},
{
"input": "-3 -768 9",
"output": "No solution"
},
{
"input": "-3 -768 4",
"output": "4"
},
{
"input": "4 972 4",
"output": "No solution"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "4 972 6",
"output": "No solution"
},
{
"input": "4 972 1",
"output": "243"
},
{
"input": "4 972 2",
"output": "No solution"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1 5",
"output": "1"
},
{
"input": "1 1 4",
"output": "1"
},
{
"input": "1 -1 1",
"output": "-1"
}
] | 92 | 0 | 3.977 | 518 |
285 | Slightly Decreasing Permutations | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=β€<=*i*<=<<=*n*), that *p**i*<=><=*p**i*<=+<=1.
You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*. | The single line contains two space-separated integers: *n*,<=*k* (1<=β€<=*n*<=β€<=105,<=0<=β€<=*k*<=<<=*n*) β the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* β the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input": "10 4",
"output": "10 9 8 7 1 2 3 4 5 6"
},
{
"input": "56893 5084",
"output": "56893 56892 56891 56890 56889 56888 56887 56886 56885 56884 56883 56882 56881 56880 56879 56878 56877 56876 56875 56874 56873 56872 56871 56870 56869 56868 56867 56866 56865 56864 56863 56862 56861 56860 56859 56858 56857 56856 56855 56854 56853 56852 56851 56850 56849 56848 56847 56846 56845 56844 56843 56842 56841 56840 56839 56838 56837 56836 56835 56834 56833 56832 56831 56830 56829 56828 56827 56826 56825 56824 56823 56822 56821 56820 56819 56818 56817 56816 56815 56814 56813 56812 56811 56810 56809 5..."
},
{
"input": "6 3",
"output": "6 5 4 1 2 3"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "310 186",
"output": "310 309 308 307 306 305 304 303 302 301 300 299 298 297 296 295 294 293 292 291 290 289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183..."
},
{
"input": "726 450",
"output": "726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599..."
},
{
"input": "438 418",
"output": "438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311..."
},
{
"input": "854 829",
"output": "854 853 852 851 850 849 848 847 846 845 844 843 842 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 786 785 784 783 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727..."
},
{
"input": "214 167",
"output": "214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 ..."
},
{
"input": "85705 56268",
"output": "85705 85704 85703 85702 85701 85700 85699 85698 85697 85696 85695 85694 85693 85692 85691 85690 85689 85688 85687 85686 85685 85684 85683 85682 85681 85680 85679 85678 85677 85676 85675 85674 85673 85672 85671 85670 85669 85668 85667 85666 85665 85664 85663 85662 85661 85660 85659 85658 85657 85656 85655 85654 85653 85652 85651 85650 85649 85648 85647 85646 85645 85644 85643 85642 85641 85640 85639 85638 85637 85636 85635 85634 85633 85632 85631 85630 85629 85628 85627 85626 85625 85624 85623 85622 85621 8..."
},
{
"input": "11417 4583",
"output": "11417 11416 11415 11414 11413 11412 11411 11410 11409 11408 11407 11406 11405 11404 11403 11402 11401 11400 11399 11398 11397 11396 11395 11394 11393 11392 11391 11390 11389 11388 11387 11386 11385 11384 11383 11382 11381 11380 11379 11378 11377 11376 11375 11374 11373 11372 11371 11370 11369 11368 11367 11366 11365 11364 11363 11362 11361 11360 11359 11358 11357 11356 11355 11354 11353 11352 11351 11350 11349 11348 11347 11346 11345 11344 11343 11342 11341 11340 11339 11338 11337 11336 11335 11334 11333 1..."
},
{
"input": "53481 20593",
"output": "53481 53480 53479 53478 53477 53476 53475 53474 53473 53472 53471 53470 53469 53468 53467 53466 53465 53464 53463 53462 53461 53460 53459 53458 53457 53456 53455 53454 53453 53452 53451 53450 53449 53448 53447 53446 53445 53444 53443 53442 53441 53440 53439 53438 53437 53436 53435 53434 53433 53432 53431 53430 53429 53428 53427 53426 53425 53424 53423 53422 53421 53420 53419 53418 53417 53416 53415 53414 53413 53412 53411 53410 53409 53408 53407 53406 53405 53404 53403 53402 53401 53400 53399 53398 53397 5..."
},
{
"input": "79193 77281",
"output": "79193 79192 79191 79190 79189 79188 79187 79186 79185 79184 79183 79182 79181 79180 79179 79178 79177 79176 79175 79174 79173 79172 79171 79170 79169 79168 79167 79166 79165 79164 79163 79162 79161 79160 79159 79158 79157 79156 79155 79154 79153 79152 79151 79150 79149 79148 79147 79146 79145 79144 79143 79142 79141 79140 79139 79138 79137 79136 79135 79134 79133 79132 79131 79130 79129 79128 79127 79126 79125 79124 79123 79122 79121 79120 79119 79118 79117 79116 79115 79114 79113 79112 79111 79110 79109 7..."
},
{
"input": "42607 42144",
"output": "42607 42606 42605 42604 42603 42602 42601 42600 42599 42598 42597 42596 42595 42594 42593 42592 42591 42590 42589 42588 42587 42586 42585 42584 42583 42582 42581 42580 42579 42578 42577 42576 42575 42574 42573 42572 42571 42570 42569 42568 42567 42566 42565 42564 42563 42562 42561 42560 42559 42558 42557 42556 42555 42554 42553 42552 42551 42550 42549 42548 42547 42546 42545 42544 42543 42542 42541 42540 42539 42538 42537 42536 42535 42534 42533 42532 42531 42530 42529 42528 42527 42526 42525 42524 42523 4..."
},
{
"input": "100000 0",
"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": "100000 99999",
"output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..."
},
{
"input": "100000 53860",
"output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..."
},
{
"input": "4 0",
"output": "1 2 3 4"
},
{
"input": "4 1",
"output": "4 1 2 3"
},
{
"input": "4 2",
"output": "4 3 1 2"
},
{
"input": "4 3",
"output": "4 3 2 1"
},
{
"input": "3 1",
"output": "3 1 2"
}
] | 186 | 9,728,000 | 3 | 519 |
|
653 | Bear and Three Balls | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easyΒ β there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above. | The first line of the input contains one integer *n* (3<=β€<=*n*<=β€<=50)Β β the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t**i*<=β€<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
"input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543",
"output": "NO"
},
{
"input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869",
"output": "YES"
},
{
"input": "3\n408 410 409",
"output": "YES"
},
{
"input": "3\n903 902 904",
"output": "YES"
},
{
"input": "3\n399 400 398",
"output": "YES"
},
{
"input": "3\n450 448 449",
"output": "YES"
},
{
"input": "3\n390 389 388",
"output": "YES"
},
{
"input": "3\n438 439 440",
"output": "YES"
},
{
"input": "11\n488 688 490 94 564 615 641 170 489 517 669",
"output": "YES"
},
{
"input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954",
"output": "YES"
},
{
"input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318",
"output": "YES"
},
{
"input": "6\n10 79 306 334 304 305",
"output": "YES"
},
{
"input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365",
"output": "YES"
},
{
"input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73",
"output": "YES"
},
{
"input": "11\n325 325 324 324 324 325 325 324 324 324 324",
"output": "NO"
},
{
"input": "7\n517 517 518 517 518 518 518",
"output": "NO"
},
{
"input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710",
"output": "NO"
},
{
"input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29",
"output": "NO"
},
{
"input": "7\n880 880 514 536 881 881 879",
"output": "YES"
},
{
"input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375",
"output": "YES"
},
{
"input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404",
"output": "YES"
},
{
"input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987",
"output": "YES"
},
{
"input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116",
"output": "NO"
},
{
"input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995",
"output": "NO"
},
{
"input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22",
"output": "YES"
},
{
"input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952",
"output": "YES"
},
{
"input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "3\n500 999 1000",
"output": "NO"
},
{
"input": "10\n101 102 104 105 107 109 110 112 113 115",
"output": "NO"
},
{
"input": "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": "NO"
},
{
"input": "50\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",
"output": "NO"
},
{
"input": "3\n1000 999 998",
"output": "YES"
},
{
"input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456",
"output": "NO"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3",
"output": "YES"
},
{
"input": "3\n999 999 1000",
"output": "NO"
},
{
"input": "9\n2 4 5 13 25 100 200 300 400",
"output": "NO"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n998 999 1000",
"output": "YES"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 2 2 4",
"output": "NO"
},
{
"input": "4\n4 3 4 5",
"output": "YES"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "NO"
},
{
"input": "3\n2 3 2",
"output": "NO"
},
{
"input": "5\n10 5 6 3 2",
"output": "NO"
},
{
"input": "3\n1 2 1",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "4\n998 999 1000 1000",
"output": "YES"
},
{
"input": "5\n2 3 9 9 4",
"output": "YES"
},
{
"input": "4\n1 2 4 4",
"output": "NO"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "7\n1 2 2 2 4 5 6",
"output": "YES"
},
{
"input": "5\n1 3 10 3 10",
"output": "NO"
},
{
"input": "3\n1 2 2",
"output": "NO"
},
{
"input": "4\n1000 1000 999 998",
"output": "YES"
},
{
"input": "3\n5 3 7",
"output": "NO"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "YES"
},
{
"input": "9\n6 6 6 5 5 5 4 4 4",
"output": "YES"
},
{
"input": "7\n5 6 6 6 7 7 7",
"output": "YES"
},
{
"input": "5\n2 3 3 3 4",
"output": "YES"
},
{
"input": "5\n2 1 2 1 3",
"output": "YES"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "3\n1000 1000 1000",
"output": "NO"
},
{
"input": "5\n1 100 2 100 3",
"output": "YES"
},
{
"input": "5\n5 4 6 5 5",
"output": "YES"
},
{
"input": "12\n1 1 1 1 2 2 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "5\n9 9 1 2 3",
"output": "YES"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "YES"
},
{
"input": "7\n1 1 1 1 2 3 3",
"output": "YES"
},
{
"input": "3\n13 13 13",
"output": "NO"
},
{
"input": "3\n42 42 42",
"output": "NO"
},
{
"input": "8\n1 1 1 1 2 2 2 2",
"output": "NO"
},
{
"input": "6\n1 1 1 1 2 3",
"output": "YES"
},
{
"input": "6\n1 1 2 2 6 6",
"output": "NO"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "NO"
},
{
"input": "9\n1 2 3 1 2 3 1 2 3",
"output": "YES"
},
{
"input": "4\n1 2 1 100",
"output": "NO"
},
{
"input": "5\n1 1 2 2 3",
"output": "YES"
}
] | 62 | 5,120,000 | 3 | 521 |
|
863 | Quasi-palindrome | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number. | The first line contains one integer number *x* (1<=β€<=*x*<=β€<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
},
{
"input": "102000",
"output": "NO"
},
{
"input": "210000000",
"output": "NO"
},
{
"input": "213443120",
"output": "YES"
},
{
"input": "99",
"output": "YES"
},
{
"input": "22002",
"output": "NO"
},
{
"input": "1010",
"output": "YES"
},
{
"input": "1201",
"output": "NO"
},
{
"input": "6460046",
"output": "NO"
},
{
"input": "503435",
"output": "NO"
},
{
"input": "21002",
"output": "NO"
},
{
"input": "101001",
"output": "NO"
},
{
"input": "200102",
"output": "NO"
},
{
"input": "20010002",
"output": "NO"
},
{
"input": "33003",
"output": "NO"
},
{
"input": "100101",
"output": "NO"
},
{
"input": "1021",
"output": "NO"
},
{
"input": "1101",
"output": "NO"
},
{
"input": "10101100",
"output": "NO"
},
{
"input": "101",
"output": "YES"
},
{
"input": "1011",
"output": "NO"
},
{
"input": "11010",
"output": "NO"
},
{
"input": "10110",
"output": "NO"
},
{
"input": "110000",
"output": "YES"
},
{
"input": "2011",
"output": "NO"
},
{
"input": "10020001",
"output": "NO"
},
{
"input": "12505021",
"output": "NO"
},
{
"input": "12310",
"output": "NO"
},
{
"input": "100501",
"output": "NO"
},
{
"input": "11001",
"output": "NO"
},
{
"input": "20020002",
"output": "NO"
},
{
"input": "202002",
"output": "NO"
},
{
"input": "1001",
"output": "YES"
},
{
"input": "1020021",
"output": "NO"
},
{
"input": "60660",
"output": "NO"
},
{
"input": "98809",
"output": "NO"
},
{
"input": "11000000",
"output": "YES"
},
{
"input": "807008",
"output": "NO"
}
] | 109 | 0 | 3 | 522 |
|
382 | Arithmetic Progression | [
"implementation",
"sortings"
] | null | null | Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills:
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has *n* cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting *n*<=+<=1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled. | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of cards. The next line contains the sequence of integers β the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108. | If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples). | [
"3\n4 1 7\n",
"1\n10\n",
"4\n1 3 5 9\n",
"4\n4 3 4 5\n",
"2\n2 4\n"
] | [
"2\n-2 10\n",
"-1\n",
"1\n7\n",
"0\n",
"3\n0 3 6\n"
] | none | [
{
"input": "3\n4 1 7",
"output": "2\n-2 10"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "4\n1 3 5 9",
"output": "1\n7"
},
{
"input": "4\n4 3 4 5",
"output": "0"
},
{
"input": "2\n2 4",
"output": "3\n0 3 6"
},
{
"input": "4\n1 3 4 5",
"output": "1\n2"
},
{
"input": "2\n3 3",
"output": "1\n3"
},
{
"input": "2\n13 2",
"output": "2\n-9 24"
},
{
"input": "5\n2 2 2 2 2",
"output": "1\n2"
},
{
"input": "6\n11 1 7 9 5 13",
"output": "1\n3"
},
{
"input": "2\n100000000 1",
"output": "2\n-99999998 199999999"
},
{
"input": "5\n2 3 1 4 6",
"output": "1\n5"
},
{
"input": "5\n1 2 2 3 4",
"output": "0"
},
{
"input": "3\n1 4 2",
"output": "1\n3"
},
{
"input": "3\n8 8 8",
"output": "1\n8"
},
{
"input": "5\n2 2 2 2 3",
"output": "0"
},
{
"input": "1\n100000000",
"output": "-1"
},
{
"input": "20\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45",
"output": "2\n0 63"
},
{
"input": "40\n100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000",
"output": "1\n100000000"
},
{
"input": "49\n81787 163451 104059 89211 96635 133755 148603 141179 159739 122619 123 144891 70651 11259 63227 3835 44667 37243 100347 26107 137467 18683 156027 59515 22395 40955 111483 52091 7547 85499 107771 178299 115195 152315 74363 126331 33531 130043 14971 48379 167163 182011 170875 78075 174587 55803 66939 29819 118907",
"output": "1\n92923"
},
{
"input": "9\n1 2 3 3 4 4 5 5 6",
"output": "0"
},
{
"input": "7\n1 1 2 3 4 5 6",
"output": "0"
},
{
"input": "2\n4 1",
"output": "2\n-2 7"
},
{
"input": "2\n2 100000000",
"output": "3\n-99999996 50000001 199999998"
},
{
"input": "8\n1 2 3 4 11 12 13 14",
"output": "0"
},
{
"input": "7\n5 40 45 50 55 60 65",
"output": "0"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "2\n1 1",
"output": "1\n1"
},
{
"input": "2\n100000000 2",
"output": "3\n-99999996 50000001 199999998"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "5\n1 3 5 9 13",
"output": "0"
},
{
"input": "5\n1 2 4 8 16",
"output": "0"
},
{
"input": "3\n2 2 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 8",
"output": "0"
},
{
"input": "3\n1 3 4",
"output": "1\n2"
},
{
"input": "5\n1 2 4 6 7",
"output": "0"
},
{
"input": "4\n1 5 9 11",
"output": "0"
},
{
"input": "4\n3 4 5 9",
"output": "0"
},
{
"input": "4\n1 5 6 8",
"output": "0"
},
{
"input": "4\n2 6 8 12",
"output": "0"
},
{
"input": "5\n1 2 3 5 7",
"output": "0"
},
{
"input": "6\n1 2 3 4 6 8",
"output": "0"
}
] | 109 | 0 | 0 | 523 |
|
0 | none | [
"none"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 62 | 5,529,600 | 0 | 524 |
|
471 | MUH and Sticks | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=β€<=*l**i*<=β€<=9) β the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wΔ±thout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 77 | 0 | 3 | 525 |
|
1,007 | Reorder the Array | [
"combinatorics",
"data structures",
"math",
"sortings",
"two pointers"
] | null | null | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$)Β β the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β the elements of the array. | Print a single integerΒ β the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. | [
"7\n10 1 1 1 5 5 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"0\n"
] | In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | [
{
"input": "7\n10 1 1 1 5 5 3",
"output": "4"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000",
"output": "3"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "7\n3 5 2 2 5 2 4",
"output": "4"
},
{
"input": "5\n1 5 4 2 3",
"output": "4"
}
] | 124 | 0 | 0 | 526 |
|
743 | Vladik and cards | [
"binary search",
"bitmasks",
"brute force",
"dp"
] | null | null | Vladik was bored on his way home and decided to play the following game. He took *n* cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
- the number of occurrences of each number from 1 to 8 in the subsequence doesn't differ by more then 1 from the number of occurrences of any other number. Formally, if there are *c**k* cards with number *k* on them in the subsequence, than for all pairs of integers the condition |*c**i*<=-<=*c**j*|<=β€<=1 must hold. - if there is at least one card with number *x* on it in the subsequence, then all cards with number *x* in this subsequence must form a continuous segment in it (but not necessarily a continuous segment in the original sequence). For example, the subsequence [1,<=1,<=2,<=2] satisfies this condition while the subsequence [1,<=2,<=2,<=1] doesn't. Note that [1,<=1,<=2,<=2] doesn't satisfy the first condition.
Please help Vladik to find the length of the longest subsequence that satisfies both conditions. | The first line contains single integer *n* (1<=β€<=*n*<=β€<=1000)Β β the number of cards in Vladik's sequence.
The second line contains the sequence of *n* positive integers not exceeding 8Β β the description of Vladik's sequence. | Print single integerΒ β the length of the longest subsequence of Vladik's sequence that satisfies both conditions. | [
"3\n1 1 1\n",
"8\n8 7 6 5 4 3 2 1\n",
"24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\n"
] | [
"1",
"8",
"17"
] | In the first sample all the numbers written on the cards are equal, so you can't take more than one card, otherwise you'll violate the first condition. | [
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "8\n8 7 6 5 4 3 2 1",
"output": "8"
},
{
"input": "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8",
"output": "17"
},
{
"input": "1\n8",
"output": "1"
},
{
"input": "2\n5 4",
"output": "2"
},
{
"input": "3\n3 3 2",
"output": "2"
},
{
"input": "18\n3 6 6 8 8 1 1 4 4 3 3 5 5 7 7 2 2 3",
"output": "16"
},
{
"input": "5\n2 6 1 2 6",
"output": "3"
},
{
"input": "6\n4 3 1 6 7 4",
"output": "5"
},
{
"input": "7\n8 8 2 6 1 8 5",
"output": "5"
},
{
"input": "8\n2 8 4 7 5 3 6 1",
"output": "8"
},
{
"input": "8\n8 6 3 6 7 5 5 3",
"output": "5"
},
{
"input": "15\n5 2 2 7 5 2 6 4 3 8 1 8 4 2 7",
"output": "9"
},
{
"input": "15\n8 8 1 6 2 2 4 5 4 2 4 8 2 5 2",
"output": "6"
},
{
"input": "16\n8 2 1 5 7 6 2 5 4 4 8 2 2 6 3 8",
"output": "10"
},
{
"input": "16\n2 2 8 8 5 5 3 3 7 7 1 1 6 6 4 4",
"output": "16"
},
{
"input": "18\n4 3 3 3 7 7 5 2 1 1 3 3 6 1 2 4 1 8",
"output": "11"
},
{
"input": "30\n5 5 4 8 6 6 7 7 8 2 2 2 1 4 4 4 8 8 6 3 5 7 7 3 7 1 6 1 1 8",
"output": "19"
},
{
"input": "30\n1 7 2 2 2 3 1 1 1 3 7 3 7 3 7 7 1 7 6 6 6 5 5 5 4 4 4 8 8 8",
"output": "24"
},
{
"input": "120\n6 7 8 5 2 8 5 4 6 4 3 2 5 6 5 7 5 7 1 7 4 6 4 1 4 1 1 7 6 7 3 7 4 7 4 6 4 7 6 6 6 5 5 7 3 5 3 7 2 2 4 2 5 6 8 4 1 2 2 8 3 3 2 5 6 4 3 6 2 4 1 4 2 8 8 3 7 6 4 7 2 7 3 3 8 8 6 8 7 7 6 8 3 2 5 2 6 5 7 5 7 5 3 2 6 2 6 5 7 8 7 7 2 6 5 4 2 3 1 8",
"output": "34"
},
{
"input": "120\n5 4 1 4 1 7 7 1 1 1 8 2 3 3 6 3 6 2 7 3 7 3 2 8 1 6 6 1 8 3 4 6 4 7 5 8 1 4 3 5 7 6 1 5 8 5 8 5 6 5 7 4 3 4 5 2 6 3 2 4 4 4 4 7 4 5 2 7 2 6 2 2 7 2 4 7 2 1 6 4 2 8 6 2 3 4 4 8 1 6 7 6 2 7 5 6 7 6 2 3 7 8 5 2 7 7 7 7 2 7 8 8 7 5 5 6 8 8 8 3",
"output": "46"
},
{
"input": "120\n6 6 6 6 3 6 6 6 6 6 6 8 2 8 8 8 8 8 4 8 8 8 8 2 1 6 1 3 1 1 1 1 1 5 1 1 1 5 2 1 7 7 7 1 7 7 3 7 7 7 7 7 7 3 7 5 6 2 1 5 4 5 4 5 5 5 6 4 5 5 5 3 5 5 4 2 4 3 2 4 4 4 4 7 4 2 4 4 3 8 4 3 3 4 7 3 3 3 3 3 3 3 3 2 2 2 1 2 7 1 2 2 2 6 2 8 2 2 3 2",
"output": "84"
},
{
"input": "120\n8 8 8 8 8 8 8 8 8 8 8 8 1 8 8 4 6 4 4 4 4 4 4 4 4 3 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 7 7 7 7 7 8 7 7 7 7 7 7 4 7 7 7 3 5 5 5 1 5 5 5 5 5 5 5 5 5 5 5 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "113"
},
{
"input": "120\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "120"
}
] | 233 | 24,780,800 | 3 | 531 |
|
234 | Reading | [
"sortings"
] | null | null | Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.
Vasya has a train lighting schedule for all *n* hours of the trip β *n* numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose *k* hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours. | The first input line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=1000,<=1<=β€<=*k*<=β€<=*n*) β the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=β€<=*a**i*<=β€<=100), *a**i* is the light level at the *i*-th hour. | In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, β the indexes of hours Vasya will read at (1<=β€<=*b**i*<=β€<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print any of them. Print the numbers *b**i* in an arbitrary order. | [
"5 3\n20 10 30 40 10\n",
"6 5\n90 20 35 40 60 100\n"
] | [
"20\n1 3 4 \n",
"35\n1 3 4 5 6 \n"
] | In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | [
{
"input": "5 3\n20 10 30 40 10",
"output": "20\n1 3 4 "
},
{
"input": "6 5\n90 20 35 40 60 100",
"output": "35\n1 3 4 5 6 "
},
{
"input": "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 29 88 63 89 47 7 52 47 55 87 77 9 81 44 13 30 43 66 74 9 42 9 72 97 61 9 94 92 29 18 7 92 68 76 43 35 71 54 49 77 50 77 68 57 24 84 73 32 85 24 37",
"output": "94\n11 14 15 21 34 73 76 "
},
{
"input": "1 1\n10",
"output": "10\n1 "
},
{
"input": "1 1\n86",
"output": "86\n1 "
},
{
"input": "100 79\n83 83 83 83 83 94 94 83 83 83 83 90 83 99 83 91 83 83 83 83 83 83 83 83 83 83 83 91 83 83 83 83 83 96 83 83 83 91 83 83 92 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 98 83 83 91 97 83 83 83 83 83 83 83 92 83 83 83 83 83 83 83 93 83 83 91 83 83 83 83 83 83 83 83 83 83 83 96 83 83 83 83 83",
"output": "83\n6 7 12 14 16 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": "20 3\n17 76 98 17 55 17 17 99 65 17 17 17 17 52 17 17 69 88 17 17",
"output": "88\n3 8 18 "
},
{
"input": "15 1\n0 78 24 24 61 60 0 65 52 57 97 51 56 13 10",
"output": "97\n11 "
},
{
"input": "50 50\n59 40 52 0 65 49 3 58 57 22 86 37 55 72 11 3 30 30 20 64 44 45 12 48 96 96 39 14 8 53 40 37 8 58 97 16 96 48 30 89 66 19 31 50 23 80 67 16 11 7",
"output": "0\n1 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 "
},
{
"input": "60 8\n59 12 34 86 57 65 42 24 62 18 94 92 43 29 95 33 73 3 69 18 36 18 34 97 85 65 74 25 26 70 46 31 57 73 78 89 95 77 94 71 38 23 30 97 69 97 76 43 76 31 38 50 13 16 55 85 47 5 71 4",
"output": "92\n11 12 15 24 37 39 44 46 "
},
{
"input": "70 5\n76 16 20 60 5 96 32 50 35 9 79 42 38 35 72 45 98 33 55 0 86 92 49 87 22 79 35 27 69 35 89 29 31 43 88 1 48 95 3 92 82 97 53 80 79 0 78 58 37 38 45 9 5 38 53 49 71 7 91 3 75 17 76 44 77 31 78 91 59 91",
"output": "92\n6 17 38 40 42 "
},
{
"input": "12 3\n18 64 98 27 36 27 65 43 39 41 69 47",
"output": "65\n3 7 11 "
},
{
"input": "15 13\n6 78 78 78 78 20 78 78 8 3 78 18 32 56 78",
"output": "8\n2 3 4 5 6 7 8 9 11 12 13 14 15 "
},
{
"input": "17 4\n75 52 24 74 70 24 24 53 24 48 24 0 67 47 24 24 6",
"output": "67\n1 4 5 13 "
},
{
"input": "14 2\n31 18 78 90 96 2 90 27 86 9 94 98 94 34",
"output": "96\n5 12 "
},
{
"input": "100 56\n56 64 54 22 46 0 51 27 8 10 5 26 68 37 51 53 4 64 82 23 38 89 97 20 23 31 7 95 55 27 33 23 95 6 64 69 27 54 36 4 96 61 68 26 46 10 61 53 32 19 28 62 7 32 86 84 12 88 92 51 53 23 80 7 36 46 48 29 12 98 72 99 16 0 94 22 83 23 12 37 29 13 93 16 53 21 8 37 67 33 33 67 35 72 3 97 46 30 9 57",
"output": "33\n1 2 3 5 7 13 14 15 16 18 19 21 22 23 28 29 33 35 36 38 39 41 42 43 45 47 48 52 55 56 58 59 60 61 63 65 66 67 70 71 72 75 77 80 83 85 88 89 90 91 92 93 94 96 97 100 "
},
{
"input": "90 41\n43 24 4 69 54 87 33 34 9 77 87 66 66 0 71 43 42 10 78 48 26 40 8 61 80 38 76 63 7 47 99 69 77 43 29 74 86 93 39 28 99 98 11 27 43 58 50 61 1 79 45 17 23 13 10 98 41 28 19 98 87 51 26 28 88 60 42 25 19 3 29 18 0 56 84 27 43 92 93 97 25 90 13 90 75 52 99 6 66 87",
"output": "52\n4 5 6 10 11 12 13 15 19 24 25 27 28 31 32 33 36 37 38 41 42 46 48 50 56 60 61 65 66 74 75 78 79 80 82 84 85 86 87 89 90 "
},
{
"input": "100 71\n29 56 85 57 40 89 93 81 92 38 81 41 18 9 89 21 81 6 95 94 38 11 90 38 6 81 61 43 81 12 36 35 33 10 81 49 59 37 81 61 95 34 43 20 94 88 57 81 42 81 50 24 85 81 1 90 33 8 59 87 17 52 91 54 81 98 28 11 24 51 95 31 98 29 5 81 91 52 41 81 7 9 81 81 13 81 3 81 10 0 37 47 62 50 81 81 81 94 93 38",
"output": "35\n2 3 4 5 6 7 8 9 10 11 12 15 17 19 20 21 23 24 26 27 28 29 31 32 35 36 37 38 39 40 41 43 45 46 47 48 49 50 51 53 54 56 59 60 62 63 64 65 66 70 71 73 76 77 78 79 80 83 84 86 88 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100 55\n72 70 77 90 86 96 60 60 60 60 87 62 60 87 0 60 82 60 86 74 60 60 60 60 60 60 78 60 60 60 96 60 60 0 60 60 89 99 60 60 60 60 60 60 89 60 88 84 60 93 0 60 60 60 75 60 67 64 65 60 65 60 72 60 76 4 60 60 60 63 96 62 78 71 63 81 89 98 60 60 69 60 61 60 60 60 85 71 82 79 67 60 60 60 79 96 2 60 60 60",
"output": "60\n1 2 3 4 5 6 11 12 14 17 19 20 27 31 37 38 45 47 48 50 55 57 58 59 61 63 65 70 71 72 73 74 75 76 77 78 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 98 99 100 "
},
{
"input": "100 27\n25 87 25 25 77 78 25 73 91 25 25 70 84 25 61 75 82 25 25 25 25 65 25 25 82 63 93 25 93 75 25 25 25 89 98 25 25 72 70 25 72 25 25 25 70 25 25 98 90 25 25 25 25 25 91 25 78 71 63 69 25 25 25 63 25 25 75 94 25 25 25 25 25 97 25 78 66 87 25 89 25 25 73 85 25 91 72 25 25 80 25 70 25 96 25 25 25 25 25 25",
"output": "75\n2 5 6 9 13 16 17 25 27 29 30 34 35 48 49 55 57 67 68 74 76 78 80 84 86 90 94 "
},
{
"input": "100 99\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "1\n2 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": "100 50\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "2\n2 4 6 8 10 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 "
},
{
"input": "100 51\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "1\n2 4 6 8 10 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 99 100 "
},
{
"input": "100 75\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "1\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 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": "100 45\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "2\n12 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 "
},
{
"input": "2 2\n2 2",
"output": "2\n1 2 "
},
{
"input": "2 1\n2 1",
"output": "2\n1 "
},
{
"input": "2 1\n1 2",
"output": "2\n2 "
},
{
"input": "3 1\n1 2 0",
"output": "2\n2 "
},
{
"input": "3 2\n0 0 0",
"output": "0\n2 3 "
},
{
"input": "3 3\n0 1 0",
"output": "0\n1 2 3 "
},
{
"input": "3 2\n99 100 99",
"output": "99\n2 3 "
},
{
"input": "1 1\n0",
"output": "0\n1 "
},
{
"input": "4 1\n100 100 0 100",
"output": "100\n4 "
},
{
"input": "4 2\n0 1 0 1",
"output": "1\n2 4 "
},
{
"input": "10 3\n0 1 2 3 0 1 2 3 0 1",
"output": "2\n4 7 8 "
},
{
"input": "10 9\n0 1 0 1 100 100 1 0 1 0",
"output": "0\n2 3 4 5 6 7 8 9 10 "
},
{
"input": "7 7\n1 0 0 0 0 0 0",
"output": "0\n1 2 3 4 5 6 7 "
},
{
"input": "7 6\n0 0 0 0 0 0 1",
"output": "0\n2 3 4 5 6 7 "
},
{
"input": "7 1\n12 33 12 88 10 0 3",
"output": "88\n4 "
},
{
"input": "7 1\n0 1 1 1 1 1 1",
"output": "1\n7 "
},
{
"input": "7 6\n1 1 1 1 1 1 0",
"output": "1\n1 2 3 4 5 6 "
},
{
"input": "7 2\n1 0 1 1 1 1 1",
"output": "1\n6 7 "
},
{
"input": "8 4\n1 1 1 1 0 0 0 0",
"output": "1\n1 2 3 4 "
},
{
"input": "7 5\n1 1 1 2 0 0 0",
"output": "0\n1 2 3 4 7 "
}
] | 60 | 6,963,200 | -1 | 533 |
|
0 | none | [
"none"
] | null | null | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up; - climb one area down; - jump to the opposite wall. That gets the ninja to the area that is exactly *k* meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area *x* of one wall, then after the jump he is located at area *x*<=+<=*k* of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than *n*, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. | The first line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous. | Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). | [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n"
] | [
"YES\n",
"NO\n"
] | In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | [
{
"input": "7 3\n---X--X\n-X--XX-",
"output": "YES"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "10 1\n-X-X-X-X-X\nX-X-X-X-X-",
"output": "YES"
},
{
"input": "5 4\n-X---\n----X",
"output": "NO"
},
{
"input": "6 2\n--X--X\nXX-X-X",
"output": "YES"
},
{
"input": "50 4\n-X-X-X--X--X--X-XX-----XX--X--------------XXX-X-X-\n--XX---XXXXXXX----XX--X--XXX--XXXX-XX--X--X--X----",
"output": "YES"
},
{
"input": "1 1\n-\nX",
"output": "YES"
},
{
"input": "2 1\n-X\nX-",
"output": "YES"
},
{
"input": "2 1\n-X\n-X",
"output": "NO"
},
{
"input": "1 20\n-\n-",
"output": "YES"
},
{
"input": "1 100000\n-\n-",
"output": "YES"
},
{
"input": "5 2\n-----\nXXXXX",
"output": "YES"
},
{
"input": "5 1\n----X\n----X",
"output": "NO"
},
{
"input": "12 4\n----X---X--X\n-----X-----X",
"output": "YES"
},
{
"input": "12 2\n-X-X-X-X-X-X\nX---XXX--X-X",
"output": "NO"
},
{
"input": "10 8\n-XXXXXXXXX\nXXXXXXXXX-",
"output": "NO"
},
{
"input": "100 10\n-X------XXX--XXX-XXXXXX---XXX---X-XX--XXX----------XX-X-XXXX-X-X-XX-X-X--XXXXX---X--X--XXX-X--XXXXXX\n---X-XXXXXXX--X-XXX--X-XX--XX----XX-X----X-X-XX-X--X-XXXXXXX-XX-X---X--XX-X-XX--XXXXXXX-X--XX--X-XXX",
"output": "NO"
},
{
"input": "12 3\n--XX--XX-XXX\n----X---XXX-",
"output": "NO"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--",
"output": "YES"
},
{
"input": "13 2\n---X---X--X-X\n--X---X-X--X-",
"output": "YES"
},
{
"input": "5 2\n---XX\n---X-",
"output": "YES"
},
{
"input": "101 1\n----------------------------------------------------------------------------------------------------X\n----------------------------------------------------------------------------------------------------X",
"output": "NO"
}
] | 2,000 | 62,976,000 | 0 | 535 |
|
808 | Average Sleep Time | [
"data structures",
"implementation",
"math"
] | null | null | It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last *n* days. So now he has a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sleep time on the *i*-th day.
The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider *k* consecutive days as a week. So there will be *n*<=-<=*k*<=+<=1 weeks to take into consideration. For example, if *k*<==<=2, *n*<==<=3 and *a*<==<=[3,<=4,<=7], then the result is .
You should write a program which will calculate average sleep times of Polycarp over all weeks. | The first line contains two integer numbers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=2Β·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105). | Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point. | [
"3 2\n3 4 7\n",
"1 1\n10\n",
"8 2\n1 2 4 100000 123 456 789 1\n"
] | [
"9.0000000000\n",
"10.0000000000\n",
"28964.2857142857\n"
] | In the third example there are *n*β-β*k*β+β1β=β7 weeks, so the answer is sums of all weeks divided by 7. | [
{
"input": "3 2\n3 4 7",
"output": "9.0000000000"
},
{
"input": "1 1\n10",
"output": "10.0000000000"
},
{
"input": "8 2\n1 2 4 100000 123 456 789 1",
"output": "28964.2857142857"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n100000",
"output": "100000.0000000000"
},
{
"input": "3 1\n1 2 3",
"output": "2.0000000000"
},
{
"input": "10 4\n11 3 5 20 12 7 9 2 2 20",
"output": "36.2857142857"
},
{
"input": "10 5\n15 9 3 2 17 10 9 18 4 19",
"output": "50.3333333333"
},
{
"input": "10 6\n19 3 20 16 14 10 1 13 7 3",
"output": "65.8000000000"
},
{
"input": "10 7\n8 16 2 13 15 9 5 13 9 2",
"output": "68.2500000000"
},
{
"input": "10 4\n127 1459 718 1183 880 1044 1857 1340 725 1496",
"output": "4574.4285714286"
},
{
"input": "10 5\n1384 1129 1780 1960 1567 1928 12 1523 1165 344",
"output": "6931.3333333333"
}
] | 77 | 0 | 0 | 536 |
|
402 | Searching for Graph | [
"brute force",
"constructive algorithms",
"graphs"
] | null | null | Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=β€<=*k*<=β€<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=+<=*p* edges.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.
Your task is to find a *p*-interesting graph consisting of *n* vertices. | The first line contains a single integer *t* (1<=β€<=*t*<=β€<=5) β the number of tests in the input. Next *t* lines each contains two space-separated integers: *n*, *p* (5<=β€<=*n*<=β€<=24; *p*<=β₯<=0; ) β the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the required graph exists. | For each of the *t* tests print 2*n*<=+<=*p* lines containing the description of the edges of a *p*-interesting graph: the *i*-th line must contain two space-separated integers *a**i*,<=*b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*;Β *a**i*<=β <=*b**i*) β two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to *n*.
Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them. | [
"1\n6 0\n"
] | [
"1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"
] | none | [
{
"input": "1\n6 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "1\n5 0",
"output": "1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"
},
{
"input": "5\n6 0\n5 0\n7 0\n8 0\n9 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6"
},
{
"input": "5\n6 1\n5 0\n7 1\n8 1\n9 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7"
},
{
"input": "5\n24 0\n23 0\n22 0\n21 0\n24 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23..."
},
{
"input": "5\n24 1\n23 1\n22 1\n21 1\n20 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n..."
},
{
"input": "5\n20 0\n19 0\n18 0\n17 0\n16 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 1..."
},
{
"input": "5\n15 0\n14 0\n13 0\n12 0\n11 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n2 3..."
},
{
"input": "5\n10 0\n20 0\n24 0\n19 0\n17 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13..."
},
{
"input": "5\n24 0\n23 0\n24 1\n23 1\n22 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23..."
},
{
"input": "5\n24 0\n24 0\n24 0\n24 0\n24 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22..."
},
{
"input": "5\n23 0\n23 0\n23 0\n23 0\n23 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n3 4\n3 5\n..."
},
{
"input": "5\n19 1\n18 1\n17 1\n16 1\n15 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n2 3\n..."
},
{
"input": "5\n15 1\n14 1\n13 1\n12 1\n11 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n..."
},
{
"input": "5\n24 2\n24 1\n24 0\n23 0\n23 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n..."
},
{
"input": "5\n24 10\n23 50\n24 228\n24 200\n23 150",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2..."
},
{
"input": "5\n24 228\n24 228\n24 228\n24 228\n24 228",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n4 20\n4 21\n4 22\n4 23\n4 24\n5 6\n5 7\n5 8\n5 9\n5..."
},
{
"input": "5\n20 1\n20 0\n19 0\n20 0\n20 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13..."
},
{
"input": "5\n21 1\n19 1\n18 1\n20 1\n17 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n..."
},
{
"input": "5\n10 1\n11 1\n12 1\n13 1\n14 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1..."
},
{
"input": "1\n24 100",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n4 20\n4 21\n4 22\n4 23\n4 24\n5 6\n5 7\n5 8\n5 9\n5..."
}
] | 77 | 33,587,200 | 3 | 537 |
|
182 | Wooden Fence | [
"dp"
] | null | null | Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal *n* different types of wood. The company uses the *i*-th type of wood to produce a board of this type that is a rectangular *a**i* by *b**i* block.
Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.
Vasya is required to construct a fence of length *l*, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled:
- there are no two successive boards of the same type - the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one
In other words, the fence is considered beautiful, if the type of the *i*-th board in the fence is different from the *i*<=-<=1-th board's type; besides, the *i*-th board's length is equal to the *i*<=-<=1-th board's width (for all *i*, starting from 2).
Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length *l*.
Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109<=+<=7). | The first line contains two integers *n* and *l* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*l*<=β€<=3000) β the number of different board types and the fence length, correspondingly. Next *n* lines contain descriptions of board types: the *i*-th line contains two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=100) β the sizes of the board of the *i*-th type. All numbers on the lines are separated by spaces. | Print a single integer β the sought number of variants modulo 1000000007 (109<=+<=7). | [
"2 3\n1 2\n2 3\n",
"1 2\n2 2\n",
"6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n"
] | [
"2\n",
"1\n",
"20\n"
] | In the first sample there are exactly two variants of arranging a beautiful fence of length 3:
- As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3. - Use one board of the second type after you turn it. That makes its length equal 3, and width β 2. | [
{
"input": "2 3\n1 2\n2 3",
"output": "2"
},
{
"input": "1 2\n2 2",
"output": "1"
},
{
"input": "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1",
"output": "20"
},
{
"input": "4 3\n1 2\n1 1\n3 1\n2 2",
"output": "4"
},
{
"input": "4 6\n1 1\n1 2\n3 1\n5 10",
"output": "0"
},
{
"input": "5 10\n1 2\n2 3\n1 2\n3 1\n2 4",
"output": "50"
},
{
"input": "1 4\n4 1",
"output": "1"
},
{
"input": "1 3\n1 1",
"output": "0"
},
{
"input": "4 6\n2 1\n1 2\n2 1\n2 1",
"output": "216"
},
{
"input": "4 10\n4 5\n5 3\n1 4\n1 2",
"output": "2"
},
{
"input": "5 8\n3 1\n2 1\n2 3\n2 1\n3 1",
"output": "62"
},
{
"input": "10 11\n3 10\n10 2\n2 6\n7 6\n8 1\n2 3\n7 10\n8 2\n6 5\n2 5",
"output": "10"
},
{
"input": "8 20\n18 18\n14 15\n8 4\n5 9\n2 7\n9 2\n9 19\n2 11",
"output": "0"
},
{
"input": "6 7\n3 1\n2 1\n1 2\n4 5\n2 5\n2 1",
"output": "94"
},
{
"input": "7 4\n1 2\n2 2\n3 3\n3 3\n1 1\n3 3\n3 1",
"output": "9"
},
{
"input": "100 3000\n1 4\n2 1\n3 3\n1 1\n5 4\n4 1\n2 1\n5 4\n1 1\n3 3\n4 3\n3 4\n4 2\n2 4\n1 2\n3 4\n5 3\n1 4\n2 4\n4 5\n1 2\n5 2\n2 2\n3 2\n4 4\n1 4\n5 5\n3 4\n4 1\n3 3\n5 2\n3 3\n4 1\n1 5\n4 3\n5 3\n4 2\n3 3\n3 5\n5 1\n5 1\n3 3\n4 3\n1 3\n4 1\n2 3\n1 3\n1 2\n5 5\n5 2\n1 5\n4 2\n1 1\n1 1\n1 2\n4 4\n5 4\n2 5\n1 3\n5 3\n1 1\n3 5\n1 4\n5 2\n2 3\n1 3\n5 1\n3 4\n5 1\n5 3\n3 2\n2 4\n5 2\n2 5\n5 4\n2 4\n1 1\n2 1\n2 3\n4 4\n1 5\n2 2\n1 3\n3 1\n3 2\n5 2\n5 5\n2 5\n2 3\n3 2\n4 1\n2 3\n5 1\n4 2\n2 4\n2 1\n5 3\n5 4\n1 1\n2 3",
"output": "440706472"
},
{
"input": "20 20\n2 1\n1 1\n2 3\n2 1\n2 1\n3 3\n2 3\n1 2\n1 1\n1 1\n2 3\n2 3\n1 3\n2 2\n2 1\n3 2\n2 1\n1 1\n1 3\n3 3",
"output": "379149793"
},
{
"input": "13 10\n4 2\n1 3\n3 3\n2 2\n3 1\n3 4\n4 1\n1 3\n2 3\n1 3\n3 1\n3 3\n2 1",
"output": "4551"
},
{
"input": "10 50\n9 7\n2 2\n7 9\n10 9\n6 1\n8 10\n10 5\n7 5\n4 5\n8 1",
"output": "42"
},
{
"input": "10 30\n12 21\n2 8\n19 7\n7 1\n27 14\n13 3\n14 7\n19 26\n21 17\n17 30",
"output": "1"
},
{
"input": "10 5\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "65610"
},
{
"input": "100 2000\n2 2\n2 1\n2 2\n1 2\n1 2\n2 2\n1 2\n1 2\n2 2\n2 1\n1 1\n2 2\n2 2\n2 1\n2 2\n2 2\n1 1\n2 2\n1 2\n2 2\n1 1\n2 1\n2 1\n2 1\n1 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 2\n1 2\n2 1\n2 2\n2 2\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n2 1\n2 1\n1 1\n2 1\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 1\n1 2\n1 2\n2 1\n2 2\n1 2\n2 1\n2 2\n1 2\n2 1\n2 1\n2 2\n1 2\n2 2\n1 1\n2 2\n2 1\n2 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 1\n2 1\n2 1\n2 2\n2 1\n1 1\n2 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n1 2\n2 1\n2 2\n2 1\n1 1\n2 2",
"output": "842986379"
},
{
"input": "100 2000\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": "370055910"
},
{
"input": "100 1500\n3 3\n3 2\n1 3\n3 1\n2 3\n3 2\n3 2\n2 1\n3 1\n2 3\n3 3\n3 1\n1 1\n3 1\n3 3\n2 2\n2 2\n1 2\n1 1\n3 1\n2 2\n2 3\n2 3\n2 2\n3 3\n3 2\n1 1\n3 3\n2 2\n1 3\n3 3\n3 1\n1 2\n3 3\n3 3\n2 2\n1 1\n3 3\n1 3\n2 1\n1 2\n2 1\n1 3\n1 3\n1 3\n1 1\n1 3\n3 1\n2 3\n1 3\n2 2\n2 1\n2 1\n2 3\n3 2\n1 2\n2 2\n1 3\n1 1\n1 3\n3 3\n1 3\n3 2\n1 3\n2 1\n2 3\n2 3\n2 3\n3 2\n1 2\n1 3\n2 3\n1 3\n2 1\n3 2\n3 3\n1 1\n3 1\n3 3\n1 3\n3 2\n3 2\n2 2\n1 3\n2 2\n3 2\n1 3\n2 2\n2 1\n3 2\n1 3\n3 2\n1 2\n2 2\n1 3\n1 1\n3 3\n2 2\n3 1\n3 3",
"output": "548967810"
},
{
"input": "100 2500\n3 1\n3 2\n3 2\n3 1\n1 1\n1 2\n3 3\n1 2\n1 2\n3 1\n3 3\n3 2\n1 3\n2 1\n2 3\n2 2\n1 3\n2 2\n2 2\n1 1\n2 3\n1 3\n1 2\n3 1\n2 3\n2 3\n3 1\n2 3\n2 3\n3 1\n1 1\n3 2\n2 3\n3 3\n3 2\n3 1\n3 2\n3 1\n2 1\n1 3\n2 2\n2 2\n3 2\n1 2\n3 1\n3 2\n3 1\n1 2\n3 1\n3 1\n3 1\n2 3\n1 3\n1 3\n2 2\n1 2\n3 3\n3 2\n3 2\n3 3\n3 3\n2 1\n1 2\n3 2\n1 2\n2 3\n1 2\n2 3\n2 3\n3 2\n3 1\n2 3\n1 2\n1 1\n1 1\n3 1\n2 3\n2 1\n2 3\n3 2\n1 1\n3 3\n1 3\n3 2\n3 2\n2 2\n2 2\n2 2\n1 1\n1 2\n1 2\n3 3\n1 1\n3 2\n1 2\n2 2\n3 3\n2 2\n1 2\n2 3",
"output": "563987225"
},
{
"input": "30 2800\n25 12\n43 10\n38 39\n14 8\n35 41\n19 11\n23 5\n28 2\n7 36\n9 36\n38 32\n28 29\n18 31\n22 6\n25 34\n43 25\n36 33\n14 24\n13 40\n1 1\n19 44\n37 18\n7 17\n18 14\n44 35\n15 37\n43 23\n34 29\n3 21\n31 47",
"output": "0"
},
{
"input": "50 100\n45 74\n41 31\n84 56\n14 8\n25 94\n71 76\n35 8\n66 67\n27 54\n67 91\n71 20\n71 91\n7 58\n13 34\n47 60\n68 32\n74 58\n78 55\n67 40\n22 67\n27 59\n2 2\n89 62\n90 60\n41 57\n66 24\n65 93\n55 8\n94 2\n82 81\n91 67\n63 68\n24 12\n95 49\n48 63\n30 23\n32 86\n10 98\n89 71\n73 35\n85 60\n22 46\n9 50\n79 75\n24 53\n48 17\n22 61\n26 49\n89 58\n77 56",
"output": "2"
},
{
"input": "40 700\n11 14\n4 14\n14 13\n12 9\n14 10\n3 9\n7 7\n5 15\n1 11\n5 7\n2 9\n7 5\n3 10\n5 14\n4 11\n13 6\n4 6\n3 9\n1 11\n8 13\n6 4\n12 10\n10 14\n8 2\n1 15\n13 13\n6 11\n7 2\n7 12\n8 7\n1 13\n13 7\n12 10\n1 7\n7 1\n4 4\n10 7\n1 4\n13 8\n13 10",
"output": "964762206"
},
{
"input": "60 900\n38 15\n10 1\n14 37\n13 1\n40 15\n31 26\n31 4\n12 5\n28 34\n37 7\n28 34\n11 30\n30 16\n27 18\n11 18\n17 6\n38 22\n31 37\n20 38\n21 23\n11 12\n24 35\n36 8\n13 13\n34 39\n20 15\n17 3\n23 17\n18 23\n26 18\n11 2\n18 30\n25 25\n32 40\n9 38\n37 39\n39 37\n5 10\n15 19\n14 21\n34 8\n7 36\n29 3\n11 21\n32 2\n21 40\n10 33\n36 39\n15 31\n38 16\n4 14\n6 16\n31 18\n15 23\n1 38\n32 24\n13 12\n15 15\n24 11\n24 27",
"output": "457432849"
},
{
"input": "50 2000\n12 1\n11 29\n7 4\n18 27\n25 17\n28 5\n1 17\n10 29\n10 21\n8 7\n23 4\n20 7\n8 24\n2 27\n13 13\n14 15\n19 15\n7 26\n24 13\n8 25\n7 11\n18 11\n19 1\n30 15\n3 24\n27 7\n24 25\n7 7\n14 23\n3 24\n25 10\n25 3\n4 11\n22 29\n27 28\n23 5\n3 6\n16 3\n30 18\n16 22\n24 7\n11 1\n10 23\n2 3\n27 28\n28 25\n20 21\n25 3\n10 3\n7 25",
"output": "771010208"
},
{
"input": "1 3000\n78 92",
"output": "0"
},
{
"input": "50 30\n9 35\n1 48\n17 43\n41 39\n28 7\n14 10\n3 45\n35 37\n31 27\n11 16\n40 8\n4 7\n15 33\n29 17\n41 45\n11 24\n6 8\n6 2\n2 42\n19 34\n7 36\n14 15\n26 2\n22 33\n15 22\n49 23\n10 41\n6 17\n21 11\n15 37\n49 26\n49 49\n15 29\n12 49\n22 13\n7 49\n25 32\n7 7\n31 37\n23 14\n5 37\n14 6\n44 21\n8 16\n22 7\n43 44\n36 44\n4 26\n22 46\n4 21",
"output": "12"
},
{
"input": "30 80\n27 10\n39 39\n87 45\n70 82\n20 50\n45 51\n67 31\n43 96\n87 26\n59 20\n42 22\n69 71\n10 30\n39 59\n42 100\n4 67\n21 55\n83 69\n33 81\n37 43\n57 12\n30 83\n34 12\n35 32\n11 12\n51 96\n100 68\n96 20\n50 61\n46 61",
"output": "1"
},
{
"input": "100 3000\n1 1\n3 3\n3 2\n1 1\n3 2\n1 3\n1 3\n1 1\n2 3\n2 3\n3 2\n1 3\n3 3\n1 1\n3 1\n2 3\n3 1\n2 1\n3 2\n3 2\n2 2\n1 2\n3 3\n3 3\n3 3\n3 3\n1 3\n3 2\n2 3\n3 2\n3 1\n1 1\n3 1\n1 3\n1 2\n2 1\n3 2\n2 3\n3 1\n3 2\n3 1\n2 1\n1 3\n1 1\n3 3\n2 2\n3 2\n3 3\n2 2\n2 3\n3 3\n2 3\n2 2\n3 3\n3 3\n1 1\n2 3\n1 1\n3 3\n3 3\n2 2\n1 2\n3 2\n3 3\n3 3\n3 3\n3 1\n1 2\n1 1\n1 1\n2 1\n1 2\n3 2\n2 3\n3 2\n1 1\n2 1\n2 2\n1 1\n1 2\n1 3\n2 2\n2 3\n2 1\n1 2\n3 1\n3 1\n3 3\n2 3\n1 1\n3 3\n2 2\n1 3\n3 1\n2 3\n2 2\n3 2\n1 1\n3 3\n3 2",
"output": "936413338"
},
{
"input": "100 3000\n3 3\n2 1\n3 3\n4 1\n2 4\n3 1\n3 4\n1 2\n3 4\n4 3\n2 2\n2 3\n4 2\n3 3\n1 3\n4 3\n3 1\n4 3\n2 2\n2 4\n2 2\n3 2\n2 1\n3 4\n1 1\n1 1\n1 2\n1 3\n2 4\n3 4\n2 4\n2 3\n3 1\n4 1\n1 3\n2 2\n3 2\n2 2\n3 3\n2 2\n4 4\n4 3\n1 3\n2 3\n1 3\n1 1\n2 3\n3 3\n4 2\n2 2\n1 1\n1 3\n4 4\n3 3\n4 2\n1 4\n4 4\n2 4\n1 3\n2 3\n1 3\n1 1\n4 4\n3 2\n2 1\n4 4\n2 1\n2 1\n2 3\n3 3\n2 4\n2 1\n4 1\n3 1\n2 3\n1 2\n1 1\n1 1\n2 2\n1 1\n4 1\n4 4\n3 2\n2 2\n1 4\n2 2\n4 3\n2 2\n4 1\n2 1\n4 2\n2 4\n2 1\n3 4\n4 2\n2 4\n3 4\n2 1\n1 1\n1 2",
"output": "822253206"
}
] | 498 | 4,710,400 | 3 | 540 |
|
895 | Pizza Separation | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. | The first line contains one integer *n* (1<=β€<=*n*<=β€<=360) Β β the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=360) Β β the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer Β β the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90β+β90)β-β(90β+β90)|β=β0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360β-β0|β=β360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170β+β10)β-β(30β+β150)|β=β0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 45 45 45 45 45 45 45",
"output": "0"
},
{
"input": "3\n120 120 120",
"output": "120"
},
{
"input": "5\n110 90 70 50 40",
"output": "40"
},
{
"input": "2\n170 190",
"output": "20"
},
{
"input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10",
"output": "10"
},
{
"input": "5\n30 60 180 60 30",
"output": "0"
},
{
"input": "2\n359 1",
"output": "358"
},
{
"input": "5\n100 100 30 100 30",
"output": "40"
},
{
"input": "5\n36 34 35 11 244",
"output": "128"
},
{
"input": "5\n96 94 95 71 4",
"output": "18"
},
{
"input": "2\n85 275",
"output": "190"
},
{
"input": "3\n281 67 12",
"output": "202"
},
{
"input": "5\n211 113 25 9 2",
"output": "62"
},
{
"input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1",
"output": "212"
},
{
"input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "92"
},
{
"input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0"
},
{
"input": "3\n1 1 358",
"output": "356"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341",
"output": "322"
},
{
"input": "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 328",
"output": "296"
},
{
"input": "70\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 291",
"output": "222"
},
{
"input": "130\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 231",
"output": "102"
},
{
"input": "200\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 161",
"output": "0"
},
{
"input": "222\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139",
"output": "0"
},
{
"input": "10\n8 3 11 4 1 10 10 1 8 304",
"output": "248"
},
{
"input": "12\n8 7 7 3 11 2 10 1 10 8 10 283",
"output": "206"
},
{
"input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275",
"output": "190"
},
{
"input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280",
"output": "200"
},
{
"input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275",
"output": "190"
},
{
"input": "30\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 189",
"output": "18"
},
{
"input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189",
"output": "18"
},
{
"input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168",
"output": "0"
},
{
"input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5",
"output": "0"
},
{
"input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "0"
},
{
"input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68",
"output": "0"
},
{
"input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0"
},
{
"input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0"
},
{
"input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0"
},
{
"input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0"
},
{
"input": "6\n27 15 28 34 41 215",
"output": "70"
},
{
"input": "7\n41 38 41 31 22 41 146",
"output": "14"
},
{
"input": "8\n24 27 34 23 29 23 30 170",
"output": "20"
},
{
"input": "9\n11 11 20 20 33 32 35 26 172",
"output": "6"
},
{
"input": "10\n36 13 28 13 33 34 23 25 34 121",
"output": "0"
},
{
"input": "11\n19 37 13 41 37 15 32 12 19 35 100",
"output": "10"
},
{
"input": "12\n37 25 34 38 21 24 34 38 11 29 28 41",
"output": "2"
},
{
"input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28",
"output": "2"
},
{
"input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44",
"output": "4"
},
{
"input": "3\n95 91 174",
"output": "12"
},
{
"input": "4\n82 75 78 125",
"output": "46"
},
{
"input": "6\n87 75 88 94 15 1",
"output": "4"
},
{
"input": "10\n27 52 58 64 45 64 1 19 2 28",
"output": "12"
},
{
"input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1",
"output": "0"
},
{
"input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3",
"output": "0"
},
{
"input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1",
"output": "0"
},
{
"input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2",
"output": "0"
},
{
"input": "5\n35 80 45 100 100",
"output": "40"
},
{
"input": "4\n90 179 90 1",
"output": "2"
},
{
"input": "5\n50 50 20 160 80",
"output": "0"
},
{
"input": "5\n30 175 30 5 120",
"output": "10"
},
{
"input": "4\n170 30 10 150",
"output": "20"
},
{
"input": "6\n90 30 90 30 90 30",
"output": "60"
},
{
"input": "4\n70 80 110 100",
"output": "20"
},
{
"input": "7\n35 45 70 100 10 10 90",
"output": "0"
},
{
"input": "6\n50 90 10 90 20 100",
"output": "20"
},
{
"input": "6\n10 155 162 1 26 6",
"output": "18"
},
{
"input": "7\n80 90 80 45 10 10 45",
"output": "20"
},
{
"input": "4\n18 36 162 144",
"output": "36"
},
{
"input": "5\n20 50 50 160 80",
"output": "40"
},
{
"input": "5\n10 30 140 20 160",
"output": "0"
},
{
"input": "6\n90 80 60 50 40 40",
"output": "20"
},
{
"input": "9\n40 20 20 20 20 20 20 40 160",
"output": "40"
},
{
"input": "4\n90 54 90 126",
"output": "72"
},
{
"input": "4\n150 170 30 10",
"output": "20"
},
{
"input": "8\n130 12 13 85 41 67 5 7",
"output": "26"
},
{
"input": "7\n70 170 20 10 30 30 30",
"output": "20"
},
{
"input": "8\n100 100 50 50 15 15 15 15",
"output": "40"
},
{
"input": "4\n100 70 80 110",
"output": "20"
},
{
"input": "5\n160 130 40 20 10",
"output": "20"
},
{
"input": "4\n20 149 151 40",
"output": "22"
},
{
"input": "4\n100 10 100 150",
"output": "60"
},
{
"input": "6\n19 64 105 168 1 3",
"output": "16"
},
{
"input": "8\n10 10 70 70 90 90 10 10",
"output": "0"
}
] | 420 | 6,348,800 | 3 | 541 |
|
855 | Marvolo Gaunt's Ring | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made.
Value of *x* is calculated as maximum of *p*Β·*a**i*<=+<=*q*Β·*a**j*<=+<=*r*Β·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=β€<=*i*<=β€<=*j*<=β€<=*k*<=β€<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=β€<=*p*,<=*q*,<=*r*<=β€<=109,<=1<=β€<=*n*<=β€<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=β€<=*a**i*<=β€<=109). | Output a single integer the maximum value of *p*Β·*a**i*<=+<=*q*Β·*a**j*<=+<=*r*Β·*a**k* that can be obtained provided 1<=β€<=*i*<=β€<=*j*<=β€<=*k*<=β€<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i*β=β*j*β=β*k*β=β5, thus making the answer as 1Β·5β+β2Β·5β+β3Β·5β=β30.
In second sample case, selecting *i*β=β*j*β=β1 and *k*β=β5 gives the answer 12. | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876",
"output": "547306902373544674"
},
{
"input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162",
"output": "1876641179289775029"
},
{
"input": "1 0 0 0\n0",
"output": "0"
},
{
"input": "1 1000000000 1000000000 1000000000\n1000000000",
"output": "3000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 1000000000\n1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 -1000000000\n1000000000",
"output": "-3000000000000000000"
},
{
"input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 1 1 1\n-1",
"output": "-3"
},
{
"input": "1 -1 -1 -1\n1",
"output": "-3"
},
{
"input": "1 1000000000 1000000000 1000000000\n-1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 1 2 3\n-1",
"output": "-6"
},
{
"input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "3 1 1 1\n-1 -1 -1",
"output": "-3"
},
{
"input": "1 -1000000000 0 0\n1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -100 -100 -100\n100",
"output": "-30000"
},
{
"input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 999999999 999999999 999999999\n-999999999",
"output": "-2999999994000000003"
},
{
"input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000",
"output": "-1999999999000000000"
},
{
"input": "3 -2 3 -2\n1 2 1",
"output": "2"
},
{
"input": "2 1 -1 1\n1 -1",
"output": "1"
},
{
"input": "1 -1000000000 1 -1000000000\n1000000000",
"output": "-1999999999000000000"
},
{
"input": "1 1000000000 1000000000 -1000000000\n-1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 0\n1000000000",
"output": "-2000000000000000000"
}
] | 77 | 14,233,600 | 3 | 544 |
|
23 | You're Given a String... | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number β length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggglgpep",
"output": "2"
},
{
"input": "iegdlraaidefgegiagrdfhihe",
"output": "2"
},
{
"input": "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg",
"output": "1"
},
{
"input": "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw",
"output": "2"
},
{
"input": "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbkvviwntdhqscvkmphnkkljizndnbjt",
"output": "3"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "99"
},
{
"input": "ikiikiikikiiikkkkkikkkkiiiiikkiiikkiikiikkkkikkkikikkikiiikkikikiiikikkkiiikkkikkikkikkkkiiikkiiiiii",
"output": "10"
},
{
"input": "ovovhoovvhohhhvhhvhhvhovoohovhhoooooovohvooooohvvoooohvvovhhvhovhhvoovhvhvoovovvhooovhhooovohvhhovhv",
"output": "8"
},
{
"input": "ccwckkkycccccckwckwkwkwkkkkyycykcccycyckwywcckwykcycykkkwcycwwcykcwkwkwwykwkwcykywwwyyykckkyycckwcwk",
"output": "5"
},
{
"input": "ttketfkefktfztezzkzfkkeetkkfktftzktezekkeezkeeetteeteefetefkzzzetekfftkeffzkktffzkzzeftfeezfefzffeef",
"output": "4"
},
{
"input": "rtharczpfznrgdnkltchafduydgbgkdjqrmjqyfmpwjwphrtsjbmswkanjlprbnduaqbcjqxlxmkspkhkcnzbqwxonzxxdmoigti",
"output": "2"
},
{
"input": "fplrkfklvwdeiynbjgaypekambmbjfnoknlhczhkdmljicookdywdgpnlnqlpunnkebnikgcgcjefeqhknvlynmvjcegvcdgvvdb",
"output": "2"
},
{
"input": "txbciieycswqpniwvzipwlottivvnfsysgzvzxwbctcchfpvlbcjikdofhpvsknptpjdbxemtmjcimetkemdbettqnbvzzbdyxxb",
"output": "2"
},
{
"input": "fmubmfwefikoxtqvmaavwjxmoqltapexkqxcsztpezfcltqavuicefxovuswmqimuikoppgqpiapqutkczgcvxzutavkujxvpklv",
"output": "3"
},
{
"input": "ipsrjylhpkjvlzncfixipstwcicxqygqcfrawpzzvckoveyqhathglblhpkjvlzncfixipfajaqobtzvthmhgbuawoxoknirclxg",
"output": "15"
},
{
"input": "kcnjsntjzcbgzjscrsrjkrbytqsrptzspzctjrorsyggrtkcnjsntjzcbgzjscrsrjyqbrtpcgqirsrrjbbbrnyqstnrozcoztt",
"output": "20"
},
{
"input": "unhcfnrhsqetuerjqcetrhlsqgfnqfntvkgxsscquolxxroqgtchffyccetrhlsqgfnqfntvkgxsscquolxxroqgtchffhfqvx",
"output": "37"
},
{
"input": "kkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckkkkkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckckckkc",
"output": "46"
},
{
"input": "mlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydbrxdmlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydik",
"output": "47"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "0"
},
{
"input": "tttttbttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttmttttttt",
"output": "85"
},
{
"input": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffff",
"output": "61"
},
{
"input": "cccccccccccccccccccccccwcccccccccccccccccccccuccccccccccccccnccccccccccccccccccccccccccccccccccccccc",
"output": "38"
},
{
"input": "ffffffffffffffffffffffffffufffgfffffffffffffffffffffffffffffffffffffffgffffffftffffffgffffffffffffff",
"output": "38"
},
{
"input": "rrrrrrrrrrrrrrrrrrrlhbrrrrrrrrurrrrrrrfrrqrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrewrrrrrrryrrxrrrrrrrrrrr",
"output": "33"
},
{
"input": "vyvvvvvvvvzvvvvvzvvvwvvvvrvvvvvvvvvvvvvvvrvvvvvvvvvpkvvpvgvvvvvvvvvvvvvgvvvvvvvvvvvvvvvvvvysvvvbvvvv",
"output": "17"
},
{
"input": "cbubbbbbbbbbbfbbbbbbbbjbobbbbbbbbbbibbubbbbjbbbnzgbbzbbfbbbbbbbbbbbfbpbbbbbbbbbbygbbbgbabbbbbbbhibbb",
"output": "12"
},
{
"input": "lrqrrrrrrrjrrrrrcdrrgrrmwvrrrrrrrrrxfzrmrmrryrrrurrrdrrrrrrrrrrererrrsrrrrrrrrrrrqrrrrcrrwjsrrlrrrrr",
"output": "10"
},
{
"input": "ssssusisisosscssssztzessssyspskjssvosiissussszsosssslsssdsssvssvsssslsssmsfjasjsssssowscsjsssszsspss",
"output": "8"
},
{
"input": "uukuuuumueuuuujuukgdhbztuuuubbguuocuozfaunqufjujuguyuuvkuuauubuubuucuvtjuuuuuusduduuuuuuuueunuuuuuzu",
"output": "7"
},
{
"input": "jpkkgwklngwqcfzmwkkpcwkkkkkekkkekkkdsykqwjkkkhkkkxdnukkkkkkmkqykkkxqklkskkrkkkkkqqjikkkkkkpknkkkkkoh",
"output": "7"
},
{
"input": "bmzbbfbbhqxwthtbbisbbbbbtbbfbbpbfbbpbkbjfbcbbbbzbbbdwmbbbrnvqdbbtbbuglrnbbbbvmbyblebbabibrevaxbbjbqb",
"output": "6"
},
{
"input": "qqqmqqqsbteqqopsuqiqumrqzpqnqgqeniqqkyqqyqqqpxzqeqqquhdqquhqqqfqjirqaqqaquxqoqqjqqqqbjbgqcqqqqicnkqc",
"output": "4"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaavaaaaaaauaaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "44"
},
{
"input": "a",
"output": "0"
},
{
"input": "fg",
"output": "0"
},
{
"input": "yy",
"output": "1"
},
{
"input": "abcabcabc",
"output": "6"
},
{
"input": "qwerqwedqwes",
"output": "3"
}
] | 0 | 0 | -1 | 545 |
711 | Bus to Udayland | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=1000)Β β the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 62 | 4,505,600 | 3 | 547 |
|
122 | Lucky Division | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=β€<=*n*<=β€<=1000) β the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 154 | 2,048,000 | -1 | 548 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.