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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
839 | Journey | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.
Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value). | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach any city from any other by the roads. | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n1 47\n1 13\n1 46\n60 1\n1 6\n23 1\n20 1\n1 52\n2 1\n26 1\n1 59\n1 66\n10 1\n1 62\n1 68\n1 55\n50 1\n33 1\n44 1\n1 34\n1 35\n1 61\n14 1\n67 1\n49 1",
"output": "1.000000000000000"
},
{
"input": "10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1",
"output": "1.500000000000000"
},
{
"input": "1",
"output": "0.000000000000000"
}
] | 109 | 307,200 | -1 | 229 |
|
686 | Free Ice Cream | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 62 | 0 | 3 | 230 |
|
914 | Conan and Agasa play a Card Game | [
"games",
"greedy",
"implementation"
] | null | null | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the *i*-th card, he removes that card and removes the *j*-th card for all *j* such that *a**j*<=<<=*a**i*.
A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards Conan has.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105), where *a**i* is the number on the *i*-th card. | If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). | [
"3\n4 5 7\n",
"2\n1 1\n"
] | [
"Conan\n",
"Agasa\n"
] | In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.
In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again. | [
{
"input": "3\n4 5 7",
"output": "Conan"
},
{
"input": "2\n1 1",
"output": "Agasa"
},
{
"input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282",
"output": "Conan"
},
{
"input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165",
"output": "Agasa"
},
{
"input": "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176",
"output": "Conan"
},
{
"input": "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846",
"output": "Conan"
},
{
"input": "3\n1 2 3",
"output": "Conan"
},
{
"input": "4\n2 3 4 5",
"output": "Conan"
},
{
"input": "10\n30757 30757 33046 41744 39918 39914 41744 39914 33046 33046",
"output": "Conan"
},
{
"input": "10\n50096 50096 50096 50096 50096 50096 28505 50096 50096 50096",
"output": "Conan"
},
{
"input": "10\n54842 54842 54842 54842 57983 54842 54842 57983 57983 54842",
"output": "Conan"
},
{
"input": "10\n87900 87900 5761 87900 87900 87900 5761 87900 87900 87900",
"output": "Agasa"
},
{
"input": "10\n53335 35239 26741 35239 35239 26741 35239 35239 53335 35239",
"output": "Agasa"
},
{
"input": "10\n75994 64716 75994 64716 75994 75994 56304 64716 56304 64716",
"output": "Agasa"
},
{
"input": "1\n1",
"output": "Conan"
},
{
"input": "5\n2 2 1 1 1",
"output": "Conan"
},
{
"input": "5\n1 4 4 5 5",
"output": "Conan"
},
{
"input": "3\n1 3 3",
"output": "Conan"
},
{
"input": "3\n2 2 2",
"output": "Conan"
},
{
"input": "5\n1 1 1 2 2",
"output": "Conan"
},
{
"input": "4\n1 2 1 2",
"output": "Agasa"
},
{
"input": "7\n7 7 7 7 6 6 6",
"output": "Conan"
},
{
"input": "3\n2 3 3",
"output": "Conan"
},
{
"input": "3\n1 1 100000",
"output": "Conan"
},
{
"input": "1\n100000",
"output": "Conan"
},
{
"input": "5\n3 3 3 4 4",
"output": "Conan"
},
{
"input": "3\n1 2 2",
"output": "Conan"
},
{
"input": "3\n4 4 5",
"output": "Conan"
},
{
"input": "1\n2",
"output": "Conan"
},
{
"input": "3\n97 97 100",
"output": "Conan"
},
{
"input": "5\n100000 100000 100000 1 1",
"output": "Conan"
},
{
"input": "7\n7 7 6 6 5 5 4",
"output": "Conan"
},
{
"input": "5\n100000 100000 100000 2 2",
"output": "Conan"
},
{
"input": "4\n3 3 2 1",
"output": "Conan"
},
{
"input": "1\n485",
"output": "Conan"
},
{
"input": "3\n4 4 100000",
"output": "Conan"
},
{
"input": "3\n1 1 2",
"output": "Conan"
},
{
"input": "3\n1 1 1",
"output": "Conan"
},
{
"input": "5\n1 1 2 2 2",
"output": "Conan"
}
] | 0 | 0 | -1 | 231 |
|
681 | A Good Contest | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct. | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155",
"output": "NO"
},
{
"input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968",
"output": "NO"
},
{
"input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290",
"output": "NO"
},
{
"input": "1\na 2400 2401",
"output": "YES"
},
{
"input": "1\nfucker 4000 4000",
"output": "NO"
},
{
"input": "1\nJora 2400 2401",
"output": "YES"
},
{
"input": "1\nACA 2400 2420",
"output": "YES"
},
{
"input": "1\nAca 2400 2420",
"output": "YES"
},
{
"input": "1\nSub_d 2401 2402",
"output": "YES"
},
{
"input": "2\nHack 2400 2401\nDum 1243 555",
"output": "YES"
},
{
"input": "1\nXXX 2400 2500",
"output": "YES"
},
{
"input": "1\nfucker 2400 2401",
"output": "YES"
},
{
"input": "1\nX 2400 2500",
"output": "YES"
},
{
"input": "1\nvineet 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2500",
"output": "YES"
},
{
"input": "1\naaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nhoge 2400 2401",
"output": "YES"
},
{
"input": "1\nInfinity 2400 2468",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2401",
"output": "YES"
},
{
"input": "1\nFuck 2400 2401",
"output": "YES"
},
{
"input": "1\nfuck 2400 2401",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "YES"
},
{
"input": "1\nalex 2400 2401",
"output": "YES"
},
{
"input": "1\nA 2400 2401",
"output": "YES"
},
{
"input": "1\na 2400 2455",
"output": "YES"
},
{
"input": "1\nlol 2400 2401",
"output": "YES"
},
{
"input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214",
"output": "YES"
},
{
"input": "1\naaaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2500",
"output": "YES"
},
{
"input": "1\nds 2400 2410",
"output": "YES"
},
{
"input": "1\nas 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2401",
"output": "YES"
},
{
"input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537",
"output": "YES"
},
{
"input": "1\ncaonima 2400 2401",
"output": "YES"
},
{
"input": "1\narr 2400 2500",
"output": "YES"
},
{
"input": "1\nx 2400 2401",
"output": "YES"
},
{
"input": "1\narrr 2400 2500",
"output": "YES"
},
{
"input": "1\nabc 2400 2405",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2537",
"output": "YES"
},
{
"input": "1\nHELLO 2400 2401",
"output": "YES"
},
{
"input": "1\neatmore 2400 2500",
"output": "YES"
},
{
"input": "1\nb 2400 2401",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nApplejack 2400 2410",
"output": "YES"
},
{
"input": "1\nabacaba 2400 2451",
"output": "YES"
},
{
"input": "1\nrekt_n00b 2500 2600",
"output": "YES"
}
] | 139 | 716,800 | 3 | 232 |
|
0 | none | [
"none"
] | null | null | Bear Limak has *n* colored balls, arranged in one long row. Balls are numbered 1 through *n*, from left to right. There are *n* possible colors, also numbered 1 through *n*. The *i*-th ball has color *t**i*.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — the number of balls.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=*n*) where *t**i* is the color of the *i*-th ball. | Print *n* integers. The *i*-th of them should be equal to the number of intervals where *i* is a dominant color. | [
"4\n1 2 1 2\n",
"3\n1 1 1\n"
] | [
"7 3 0 0 \n",
"6 0 0 \n"
] | In the first sample, color 2 is dominant in three intervals:
- An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. - An interval [4, 4] contains one ball, with color 2 again. - An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them. | [
{
"input": "4\n1 2 1 2",
"output": "7 3 0 0 "
},
{
"input": "3\n1 1 1",
"output": "6 0 0 "
},
{
"input": "10\n9 1 5 2 9 2 9 2 1 1",
"output": "18 30 0 0 1 0 0 0 6 0 "
},
{
"input": "50\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 47 22 34 21 21 30 7 22 21 32 19 34 19 34 22 7 28 6 13 19 30 13 30",
"output": "0 0 0 0 0 22 40 0 0 0 0 0 98 0 0 0 5 0 675 0 165 9 0 61 0 0 0 5 0 6 0 4 0 183 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 "
},
{
"input": "150\n28 124 138 71 71 18 78 136 138 93 145 93 18 15 71 47 47 64 18 72 138 72 18 150 7 71 109 149 18 115 149 149 15 78 124 27 72 124 28 108 138 109 108 111 148 138 78 27 28 150 138 65 15 145 109 47 102 62 28 7 115 108 102 149 150 27 111 64 149 124 13 21 108 64 7 15 72 72 124 47 102 28 109 18 124 28 111 138 7 13 21 62 136 62 13 64 71 7 130 47 77 65 71 148 15 93 64 65 28 65 13 78 78 47 115 138 28 115 72 136 124 145 150 62 105 78 71 102 109 150 27 130 62 7 93 72 93 62 7 124 72 21 62 18 62 7 108 78 148 149",
"output": "0 0 0 0 0 0 1863 0 0 0 0 0 604 0 97 0 0 1026 0 0 12 0 0 0 0 0 208 2982 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1400 0 158 371 0 0 0 0 0 92 296 0 0 0 0 1 199 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 151 0 0 1 0 0 230 37 0 6 0 0 0 44 0 0 0 0 0 0 0 0 174 0 0 0 0 0 2 0 0 0 0 0 4 0 729 0 0 0 0 0 0 4 0 0 4 486 29 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n2 1",
"output": "2 1 "
}
] | 1,450 | 115,609,600 | 0 | 234 |
|
651 | Joysticks | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped. | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 8",
"output": "13"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "24 15",
"output": "36"
},
{
"input": "19 30",
"output": "47"
},
{
"input": "15 31",
"output": "44"
},
{
"input": "14 15",
"output": "27"
},
{
"input": "58 33",
"output": "89"
},
{
"input": "15 25",
"output": "38"
},
{
"input": "59 45",
"output": "102"
},
{
"input": "3 73",
"output": "74"
},
{
"input": "48 1",
"output": "47"
},
{
"input": "100 25",
"output": "122"
},
{
"input": "40 49",
"output": "86"
},
{
"input": "85 73",
"output": "155"
},
{
"input": "29 1",
"output": "28"
},
{
"input": "74 25",
"output": "97"
},
{
"input": "24 57",
"output": "78"
},
{
"input": "23 12",
"output": "33"
},
{
"input": "2 99",
"output": "99"
},
{
"input": "98 2",
"output": "97"
},
{
"input": "2 97",
"output": "97"
},
{
"input": "30 54",
"output": "81"
},
{
"input": "32 53",
"output": "82"
},
{
"input": "32 54",
"output": "84"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 2",
"output": "3"
}
] | 109 | 307,200 | 3 | 235 |
|
6 | Triangle | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 216 | 409,600 | 3.942948 | 236 |
278 | Circle Line | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces. | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"input": "6\n89 82 87 32 67 33\n4 4",
"output": "0"
},
{
"input": "7\n2 3 17 10 2 2 2\n4 2",
"output": "18"
},
{
"input": "3\n4 37 33\n3 3",
"output": "0"
},
{
"input": "8\n87 40 96 7 86 86 72 97\n6 8",
"output": "158"
},
{
"input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8",
"output": "348"
},
{
"input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7",
"output": "0"
},
{
"input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16",
"output": "452"
},
{
"input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6",
"output": "337"
},
{
"input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64",
"output": "1740"
},
{
"input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5",
"output": "2127"
},
{
"input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57",
"output": "932"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6",
"output": "997"
},
{
"input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24",
"output": "195"
},
{
"input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10",
"output": "60"
},
{
"input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25",
"output": "2523"
},
{
"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\n1 51",
"output": "5000"
},
{
"input": "4\n1 1 1 1\n2 4",
"output": "2"
},
{
"input": "4\n1 1 2 1\n2 4",
"output": "2"
}
] | 186 | 6,656,000 | -1 | 237 |
|
812 | Sagheer and Crossroads | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (*l* — left, *s* — straight, *r* — right) and a light *p* for a pedestrian crossing.
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible. | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "1 1 1 0\n0 1 0 1\n1 1 1 0\n1 1 1 1",
"output": "YES"
},
{
"input": "0 1 1 0\n0 1 0 0\n1 0 0 1\n1 0 0 0",
"output": "YES"
},
{
"input": "1 0 0 0\n0 1 0 0\n1 1 0 0\n0 1 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n1 1 1 0",
"output": "YES"
},
{
"input": "1 1 0 0\n0 1 0 1\n1 1 1 0\n0 0 1 1",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 1 0 1\n1 0 1 0\n0 0 1 0",
"output": "YES"
},
{
"input": "1 1 1 0\n0 1 0 1\n1 1 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 0 0\n0 1 0 0\n1 1 1 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 1 0\n1 1 0 0\n1 1 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n1 1 0 0\n1 0 1 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n1 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 1 1 0\n1 1 0 1\n1 0 0 1\n1 1 1 0",
"output": "YES"
},
{
"input": "1 0 0 0\n1 1 0 0\n1 1 0 1\n0 0 1 0",
"output": "YES"
},
{
"input": "0 0 0 0\n1 1 0 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 1 0 0\n1 1 0 1\n1 0 0 1\n1 1 0 1",
"output": "YES"
},
{
"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 0 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 1 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n1 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 1 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 1 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 1 0",
"output": "YES"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n1 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 1 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n1 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 1 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 1 0",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n1 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 1 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n1 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 1 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 1 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n1 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n1 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 1 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1",
"output": "YES"
},
{
"input": "1 0 0 0\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "1 1 1 0\n1 1 1 0\n1 1 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 1\n0 0 0 0\n0 1 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 1\n1 0 0 0\n0 0 0 0",
"output": "YES"
}
] | 46 | 0 | 0 | 240 |
|
540 | Bad Luck Island | [
"dp",
"probabilities"
] | null | null | The Bad Luck Island is inhabited by three kinds of species: *r* rocks, *s* scissors and *p* papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. | The single line contains three integers *r*, *s* and *p* (1<=≤<=*r*,<=*s*,<=*p*<=≤<=100) — the original number of individuals in the species of rock, scissors and paper, respectively. | Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10<=-<=9. | [
"2 2 2\n",
"2 1 2\n",
"1 1 3\n"
] | [
"0.333333333333 0.333333333333 0.333333333333\n",
"0.150000000000 0.300000000000 0.550000000000\n",
"0.057142857143 0.657142857143 0.285714285714\n"
] | none | [
{
"input": "2 2 2",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "2 1 2",
"output": "0.150000000000 0.300000000000 0.550000000000"
},
{
"input": "1 1 3",
"output": "0.057142857143 0.657142857143 0.285714285714"
},
{
"input": "3 2 1",
"output": "0.487662337662 0.072077922078 0.440259740260"
},
{
"input": "100 100 100",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "1 100 100",
"output": "0.366003713151 0.633996286849 0.000000000000"
},
{
"input": "100 1 100",
"output": "0.000000000000 0.366003713151 0.633996286849"
},
{
"input": "100 100 1",
"output": "0.633996286849 0.000000000000 0.366003713151"
},
{
"input": "1 100 99",
"output": "0.369700913626 0.630299086374 0.000000000000"
},
{
"input": "99 1 100",
"output": "0.000000000000 0.369700913626 0.630299086374"
},
{
"input": "100 99 1",
"output": "0.630299086374 0.000000000000 0.369700913626"
},
{
"input": "100 1 99",
"output": "0.000000000000 0.362287378787 0.637712621213"
},
{
"input": "1 99 100",
"output": "0.362287378787 0.637712621213 0.000000000000"
},
{
"input": "99 100 1",
"output": "0.637712621213 0.000000000000 0.362287378787"
},
{
"input": "1 1 1",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "100 100 2",
"output": "0.405362332237 0.000000000000 0.594637667763"
},
{
"input": "100 2 100",
"output": "0.000000000000 0.594637667763 0.405362332237"
},
{
"input": "2 100 100",
"output": "0.594637667763 0.405362332237 0.000000000000"
},
{
"input": "3 3 3",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "44 54 32",
"output": "0.106782618787 0.143399200449 0.749818180764"
},
{
"input": "100 90 5",
"output": "0.082441556638 0.000000001849 0.917558441513"
},
{
"input": "90 5 100",
"output": "0.000000001849 0.917558441513 0.082441556638"
},
{
"input": "5 100 90",
"output": "0.917558441513 0.082441556638 0.000000001849"
},
{
"input": "100 5 90",
"output": "0.000000005097 0.850289405958 0.149710588945"
},
{
"input": "5 90 100",
"output": "0.850289405958 0.149710588945 0.000000005097"
},
{
"input": "90 100 5",
"output": "0.149710588945 0.000000005097 0.850289405958"
},
{
"input": "4 4 4",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "35 38 78",
"output": "0.686231300287 0.301686382598 0.012082317115"
},
{
"input": "100 98 99",
"output": "0.336951942791 0.350590779089 0.312457278120"
},
{
"input": "98 100 99",
"output": "0.329240307786 0.316221888918 0.354537803296"
},
{
"input": "98 99 100",
"output": "0.350590779089 0.312457278120 0.336951942791"
},
{
"input": "100 99 98",
"output": "0.316221888918 0.354537803296 0.329240307786"
},
{
"input": "99 100 98",
"output": "0.312457278120 0.336951942791 0.350590779089"
},
{
"input": "99 98 100",
"output": "0.354537803296 0.329240307786 0.316221888918"
},
{
"input": "5 5 5",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "100 100 99",
"output": "0.320730423530 0.341631521601 0.337638054869"
},
{
"input": "100 99 100",
"output": "0.341631521601 0.337638054869 0.320730423530"
},
{
"input": "99 100 100",
"output": "0.337638054869 0.320730423530 0.341631521601"
},
{
"input": "100 99 99",
"output": "0.328877908413 0.346125932336 0.324996159251"
},
{
"input": "99 100 99",
"output": "0.324996159251 0.328877908413 0.346125932336"
},
{
"input": "99 99 100",
"output": "0.346125932336 0.324996159251 0.328877908413"
},
{
"input": "19 18 23",
"output": "0.367367874268 0.441556405078 0.191075720654"
},
{
"input": "80 80 80",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "80 80 78",
"output": "0.304007530347 0.347995449492 0.347997020160"
},
{
"input": "80 80 79",
"output": "0.318598848470 0.340767700830 0.340633450700"
},
{
"input": "80 80 81",
"output": "0.348184483745 0.325727680711 0.326087835544"
},
{
"input": "80 78 80",
"output": "0.347995449492 0.347997020160 0.304007530347"
},
{
"input": "80 79 80",
"output": "0.340767700830 0.340633450700 0.318598848470"
},
{
"input": "80 81 80",
"output": "0.325727680711 0.326087835544 0.348184483745"
},
{
"input": "78 80 80",
"output": "0.347997020160 0.304007530347 0.347995449492"
},
{
"input": "79 80 80",
"output": "0.340633450700 0.318598848470 0.340767700830"
},
{
"input": "81 80 80",
"output": "0.326087835544 0.348184483745 0.325727680711"
},
{
"input": "2 1 1",
"output": "0.333333333333 0.133333333333 0.533333333333"
},
{
"input": "1 2 1",
"output": "0.533333333333 0.333333333333 0.133333333333"
},
{
"input": "1 1 2",
"output": "0.133333333333 0.533333333333 0.333333333333"
},
{
"input": "2 2 1",
"output": "0.550000000000 0.150000000000 0.300000000000"
},
{
"input": "1 2 2",
"output": "0.300000000000 0.550000000000 0.150000000000"
},
{
"input": "1 2 3",
"output": "0.174025974026 0.692207792208 0.133766233766"
},
{
"input": "1 3 2",
"output": "0.440259740260 0.487662337662 0.072077922078"
},
{
"input": "2 3 1",
"output": "0.692207792208 0.133766233766 0.174025974026"
},
{
"input": "3 1 2",
"output": "0.133766233766 0.174025974026 0.692207792208"
},
{
"input": "2 1 3",
"output": "0.072077922078 0.440259740260 0.487662337662"
},
{
"input": "10 2 69",
"output": "0.000000000001 0.979592460371 0.020407539628"
},
{
"input": "99 99 99",
"output": "0.333333333333 0.333333333333 0.333333333333"
},
{
"input": "1 100 68",
"output": "0.504856156201 0.495143843799 0.000000000000"
},
{
"input": "1 100 69",
"output": "0.499807252268 0.500192747732 0.000000000000"
},
{
"input": "100 68 1",
"output": "0.495143843799 0.000000000000 0.504856156201"
},
{
"input": "100 69 1",
"output": "0.500192747732 0.000000000000 0.499807252268"
},
{
"input": "68 1 100",
"output": "0.000000000000 0.504856156201 0.495143843799"
},
{
"input": "69 1 100",
"output": "0.000000000000 0.499807252268 0.500192747732"
},
{
"input": "40 100 50",
"output": "0.504950275130 0.003137391318 0.491912333552"
},
{
"input": "41 100 50",
"output": "0.471692521594 0.003711367492 0.524596110914"
},
{
"input": "100 50 40",
"output": "0.003137391318 0.491912333552 0.504950275130"
},
{
"input": "100 50 41",
"output": "0.003711367492 0.524596110914 0.471692521594"
},
{
"input": "50 40 100",
"output": "0.491912333552 0.504950275130 0.003137391318"
},
{
"input": "50 41 100",
"output": "0.524596110914 0.471692521594 0.003711367492"
},
{
"input": "4 3 2",
"output": "0.380033049657 0.128974183711 0.490992766632"
},
{
"input": "3 3 2",
"output": "0.448942486085 0.194141929499 0.356915584416"
},
{
"input": "3 2 4",
"output": "0.128974183711 0.490992766632 0.380033049657"
},
{
"input": "3 2 3",
"output": "0.194141929499 0.356915584416 0.448942486085"
},
{
"input": "2 4 3",
"output": "0.490992766632 0.380033049657 0.128974183711"
},
{
"input": "2 3 3",
"output": "0.356915584416 0.448942486085 0.194141929499"
},
{
"input": "94 62 53",
"output": "0.032741579903 0.688734095294 0.278524324802"
},
{
"input": "92 42 99",
"output": "0.156634527800 0.841252178878 0.002113293322"
},
{
"input": "57 88 2",
"output": "0.628039075774 0.000000000036 0.371960924190"
},
{
"input": "49 85 47",
"output": "0.185241468442 0.036259808833 0.778498722726"
},
{
"input": "48 16 81",
"output": "0.009800033922 0.990059771027 0.000140195051"
},
{
"input": "39 96 87",
"output": "0.856896275913 0.001822013551 0.141281710536"
},
{
"input": "100 91 51",
"output": "0.008569274339 0.316910121953 0.674520603708"
},
{
"input": "90 92 97",
"output": "0.412664975931 0.267301641052 0.320033383016"
},
{
"input": "86 25 84",
"output": "0.016023421282 0.983316299665 0.000660279053"
},
{
"input": "80 1 89",
"output": "0.000000000000 0.404923676688 0.595076323312"
},
{
"input": "67 95 88",
"output": "0.419687207048 0.074718763764 0.505594029188"
},
{
"input": "50 93 89",
"output": "0.693218455167 0.011706551519 0.295074993314"
},
{
"input": "27 71 76",
"output": "0.954421631610 0.002613537210 0.042964831180"
},
{
"input": "18 47 22",
"output": "0.741659614574 0.008276779449 0.250063605977"
}
] | 2,000 | 34,816,000 | 0 | 241 |
|
474 | Worms | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms. | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile. | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 280 | 14,643,200 | 3 | 242 |
|
977 | Less or Equal | [
"sortings"
] | null | null | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no such $x$, print "-1" (without quotes). | The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. | Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
If there is no such $x$, print "-1" (without quotes). | [
"7 4\n3 7 5 1 10 3 20\n",
"7 2\n3 7 5 1 10 3 20\n"
] | [
"6",
"-1\n"
] | In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ elements of the given sequence will be also less than or equal to this number. | [
{
"input": "7 4\n3 7 5 1 10 3 20",
"output": "5"
},
{
"input": "7 2\n3 7 5 1 10 3 20",
"output": "-1"
},
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "1 0\n2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "3 0\n3 3 3",
"output": "2"
},
{
"input": "3 0\n2 2 3",
"output": "1"
},
{
"input": "5 0\n3 4 5 6 7",
"output": "2"
},
{
"input": "4 0\n2 3 4 5",
"output": "1"
},
{
"input": "2 2\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "7 2\n2 7 5 1 10 2 20",
"output": "-1"
},
{
"input": "2 1\n1 1",
"output": "-1"
},
{
"input": "5 3\n1 3 3 4 5",
"output": "3"
},
{
"input": "4 4\n1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
}
] | 30 | 0 | 0 | 243 |
|
63 | Sweets Game | [
"bitmasks",
"dfs and similar",
"dp",
"games",
"implementation"
] | E. Sweets Game | 3 | 256 | Karlsson has visited Lillebror again. They found a box of chocolates and a big whipped cream cake at Lillebror's place. Karlsson immediately suggested to divide the sweets fairly between Lillebror and himself. Specifically, to play together a game he has just invented with the chocolates. The winner will get the cake as a reward.
The box of chocolates has the form of a hexagon. It contains 19 cells for the chocolates, some of which contain a chocolate. The players move in turns. During one move it is allowed to eat one or several chocolates that lay in the neighboring cells on one line, parallel to one of the box's sides. The picture below shows the examples of allowed moves and of an unacceptable one. The player who cannot make a move loses.
Karlsson makes the first move as he is Lillebror's guest and not vice versa. The players play optimally. Determine who will get the cake. | The input data contains 5 lines, containing 19 words consisting of one symbol. The word "O" means that the cell contains a chocolate and a "." stands for an empty cell. It is guaranteed that the box contains at least one chocolate. See the examples for better understanding. | If Karlsson gets the cake, print "Karlsson" (without the quotes), otherwise print "Lillebror" (yet again without the quotes). | [
". . .\n . . O .\n. . O O .\n . . . .\n . . .\n",
". . .\n . . . O\n. . . O .\n O . O .\n . O .\n"
] | [
"Lillebror",
"Karlsson"
] | none | [
{
"input": " . . .\n . . O .\n. . O O .\n . . . .\n . . .",
"output": "Lillebror"
},
{
"input": " . . .\n . . . O\n. . . O .\n O . O .\n . O .",
"output": "Karlsson"
},
{
"input": " . . .\n . . . .\n. . . . .\n . . O .\n . . .",
"output": "Karlsson"
},
{
"input": " . . .\n . . . .\n. . . . .\n O . . .\n . . O",
"output": "Lillebror"
},
{
"input": " . . .\n . O . .\n. . . O .\n . O . .\n . . .",
"output": "Karlsson"
},
{
"input": " . O O\n . . O .\n. . . . .\n . . . .\n . . .",
"output": "Lillebror"
},
{
"input": " . . O\n O . O .\n. . O . .\n . O . .\n O . .",
"output": "Karlsson"
},
{
"input": " . . .\n . . O .\n. O . O .\n O . . .\n . . .",
"output": "Lillebror"
},
{
"input": " O O .\n O O . .\n. . . . .\n . . . .\n . O .",
"output": "Lillebror"
},
{
"input": " . O O\n . O . O\n. O . . .\n . . . .\n . . .",
"output": "Karlsson"
},
{
"input": " . O O\n . O . O\n. . . . .\n . . . .\n . . O",
"output": "Lillebror"
},
{
"input": " O . .\n . O O O\n. O . . .\n . . . .\n . . .",
"output": "Karlsson"
},
{
"input": " . . .\n O . . O\n. . O . .\n . . O .\n . O .",
"output": "Karlsson"
},
{
"input": " . . .\n . O . .\n. O O . .\n . . O .\n . O .",
"output": "Karlsson"
},
{
"input": " . . O\n . . . O\n. . . O .\n . . O .\n . O .",
"output": "Karlsson"
},
{
"input": " . . .\n . . . .\nO . O . .\n O O . .\n O . .",
"output": "Lillebror"
},
{
"input": " . . .\n . . . .\n. O . O .\n . O O .\n O . .",
"output": "Lillebror"
},
{
"input": " O . .\n O O . .\n. . . . .\n O . O .\n . O .",
"output": "Karlsson"
},
{
"input": " . . .\n . . O O\n. . O . O\n . . O .\n . O .",
"output": "Karlsson"
},
{
"input": " . . O\n . O . O\n. . O O .\n . . O .\n . . .",
"output": "Karlsson"
},
{
"input": " . . O\n O . O O\nO O . . .\n . . . .\n . . .",
"output": "Lillebror"
},
{
"input": " . . .\n . O O .\nO . . O .\n . . . O\n . . O",
"output": "Lillebror"
},
{
"input": " . . .\n . . . O\n. . . O O\n . . O O\n . O O",
"output": "Karlsson"
},
{
"input": " . . .\n O . . O\n. O . O .\n . O O .\n . O .",
"output": "Lillebror"
},
{
"input": " . O .\n . . O .\n. O O . .\n O . O .\n . O .",
"output": "Lillebror"
},
{
"input": " O . O\n . . . .\nO . O . O\n . . . .\n O . O",
"output": "Karlsson"
},
{
"input": " . . .\n . O O O\n. O O . .\n O . . .\n O O .",
"output": "Karlsson"
},
{
"input": " . O O\n O O . O\nO O . O .\n . . . .\n . . .",
"output": "Lillebror"
},
{
"input": " . O O\n . O O O\n. . O O O\n . . . .\n . . .",
"output": "Lillebror"
},
{
"input": " . . .\n O O O .\nO O . O .\n O . O .\n . O .",
"output": "Karlsson"
},
{
"input": " O O O\n . O . O\nO O O O .\n . . . .\n . . .",
"output": "Lillebror"
},
{
"input": " . O O\n O . O O\nO O . . .\n . . . .\n O O O",
"output": "Karlsson"
},
{
"input": " O . O\n O . O .\nO . O . .\n O O . .\n O O O",
"output": "Karlsson"
},
{
"input": " . O O\n . O O O\n. . O . .\n O O . .\n O O O",
"output": "Karlsson"
},
{
"input": " . O O\n O O O O\nO . O O .\n O O . .\n . . .",
"output": "Lillebror"
},
{
"input": " . O .\n O . . .\nO O O O .\n O O O O\n . . O",
"output": "Lillebror"
},
{
"input": " O . O\n . O O O\n. . . . O\n O O O O\n . . O",
"output": "Lillebror"
},
{
"input": " . . O\n . O O .\nO . O . O\n O O O O\n . . O",
"output": "Lillebror"
},
{
"input": " . . .\n O O O .\n. O O O .\n O . O O\n O O O",
"output": "Karlsson"
},
{
"input": " O O O\n . O . O\nO O O O .\n . . O .\n O . O",
"output": "Karlsson"
},
{
"input": " O O O\n O O . O\nO O . O .\n . . O .\n O . O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO . . . O\n O . . O\n O . .",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\n. O O O .\n . O O .\n . . .",
"output": "Lillebror"
},
{
"input": " O . O\n O O O O\nO O . O O\n . O O .\n . . .",
"output": "Lillebror"
},
{
"input": " O O O\n O . . O\nO O O O O\n O . . .\n O . .",
"output": "Lillebror"
},
{
"input": " O O O\n . O O .\nO O . O O\n O . O .\n O . .",
"output": "Lillebror"
},
{
"input": " O O O\n O . . O\n. O O O .\n . . . O\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O . . O\nO . . . O\n O . . O\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O O O O\n. O . O O\n O . . .\n O O .",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O O O .\n . . . .\n O O .",
"output": "Karlsson"
},
{
"input": " . . .\n . O O O\nO O O O O\n O O O O\n . O .",
"output": "Karlsson"
},
{
"input": " O O O\n . O O O\nO . . . O\n O O . O\n . O O",
"output": "Lillebror"
},
{
"input": " O . O\n O O O .\n. O O O .\n . O O .\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O O O O\n. . O . .\n O . . O\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O . O .\n. . . O O\n O O O O\n O O O",
"output": "Karlsson"
},
{
"input": " O O .\n O . O .\nO O O O O\n O O O O\n . . O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O O O .\n O O O .\n . . .",
"output": "Karlsson"
},
{
"input": " . O O\n O O O O\nO O O O O\n O O O .\n . . .",
"output": "Lillebror"
},
{
"input": " O . O\n O O O O\n. O . O O\n O O . .\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O . O .\nO . . O O\n O . O O\n O O O",
"output": "Lillebror"
},
{
"input": " . O .\n O O . O\nO . O O O\n O O O O\n O O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O . O\nO . O O O\n O . O O\n O O .",
"output": "Karlsson"
},
{
"input": " O O O\n O O . O\n. O . O O\n O O . O\n O O O",
"output": "Lillebror"
},
{
"input": " . O O\n O . O O\nO O . O O\n . O O O\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O O . O\nO . O O O\n O O O O\n . O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O . O O\n O . O O\n O O .",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O O O O\n O O O O\n . . .",
"output": "Lillebror"
},
{
"input": " O O O\n O O . O\nO O . O O\n O . O O\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O O O O\nO . O O .\n . O O O\n O O O",
"output": "Lillebror"
},
{
"input": " O . O\n O O O O\nO O O O O\n . O O .\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O . O O\nO O O . O\n O O O O\n O O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O .\nO O O O O\n O O O O\n . O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O .\nO O O O O\n O O O O\n O O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O O O O\n O O O O\n . O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O O O O\n O . O O\n O O O",
"output": "Karlsson"
},
{
"input": " O O O\n O O O O\nO O . O O\n O O O O\n O O O",
"output": "Lillebror"
},
{
"input": " O O O\n O O O O\nO O O O O\n O O O O\n O O O",
"output": "Karlsson"
},
{
"input": " . . .\n O . . O\n. . . . .\n O . . O\n O O O",
"output": "Karlsson"
},
{
"input": " . O O\n O O . O\nO . O O .\n O O . O\n . O O",
"output": "Karlsson"
},
{
"input": " . O O\n . O . .\nO . O O .\n O O . O\n . . O",
"output": "Karlsson"
}
] | 716 | 9,318,400 | 3.86331 | 244 |
515 | Drazil and Factorial | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
"input": "8\n68931246",
"output": "77553333332222222"
},
{
"input": "7\n4424368",
"output": "75333332222222222"
},
{
"input": "6\n576825",
"output": "7755532222"
},
{
"input": "5\n97715",
"output": "7775332"
},
{
"input": "3\n915",
"output": "75332"
},
{
"input": "2\n26",
"output": "532"
},
{
"input": "1\n4",
"output": "322"
},
{
"input": "15\n028745260720699",
"output": "7777755533333332222222222"
},
{
"input": "13\n5761790121605",
"output": "7775555333322"
},
{
"input": "10\n3312667105",
"output": "755533332"
},
{
"input": "1\n7",
"output": "7"
},
{
"input": "15\n989898989898989",
"output": "777777777777777333333333333333322222222222222222222222222222"
},
{
"input": "15\n000000000000007",
"output": "7"
},
{
"input": "15\n999999999999990",
"output": "77777777777777333333333333333333333333333322222222222222"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "1\n4",
"output": "322"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n6",
"output": "53"
},
{
"input": "1\n7",
"output": "7"
},
{
"input": "1\n9",
"output": "7332"
},
{
"input": "2\n09",
"output": "7332"
},
{
"input": "13\n1337251172966",
"output": "777555333333222"
},
{
"input": "15\n987654329876543",
"output": "777777555533333333332222222222222"
},
{
"input": "9\n234567899",
"output": "777755333333322222222"
},
{
"input": "2\n99",
"output": "77333322"
},
{
"input": "2\n66",
"output": "5533"
},
{
"input": "3\n999",
"output": "777333333222"
},
{
"input": "5\n99999",
"output": "77777333333333322222"
},
{
"input": "9\n123456789",
"output": "77755333332222222"
},
{
"input": "9\n987654321",
"output": "77755333332222222"
},
{
"input": "3\n666",
"output": "555333"
},
{
"input": "2\n26",
"output": "532"
},
{
"input": "6\n555777",
"output": "777555"
},
{
"input": "10\n1234567899",
"output": "777755333333322222222"
},
{
"input": "4\n6666",
"output": "55553333"
},
{
"input": "4\n9754",
"output": "775333222"
},
{
"input": "2\n95",
"output": "75332"
},
{
"input": "14\n11122233344455",
"output": "55333333222222222"
},
{
"input": "12\n836544897832",
"output": "77777553333333222222222222222"
}
] | 0 | 0 | -1 | 245 |
|
777 | Shell Game | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball? | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n0",
"output": "1"
},
{
"input": "2\n0",
"output": "1"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "4\n0",
"output": "2"
},
{
"input": "4\n1",
"output": "0"
},
{
"input": "5\n0",
"output": "0"
},
{
"input": "5\n1",
"output": "2"
},
{
"input": "5\n2",
"output": "1"
},
{
"input": "6\n0",
"output": "0"
},
{
"input": "6\n1",
"output": "1"
},
{
"input": "6\n2",
"output": "2"
},
{
"input": "7\n0",
"output": "1"
},
{
"input": "7\n1",
"output": "0"
},
{
"input": "7\n2",
"output": "2"
},
{
"input": "100000\n0",
"output": "2"
},
{
"input": "100000\n1",
"output": "0"
},
{
"input": "100000\n2",
"output": "1"
},
{
"input": "99999\n1",
"output": "1"
},
{
"input": "99998\n1",
"output": "2"
},
{
"input": "99997\n1",
"output": "0"
},
{
"input": "99996\n1",
"output": "1"
},
{
"input": "99995\n1",
"output": "2"
},
{
"input": "1999999995\n0",
"output": "2"
},
{
"input": "1999999995\n1",
"output": "1"
},
{
"input": "1999999995\n2",
"output": "0"
},
{
"input": "1999999996\n0",
"output": "2"
},
{
"input": "1999999996\n1",
"output": "0"
},
{
"input": "1999999996\n2",
"output": "1"
},
{
"input": "1999999997\n0",
"output": "0"
},
{
"input": "1999999997\n1",
"output": "2"
},
{
"input": "1999999997\n2",
"output": "1"
},
{
"input": "1999999998\n0",
"output": "0"
},
{
"input": "1999999998\n1",
"output": "1"
},
{
"input": "1999999998\n2",
"output": "2"
},
{
"input": "1999999999\n0",
"output": "1"
},
{
"input": "1999999999\n1",
"output": "0"
},
{
"input": "1999999999\n2",
"output": "2"
},
{
"input": "2000000000\n1",
"output": "2"
},
{
"input": "2000000000\n2",
"output": "0"
},
{
"input": "1234567890\n0",
"output": "0"
},
{
"input": "1234567890\n1",
"output": "1"
},
{
"input": "1234567890\n2",
"output": "2"
},
{
"input": "123456789\n0",
"output": "2"
},
{
"input": "123456789\n1",
"output": "1"
},
{
"input": "123456789\n2",
"output": "0"
},
{
"input": "123456790\n0",
"output": "2"
},
{
"input": "12\n2",
"output": "2"
},
{
"input": "32\n1",
"output": "2"
},
{
"input": "20\n2",
"output": "0"
},
{
"input": "10\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "76994383\n1",
"output": "0"
},
{
"input": "25\n2",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "12\n0",
"output": "0"
},
{
"input": "150\n2",
"output": "2"
},
{
"input": "15\n0",
"output": "2"
},
{
"input": "21\n2",
"output": "0"
},
{
"input": "18\n2",
"output": "2"
},
{
"input": "8\n2",
"output": "0"
},
{
"input": "10\n0",
"output": "2"
},
{
"input": "16\n0",
"output": "2"
}
] | 108 | 307,200 | 3 | 246 |
|
81 | Plug-in | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu".
Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something!
Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "il",
"output": "il"
},
{
"input": "gfj",
"output": "gfj"
},
{
"input": "babbbbbababa",
"output": "babababa"
},
{
"input": "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa",
"output": "babababababababababababa"
},
{
"input": "aab",
"output": "b"
},
{
"input": "abb",
"output": "a"
},
{
"input": "aba",
"output": "aba"
},
{
"input": "ab",
"output": "ab"
}
] | 156 | 2,457,600 | 3.917422 | 248 |
999 | Mishka and Contest | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve? | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems. | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62",
"output": "100"
},
{
"input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98",
"output": "98"
},
{
"input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2",
"output": "39"
},
{
"input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16",
"output": "99"
},
{
"input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1",
"output": "1"
},
{
"input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "3 2\n1 4 1",
"output": "2"
},
{
"input": "1 2\n100",
"output": "0"
},
{
"input": "7 4\n4 2 3 4 4 2 3",
"output": "7"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "1 2\n15",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "5 3\n3 4 3 2 1",
"output": "4"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "1 5\n1",
"output": "1"
},
{
"input": "6 6\n7 1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n6 5 5 5 5",
"output": "4"
},
{
"input": "1 4\n2",
"output": "1"
},
{
"input": "9 4\n1 2 1 2 4 2 1 2 1",
"output": "9"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n5",
"output": "1"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4",
"output": "71"
},
{
"input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90",
"output": "63"
},
{
"input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8",
"output": "61"
},
{
"input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22",
"output": "72"
},
{
"input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2",
"output": "52"
},
{
"input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90",
"output": "60"
},
{
"input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10",
"output": "56"
},
{
"input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90",
"output": "61"
},
{
"input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24",
"output": "99"
},
{
"input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50",
"output": "99"
},
{
"input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48",
"output": "99"
},
{
"input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57",
"output": "99"
},
{
"input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93",
"output": "99"
},
{
"input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33",
"output": "3"
},
{
"input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51",
"output": "3"
},
{
"input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49",
"output": "6"
},
{
"input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8",
"output": "66"
},
{
"input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95",
"output": "0"
},
{
"input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66",
"output": "0"
},
{
"input": "2 8\n8 8",
"output": "2"
},
{
"input": "1 6\n3",
"output": "1"
},
{
"input": "1 5\n5",
"output": "1"
}
] | 1,000 | 1,228,800 | 0 | 250 |
|
24 | Ring road | [
"graphs"
] | A. Ring road | 2 | 256 | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all *n* roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other? | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* to city *b**i*, redirecting the traffic costs *c**i*. | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | [
"3\n1 3 1\n1 2 1\n3 2 1\n",
"3\n1 3 1\n1 2 5\n3 2 1\n",
"6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n"
] | [
"1\n",
"2\n",
"39\n",
"0\n"
] | none | [
{
"input": "3\n1 3 1\n1 2 1\n3 2 1",
"output": "1"
},
{
"input": "3\n1 3 1\n1 2 5\n3 2 1",
"output": "2"
},
{
"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42",
"output": "39"
},
{
"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5",
"output": "0"
},
{
"input": "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54",
"output": "143"
},
{
"input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90",
"output": "267"
},
{
"input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40",
"output": "435"
},
{
"input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 93\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2",
"output": "413"
},
{
"input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45",
"output": "950"
},
{
"input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99",
"output": "1117"
},
{
"input": "3\n3 1 1\n2 1 1\n2 3 1",
"output": "1"
}
] | 154 | 2,867,200 | 3.956159 | 251 |
381 | Sereja and Dima | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24",
"output": "644 500"
},
{
"input": "1\n3",
"output": "3 0"
},
{
"input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646",
"output": "6848 6568"
},
{
"input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727",
"output": "9562 9561"
},
{
"input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12",
"output": "315 315"
},
{
"input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304",
"output": "3238 2222"
},
{
"input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325",
"output": "5246 4864"
},
{
"input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71",
"output": "8147 7807"
},
{
"input": "1\n1",
"output": "1 0"
}
] | 31 | 0 | 3 | 253 |
|
96 | Football | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 92 | 0 | 3.977 | 254 |
20 | BerOS file system | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form. | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "/a//aa/a//",
"output": "/a/aa/a"
},
{
"input": "/aa//b/aa",
"output": "/aa/b/aa"
},
{
"input": "////////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/"
},
{
"input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/",
"output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb"
},
{
"input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt"
},
{
"input": "///a//a////a/a//a//a//a/////",
"output": "/a/a/a/a/a/a/a"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a",
"output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a"
},
{
"input": "///////////////////////////////////////////////////////////////////////////////////////////////////z",
"output": "/z"
},
{
"input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/z"
}
] | 124 | 0 | 3.969 | 256 |
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"
}
] | 92 | 0 | 0 | 258 |
560 | Gerald is into Art | [
"constructive algorithms",
"implementation"
] | null | null | Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rectangles.
Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough? | The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000. | If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). | [
"3 2\n1 3\n2 1\n",
"5 5\n3 3\n3 3\n",
"4 2\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | That's how we can place the pictures in the first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's how we can do it in the third one.
<img class="tex-graphics" src="https://espresso.codeforces.com/dafdf616eaa5ef10cd3c9ccdc7fba7ece392268c.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "3 2\n1 3\n2 1",
"output": "YES"
},
{
"input": "5 5\n3 3\n3 3",
"output": "NO"
},
{
"input": "4 2\n2 3\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 1",
"output": "YES"
},
{
"input": "1000 1000\n999 999\n1 1000",
"output": "YES"
},
{
"input": "7 7\n5 5\n2 4",
"output": "YES"
},
{
"input": "3 3\n2 2\n2 2",
"output": "NO"
},
{
"input": "2 9\n5 1\n3 2",
"output": "YES"
},
{
"input": "9 9\n3 8\n5 2",
"output": "YES"
},
{
"input": "10 10\n10 5\n4 3",
"output": "YES"
},
{
"input": "10 6\n10 1\n5 7",
"output": "YES"
},
{
"input": "6 10\n6 3\n6 2",
"output": "YES"
},
{
"input": "7 10\n7 5\n1 7",
"output": "YES"
},
{
"input": "10 10\n7 4\n3 5",
"output": "YES"
},
{
"input": "4 10\n1 1\n9 3",
"output": "YES"
},
{
"input": "8 7\n1 7\n3 2",
"output": "YES"
},
{
"input": "5 10\n5 2\n3 5",
"output": "YES"
},
{
"input": "9 9\n9 7\n2 9",
"output": "YES"
},
{
"input": "8 10\n3 8\n7 4",
"output": "YES"
},
{
"input": "10 10\n6 6\n4 9",
"output": "YES"
},
{
"input": "8 9\n7 6\n2 3",
"output": "YES"
},
{
"input": "10 10\n9 10\n6 1",
"output": "YES"
},
{
"input": "90 100\n52 76\n6 47",
"output": "YES"
},
{
"input": "84 99\n82 54\n73 45",
"output": "YES"
},
{
"input": "100 62\n93 3\n100 35",
"output": "YES"
},
{
"input": "93 98\n75 32\n63 7",
"output": "YES"
},
{
"input": "86 100\n2 29\n71 69",
"output": "YES"
},
{
"input": "96 100\n76 21\n78 79",
"output": "YES"
},
{
"input": "99 100\n95 68\n85 32",
"output": "YES"
},
{
"input": "97 100\n95 40\n70 60",
"output": "YES"
},
{
"input": "100 100\n6 45\n97 54",
"output": "YES"
},
{
"input": "99 100\n99 72\n68 1",
"output": "YES"
},
{
"input": "88 100\n54 82\n86 45",
"output": "YES"
},
{
"input": "91 100\n61 40\n60 88",
"output": "YES"
},
{
"input": "100 100\n36 32\n98 68",
"output": "YES"
},
{
"input": "78 86\n63 8\n9 4",
"output": "YES"
},
{
"input": "72 93\n38 5\n67 64",
"output": "YES"
},
{
"input": "484 1000\n465 2\n9 535",
"output": "YES"
},
{
"input": "808 1000\n583 676\n527 416",
"output": "YES"
},
{
"input": "965 1000\n606 895\n533 394",
"output": "YES"
},
{
"input": "824 503\n247 595\n151 570",
"output": "YES"
},
{
"input": "970 999\n457 305\n542 597",
"output": "YES"
},
{
"input": "332 834\n312 23\n505 272",
"output": "YES"
},
{
"input": "886 724\n830 439\n102 594",
"output": "YES"
},
{
"input": "958 1000\n326 461\n836 674",
"output": "YES"
},
{
"input": "903 694\n104 488\n567 898",
"output": "YES"
},
{
"input": "800 1000\n614 163\n385 608",
"output": "YES"
},
{
"input": "926 1000\n813 190\n187 615",
"output": "YES"
},
{
"input": "541 1000\n325 596\n403 56",
"output": "YES"
},
{
"input": "881 961\n139 471\n323 731",
"output": "YES"
},
{
"input": "993 1000\n201 307\n692 758",
"output": "YES"
},
{
"input": "954 576\n324 433\n247 911",
"output": "YES"
},
{
"input": "7 3\n7 8\n1 5",
"output": "NO"
},
{
"input": "5 9\n2 7\n8 10",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10",
"output": "NO"
},
{
"input": "2 7\n8 3\n2 7",
"output": "NO"
},
{
"input": "1 4\n7 2\n3 2",
"output": "NO"
},
{
"input": "5 8\n5 1\n10 5",
"output": "NO"
},
{
"input": "3 5\n3 6\n10 7",
"output": "NO"
},
{
"input": "6 2\n6 6\n1 2",
"output": "NO"
},
{
"input": "10 3\n6 6\n4 7",
"output": "NO"
},
{
"input": "9 10\n4 8\n5 6",
"output": "YES"
},
{
"input": "3 8\n3 2\n8 7",
"output": "NO"
},
{
"input": "3 3\n3 4\n3 6",
"output": "NO"
},
{
"input": "6 10\n1 8\n3 2",
"output": "YES"
},
{
"input": "8 1\n7 5\n3 9",
"output": "NO"
},
{
"input": "9 7\n5 2\n4 1",
"output": "YES"
},
{
"input": "100 30\n42 99\n78 16",
"output": "NO"
},
{
"input": "64 76\n5 13\n54 57",
"output": "YES"
},
{
"input": "85 19\n80 18\n76 70",
"output": "NO"
},
{
"input": "57 74\n99 70\n86 29",
"output": "NO"
},
{
"input": "22 21\n73 65\n92 35",
"output": "NO"
},
{
"input": "90 75\n38 2\n100 61",
"output": "NO"
},
{
"input": "62 70\n48 12\n75 51",
"output": "NO"
},
{
"input": "23 17\n34 71\n98 34",
"output": "NO"
},
{
"input": "95 72\n65 31\n89 50",
"output": "NO"
},
{
"input": "68 19\n39 35\n95 65",
"output": "NO"
},
{
"input": "28 65\n66 27\n5 72",
"output": "NO"
},
{
"input": "100 16\n41 76\n24 15",
"output": "NO"
},
{
"input": "21 63\n28 73\n60 72",
"output": "NO"
},
{
"input": "85 18\n37 84\n35 62",
"output": "NO"
},
{
"input": "58 64\n98 30\n61 52",
"output": "NO"
},
{
"input": "32 891\n573 351\n648 892",
"output": "NO"
},
{
"input": "796 846\n602 302\n600 698",
"output": "NO"
},
{
"input": "665 289\n608 360\n275 640",
"output": "NO"
},
{
"input": "237 595\n318 161\n302 838",
"output": "NO"
},
{
"input": "162 742\n465 429\n571 29",
"output": "NO"
},
{
"input": "222 889\n491 923\n76 195",
"output": "NO"
},
{
"input": "794 140\n166 622\n378 905",
"output": "NO"
},
{
"input": "663 287\n193 212\n615 787",
"output": "NO"
},
{
"input": "427 433\n621 441\n868 558",
"output": "NO"
},
{
"input": "1000 388\n332 49\n735 699",
"output": "NO"
},
{
"input": "868 535\n409 690\n761 104",
"output": "YES"
},
{
"input": "632 786\n710 208\n436 290",
"output": "YES"
},
{
"input": "501 932\n463 636\n363 918",
"output": "NO"
},
{
"input": "73 79\n626 483\n924 517",
"output": "NO"
},
{
"input": "190 34\n653 163\n634 314",
"output": "NO"
},
{
"input": "2 4\n1 3\n1 4",
"output": "YES"
},
{
"input": "3 10\n1 1\n1 11",
"output": "NO"
},
{
"input": "5 4\n3 3\n2 6",
"output": "NO"
},
{
"input": "3 4\n1 6\n2 3",
"output": "NO"
}
] | 62 | 0 | 0 | 259 |
|
614 | Link/Cut Tree | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him! | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output": "97969 30664297 9597924961 "
},
{
"input": "5482 100347128000 342",
"output": "116964 40001688 13680577296 "
},
{
"input": "3680 37745933600 10",
"output": "10000 100000 1000000 10000000 100000000 1000000000 10000000000 "
},
{
"input": "17098 191120104800 43",
"output": "79507 3418801 147008443 6321363049 "
},
{
"input": "10462 418807699200 2",
"output": "16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 "
},
{
"input": "30061 641846400000 3",
"output": "59049 177147 531441 1594323 4782969 14348907 43046721 129140163 387420489 1162261467 3486784401 10460353203 31381059609 94143178827 282429536481 "
},
{
"input": "1 1000000000000000000 2",
"output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 70368744177664 140737488355328 281474976710656 562949953421312 1125899906842624 2251799813685248 4503599627370496 900719925474099..."
},
{
"input": "32 2498039712000 4",
"output": "64 256 1024 4096 16384 65536 262144 1048576 4194304 16777216 67108864 268435456 1073741824 4294967296 17179869184 68719476736 274877906944 1099511627776 "
},
{
"input": "1 2576683920000 2",
"output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 "
},
{
"input": "5 25 5",
"output": "5 25 "
},
{
"input": "1 90 90",
"output": "1 90 "
},
{
"input": "95 2200128528000 68",
"output": "4624 314432 21381376 1453933568 98867482624 "
},
{
"input": "64 426314644000 53",
"output": "2809 148877 7890481 418195493 22164361129 "
},
{
"input": "198765 198765 198765",
"output": "198765 "
},
{
"input": "42 2845016496000 12",
"output": "144 1728 20736 248832 2985984 35831808 429981696 5159780352 61917364224 743008370688 "
},
{
"input": "6 6 3",
"output": "-1"
},
{
"input": "1 10 11",
"output": "1 "
},
{
"input": "2 10 11",
"output": "-1"
},
{
"input": "87 160 41",
"output": "-1"
},
{
"input": "237171123124584251 923523399718980912 7150",
"output": "-1"
},
{
"input": "101021572000739548 453766043506276015 8898",
"output": "-1"
},
{
"input": "366070689449360724 928290634811046396 8230",
"output": "-1"
},
{
"input": "438133886369772308 942612870269666780 7193",
"output": "-1"
},
{
"input": "10 10 10",
"output": "10 "
},
{
"input": "16 16 256",
"output": "-1"
},
{
"input": "1 1000000000000000000 1000000000",
"output": "1 1000000000 1000000000000000000 "
},
{
"input": "1000000000000000000 1000000000000000000 1000000000",
"output": "1000000000000000000 "
},
{
"input": "1000000000 1000000000000000000 1000000000",
"output": "1000000000 1000000000000000000 "
},
{
"input": "1 1 4",
"output": "1 "
},
{
"input": "1 999999999999999999 1000000000",
"output": "1 1000000000 "
},
{
"input": "1 1000000000000000000 999999990",
"output": "1 999999990 999999980000000100 "
},
{
"input": "1 1000000000000000000 999999984",
"output": "1 999999984 999999968000000256 "
},
{
"input": "1 1000000000000000000 324325",
"output": "1 324325 105186705625 34114678301828125 "
},
{
"input": "1 1000000000000000000 999999523",
"output": "1 999999523 999999046000227529 "
},
{
"input": "1 243 3",
"output": "1 3 9 27 81 243 "
},
{
"input": "62769392426654367 567152589733560993 688813",
"output": "326816522793383797 "
},
{
"input": "1 1000000000000000000 690852001",
"output": "1 690852001 477276487285704001 "
},
{
"input": "1 1000000000000000000 918745157",
"output": "1 918745157 844092663510954649 "
},
{
"input": "1 1000000000000000000 131299843",
"output": "1 131299843 17239648771824649 "
},
{
"input": "2861381721051425 2861381721051425 1234",
"output": "-1"
}
] | 31 | 0 | 0 | 260 |
|
384 | Coder | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C"
},
{
"input": "15",
"output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C"
},
{
"input": "100",
"output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "101",
"output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "500",
"output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...."
},
{
"input": "501",
"output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..."
},
{
"input": "755",
"output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "888",
"output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "998",
"output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "999",
"output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1000",
"output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1",
"output": "1\nC"
}
] | 62 | 4,608,000 | 3 | 261 |
|
358 | Dima and Text Messages | [
"brute force",
"strings"
] | null | null | Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3*word*1<3*word*2<3 ... *word**n*<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. | In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. | [
"3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n"
] | [
"yes\n",
"no\n"
] | Please note that Dima got a good old kick in the pants for the second sample from the statement. | [
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3",
"output": "yes"
},
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3",
"output": "yes"
},
{
"input": "4\na\nb\nc\nd\n<3a<3b<3c<3d",
"output": "no"
},
{
"input": "4\na\nb\nc\nd\na<3b<3c<3d<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<3you<3",
"output": "yes"
},
{
"input": "1\na\na",
"output": "no"
},
{
"input": "1\na\n<3a<3b",
"output": "yes"
},
{
"input": "1\naa\n<3a<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww",
"output": "yes"
},
{
"input": "3\ni\nlove\nyou\n<3ilove<23you<3",
"output": "no"
},
{
"input": "2\na\ni\n<3ai<3",
"output": "no"
}
] | 233 | 5,836,800 | 3 | 262 |
|
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"
}
] | 62 | 6,758,400 | 3 | 263 |
|
4 | Watermelon | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 124 | 0 | 0 | 265 |
996 | Hit the Lottery | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 78 | 0 | 3 | 267 |
|
484 | Bits | [
"bitmasks",
"constructive algorithms"
] | null | null | Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the smallest of them. | The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000).
Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). | For each query print the answer in a separate line. | [
"3\n1 2\n2 4\n1 10\n"
] | [
"1\n3\n7\n"
] | The binary representations of numbers from 1 to 10 are listed below:
1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub>
2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub>
3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub>
4<sub class="lower-index">10</sub> = 100<sub class="lower-index">2</sub>
5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>
6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>
7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>
8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>
9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub>
10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub> | [
{
"input": "3\n1 2\n2 4\n1 10",
"output": "1\n3\n7"
},
{
"input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10",
"output": "1\n1\n3\n3\n3\n3\n7\n7\n7\n7\n2\n3\n3\n3\n3\n7\n7\n7\n7\n3\n3\n3\n3\n7\n7\n7\n7\n4\n5\n5\n7\n7\n7\n7\n5\n5\n7\n7\n7\n7\n6\n7\n7\n7\n7\n7\n7\n7\n7\n8\n9\n9\n9\n9\n10"
},
{
"input": "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000",
"output": "7\n63\n511\n8191\n65535\n524287\n8388607\n67108863\n536870911\n8589934591\n68719476735\n549755813887\n8796093022207\n70368744177663\n562949953421311\n9007199254740991\n72057594037927935\n576460752303423487"
},
{
"input": "3\n0 0\n1 3\n2 4",
"output": "0\n3\n3"
},
{
"input": "17\n0 0\n0 8\n1 8\n36 39\n3 4\n3 7\n2 17\n8 12\n9 12\n10 12\n10 15\n6 14\n8 15\n9 15\n15 15\n100000000000000000 1000000000000000000\n99999999999999999 1000000000000000000",
"output": "0\n7\n7\n39\n3\n7\n15\n11\n11\n11\n15\n7\n15\n15\n15\n576460752303423487\n576460752303423487"
}
] | 1,000 | 0 | 0 | 269 |
|
570 | Elections | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections. | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*.
It is guaranteed that the total number of people in all the cities does not exceed 109. | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index. | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{
"input": "2 2\n1 2\n2 1",
"output": "1"
},
{
"input": "2 2\n2 1\n2 1",
"output": "1"
},
{
"input": "2 2\n1 2\n1 2",
"output": "2"
},
{
"input": "3 3\n0 0 0\n1 1 1\n2 2 2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9",
"output": "5"
},
{
"input": "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n0 1 1 0",
"output": "1"
},
{
"input": "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0",
"output": "1"
},
{
"input": "4 4\n1 4 1 300\n3 1 2 1\n5 0 0 2\n0 1 10 100",
"output": "1"
},
{
"input": "5 5\n15 45 15 300 10\n53 15 25 51 10\n5 50 50 2 10\n1000 1 10 100 10\n10 10 10 10 10",
"output": "1"
},
{
"input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "1"
},
{
"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": "1"
},
{
"input": "1 100\n859\n441\n272\n47\n355\n345\n612\n569\n545\n599\n410\n31\n720\n303\n58\n537\n561\n730\n288\n275\n446\n955\n195\n282\n153\n455\n996\n121\n267\n702\n769\n560\n353\n89\n990\n282\n801\n335\n573\n258\n722\n768\n324\n41\n249\n125\n557\n303\n664\n945\n156\n884\n985\n816\n433\n65\n976\n963\n85\n647\n46\n877\n665\n523\n714\n182\n377\n549\n994\n385\n184\n724\n447\n99\n766\n353\n494\n747\n324\n436\n915\n472\n879\n582\n928\n84\n627\n156\n972\n651\n159\n372\n70\n903\n590\n480\n184\n540\n270\n892",
"output": "1"
},
{
"input": "100 1\n439 158 619 538 187 153 973 781 610 475 94 947 449 531 220 51 788 118 189 501 54 434 465 902 280 635 688 214 737 327 682 690 683 519 261 923 254 388 529 659 662 276 376 735 976 664 521 285 42 147 187 259 407 977 879 465 522 17 550 701 114 921 577 265 668 812 232 267 135 371 586 201 608 373 771 358 101 412 195 582 199 758 507 882 16 484 11 712 916 699 783 618 405 124 904 257 606 610 230 718",
"output": "54"
},
{
"input": "1 99\n511\n642\n251\n30\n494\n128\n189\n324\n884\n656\n120\n616\n959\n328\n411\n933\n895\n350\n1\n838\n996\n761\n619\n131\n824\n751\n707\n688\n915\n115\n244\n476\n293\n986\n29\n787\n607\n259\n756\n864\n394\n465\n303\n387\n521\n582\n485\n355\n299\n997\n683\n472\n424\n948\n339\n383\n285\n957\n591\n203\n866\n79\n835\n980\n344\n493\n361\n159\n160\n947\n46\n362\n63\n553\n793\n754\n429\n494\n523\n227\n805\n313\n409\n243\n927\n350\n479\n971\n825\n460\n544\n235\n660\n327\n216\n729\n147\n671\n738",
"output": "1"
},
{
"input": "99 1\n50 287 266 159 551 198 689 418 809 43 691 367 160 664 86 805 461 55 127 950 576 351 721 493 972 560 934 885 492 92 321 759 767 989 883 7 127 413 404 604 80 645 666 874 371 718 893 158 722 198 563 293 134 255 742 913 252 378 859 721 502 251 839 284 133 209 962 514 773 124 205 903 785 859 911 93 861 786 747 213 690 69 942 697 211 203 284 961 351 137 962 952 408 249 238 850 944 40 346",
"output": "34"
},
{
"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 2",
"output": "100"
},
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 1\n0 0",
"output": "1"
},
{
"input": "2 2\n0 0\n0 0",
"output": "1"
},
{
"input": "2 2\n1 2\n0 0",
"output": "1"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 0",
"output": "1"
},
{
"input": "2 3\n0 0\n0 0\n0 1",
"output": "1"
},
{
"input": "3 2\n1 1 3\n0 0 0",
"output": "1"
},
{
"input": "3 4\n1 10 3\n0 0 0\n0 0 0\n0 0 0",
"output": "1"
},
{
"input": "2 4\n2 1\n1 2\n0 0\n1 2",
"output": "1"
},
{
"input": "2 2\n0 1\n0 1",
"output": "2"
},
{
"input": "2 3\n1 2\n0 0\n2 1",
"output": "1"
},
{
"input": "2 2\n0 0\n4 5",
"output": "1"
},
{
"input": "3 2\n10 15 20\n0 0 0",
"output": "1"
},
{
"input": "3 4\n0 0 0\n0 0 0\n0 0 0\n1 2 3",
"output": "1"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 1",
"output": "1"
},
{
"input": "3 3\n0 0 0\n1 2 3\n1 3 2",
"output": "1"
},
{
"input": "3 1\n0 0 0",
"output": "1"
},
{
"input": "3 3\n0 0 1\n0 0 0\n0 0 0",
"output": "1"
}
] | 46 | 0 | 0 | 270 |
|
385 | Bear and Raspberry | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77",
"output": "87"
},
{
"input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93",
"output": "84"
},
{
"input": "6 100\n10 9 8 7 6 5",
"output": "0"
},
{
"input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46",
"output": "78"
},
{
"input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44",
"output": "0"
},
{
"input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62",
"output": "4"
},
{
"input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71",
"output": "0"
},
{
"input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1",
"output": "0"
},
{
"input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27",
"output": "63"
},
{
"input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22",
"output": "38"
},
{
"input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83",
"output": "91"
},
{
"input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14",
"output": "79"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24",
"output": "91"
},
{
"input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49",
"output": "83"
},
{
"input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70",
"output": "94"
},
{
"input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42",
"output": "43"
},
{
"input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0",
"output": "100"
},
{
"input": "3 1\n1 2 3",
"output": "0"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "0"
},
{
"input": "3 100\n1 2 3",
"output": "0"
},
{
"input": "2 100\n0 0",
"output": "0"
},
{
"input": "2 90\n10 5",
"output": "0"
},
{
"input": "2 5\n5 4",
"output": "0"
},
{
"input": "3 1\n19 20 1",
"output": "18"
},
{
"input": "5 1\n5 10 7 4 20",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "0"
}
] | 139 | 0 | 3 | 271 |
|
592 | The Big Race | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today? | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "3000000000000000000 2999999999999999873 2999999999999999977",
"output": "23437499999999999/23437500000000000"
},
{
"input": "9 6 1",
"output": "1/9"
},
{
"input": "32 9 2",
"output": "3/32"
},
{
"input": "976 5 6",
"output": "41/244"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 714 345",
"output": "689/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 1173508 8918834",
"output": "1173507/329245015"
},
{
"input": "321076647734423976 7 7",
"output": "1/1"
},
{
"input": "455227494055672047 92 28",
"output": "19792499741550983/455227494055672047"
},
{
"input": "595779167455745259 6954 8697",
"output": "205511958419723/595779167455745259"
},
{
"input": "1000000000000000000 1000000000 2000000000",
"output": "1/2"
},
{
"input": "462643382718281828 462643382718281507 462643382718281701",
"output": "33045955908448679/33045955908448702"
},
{
"input": "4000000000000000000 9999999999999997 99999999999999999",
"output": "2499999999999999/1000000000000000000"
},
{
"input": "4003000100004000000 9999999099999999 99999999999999999",
"output": "4999999549999999/2001500050002000000"
},
{
"input": "4903000100004000000 58997960959949999 99933992929999999",
"output": "29498980479974999/2451500050002000000"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "232 17 83",
"output": "2/29"
},
{
"input": "5496272 63 200",
"output": "13765/2748136"
},
{
"input": "180 174 53",
"output": "13/45"
},
{
"input": "1954 190 537",
"output": "189/1954"
},
{
"input": "146752429 510 514",
"output": "571199/146752429"
},
{
"input": "579312860 55 70",
"output": "10344881/144828215"
},
{
"input": "1 9 9",
"output": "1/1"
},
{
"input": "95 19 19",
"output": "1/1"
},
{
"input": "404 63 441",
"output": "31/202"
},
{
"input": "5566 4798 4798",
"output": "1/1"
},
{
"input": "118289676 570846883 570846883",
"output": "1/1"
},
{
"input": "763 358 358",
"output": "1/1"
},
{
"input": "85356138 7223 482120804",
"output": "3611/42678069"
},
{
"input": "674664088 435395270 5",
"output": "9/674664088"
},
{
"input": "762200126044291557 370330636048898430 6",
"output": "17/762200126044291557"
},
{
"input": "917148533938841535 47 344459175789842163",
"output": "28/183429706787768307"
},
{
"input": "360212127113008697 877228952036215545 5259",
"output": "5258/360212127113008697"
},
{
"input": "683705963104411677 89876390 116741460012229240",
"output": "539258339/683705963104411677"
},
{
"input": "573003994959686829 275856334120822851 1319886766128339",
"output": "3959660298385016/573003994959686829"
},
{
"input": "409853735661743839 413850294331656955 413850294331656955",
"output": "1/1"
},
{
"input": "19 1 19",
"output": "1/19"
},
{
"input": "576 18 32",
"output": "1/16"
},
{
"input": "9540 10 954",
"output": "1/477"
},
{
"input": "101997840 6 16999640",
"output": "1/8499820"
},
{
"input": "955944 1278 748",
"output": "1/639"
},
{
"input": "482120804 66748 7223",
"output": "1/66748"
},
{
"input": "370330636048898430 61721772674816405 6",
"output": "1/61721772674816405"
},
{
"input": "344459175789842163 7328918633826429 47",
"output": "1/7328918633826429"
},
{
"input": "877228952036215545 166805277055755 5259",
"output": "1/55601759018585"
},
{
"input": "116741460012229240 1298911316 89876390",
"output": "1/649455658"
},
{
"input": "275856334120822851 209 1319886766128339",
"output": "1/1319886766128339"
},
{
"input": "413850294331656955 1 413850294331656955",
"output": "1/413850294331656955"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 3931027 6443236",
"output": "357366/29931365"
},
{
"input": "321076647734423976 7 8",
"output": "1672274206950125/13378193655600999"
},
{
"input": "455227494055672047 71 60",
"output": "6411654845854559/455227494055672047"
},
{
"input": "595779167455745259 9741 9331",
"output": "61162012885196/595779167455745259"
},
{
"input": "6470 80 160",
"output": "327/647"
},
{
"input": "686325 828 1656",
"output": "114511/228775"
},
{
"input": "4535304 2129 4258",
"output": "755973/1511768"
},
{
"input": "40525189 6365 12730",
"output": "20265394/40525189"
},
{
"input": "675297075 25986 51972",
"output": "112553659/225099025"
},
{
"input": "5681598412 75376 226128",
"output": "1893897375/5681598412"
},
{
"input": "384118571739435733 619773000 1859319000",
"output": "128039524053435733/384118571739435733"
},
{
"input": "391554751752251913 625743359 1877230077",
"output": "130518250652782079/391554751752251913"
},
{
"input": "390728504279201198 625082797 1250165594",
"output": "195364252413988195/390728504279201198"
},
{
"input": "389902265396085075 624421544 1248843088",
"output": "64983710976697837/129967421798695025"
},
{
"input": "734812071040507372 857211800 2571635400",
"output": "61234339274051543/183703017760126843"
},
{
"input": "1 1 2",
"output": "0/1"
},
{
"input": "3 1 4",
"output": "0/1"
},
{
"input": "8 2 3",
"output": "3/8"
},
{
"input": "64 32 16",
"output": "1/2"
},
{
"input": "1 1 1000000000",
"output": "0/1"
},
{
"input": "1000000000 1 1",
"output": "1/1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1/1"
},
{
"input": "1000000000 2 4",
"output": "1/2"
},
{
"input": "1000000000 123 456",
"output": "6579023/1000000000"
},
{
"input": "1000000000 123123 654",
"output": "24851/1000000000"
},
{
"input": "123456 123 456",
"output": "215/30864"
},
{
"input": "123456 1234567 123",
"output": "61/61728"
},
{
"input": "314159265 271 8281",
"output": "37939/314159265"
},
{
"input": "11071994 4231 1324",
"output": "2647/11071994"
},
{
"input": "961748927 961748941 982451653",
"output": "1/1"
},
{
"input": "15485221 1259 90863",
"output": "1258/15485221"
},
{
"input": "5000000000000000000 4999999999999999837 4999999999999999963",
"output": "1249999999999999959/1250000000000000000"
},
{
"input": "4000000000000000000 3999999999999999691 3999999999999999887",
"output": "399999999999999969/400000000000000000"
},
{
"input": "999999999999999999 999999999999999709 999999999999999737",
"output": "333333333333333236/333333333333333333"
},
{
"input": "799999999999999999 799999999999999969 799999999999999991",
"output": "799999999999999968/799999999999999999"
},
{
"input": "812312312312312222 812312312312311897 812312312312312029",
"output": "406156156156155948/406156156156156111"
},
{
"input": "500000000000000000 499999999999999927 499999999999999931",
"output": "249999999999999963/250000000000000000"
},
{
"input": "555555555555555555 555555555555555083 555555555555555229",
"output": "50505050505050462/50505050505050505"
},
{
"input": "199419941994199419 199419941994199369 199419941994199391",
"output": "66473313998066456/66473313998066473"
},
{
"input": "145685485411238588 145685485411238483 145685485411238573",
"output": "72842742705619241/72842742705619294"
},
{
"input": "314159265358979323 314159265358979167 314159265358979213",
"output": "314159265358979166/314159265358979323"
},
{
"input": "10 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "5 100000000000000000 99999999999999999",
"output": "1/1"
},
{
"input": "5 1000000000000 1000000000001",
"output": "1/1"
},
{
"input": "5 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 10 11",
"output": "1/1"
},
{
"input": "10 123456789123456789 723456789123456781",
"output": "1/1"
},
{
"input": "12345678910 123456789101112131 123456789101112132",
"output": "1/1"
},
{
"input": "5 499999999999999999 499999999999999998",
"output": "1/1"
}
] | 109 | 0 | 0 | 272 |
|
39 | C*++ Calculations | [
"expression parsing",
"greedy"
] | A. C*++ Calculations | 2 | 64 | C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (*expression* is the main term):
- *expression* ::= *summand* | *expression*<=+<=*summand* | *expression*<=-<=*summand* - *summand* ::= *increment* | *coefficient***increment* - *increment* ::= a++ | ++a - *coefficient* ::= 0|1|2|...|1000
For example, "5*a++-3*++a+a++" is a valid expression in C*++.
Thus, we have a sum consisting of several summands divided by signs "+" or "-". Every summand is an expression "a++" or "++a" multiplied by some integer coefficient. If the coefficient is omitted, it is suggested being equal to 1.
The calculation of such sum in C*++ goes the following way. First all the summands are calculated one after another, then they are summed by the usual arithmetic rules. If the summand contains "a++", then during the calculation first the value of the "a" variable is multiplied by the coefficient, then value of "a" is increased by 1. If the summand contains "++a", then the actions on it are performed in the reverse order: first "a" is increased by 1, then — multiplied by the coefficient.
The summands may be calculated in any order, that's why sometimes the result of the calculation is completely unpredictable! Your task is to find its largest possible value. | The first input line contains an integer *a* (<=-<=1000<=≤<=*a*<=≤<=1000) — the initial value of the variable "a". The next line contains an expression in C*++ language of the described type. The number of the summands in the expression does not exceed 1000. It is guaranteed that the line describing the expression contains no spaces and tabulation. | Output a single number — the maximal possible value of the expression. | [
"1\n5*a++-3*++a+a++\n",
"3\na+++++a\n"
] | [
"11\n",
"8\n"
] | Consider the second example. Initially *a* = 3. Suppose that at first the first summand is calculated, and then the second one is. The first summand gets equal to 3, and the value of *a* is increased by 1. At the calculation of the second summand *a* is increased once more (gets equal to 5). The value of the second summand is 5, and together they give 8. If we calculate the second summand first and the first summand later, then the both summands equals to 4, and the result is 8, too. | [
{
"input": "1\n5*a++-3*++a+a++",
"output": "11"
},
{
"input": "3\na+++++a",
"output": "8"
},
{
"input": "-668\n820*a+++402*++a-482*++a",
"output": "-492358"
},
{
"input": "902\n600*++a+411*a+++20*a++-340*++a-306*++a+485*a++-776*a+++417*a+++70*a++-703*a++",
"output": "-97296"
},
{
"input": "-215\n840*++a+183*++a-975*++a+301*a+++874*a++",
"output": "-256096"
},
{
"input": "-211\n849*a++-419*a+++720*++a-543*a+++193*a++-506*++a",
"output": "-55460"
},
{
"input": "-206\n859*a++-655*a+++466*++a-786*++a+512*a+++628*a+++747*a++",
"output": "-351932"
},
{
"input": "-441\n214*++a+30*++a-390*++a-112*++a-409*++a+287*a++-660*++a-740*++a-695*a++-830*++a+554*a++",
"output": "1211971"
},
{
"input": "875\n132*a+++960*++a+510*a++-37*++a-923*++a-892*a+++427*a+++384*a++-253*a++-82*a+++506*a+++815*a+++499*++a",
"output": "1829041"
},
{
"input": "399\n469*++a-935*++a-838*++a-468*++a+79*++a-89*++a-863*++a+531*a++-523*a++-583*++a-411*++a+301*++a+201*a++-108*a+++581*a+++938*++a-16*a++-632*a+++146*a++-230*++a+151*++a-618*a+++593*a+++320*++a+750*++a+185*a++-68*++a+839*a++-853*a+++761*a++-442*a++-385*a++-487*a++-573*a++-820*a++-123*a+++792*++a+95*++a+228*++a-945*a+++126*++a-888*++a-745*++a-217*a++-883*++a-632*++a+82*a++-371*++a-14*++a+528*a++",
"output": "-2184221"
},
{
"input": "-677\n490*++a",
"output": "-331240"
},
{
"input": "-744\n672*a++-975*a++-394*a+++968*a+++222*a+++988*++a+504*++a-782*a++-321*++a+980*++a-483*a++-554*++a-347*++a-180*++a-390*a+++403*a++-617*a+++378*a+++544*++a-978*a+++952*a++-618*a++-516*++a-990*++a+540*++a-398*++a-187*++a+401*++a+829*a++-187*++a-185*a++-529*a++",
"output": "1091591"
},
{
"input": "-496\n589*a+++507*++a+59*++a-507*a+++951*++a+99*++a-651*++a-985*a++-61*a+++588*a++-412*a++-756*a+++978*a+++58*++a-230*++a-391*++a-574*a++",
"output": "408226"
},
{
"input": "217\n828*a+++340*++a-450*a++-575*++a-821*++a+89*a++-543*++a-61*++a+629*++a-956*++a-685*++a-424*a++",
"output": "-565304"
},
{
"input": "189\n360*++a+889*a++-940*a++-272*a+++437*++a-495*++a+194*++a-339*++a-503*++a+335*++a-459*a++-285*a++-738*++a-554*a++-68*++a",
"output": "-447974"
},
{
"input": "-589\n561*a++-754*++a-577*a+++393*++a-636*++a-481*++a+645*a++-931*++a+198*a++-788*a++-925*a++-580*a++-506*++a-722*a++-33*++a+743*a++-506*++a+243*a++-416*a++-438*a+++23*++a-745*++a-865*a++",
"output": "4173855"
},
{
"input": "-693\n372*++a-195*a++-542*a+++15*a++-560*a+++268*a+++266*a+++476*a++-267*a+++608*a+++766*++a-861*a++-649*a++-973*++a-840*++a+586*++a-346*++a-940*a++-177*a++-925*a++-608*++a+816*++a+150*a+++494*++a",
"output": "2186029"
},
{
"input": "7\na+++a++-a++-a+++5*a++-2*a++",
"output": "50"
},
{
"input": "1000\na++",
"output": "1000"
},
{
"input": "1000\n++a",
"output": "1001"
},
{
"input": "332\n++a",
"output": "333"
},
{
"input": "4\n0*a++",
"output": "0"
},
{
"input": "584\n7*++a",
"output": "4095"
}
] | 372 | 2,252,800 | 0 | 273 |
333 | Secrets | [
"greedy"
] | null | null | Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.
One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?
The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of *n* marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least *n* marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want. | The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017).
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. | In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.
In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives. | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "3"
},
{
"input": "10",
"output": "4"
},
{
"input": "100000000000000000",
"output": "33333333333333334"
},
{
"input": "99999999999999999",
"output": "3703703703703704"
},
{
"input": "50031545098999707",
"output": "1"
},
{
"input": "16677181699666569",
"output": "1"
},
{
"input": "72900000000000",
"output": "33333333334"
},
{
"input": "99999999999999997",
"output": "33333333333333333"
},
{
"input": "58061299250691018",
"output": "32"
},
{
"input": "49664023559436051",
"output": "128191526"
},
{
"input": "66708726798666276",
"output": "2"
},
{
"input": "29442431889534807",
"output": "48"
},
{
"input": "70414767176369958",
"output": "13"
},
{
"input": "93886356235159944",
"output": "51"
},
{
"input": "97626528902553453",
"output": "551104613133"
},
{
"input": "52013157885656046",
"output": "880847395988"
},
{
"input": "37586570003500923",
"output": "548"
},
{
"input": "34391854792828422",
"output": "582429080812"
},
{
"input": "205891132094649",
"output": "1"
},
{
"input": "243",
"output": "1"
},
{
"input": "5559060566555523",
"output": "1"
},
{
"input": "81",
"output": "1"
},
{
"input": "108",
"output": "2"
},
{
"input": "2",
"output": "1"
},
{
"input": "1129718145924",
"output": "2"
}
] | 124 | 0 | 3 | 274 |
|
665 | Simple Strings | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
"input": "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr",
"output": "rxaxraxrxaxaxrararxaxararaxrxarxarxrxrarxraxraxrxaxrxraxraxrxrxaxaxrxaxararxrxarxarxaxrararxraxraxra"
},
{
"input": "aazz",
"output": "baza"
},
{
"input": "zz",
"output": "za"
},
{
"input": "gg",
"output": "ga"
},
{
"input": "qasdasd",
"output": "qasdasd"
},
{
"input": "aa",
"output": "ba"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "zza",
"output": "zba"
},
{
"input": "g",
"output": "g"
},
{
"input": "nnop",
"output": "naop"
},
{
"input": "xx",
"output": "xa"
}
] | 46 | 204,800 | -1 | 275 |
|
14 | Young Photographer | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack. | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n1 9",
"output": "1"
},
{
"input": "1 10\n123 12",
"output": "2"
},
{
"input": "1 17\n10 17",
"output": "0"
},
{
"input": "1 22\n22 33",
"output": "0"
},
{
"input": "1 3\n1 2",
"output": "1"
},
{
"input": "2 5\n0 3\n2 1",
"output": "3"
},
{
"input": "3 3\n7 3\n6 4\n3 7",
"output": "1"
},
{
"input": "4 9\n8 6\n11 5\n5 11\n8 3",
"output": "1"
},
{
"input": "2 4\n1 4\n4 0",
"output": "0"
},
{
"input": "3 7\n5 8\n7 5\n4 7",
"output": "0"
},
{
"input": "4 7\n8 2\n5 7\n8 2\n5 8",
"output": "0"
},
{
"input": "2 3\n4 1\n4 1",
"output": "0"
},
{
"input": "3 8\n7 2\n3 7\n5 2",
"output": "3"
},
{
"input": "4 0\n9 1\n8 1\n8 4\n4 5",
"output": "4"
},
{
"input": "4 7\n2 5\n3 6\n3 5\n7 4",
"output": "2"
},
{
"input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16",
"output": "2"
},
{
"input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2",
"output": "19"
},
{
"input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18",
"output": "0"
},
{
"input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101",
"output": "0"
},
{
"input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88",
"output": "0"
},
{
"input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11",
"output": "5"
},
{
"input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32",
"output": "6"
},
{
"input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50",
"output": "4"
},
{
"input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121",
"output": "0"
},
{
"input": "1 21\n973 373",
"output": "352"
},
{
"input": "2 212\n831 551\n810 753",
"output": "541"
},
{
"input": "3 404\n690 728\n820 260\n186 402",
"output": "-1"
},
{
"input": "4 906\n548 906\n830 457\n228 638\n464 167",
"output": "-1"
},
{
"input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62",
"output": "-1"
},
{
"input": "3 183\n416 335\n773 648\n434 198",
"output": "-1"
},
{
"input": "3 868\n251 927\n862 464\n157 756",
"output": "112"
},
{
"input": "3 242\n397 208\n951 279\n570 622",
"output": "-1"
},
{
"input": "3 618\n543 800\n38 94\n293 179",
"output": "-1"
},
{
"input": "3 993\n378 81\n127 911\n16 737",
"output": "615"
},
{
"input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842",
"output": "-1"
},
{
"input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478",
"output": "-1"
},
{
"input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393",
"output": "-1"
},
{
"input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348",
"output": "-1"
},
{
"input": "1 21\n0 1000",
"output": "0"
}
] | 92 | 0 | 0 | 277 |
611 | New Year and Old Property | [
"bitmasks",
"brute force",
"implementation"
] | null | null | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros. | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. | Print one integer – the number of years Limak will count in his chosen interval. | [
"5 10\n",
"2015 2015\n",
"100 105\n",
"72057594000000000 72057595000000000\n"
] | [
"2\n",
"1\n",
"0\n",
"26\n"
] | In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property. | [
{
"input": "5 10",
"output": "2"
},
{
"input": "2015 2015",
"output": "1"
},
{
"input": "100 105",
"output": "0"
},
{
"input": "72057594000000000 72057595000000000",
"output": "26"
},
{
"input": "1 100",
"output": "16"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1 1000000000000000000",
"output": "1712"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 7",
"output": "3"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "2 5",
"output": "2"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "3"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "3 4",
"output": "0"
},
{
"input": "3 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "4 4",
"output": "0"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "2"
},
{
"input": "5 7",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "7 7",
"output": "0"
},
{
"input": "1 8",
"output": "3"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "7 8",
"output": "0"
},
{
"input": "8 8",
"output": "0"
},
{
"input": "1 1022",
"output": "45"
},
{
"input": "1 1023",
"output": "45"
},
{
"input": "1 1024",
"output": "45"
},
{
"input": "1 1025",
"output": "45"
},
{
"input": "1 1026",
"output": "45"
},
{
"input": "509 1022",
"output": "11"
},
{
"input": "510 1022",
"output": "10"
},
{
"input": "511 1022",
"output": "9"
},
{
"input": "512 1022",
"output": "9"
},
{
"input": "513 1022",
"output": "9"
},
{
"input": "509 1023",
"output": "11"
},
{
"input": "510 1023",
"output": "10"
},
{
"input": "511 1023",
"output": "9"
},
{
"input": "512 1023",
"output": "9"
},
{
"input": "513 1023",
"output": "9"
},
{
"input": "509 1024",
"output": "11"
},
{
"input": "510 1024",
"output": "10"
},
{
"input": "511 1024",
"output": "9"
},
{
"input": "512 1024",
"output": "9"
},
{
"input": "513 1024",
"output": "9"
},
{
"input": "509 1025",
"output": "11"
},
{
"input": "510 1025",
"output": "10"
},
{
"input": "511 1025",
"output": "9"
},
{
"input": "512 1025",
"output": "9"
},
{
"input": "513 1025",
"output": "9"
},
{
"input": "1 1000000000",
"output": "408"
},
{
"input": "10000000000 70000000000000000",
"output": "961"
},
{
"input": "1 935829385028502935",
"output": "1712"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "58"
},
{
"input": "500000000000000000 576460752303423488",
"output": "57"
},
{
"input": "576460752303423488 1000000000000000000",
"output": "1"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1124800395214847 36011204832919551",
"output": "257"
},
{
"input": "1124800395214847 36011204832919550",
"output": "256"
},
{
"input": "1124800395214847 36011204832919552",
"output": "257"
},
{
"input": "1124800395214846 36011204832919551",
"output": "257"
},
{
"input": "1124800395214848 36011204832919551",
"output": "256"
},
{
"input": "1 287104476244869119",
"output": "1603"
},
{
"input": "1 287104476244869118",
"output": "1602"
},
{
"input": "1 287104476244869120",
"output": "1603"
},
{
"input": "492581209243647 1000000000000000000",
"output": "583"
},
{
"input": "492581209243646 1000000000000000000",
"output": "583"
},
{
"input": "492581209243648 1000000000000000000",
"output": "582"
},
{
"input": "1099444518911 1099444518911",
"output": "1"
},
{
"input": "1099444518910 1099444518911",
"output": "1"
},
{
"input": "1099444518911 1099444518912",
"output": "1"
},
{
"input": "1099444518910 1099444518912",
"output": "1"
},
{
"input": "864691128455135231 864691128455135231",
"output": "1"
},
{
"input": "864691128455135231 864691128455135232",
"output": "1"
},
{
"input": "864691128455135230 864691128455135232",
"output": "1"
},
{
"input": "864691128455135230 864691128455135231",
"output": "1"
},
{
"input": "864691128455135231 1000000000000000000",
"output": "1"
},
{
"input": "864691128455135232 1000000000000000000",
"output": "0"
},
{
"input": "864691128455135230 1000000000000000000",
"output": "1"
},
{
"input": "576460752303423487 576460752303423487",
"output": "0"
},
{
"input": "1 576460752303423487",
"output": "1711"
},
{
"input": "1 576460752303423486",
"output": "1711"
},
{
"input": "2 1000000000000000000",
"output": "1712"
},
{
"input": "3 1000000000000000000",
"output": "1711"
},
{
"input": "4 1000000000000000000",
"output": "1711"
},
{
"input": "5 1000000000000000000",
"output": "1711"
},
{
"input": "6 1000000000000000000",
"output": "1710"
},
{
"input": "5 6",
"output": "2"
},
{
"input": "1 2",
"output": "1"
}
] | 0 | 0 | -1 | 282 |
|
330 | Cakeminator | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat. | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "0"
},
{
"input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS",
"output": "0"
},
{
"input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS",
"output": "30"
},
{
"input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..",
"output": "80"
},
{
"input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS",
"output": "0"
},
{
"input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..",
"output": "17"
},
{
"input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS",
"output": "0"
},
{
"input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S",
"output": "64"
},
{
"input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S",
"output": "28"
},
{
"input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S",
"output": "10"
},
{
"input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.",
"output": "0"
},
{
"input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS",
"output": "0"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "4 3\n.S.\nS.S\n.S.\nS.S",
"output": "0"
},
{
"input": "2 3\n...\nSSS",
"output": "3"
},
{
"input": "2 4\nS.SS\nS.SS",
"output": "2"
},
{
"input": "2 2\n..\n.S",
"output": "3"
},
{
"input": "3 2\n.S\n.S\nSS",
"output": "0"
},
{
"input": "2 4\nSS.S\n..S.",
"output": "0"
},
{
"input": "2 3\n...\nS..",
"output": "5"
}
] | 60 | 0 | 0 | 283 |
|
148 | Escape | [
"implementation",
"math"
] | null | null | The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend *f* hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is *c* miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the castle before the dragon reached her, and doesn't need an extra bijou to hold him off. | The input data contains integers *v**p*,<=*v**d*,<=*t*,<=*f* and *c*, one per line (1<=≤<=*v**p*,<=*v**d*<=≤<=100, 1<=≤<=*t*,<=*f*<=≤<=10, 1<=≤<=*c*<=≤<=1000). | Output the minimal number of bijous required for the escape to succeed. | [
"1\n2\n1\n1\n10\n",
"1\n2\n1\n1\n8\n"
] | [
"2\n",
"1\n"
] | In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou. | [
{
"input": "1\n2\n1\n1\n10",
"output": "2"
},
{
"input": "1\n2\n1\n1\n8",
"output": "1"
},
{
"input": "5\n8\n1\n2\n100",
"output": "2"
},
{
"input": "2\n100\n10\n10\n739",
"output": "22"
},
{
"input": "17\n99\n2\n3\n293",
"output": "3"
},
{
"input": "5\n5\n1\n1\n1000",
"output": "0"
},
{
"input": "100\n99\n1\n1\n1000",
"output": "0"
},
{
"input": "1\n100\n1\n1\n1",
"output": "0"
},
{
"input": "1\n100\n1\n1\n1000",
"output": "152"
},
{
"input": "10\n1\n10\n1\n11",
"output": "0"
},
{
"input": "98\n94\n4\n3\n437",
"output": "0"
},
{
"input": "58\n4\n1\n10\n392",
"output": "0"
},
{
"input": "74\n11\n8\n7\n835",
"output": "0"
},
{
"input": "86\n21\n7\n2\n982",
"output": "0"
},
{
"input": "2\n27\n4\n9\n937",
"output": "15"
},
{
"input": "62\n89\n8\n1\n83",
"output": "0"
},
{
"input": "78\n7\n7\n6\n38",
"output": "0"
},
{
"input": "94\n14\n2\n3\n481",
"output": "0"
},
{
"input": "6\n24\n9\n8\n628",
"output": "3"
},
{
"input": "59\n7\n8\n10\n357",
"output": "0"
},
{
"input": "75\n26\n4\n3\n504",
"output": "0"
},
{
"input": "87\n32\n3\n8\n754",
"output": "0"
},
{
"input": "51\n42\n10\n4\n901",
"output": "0"
},
{
"input": "63\n4\n7\n1\n48",
"output": "0"
},
{
"input": "79\n10\n4\n6\n3",
"output": "0"
},
{
"input": "95\n20\n9\n3\n149",
"output": "0"
},
{
"input": "55\n35\n5\n10\n592",
"output": "0"
},
{
"input": "71\n45\n2\n6\n547",
"output": "0"
},
{
"input": "83\n7\n7\n7\n46",
"output": "0"
},
{
"input": "100\n32\n1\n8\n537",
"output": "0"
},
{
"input": "17\n42\n10\n5\n684",
"output": "1"
},
{
"input": "77\n1\n6\n8\n831",
"output": "0"
},
{
"input": "93\n19\n3\n3\n82",
"output": "0"
},
{
"input": "5\n25\n8\n9\n228",
"output": "2"
},
{
"input": "21\n35\n5\n6\n535",
"output": "1"
},
{
"input": "85\n45\n2\n1\n682",
"output": "0"
},
{
"input": "97\n4\n8\n8\n829",
"output": "0"
},
{
"input": "13\n14\n3\n3\n79",
"output": "0"
},
{
"input": "25\n28\n4\n9\n226",
"output": "0"
},
{
"input": "34\n9\n6\n6\n70",
"output": "0"
},
{
"input": "50\n15\n1\n3\n216",
"output": "0"
},
{
"input": "10\n25\n9\n8\n363",
"output": "1"
},
{
"input": "26\n36\n4\n7\n318",
"output": "0"
},
{
"input": "38\n50\n1\n8\n761",
"output": "1"
},
{
"input": "2\n12\n6\n4\n907",
"output": "10"
},
{
"input": "14\n18\n5\n9\n862",
"output": "1"
},
{
"input": "30\n28\n4\n6\n9",
"output": "0"
},
{
"input": "46\n39\n8\n3\n964",
"output": "0"
},
{
"input": "6\n45\n7\n8\n407",
"output": "4"
},
{
"input": "67\n34\n7\n4\n954",
"output": "0"
},
{
"input": "31\n40\n6\n1\n397",
"output": "0"
},
{
"input": "43\n50\n1\n8\n544",
"output": "1"
},
{
"input": "59\n9\n7\n3\n498",
"output": "0"
},
{
"input": "71\n19\n2\n10\n645",
"output": "0"
},
{
"input": "35\n37\n9\n5\n792",
"output": "0"
},
{
"input": "47\n43\n10\n9\n43",
"output": "0"
},
{
"input": "63\n53\n5\n4\n189",
"output": "0"
},
{
"input": "79\n11\n2\n1\n144",
"output": "0"
},
{
"input": "39\n22\n8\n6\n291",
"output": "0"
},
{
"input": "49\n7\n2\n5\n326",
"output": "0"
},
{
"input": "2\n1\n1\n1\n1000",
"output": "0"
},
{
"input": "100\n1\n1\n1\n1000",
"output": "0"
},
{
"input": "2\n1\n1\n1\n100",
"output": "0"
},
{
"input": "2\n1\n1\n1\n10",
"output": "0"
},
{
"input": "5\n3\n3\n3\n999",
"output": "0"
}
] | 184 | 0 | 3 | 284 |
|
312 | Whose sentence is it? | [
"implementation",
"strings"
] | null | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n"
] | [
"Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"
] | none | [
{
"input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .",
"output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iapelala.\nCFPlbUgObrXLejPNu.F\nZSUfvisiHyrIMjMlala.\nmiao. lala.\nd,IWSeumytrVlala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's"
},
{
"input": "10\nmiao.,taUvXPVlala.\nmiao.txEeId.X_lala.\nLZIeAEd JaeBVlala.\ncKPIsWpwIlala.\nfYp.eSvn,g\nKMx,nFEslala.\nmiao.QtMyxYqiajjuM\nDutxNkCqywgcnCYskcd\ngFLKACjeqfD\n,Ss UmY.wJvcX",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.Plala.\nDVm,VYslala.\nmiao.rlala.\nmiao.,KQNL.fO_.QRc\nUBLCKEUePlala.\nIouS.Alala.\nmiao.lala.\nmiao.rlala.\nEJZwRJeKlala.\nmiao.Olala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nRainbow's\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.grFTpju.jCLRnZ\ng.pVHYA_Usnm\nlloWONolcMFElala.\nAW,n.JJkOTe.Nd\n.bP.HvKlala.\nGziqPGQa,lala.\nmiao.,QkOCH.vFlala.\n.PUtOwImvUsoeh \nmiao.Z,KIds.R\nmiao.,_MDzoaAiJlala.",
"output": "Rainbow's\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.xWfjV\nHFVrGCDQXyZ,Sbm\nLMDS.xVkTCAY.vm\nmiao.lLBglala.\nnl,jRPyClala.\nFYnHoXlala.\nmiao. oxaHE\n.WTrw_mNpOQCa\nHOk..wHYoyMhl\nQX,XpMuPIROM",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nJBQqiXlala.\npUNUWQRiMPCXv\nAiLnfNHWznwkC.lala.\nmiao.Dl_Oy\nxJJJkVkdfOzQBH_SmKh\nfgD_IHvdHiorE,W\nmiao.usBKixglala.\nwCpqPUzEtD\nmiao.rlala.\nmiao.JylcGvWlala.",
"output": "Freda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao..FLhPl_Wjslala.\nmiao. tdEGtfdJlala.\nGAzEUlala.\nKCcmOa .aKBlZyYsdu.V\nmiao.lala.\njKylnM,FXK\nmiao.GBWqjGH.v\nmiao.RefxS Cni.\nOxaaEihuHQR_s,\nmiao.a,Axtlala.",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nNo.I_aTXlala.\nmiao.JKSCoRZS\nnOBMIlala.\nmiao.nlala.\nmiao._xqxoHIIlala.\nmiao.NJPy SWyiUDWc\nmiao.cCnahFaqqj.Xqp\nnreSMDeXPPYAQxI,W\nAktPajWimdd_qRn\nmiao.QHwKCYlala.",
"output": "Freda's\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\n \n,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ \n \nmiao.miao.miao.\nlala.lala.lala.\nlala.miao.\nmiaolala. \nmiao.lala\nmiaolala_\n,.._ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nduClyjMIPsEuWmx_Ce.byVoizYlTM,sF\nuZHsNip_,Mwtg,FZjM_LzPC,_pSvEOyTHfAOvoZXvxCZdgYDTCDdCAoSVZWyxXGcLgWlala.\nEGtJFPAvTEcqjkhaGxdduaQ_rmUzF.WaU, EIuX B,aVzFFpFrxpwADXuayRD azDfj \n_tJqYzXyqc.,u.F,mUYukveBPWnPq,f,dJnPHuBazdnbRHfzwNUdRbheAIjcoaPcnLvocrzcioxCapb R\n.YUBeb_zmwUt.QQuUdQIiOXtqshcsycEe,HLytHlala.\ndJndLqGBHt.GfpN.BgvsbXoLh_DIzAJOtFDmLSCYEztvPcS_GHPxivzV,NPMmSAtfk.Mg.w,A UcCt_lCD.csEzyJJBYtSMkzqiA\nmiao.qlala.\nmiao.FmDlY\nmiao.UQI.aJmnanNvRLskuVaMybDMsOlala.\nmiao.lala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.vyscfysAtWcPkpFHdwZqAQ,UPPcjhKQTlala.\nmiao.KESqus DybUuYFoWVpo..LWZh.UqEdUsTHFlKfzqkThAUPklala.\nUNoE vfZIAdxkiWKhsHPfsqRPTNQoHgAxooVLYxRzugHjo jaEHWQFF\nCCmdIwr.UkoiYWK.Z,,ZesMpISTXNgnpYnJaWquCyL,gO\n.JvOayhXK_bgoYbfAtnXg\nbvdSzRrXoGxVgWvdXnsjEnEfxDzIQo_aZVGDGrzwuAMtzVAHioMBx_DHuTxyieGbGuSRNUojOREqxBBxvCgqAOMzwIWT\nMBuaWduZmRaOGyIPzWOsBVeqtDrblAbXxmM_uRfqMvnVlLEuhVKlhidN_aigiXyq,ZEDqQAx\nmiao.wCHVCuVKNePKmIUFLL_lala.\nmiao.iAqstXHUv\n pMO yvPkNtnNwmUCao W,wW.OvIMVaEeVYHmqaniWq.ivlala.",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's"
},
{
"input": "10\nmiao.\nmiao.jrwLBCpNaDCjyoK.PFzbwWU.h.. wfQquG_P..lala.\nmiao.LGlYdKjw__.Chlala.\nW.wtr qG KDOHj.xWxPbXIXjD_,GJZDaAZ,JBHphsjWJwSKcZAIAi\nmiao.pHsGAZQDWPJQwKC.zHjJituLgp.eUrzObTI.wrpect.FMUJqu,Zuslala.\nmiao.YVlOpXccUA_YU igbsbZbhOVwyYTyOjnWqgiTmxwAuFa.flCHn.,MtVbqxZQl_BGHXWkwijGjuL, ,ezyNlala.\nmiao.xCrVSz.aMv UOSOroDlQxWeBmlWe.FA.ZfUmviMlala.\nxebAlala.\nmiao.qVSxqf vOTlala.\nD.oBUwsLQRgXAoNkQJhQN.w.oMhuvtujnmiwgQYMfjlNTSHh .lSKgI.OEp",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nZXXzYlTiQU\nkXE.DdcbOojSaSgjMcFBPubKHefEVAzbi,PDFgSZIz,lala.\nxEfrTCjKhhwBC.UNmJXgTGUdkQeVDlala.\nLfaEw.jvMmuOBWtfoiJNtDIlQAVWNU,xWK_efBBtfkM\nqtBpqKZMWZMX_NKrUAEKYyQcLZWQlqbM\nmiao.PrJEbUtInremuaKRItqXOrfQEjQcAak VQ\nMpGCq awvQaHRvDr uvtVMKsvZI\nmiao.A.RVGu.szCEp.pXQJwL EuTltlN.WradoTvWHJyhcNSoulala.\nmiao.rzlUHzUdxtDRpWRuc,QZwEBfsKKGHMLGtFymPPQdptLFlzZ_ORWqrlfOrlntuDkpXEvz.CxwAsFYUvpnOnFWG\nmiao.VXUoNBwlgBwcna_n.CgAAcKKUuiVA.doOJKHpMdwNwlHAcLpdfN.Awa SthrlEWpUcuOonUTxIQNszYcHDXxnhArrM..A",
"output": "OMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's"
},
{
"input": "10\nmiao.qbxBFzrjtWv.yOk\nDBgi,loApO AACrGnwssCHN\nmiao.LV.wbQEE_V.BSAtdTIHTQOJVJ_nGOthbL,nJvQ.UeWFpsa.GGsK_Uv,HQxHS,AN_bkrolala.\nmiao.tBEqk rIQuByGKhfq_iP.BW,nySZEfrfySEcqnnIzxC,lrjIiivbxlkoVXJFiegGFRn NO,txGPhVBcv.CVhMmNO zlala.\nmiao.aBZWDWxk.wkR ,NyCzGxJnJDqBZpetdUPAmmBZDXl_Tbflala.\nmiao. XN,uMwWm. VqloYr..jTLszlala.\n.rshcgfZ.eZOdMu_RMh\nmiao.ahiwpECEe.lala.\nLeoUSroTekQAMSO__M L_ZEeRD_tUihYvQETFB,RzJmFtFiKrU\nBtygQG_OoFEFBL.KsVWTYbtqtalXoStFCZ RINHda.NuLmlkRB.vAQJFvelbsfoJ.T,M sJn",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nYoYBCcaqhXLfvKKf.UYMODTHyPZlala.\ncxgWn J.Q\nmiao.nwH.IHntgKYDhdsjU DMTHXEVRyeJP ZaAecCIBJXuv.YjhEmtbjvjKnK.U,oc,x\nmiao.EcQ.FDtRJgmpAzxhq.RwXBLxjyC,IeMqaFoheMPFCGWBcwUAFnbiwlbz_fcsEGPfJaeryCtFocBNEWTlala.\nmiao.W\nmiao. ZQpIeyCXJSnFgAIzu.THfrmyoogYWQzFqblala.\nmiao.ifzdCwnTDcxpvdr OTC.YqPv.MKDp..utICtAsbfYyGlala.\nmiao.\nmiao.tS.U.wH.s,CxORZJsBAHLi,fXeoDJWVBH\nrcUMpeupOVRKrcIRAvU.rP kgUEfoeXcrFPQOBYG.BNvAQPg.XHMWizhLpZNljXc .LQmVXCi",
"output": "Freda's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nlala.\nmiao.milalala.lmmialamiao.la.o.iao.a.ao.\nmialala.o.\nmiao.millala.allala.amiao..miao.miao.lala.ao.miammiao.iao.o.\nmiao.miaomiao..\nlalmiao.amiao..\nmiao.lala.lamiamiaolala..o.lalala.miao..\nmlala.iao.lalamiao..\nlmlala.iao.alalamiao.lmialala.lala.miao.o.alala..lala..lalmiaomiao..lalmiao.a.lalamiao..miao.alala..\nlalllamiao.la.lala.alamiao.lalalala.lala..miao.lamiao.la.lallalamiao..a..a.",
"output": "Freda's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nlalllala.ala.lala.a.mmimiao.aomiao.lllala.ala.amiao.la.mialalala.la.o..imiao.miao.amlala.iao.o.\nmilala.alllala.ala.amiao.lamiao..o.\nlala.lalalala..lalalala..\nlala.miao.\nmimiao.ao.lala.\nlalmiao.amlala.iamialala.o.o..\nlalammlala.iaolammiao.imiao.ao.la..iao..\nmiao.mialala.omiao..mlala.iaolala..\nmiamiao.o.llallala.ala.la.miao.ala.miao.mimialmiao.ala.o.alala.miaomiao..olala..\nmialala.lamiao.la.lala.miao.ollala.allala.ala.lmiaommiao.imiao.ao.lallallala.a.miao.a..a..",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nlamiao.lamiao.mimiao.ao..\nllala.almiaomiao..lala.miao.a.\nlalala.lala.lalala.lala.lalala..la.\nlalala.la.miao.\nmiao.llalallala.miao.a.la.lala.almimiao.ao.a.\nmiao.mlala.ilala.aomilala.ao..\nmilala.ao.\nmmiao.iao.\nmlala.lala.ialalmiao.alala..olala.lala..\nlala.lmlalalalalala...iao.milala.aommiao.iao..alamiaolallala.milala.ao.a..lalalmiao.a..llala.amiao..",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "4\n \n miao. \n lala. \n ",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "1\nMiao.",
"output": "OMG>.< I don't know!"
},
{
"input": "1\nm",
"output": "OMG>.< I don't know!"
},
{
"input": "1\nMiAo.sdsdlala.",
"output": "Freda's"
},
{
"input": "1\nLalA.",
"output": "OMG>.< I don't know!"
},
{
"input": "3\n.\nm\nl",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
}
] | 92 | 0 | 0 | 286 |
|
320 | Magic Numbers | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 92 | 0 | 3 | 287 |
|
984 | Minesweeper | [
"implementation"
] | null | null | One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $n \times m$, where each cell is either empty, or contains a digit from $1$ to $8$, or a bomb. The field is valid if for each cell:
- if there is a digit $k$ in the cell, then exactly $k$ neighboring cells have bombs. - if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $8$ neighboring cells). | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.
The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive. | Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily. | [
"3 3\n111\n1*1\n111\n",
"2 4\n*.*.\n1211\n"
] | [
"YES",
"NO"
] | In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)). | [
{
"input": "3 3\n111\n1*1\n111",
"output": "YES"
},
{
"input": "2 4\n*.*.\n1211",
"output": "NO"
},
{
"input": "1 10\n.....1*1..",
"output": "YES"
},
{
"input": "1 1\n4",
"output": "NO"
},
{
"input": "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542..11\n.13**1..1*\n..2*31..11\n..111..111\n.......1*1\n.......111",
"output": "YES"
},
{
"input": "10 17\n12*2*22123*31....\n2*333*3*4***3211.\n*22*213**4***3*1.\n11111.12224*6*21.\n221..111.14**4311\n**2233*212****2*1\n*55***4*13*544421\n2***54*322*21**31\n13*4*33*221114*4*\n.1122*22*1...2*31",
"output": "YES"
},
{
"input": "10 10\n**********\n**********\n**********\n**********\n**********\n******3***\n**********\n**********\n**********\n***3.5****",
"output": "NO"
},
{
"input": "21 10\n62637783*1\n23*51**531\n35*7*6.**.\n.*3***581*\n2.32*745**\n83*7*6*6*5\n*74.**6**3\n323*6**7*6\n3454*67.*1\n**63265*6*\n3725*4553*\n24****5**4\n23.34****4\n55257*1*4*\n4*3253*456\n**.3*45488\n*7318**4*5\n234.*4557*\n12..21*.*3\n286.225*4*\n834*11*.3*",
"output": "NO"
},
{
"input": "10 10\n**********\n*********6\n*********5\n**********\n**********\n**********\n**********\n**********\n**********\n**********",
"output": "NO"
},
{
"input": "100 1\n.\n.\n.\n.\n1\n*\n2\n*\n1\n.\n.\n.\n.\n.\n.\n1\n*\n1\n1\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n1\n*\n2\n*\n*\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n1\n*\n2\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "YES"
},
{
"input": "1 100\n*************5****5****************************************************4****************************",
"output": "NO"
},
{
"input": "1 100\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*",
"output": "NO"
},
{
"input": "1 10\n881111882*",
"output": "NO"
},
{
"input": "5 5\n*2221\n24**2\n*3*5*\n3425*\n**12*",
"output": "NO"
},
{
"input": "5 5\n****2\n4***4\n3****\n3*563\n*22**",
"output": "NO"
},
{
"input": "5 5\n***2.\n5**31\n**6**\n***43\n**31*",
"output": "NO"
},
{
"input": "5 5\n*32**\n4*3*4\n**44*\n**45*\n*4***",
"output": "NO"
},
{
"input": "3 3\n***\n*2*\n***",
"output": "NO"
},
{
"input": "1 1\n*",
"output": "YES"
},
{
"input": "1 2\n*1",
"output": "YES"
},
{
"input": "1 2\n*2",
"output": "NO"
},
{
"input": "2 2\n32\n**",
"output": "NO"
},
{
"input": "3 3\n...\n232\n***",
"output": "YES"
},
{
"input": "3 2\n..\n11\n.*",
"output": "NO"
},
{
"input": "2 3\n1*2\n3*2",
"output": "NO"
},
{
"input": "1 3\n.*.",
"output": "NO"
},
{
"input": "3 1\n.\n*\n.",
"output": "NO"
},
{
"input": "3 1\n1\n*\n1",
"output": "YES"
},
{
"input": "3 1\n*\n1\n*",
"output": "NO"
},
{
"input": "1 3\n1**",
"output": "YES"
},
{
"input": "1 1\n8",
"output": "NO"
},
{
"input": "1 1\n.",
"output": "YES"
},
{
"input": "1 2\n2*",
"output": "NO"
},
{
"input": "2 1\n*\n2",
"output": "NO"
},
{
"input": "2 1\n*\n*",
"output": "YES"
},
{
"input": "2 1\n.\n1",
"output": "NO"
},
{
"input": "1 3\n..1",
"output": "NO"
},
{
"input": "3 3\n112\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n11.\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n151\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n1.1\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n611\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n.11\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n2*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n**1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n5*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n.*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n411",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n.11",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n121",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n1.1",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n115",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n11.",
"output": "NO"
},
{
"input": "3 3\n111\n1*4\n111",
"output": "NO"
},
{
"input": "3 3\n111\n1*.\n111",
"output": "NO"
},
{
"input": "1 4\n*222",
"output": "NO"
},
{
"input": "1 1\n*",
"output": "YES"
},
{
"input": "2 2\n**\n**",
"output": "YES"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "NO"
},
{
"input": "3 3\n***\n***\n***",
"output": "YES"
},
{
"input": "3 3\n***\n*4*\n***",
"output": "NO"
},
{
"input": "2 6\n....1.\n.....*",
"output": "NO"
},
{
"input": "5 5\n*****\n*****\n*****\n*****\n*****",
"output": "YES"
},
{
"input": "4 1\n.\n*\n.\n.",
"output": "NO"
},
{
"input": "2 2\n2*\n11",
"output": "NO"
},
{
"input": "3 3\n888\n888\n888",
"output": "NO"
},
{
"input": "1 4\n*22*",
"output": "NO"
}
] | 93 | 2,867,200 | -1 | 288 |
|
315 | Sereja and Array | [
"implementation"
] | null | null | Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*.
Help Sereja, complete all his operations. | The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*). | For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input. | [
"10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n"
] | [
"2\n9\n11\n20\n30\n40\n39\n"
] | none | [
{
"input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9",
"output": "2\n9\n11\n20\n30\n40\n39"
},
{
"input": "1 3\n1\n1 1 2\n2 1\n3 1",
"output": "3"
},
{
"input": "1 1\n1\n3 1",
"output": "1"
},
{
"input": "6 6\n202714501 613423725 367325359 862808465 182588146 745008828\n2 492\n2 1943\n1 3 173984392\n1 3 9356383\n3 4\n1 5 472683539",
"output": "862810900"
},
{
"input": "6 5\n545129895 918519812 2334334 565540665 484519712 904102869\n3 3\n1 2 641196860\n2 779\n2 3036\n3 1",
"output": "2334334\n545133710"
},
{
"input": "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119",
"output": "780579549"
},
{
"input": "4 4\n529316834 995684640 949078705 317773978\n3 3\n3 1\n2 6271\n1 1 856879574",
"output": "949078705\n529316834"
},
{
"input": "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2288\n1 5 332270946",
"output": "695181967"
}
] | 389 | 11,776,000 | 3 | 289 |
|
332 | Down the Hatch! | [
"implementation"
] | null | null | Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All *n* people who came to the barbecue sat in a circle (thus each person received a unique index *b**i* from 0 to *n*<=-<=1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the *j*-th turn was made by the person with index *b**i*, then this person acted like that:
1. he pointed at the person with index (*b**i*<=+<=1) *mod* *n* either with an elbow or with a nod (*x* *mod* *y* is the remainder after dividing *x* by *y*); 1. if *j*<=≥<=4 and the players who had turns number *j*<=-<=1, *j*<=-<=2, *j*<=-<=3, made during their turns the same moves as player *b**i* on the current turn, then he had drunk a glass of juice; 1. the turn went to person number (*b**i*<=+<=1) *mod* *n*.
The person who was pointed on the last turn did not make any actions.
The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody. | The first line contains a single integer *n* (4<=≤<=*n*<=≤<=2000) — the number of participants in the game. The second line describes the actual game: the *i*-th character of this line equals 'a', if the participant who moved *i*-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns. | Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. | [
"4\nabbba\n",
"4\nabbab\n"
] | [
"1\n",
"0\n"
] | In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different. | [
{
"input": "4\nabbba",
"output": "1"
},
{
"input": "4\nabbab",
"output": "0"
},
{
"input": "4\naaa",
"output": "0"
},
{
"input": "4\naab",
"output": "0"
},
{
"input": "4\naabaabbba",
"output": "1"
},
{
"input": "6\naaaaaaaaaaaaaaaa",
"output": "2"
},
{
"input": "7\nabbbaaabbbaaaab",
"output": "2"
},
{
"input": "9\naaaabaaaaa",
"output": "1"
},
{
"input": "4\na",
"output": "0"
},
{
"input": "4\nb",
"output": "0"
},
{
"input": "4\nab",
"output": "0"
},
{
"input": "4\nbb",
"output": "0"
},
{
"input": "4\naba",
"output": "0"
},
{
"input": "4\nbbb",
"output": "0"
},
{
"input": "4\nabab",
"output": "0"
},
{
"input": "4\nabaa",
"output": "0"
},
{
"input": "4\nabbbaaabba",
"output": "1"
},
{
"input": "4\nababba",
"output": "0"
},
{
"input": "4\naaaaaa",
"output": "1"
},
{
"input": "5\nbbbbaabaaa",
"output": "0"
},
{
"input": "2000\na",
"output": "0"
},
{
"input": "2000\naabaaabaabababbbbbbabbbbb",
"output": "0"
},
{
"input": "4\nabbb",
"output": "0"
},
{
"input": "5\nbbbbb",
"output": "0"
}
] | 0 | 0 | -1 | 290 |
|
742 | Arpa’s obvious problem and Mehrdad’s terrible solution | [
"brute force",
"math",
"number theory"
] | null | null | There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation).
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem. | First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer: the answer to the problem. | [
"2 3\n1 2\n",
"6 1\n5 1 2 3 4 1\n"
] | [
"1",
"2"
] | In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1.
In the second sample the only two pairs are *i* = 3, *j* = 4 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png" style="max-width: 100.0%;max-height: 100.0%;"/>) and *i* = 1, *j* = 5 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png" style="max-width: 100.0%;max-height: 100.0%;"/>).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). | [
{
"input": "2 3\n1 2",
"output": "1"
},
{
"input": "6 1\n5 1 2 3 4 1",
"output": "2"
},
{
"input": "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423",
"output": "0"
},
{
"input": "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 135 519 174 147 201 564 182 359 41 465 162 125 378 342 144 549 363 309",
"output": "1"
},
{
"input": "27 41\n156 148 86 161 113 80 185 15 204 185 205 95 147 146 133 187 114 8 11 120 117 167 100 171 140 102 174",
"output": "1"
},
{
"input": "10 208\n399 912 747 631 510 622 234 707 483 496",
"output": "0"
},
{
"input": "64 43\n78 90 211 205 198 4 172 43 163 21 58 145 28 66 210 68 79 90 155 123 9 119 188 151 180 157 44 163 20 71 28 120 163 141 170 206 31 34 21 195 72 194 83 163 140 40 182 208 127 128 110 72 184 157 128 189 146 35 51 206 62 8 117 61",
"output": "8"
},
{
"input": "69 25\n68 26 8 121 96 101 106 87 103 14 86 26 76 85 70 50 4 4 97 89 44 98 33 65 76 64 98 95 30 5 93 121 97 85 47 50 66 2 46 79 46 22 68 59 75 94 104 105 91 97 121 6 32 94 101 125 32 91 76 57 110 31 27 97 91 49 45 37 92",
"output": "21"
},
{
"input": "64 118\n361 547 410 294 448 377 482 490 13 116 346 50 251 330 443 128 543 580 370 489 337 509 414 291 228 71 245 308 319 314 154 39 317 288 145 248 547 152 262 278 89 108 522 238 128 575 112 469 86 230 310 492 127 270 475 25 179 72 345 444 17 332 544 338",
"output": "3"
},
{
"input": "52 231\n229 492 1005 498 786 274 773 573 316 774 977 110 709 49 131 81 1146 1028 451 451 776 470 996 363 581 484 1023 858 1115 273 1105 4 445 509 428 125 432 131 360 404 280 808 649 4 499 1097 831 512 208 996 430 1010",
"output": "0"
},
{
"input": "4 0\n1 2 3 4",
"output": "0"
},
{
"input": "3 0\n2 2 2",
"output": "3"
},
{
"input": "5 0\n1 1 1 1 1",
"output": "10"
},
{
"input": "3 0\n1 1 1",
"output": "3"
},
{
"input": "4 0\n2 2 2 2",
"output": "6"
},
{
"input": "3 0\n10 10 10",
"output": "3"
},
{
"input": "3 0\n3 3 3",
"output": "3"
},
{
"input": "4 0\n1 1 1 1",
"output": "6"
},
{
"input": "3 0\n4 4 4",
"output": "3"
},
{
"input": "2 0\n2 2",
"output": "1"
},
{
"input": "2 0\n2 3",
"output": "0"
},
{
"input": "2 0\n1 2",
"output": "0"
},
{
"input": "5 0\n5 5 5 5 5",
"output": "10"
},
{
"input": "6 0\n1 1 1 1 1 1",
"output": "15"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "4 0\n1 1 3 3",
"output": "2"
},
{
"input": "2 0\n10 10",
"output": "1"
},
{
"input": "4 0\n3 3 3 3",
"output": "6"
},
{
"input": "5 0\n1 1 1 2 2",
"output": "4"
},
{
"input": "5 0\n1 1 2 2 3",
"output": "2"
},
{
"input": "10 0\n1 1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "2 0\n3 3",
"output": "1"
}
] | 1,000 | 12,492,800 | 0 | 291 |
|
908 | New Year and Buggy Bot | [
"brute force",
"implementation"
] | null | null | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.
The robot can only move up, left, right, or down.
When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.
The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.
Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit. | The first line of input will contain two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50), denoting the dimensions of the maze.
The next *n* lines will contain exactly *m* characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The last line will contain a single string *s* (1<=≤<=|*s*|<=≤<=100) — the instructions given to the robot. Each character of *s* is a digit from 0 to 3. | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | [
"5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n",
"6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021\n",
"5 3\n...\n.S.\n###\n.E.\n...\n3\n"
] | [
"1\n",
"14\n",
"0\n"
] | For the first sample, the only valid mapping is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a55361bde12e4223a96f0e1d83b94428f26f02.png" style="max-width: 100.0%;max-height: 100.0%;"/>, where *D* is down, *L* is left, *U* is up, *R* is right. | [
{
"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012",
"output": "1"
},
{
"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021",
"output": "14"
},
{
"input": "5 3\n...\n.S.\n###\n.E.\n...\n3",
"output": "0"
},
{
"input": "10 10\n.#......#.\n#.........\n#.........\n....#.#..E\n.......#..\n....##....\n....S.....\n....#.....\n.........#\n...##...#.\n23323332313123221123020122221313323310313122323233",
"output": "0"
},
{
"input": "8 9\n.........\n.........\n.........\n.E.#.....\n.........\n.........\n...#.S...\n.........\n10001100111000010121100000110110110100000100000100",
"output": "2"
},
{
"input": "15 13\n.............\n.............\n.............\n.........#...\n..#..........\n.............\n..........E..\n.............\n.............\n.#...........\n.....#.......\n..........#..\n..........S..\n.............\n.........#...\n32222221111222312132110100022020202131222103103330",
"output": "2"
},
{
"input": "5 5\n.....\n.....\n..SE.\n.....\n.....\n012330213120031231022103231013201032301223011230102320130231321012030321213002133201130201322031",
"output": "24"
},
{
"input": "2 2\nS.\n.E\n23",
"output": "4"
},
{
"input": "2 2\nS.\n.E\n03",
"output": "4"
},
{
"input": "2 2\nSE\n..\n22",
"output": "6"
},
{
"input": "2 2\nS.\nE.\n11",
"output": "6"
},
{
"input": "2 2\n#E\nS.\n01",
"output": "2"
},
{
"input": "10 10\n####S.####\n#####.####\n#####.####\n#####.####\n#####..###\n######.###\n######.###\n######.E##\n##########\n##########\n0111101110",
"output": "2"
},
{
"input": "10 10\n#####..E##\n#####.S.##\n#####...##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n20",
"output": "4"
},
{
"input": "10 10\n#####ES.##\n######.###\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n3",
"output": "6"
},
{
"input": "2 10\nS........E\n..........\n33333333333333333",
"output": "6"
},
{
"input": "2 2\n..\nSE\n0",
"output": "6"
},
{
"input": "2 2\nSE\n##\n0",
"output": "6"
},
{
"input": "2 2\nS.\nE.\n012",
"output": "8"
},
{
"input": "2 3\nS.E\n###\n1222",
"output": "0"
},
{
"input": "2 5\nS...E\n.....\n133330",
"output": "1"
},
{
"input": "5 5\n.....\n.....\n.S.E.\n.....\n.....\n001111",
"output": "6"
},
{
"input": "3 5\n....S\n....#\n....E\n0112",
"output": "1"
},
{
"input": "2 2\nSE\n..\n123",
"output": "8"
},
{
"input": "2 10\n........ES\n..........\n123",
"output": "8"
},
{
"input": "2 2\nS.\n.E\n2311",
"output": "4"
},
{
"input": "2 2\nS.\n.E\n0012",
"output": "0"
},
{
"input": "2 7\nS.....E\n#######\n01111111",
"output": "0"
},
{
"input": "2 2\nS.\n.E\n1123",
"output": "0"
},
{
"input": "2 3\nS.E\n...\n0111",
"output": "0"
},
{
"input": "2 50\n.................................................E\nS.................................................\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "0"
},
{
"input": "5 2\n..\n..\n..\n..\nSE\n0",
"output": "6"
},
{
"input": "3 3\nE..\n.S.\n...\n001123110023221103",
"output": "0"
},
{
"input": "2 2\nS#\nE#\n012",
"output": "6"
},
{
"input": "2 2\nES\n..\n011",
"output": "6"
},
{
"input": "2 2\nSE\n..\n011",
"output": "6"
},
{
"input": "2 2\nS.\nE.\n102",
"output": "8"
},
{
"input": "3 2\nE#\n##\nS#\n0112",
"output": "0"
}
] | 109 | 23,552,000 | 3 | 294 |
|
32 | Reconnaissance | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different. | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
"output": "20"
},
{
"input": "10 4\n11 6 76 49 28 20 57 152 5 32",
"output": "4"
},
{
"input": "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 310 382 770 337 18 189 570 177 29 54 855 171 205 291 299 935 620 180 114 358 88 292 118 400 218 537 369 60 683 192 13 537 59 824 264 191 3 300",
"output": "2404"
}
] | 1,184 | 0 | 3.704 | 297 |
47 | Coins | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B. | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "A>C\nA>B\nB<C",
"output": "BCA"
},
{
"input": "C<B\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nA>B\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nA<C",
"output": "ABC"
},
{
"input": "C<B\nB<A\nC>A",
"output": "Impossible"
},
{
"input": "B<C\nC<A\nA>B",
"output": "BCA"
},
{
"input": "A>B\nC<B\nC<A",
"output": "CBA"
},
{
"input": "B>A\nC>B\nA>C",
"output": "Impossible"
},
{
"input": "B<A\nC>B\nC>A",
"output": "BAC"
},
{
"input": "A<B\nC>B\nA<C",
"output": "ABC"
},
{
"input": "A<B\nC<A\nB<C",
"output": "Impossible"
},
{
"input": "A>C\nC<B\nB>A",
"output": "CAB"
},
{
"input": "C>A\nA<B\nB>C",
"output": "ACB"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "B>C\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA<B\nB>C",
"output": "ACB"
},
{
"input": "B>A\nA>C\nB>C",
"output": "CAB"
},
{
"input": "B<A\nA<C\nC<B",
"output": "Impossible"
},
{
"input": "A<C\nB>C\nA>B",
"output": "Impossible"
},
{
"input": "B>A\nC<A\nC>B",
"output": "Impossible"
},
{
"input": "A>C\nC>B\nB<A",
"output": "BCA"
},
{
"input": "B<C\nB<A\nA>C",
"output": "BCA"
},
{
"input": "A>B\nC>B\nA<C",
"output": "BAC"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA>B\nB>C",
"output": "Impossible"
},
{
"input": "B>A\nB>C\nA<C",
"output": "ACB"
},
{
"input": "B>C\nC<A\nB<A",
"output": "CBA"
},
{
"input": "C>A\nB>A\nB>C",
"output": "ACB"
},
{
"input": "B<A\nB>C\nA<C",
"output": "Impossible"
},
{
"input": "B<C\nA<B\nC>A",
"output": "ABC"
},
{
"input": "C<B\nB>A\nA>C",
"output": "CAB"
},
{
"input": "A>B\nC>A\nB<C",
"output": "BAC"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "B>C\nC>A\nA>B",
"output": "Impossible"
},
{
"input": "B<A\nB>C\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nC>A",
"output": "ABC"
},
{
"input": "A>C\nA>B\nB>C",
"output": "CBA"
},
{
"input": "B<C\nA>B\nA<C",
"output": "BAC"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "C>B\nA<B\nC<A",
"output": "Impossible"
},
{
"input": "A<C\nC<B\nA>B",
"output": "Impossible"
},
{
"input": "B>C\nA<B\nA<C",
"output": "ACB"
},
{
"input": "C>A\nA<B\nC>B",
"output": "ABC"
}
] | 92 | 0 | 3.977 | 298 |
735 | Tennis Championship | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output": "27"
},
{
"input": "3000000000",
"output": "45"
},
{
"input": "123456789123456789",
"output": "81"
},
{
"input": "5",
"output": "3"
},
{
"input": "143",
"output": "9"
},
{
"input": "144",
"output": "10"
},
{
"input": "145",
"output": "10"
},
{
"input": "232",
"output": "10"
},
{
"input": "233",
"output": "11"
},
{
"input": "234",
"output": "11"
},
{
"input": "679891637638612257",
"output": "84"
},
{
"input": "679891637638612258",
"output": "85"
},
{
"input": "679891637638612259",
"output": "85"
},
{
"input": "1000000000000000000",
"output": "85"
},
{
"input": "10235439547",
"output": "47"
},
{
"input": "1240723548",
"output": "43"
},
{
"input": "92353046212453",
"output": "66"
},
{
"input": "192403205846532",
"output": "68"
},
{
"input": "13925230525389",
"output": "62"
},
{
"input": "12048230592523",
"output": "62"
},
{
"input": "19204385325853",
"output": "63"
},
{
"input": "902353283921",
"output": "56"
},
{
"input": "793056859214355",
"output": "70"
},
{
"input": "982045466234565",
"output": "71"
},
{
"input": "126743950353465",
"output": "67"
},
{
"input": "12405430465",
"output": "47"
},
{
"input": "10238439257768",
"output": "61"
},
{
"input": "1728493055346",
"output": "58"
},
{
"input": "927553829046",
"output": "56"
},
{
"input": "62735129403",
"output": "51"
},
{
"input": "71624823950223",
"output": "65"
},
{
"input": "8902353464851212",
"output": "75"
},
{
"input": "61824012598535",
"output": "65"
},
{
"input": "1294902504603347",
"output": "71"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "3"
},
{
"input": "8",
"output": "4"
},
{
"input": "9",
"output": "4"
},
{
"input": "11",
"output": "4"
},
{
"input": "12",
"output": "4"
},
{
"input": "13",
"output": "5"
},
{
"input": "14",
"output": "5"
},
{
"input": "15",
"output": "5"
},
{
"input": "16",
"output": "5"
},
{
"input": "17",
"output": "5"
},
{
"input": "18",
"output": "5"
},
{
"input": "19",
"output": "5"
},
{
"input": "20",
"output": "5"
},
{
"input": "21",
"output": "6"
},
{
"input": "22",
"output": "6"
},
{
"input": "23",
"output": "6"
},
{
"input": "355687428096000",
"output": "69"
},
{
"input": "576460752303423488",
"output": "84"
},
{
"input": "32212254719",
"output": "49"
},
{
"input": "26388279066623",
"output": "63"
},
{
"input": "618473717761",
"output": "56"
},
{
"input": "262406072477",
"output": "54"
}
] | 109 | 0 | 3 | 299 |
|
884 | Japanese Crosswords Strike Back | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output": "YES"
},
{
"input": "10 1\n5 78 3 87 4 9 5 8 9 1235",
"output": "NO"
},
{
"input": "3 12\n3 3 3",
"output": "NO"
},
{
"input": "3 9\n2 2 2",
"output": "NO"
},
{
"input": "2 5\n1 1",
"output": "NO"
},
{
"input": "1 2\n1",
"output": "NO"
},
{
"input": "3 13\n3 3 3",
"output": "NO"
},
{
"input": "3 6\n1 1 1",
"output": "NO"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "3 11\n3 3 2",
"output": "NO"
},
{
"input": "2 6\n1 3",
"output": "NO"
},
{
"input": "3 10\n2 2 2",
"output": "NO"
},
{
"input": "3 8\n2 1 1",
"output": "NO"
},
{
"input": "1 5\n2",
"output": "NO"
},
{
"input": "1 3\n1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "2 10\n4 4",
"output": "NO"
},
{
"input": "2 8\n2 3",
"output": "NO"
},
{
"input": "2 4\n1 1",
"output": "NO"
},
{
"input": "3 10\n1 2 4",
"output": "NO"
},
{
"input": "3 10\n2 1 3",
"output": "NO"
},
{
"input": "2 6\n1 2",
"output": "NO"
},
{
"input": "3 4\n1 1 1",
"output": "NO"
},
{
"input": "3 11\n1 2 4",
"output": "NO"
},
{
"input": "3 12\n3 3 2",
"output": "NO"
},
{
"input": "4 9\n1 1 1 1",
"output": "NO"
},
{
"input": "1 10\n9",
"output": "NO"
},
{
"input": "1 7\n5",
"output": "NO"
},
{
"input": "2 5\n1 2",
"output": "NO"
},
{
"input": "3 8\n1 1 2",
"output": "NO"
},
{
"input": "3 7\n1 1 1",
"output": "NO"
},
{
"input": "1 10\n1",
"output": "NO"
},
{
"input": "3 10\n2 3 4",
"output": "NO"
},
{
"input": "3 9\n1 2 3",
"output": "NO"
},
{
"input": "3 9\n3 3 2",
"output": "NO"
},
{
"input": "3 6\n3 3 2",
"output": "NO"
},
{
"input": "1 1\n3",
"output": "NO"
},
{
"input": "1 3\n2",
"output": "NO"
},
{
"input": "3 10\n3 3 3",
"output": "NO"
},
{
"input": "3 5\n1 1 1",
"output": "YES"
},
{
"input": "2 1\n100 100",
"output": "NO"
},
{
"input": "3 3\n3 3 3",
"output": "NO"
},
{
"input": "4 17\n3 3 9 1",
"output": "NO"
},
{
"input": "4 1660\n1505 13 37 100",
"output": "NO"
},
{
"input": "3 5\n3 3 2",
"output": "NO"
},
{
"input": "4 10\n3 3 2 5",
"output": "NO"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n2",
"output": "NO"
},
{
"input": "5 10\n1 2 2 4 5",
"output": "NO"
},
{
"input": "2 1\n1 1",
"output": "NO"
}
] | 92 | 7,372,800 | 3 | 301 |
|
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 | 0 | 302 |
|
337 | Puzzles | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).
The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on.
Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5. | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903",
"output": "13"
},
{
"input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94",
"output": "3"
},
{
"input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190",
"output": "31"
},
{
"input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997",
"output": "0"
},
{
"input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176",
"output": "412"
},
{
"input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886",
"output": "938"
},
{
"input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993",
"output": "937"
},
{
"input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7",
"output": "0"
},
{
"input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19",
"output": "12"
},
{
"input": "40 50\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",
"output": "0"
},
{
"input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17",
"output": "31"
},
{
"input": "2 2\n1000 4",
"output": "996"
},
{
"input": "2 3\n4 502 1000",
"output": "498"
},
{
"input": "3 3\n4 1000 4",
"output": "996"
}
] | 62 | 0 | 0 | 303 |
|
221 | Little Elephant and Function | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"input": "7",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1000",
"output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "999",
"output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "998",
"output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "997",
"output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "900",
"output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "101",
"output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "67",
"output": "67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 "
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "971",
"output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "683",
"output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "99",
"output": "99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 "
},
{
"input": "811",
"output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "875",
"output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "291",
"output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "419",
"output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "21",
"output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
},
{
"input": "22",
"output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "23",
"output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "24",
"output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 "
},
{
"input": "25",
"output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "
}
] | 218 | 0 | 3 | 304 |
|
135 | Rectangle and Square | [
"brute force",
"geometry",
"math"
] | null | null | Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case. | You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide. | Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct.
If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed. | [
"0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2\n",
"0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n",
"0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1\n"
] | [
"YES\n5 6 7 8\n1 2 3 4\n",
"NO\n",
"YES\n1 2 3 4\n5 6 7 8\n"
] | Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes. | [
{
"input": "0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7",
"output": "NO"
},
{
"input": "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "-160 336\n-76 672\n8 168\n-580 588\n-1000 504\n-496 840\n-496 84\n-664 0",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "8 -328\n-440 568\n-104 8\n-1000 -664\n8 456\n-328 8\n-552 120\n-664 -1000",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "65 852\n-645 284\n-361 710\n-1000 71\n-219 284\n207 426\n-716 0\n-929 355",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "980 518\n584 -670\n-208 914\n-736 -340\n-604 -274\n-1000 -736\n-604 -1000\n-340 -604",
"output": "YES\n1 2 3 5\n4 6 7 8"
},
{
"input": "48 264\n144 240\n24 0\n168 48\n120 144\n0 72\n144 120\n24 168",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "576 -616\n192 -424\n384 152\n768 248\n384 -1000\n0 -808\n480 -232\n864 -136",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "547 -167\n-1000 -762\n190 904\n-762 -1000\n-167 71\n904 547\n71 -167\n-167 190",
"output": "YES\n1 3 6 8\n2 4 5 7"
},
{
"input": "-1000 -736\n1200 408\n1728 12\n188 -1000\n1332 -516\n-736 -208\n452 -472\n804 -120",
"output": "NO"
},
{
"input": "210 140\n140 0\n210 210\n455 140\n70 210\n525 385\n0 70\n280 455",
"output": "YES\n1 2 5 7\n3 4 6 8"
},
{
"input": "-1000 -829\n-715 -601\n311 197\n197 -715\n-829 -1000\n-601 311\n-658 -487\n-487 -658",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "329 -859\n282 -765\n376 81\n0 -906\n47 -1000\n846 -577\n940 -13\n282 -483",
"output": "YES\n3 6 7 8\n1 2 4 5"
},
{
"input": "40 100\n210 20\n100 60\n120 230\n0 40\n60 0\n60 80\n270 170",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-252 -1000\n-1000 -932\n-864 20\n-796 -864\n768 -388\n-932 -796\n-864 -1000\n156 632",
"output": "YES\n2 4 6 7\n1 3 5 8"
},
{
"input": "351 234\n234 741\n234 351\n702 819\n117 0\n0 117\n312 273\n780 351",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "434 372\n0 62\n496 868\n868 620\n620 248\n248 496\n62 434\n372 0",
"output": "YES\n3 4 5 6\n1 2 7 8"
},
{
"input": "-40 -1000\n-440 120\n2200 -200\n1800 920\n-200 -680\n-840 120\n-40 -360\n-1000 -200",
"output": "NO"
},
{
"input": "-850 -1000\n-475 -325\n1025 800\n-325 575\n-325 -850\n-1000 -475\n-100 -775\n1250 -550",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "70 64\n32 0\n58 48\n48 80\n72 50\n0 48\n56 62\n80 32",
"output": "YES\n1 3 5 7\n2 4 6 8"
},
{
"input": "937 937\n-851 43\n-404 1086\n43 -106\n788 -404\n-553 -255\n-1000 -851\n-106 -1000",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-1 -223\n554 110\n-778 -1000\n-667 -445\n-1000 -667\n-445 -778\n443 -334\n110 221",
"output": "YES\n3 4 5 6\n1 2 7 8"
},
{
"input": "1610 0\n1700 270\n-1000 -900\n2105 315\n800 0\n-190 -900\n1925 90\n1880 495",
"output": "NO"
},
{
"input": "-360 120\n600 440\n-680 -40\n440 600\n-520 -360\n-200 -200\n-840 -1000\n-1000 -840",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-11 220\n-11 22\n176 -66\n-198 -22\n-198 176\n220 -198\n0 88\n44 -44",
"output": "NO"
},
{
"input": "378 504\n504 504\n126 0\n504 126\n0 378\n252 546\n294 798\n546 756",
"output": "YES\n1 3 4 5\n2 6 7 8"
},
{
"input": "312 468\n312 0\n728 728\n468 676\n520 416\n0 0\n780 468\n0 468",
"output": "YES\n3 4 5 7\n1 2 6 8"
},
{
"input": "180 100\n180 220\n80 0\n240 760\n0 80\n100 180\n720 160\n780 700",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "-1000 -742\n1064 290\n32 634\n720 -742\n-742 -226\n-312 -398\n-484 -1000\n-226 -484",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "-153 -238\n-204 34\n102 119\n34 0\n-663 -306\n0 68\n-612 -578\n136 51",
"output": "NO"
},
{
"input": "-620 -1000\n-1000 -620\n976 672\n-240 140\n596 140\n140 -240\n1052 216\n520 596",
"output": "YES\n3 5 7 8\n1 2 4 6"
},
{
"input": "203 232\n232 348\n58 0\n0 58\n319 203\n290 232\n348 319\n232 290",
"output": "YES\n1 2 5 7\n3 4 6 8"
},
{
"input": "-328 260\n-664 -1000\n-1000 -496\n92 -496\n-1000 -1000\n-664 -496\n-496 -328\n260 92",
"output": "YES\n1 4 7 8\n2 3 5 6"
},
{
"input": "-586 414\n-931 0\n-103 276\n-448 897\n-655 414\n35 759\n-586 345\n-1000 69",
"output": "YES\n1 3 4 6\n2 5 7 8"
},
{
"input": "-424 920\n-1000 152\n344 -232\n-232 536\n-424 -1000\n-616 -40\n344 -616\n536 728",
"output": "YES\n1 3 6 8\n2 4 5 7"
},
{
"input": "427 -451\n549 -573\n122 -1000\n0 -85\n183 -512\n427 98\n610 -329\n0 -878",
"output": "YES\n4 5 6 7\n1 2 3 8"
},
{
"input": "89 -307\n-109 -505\n-10 89\n-1000 -604\n-505 -1000\n-406 -10\n-307 -406\n-604 -109",
"output": "YES\n1 3 6 7\n2 4 5 8"
},
{
"input": "5 0\n16 -54\n9 5\n0 4\n0 -6\n4 9\n40 -24\n-24 -36",
"output": "NO"
},
{
"input": "-845 860\n-535 -225\n-380 85\n395 550\n-225 -535\n-1000 -690\n-690 -1000\n-70 1325",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "702 628\n-334 -408\n-482 -852\n850 -704\n-408 -334\n-926 -1000\n-1000 -926\n-630 480",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "-465 -37\n-465 -1000\n177 -37\n-144 177\n-1000 -37\n-1000 -1000\n-358 -144\n-37 -358",
"output": "YES\n3 4 7 8\n1 2 5 6"
},
{
"input": "-1000 176\n408 88\n-384 528\n-648 704\n-472 792\n-736 0\n-384 0\n320 880",
"output": "YES\n2 5 7 8\n1 3 4 6"
},
{
"input": "-1000 786\n-906 1256\n-671 1021\n-812 974\n598 316\n-765 1303\n598 -1000\n-1000 -530",
"output": "NO"
},
{
"input": "550 -70\n-8 -597\n-70 -628\n-39 -690\n-1000 -380\n23 -659\n-70 550\n-380 -1000",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "184 230\n46 0\n0 184\n23 184\n115 552\n483 460\n391 92\n230 46",
"output": "YES\n4 5 6 7\n1 2 3 8"
},
{
"input": "692 -60\n-812 316\n128 880\n-248 -624\n-812 692\n-1000 -1000\n-1000 692\n-812 -1000",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "-1000 -852\n-852 -1000\n332 480\n36 1812\n184 2996\n480 332\n-408 776\n-556 -408",
"output": "NO"
},
{
"input": "68 0\n374 221\n306 204\n323 136\n272 340\n391 153\n0 272\n340 68",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "296 -163\n350 -190\n-190 -1000\n701 -730\n782 -244\n215 -649\n-1000 -460\n-460 350",
"output": "YES\n1 4 5 6\n2 3 7 8"
},
{
"input": "280 0\n504 420\n0 0\n0 168\n644 504\n280 168\n532 532\n616 392",
"output": "YES\n2 5 7 8\n1 3 4 6"
},
{
"input": "728 656\n584 152\n1160 152\n-1000 -1000\n1016 944\n-568 -424\n1448 440\n1016 728",
"output": "NO"
},
{
"input": "0 25\n725 325\n250 225\n575 675\n375 175\n225 525\n25 0\n225 250",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "116 488\n-628 -1000\n-70 -70\n116 1604\n-814 860\n488 -628\n860 674\n-1000 116",
"output": "YES\n3 4 5 7\n1 2 6 8"
},
{
"input": "-208 -703\n-109 -604\n-406 -10\n287 188\n-208 -406\n-1000 -802\n-901 -1000\n485 -505",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "1136 602\n1403 -21\n-21 -911\n-1000 424\n-733 513\n-288 -1000\n780 -288\n513 335",
"output": "NO"
},
{
"input": "760 980\n1420 -120\n320 -780\n-1000 -560\n100 -340\n-340 320\n-560 -1000\n-340 100",
"output": "YES\n1 2 3 6\n4 5 7 8"
},
{
"input": "2843 260\n3347 890\n2780 827\n1520 134\n-1000 -874\n2276 8\n-244 -1000\n3410 323",
"output": "NO"
},
{
"input": "0 336\n112 476\n196 448\n336 0\n560 896\n140 560\n224 532\n896 560",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "0 39\n169 117\n182 182\n104 130\n117 195\n65 0\n39 104\n104 65",
"output": "YES\n2 3 4 5\n1 6 7 8"
},
{
"input": "-610 40\n-1000 -220\n-870 -1000\n-220 352\n-298 -350\n-220 -90\n92 -38\n-90 -870",
"output": "YES\n1 4 5 7\n2 3 6 8"
},
{
"input": "560 140\n0 140\n280 280\n560 700\n420 560\n700 560\n140 0\n700 420",
"output": "YES\n1 3 5 8\n2 4 6 7"
},
{
"input": "400 -580\n-580 -895\n-475 -720\n-580 -1000\n-405 -1000\n-20 400\n-300 -825\n-1000 -20",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "-736 -560\n56 -560\n-208 320\n-736 -472\n56 760\n-648 320\n-1000 -1000\n144 232",
"output": "NO"
},
{
"input": "688 516\n387 258\n0 129\n387 430\n43 0\n430 129\n774 215\n473 129",
"output": "YES\n1 4 7 8\n2 3 5 6"
},
{
"input": "-856 -1000\n224 872\n-136 8\n584 656\n8 512\n368 296\n8 -136\n-1000 -856",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-880 0\n400 -240\n-640 480\n-160 240\n-240 480\n-520 360\n320 0\n-1000 120",
"output": "NO"
},
{
"input": "58 0\n0 58\n377 145\n261 203\n203 261\n406 29\n290 0\n261 116",
"output": "YES\n3 6 7 8\n1 2 4 5"
},
{
"input": "420 280\n308 196\n336 392\n224 308\n0 224\n224 280\n56 0\n280 56",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "136 -1000\n544 -864\n408 -456\n816 156\n340 88\n884 -320\n0 -592\n408 -388",
"output": "YES\n1 2 3 7\n4 5 6 8"
},
{
"input": "920 -360\n2088 200\n-1000 600\n2024 -56\n1576 -184\n1240 -1000\n-680 -40\n1512 -440",
"output": "NO"
},
{
"input": "528 660\n792 660\n660 528\n528 0\n0 132\n330 462\n132 0\n990 198",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "248 404\n872 794\n950 846\n560 -1000\n-1000 716\n924 716\n1002 768\n-688 -688",
"output": "NO"
},
{
"input": "-656 0\n-140 344\n-140 516\n-484 860\n-1000 344\n-54 946\n204 602\n-398 688",
"output": "YES\n2 6 7 8\n1 3 4 5"
},
{
"input": "744 -19\n-1000 -782\n-237 90\n-128 -346\n-346 -891\n-891 -1000\n635 -1000\n-19 -564",
"output": "YES\n1 3 5 7\n2 4 6 8"
},
{
"input": "420 -664\n0 -160\n420 260\n-840 -412\n420 -580\n-840 92\n420 -160\n0 -1000",
"output": "NO"
},
{
"input": "558 930\n0 837\n930 558\n310 775\n372 0\n0 372\n124 651\n186 961",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "-1000 448\n120 448\n876 224\n1212 -84\n36 588\n372 280\n-776 0\n-104 896",
"output": "NO"
},
{
"input": "-320 904\n3896 -184\n224 224\n3624 -48\n-1000 360\n-456 -320\n-864 -864\n-592 -1000",
"output": "NO"
},
{
"input": "302 488\n-814 860\n-70 984\n-690 116\n-814 -1000\n488 302\n54 240\n-1000 -814",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "0 0\n4 -16\n24 36\n-60 60\n-56 44\n36 43\n40 12\n52 19",
"output": "NO"
},
{
"input": "-1000 282\n-154 705\n-859 0\n974 846\n833 141\n128 282\n-13 423\n269 987",
"output": "YES\n4 5 6 8\n1 2 3 7"
},
{
"input": "20 -40\n-40 60\n-20 -15\n100 -90\n40 45\n0 0\n60 60\n40 10",
"output": "NO"
},
{
"input": "-192 -192\n-495 616\n-1000 -596\n414 -91\n313 717\n-394 -192\n-798 -1000\n10 -596",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-1000 -637\n-516 -274\n-274 -153\n-32 -516\n452 210\n210 -516\n-758 -1000\n-274 452",
"output": "YES\n2 5 6 8\n1 3 4 7"
},
{
"input": "-799 407\n-665 -531\n-531 -866\n-866 -1000\n-263 -933\n809 407\n1345 -933\n-1000 -665",
"output": "NO"
},
{
"input": "-1000 640\n-16 640\n312 -1000\n968 -16\n640 968\n-672 -344\n-672 -1000\n968 -672",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "-1000 -676\n-136 -460\n-460 188\n188 80\n-568 -460\n-460 -136\n-676 -1000\n80 -568",
"output": "YES\n3 4 5 8\n1 2 6 7"
},
{
"input": "748 68\n663 -34\n0 680\n425 0\n663 -68\n425 680\n0 0\n578 -170",
"output": "NO"
},
{
"input": "248 92\n-1000 -792\n-584 -376\n-168 40\n-116 -376\n-792 -1000\n-376 -584\n300 -324",
"output": "YES\n1 4 5 8\n2 3 6 7"
},
{
"input": "140 42\n126 84\n-154 238\n-420 406\n14 0\n0 42\n-518 532\n-56 112",
"output": "NO"
},
{
"input": "477 0\n636 371\n106 689\n212 265\n0 53\n530 795\n53 530\n530 477",
"output": "YES\n2 3 4 6\n1 5 7 8"
},
{
"input": "0 -814\n93 -256\n372 -349\n186 23\n837 -628\n744 -442\n93 -1000\n465 -70",
"output": "YES\n2 3 4 8\n1 5 6 7"
},
{
"input": "-832 -286\n-748 -664\n-916 -1000\n302 -160\n-328 344\n-202 -790\n-1000 -748\n-664 -916",
"output": "YES\n1 4 5 6\n2 3 7 8"
},
{
"input": "25 10\n0 10\n41 34\n5 0\n39 30\n37 36\n35 32\n20 20",
"output": "YES\n3 5 6 7\n1 2 4 8"
},
{
"input": "-522 -1000\n912 1629\n912 434\n-283 1629\n-1000 -283\n195 -522\n-283 195\n-283 2824",
"output": "NO"
},
{
"input": "-586 -310\n-310 104\n104 -586\n-172 -1000\n-1000 -310\n-724 -862\n-34 -448\n-586 -1000",
"output": "YES\n1 4 6 7\n2 3 5 8"
},
{
"input": "-445 -1\n-556 -1000\n554 443\n-1000 -445\n-445 -334\n443 -445\n-1 -556\n-334 554",
"output": "YES\n1 2 4 7\n3 5 6 8"
},
{
"input": "-288 -822\n-733 -110\n-733 -1000\n1047 -555\n-1000 -911\n780 780\n-466 -199\n-555 513",
"output": "YES\n1 4 6 8\n2 3 5 7"
},
{
"input": "2024 8\n1352 -1000\n1016 -244\n512 344\n1856 344\n2360 -748\n-1000 -664\n344 -664",
"output": "NO"
},
{
"input": "-1000 -400\n1190 450\n1460 420\n800 50\n1250 -550\n1100 360\n1370 330\n-550 -1000",
"output": "NO"
},
{
"input": "1175 450\n-130 -1000\n160 160\n-1000 -1000\n-1000 450\n-130 450\n1465 -565\n450 -855",
"output": "YES\n1 3 7 8\n2 4 5 6"
},
{
"input": "424 -288\n-1000 -466\n68 246\n246 1492\n-644 -1000\n-644 -110\n-1000 1136\n602 246",
"output": "YES\n4 6 7 8\n1 2 3 5"
},
{
"input": "-471 -80\n-1000 35\n-402 127\n150 -885\n-885 -1000\n35 150\n-333 -11\n-540 58",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-400 -1000\n-400 1000\n600 400\n400 1000\n400 1200\n-1000 -400\n-200 200\n1000 400",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "292 1414\n802 1312\n-1000 -1000\n462 2400\n-184 -235\n-847 326\n-31 1091\n972 2298",
"output": "NO"
},
{
"input": "0 0\n8 12\n14 4\n0 10\n7 5\n5 10\n15 11\n5 0",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "60 260\n280 0\n100 240\n80 200\n0 0\n0 400\n280 400\n40 220",
"output": "YES\n1 3 4 8\n2 5 6 7"
},
{
"input": "-850 -1000\n-1000 -850\n-800 -250\n250 -700\n-50 50\n-500 -1000\n-650 -800\n-800 -650",
"output": "YES\n3 4 5 6\n1 2 7 8"
},
{
"input": "-125 -825\n1100 -475\n400 -300\n-1000 -475\n-475 400\n-650 -1000\n50 225\n750 750",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "-725 1596\n155 -1000\n-758 1530\n-571 1376\n-1000 320\n-692 1497\n-659 1563\n584 56",
"output": "NO"
},
{
"input": "-638 3887\n-1000 1896\n448 1353\n-95 4430\n-457 -1000\n-276 4611\n-95 4249\n-819 4068",
"output": "NO"
},
{
"input": "216 0\n828 504\n648 612\n504 432\n756 792\n288 576\n0 144\n936 684",
"output": "YES\n2 3 5 8\n1 4 6 7"
},
{
"input": "72 32\n4 40\n44 32\n32 0\n40 72\n20 16\n28 56\n0 40",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "457 -329\n-530 611\n-624 0\n-953 658\n-577 188\n-859 -141\n692 -188\n-1000 235",
"output": "NO"
},
{
"input": "-841 -205\n590 -205\n-1000 -1000\n-364 1385\n-682 113\n-841 -1000\n-1000 -205\n908 1067",
"output": "YES\n2 4 5 8\n1 3 6 7"
},
{
"input": "-1000 -604\n-604 1112\n-340 -736\n452 1376\n-604 -340\n-736 -1000\n716 320\n-340 56",
"output": "YES\n1 3 5 6\n2 4 7 8"
},
{
"input": "-260 332\n-112 776\n776 184\n-1000 -1000\n-112 1368\n-852 36\n628 924\n36 36",
"output": "NO"
},
{
"input": "600 0\n460 600\n500 960\n0 200\n660 760\n300 800\n100 500\n700 300",
"output": "YES\n2 3 5 6\n1 4 7 8"
},
{
"input": "15 160\n-101 334\n-855 -1000\n-275 -101\n-1000 -855\n160 15\n160 -275\n334 160",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "0 108\n216 144\n480 360\n0 0\n60 108\n240 192\n60 0\n-24 -24",
"output": "NO"
},
{
"input": "344 -200\n-200 -520\n-680 -1000\n280 -8\n-1000 -680\n536 -136\n-520 -200\n472 56",
"output": "YES\n1 4 6 8\n2 3 5 7"
},
{
"input": "270 2024\n-486 -1000\n-162 2672\n162 2888\n540 728\n918 1862\n-864 1160\n486 2510",
"output": "NO"
},
{
"input": "0 336\n128 80\n240 272\n0 0\n368 -112\n128 -256\n144 96\n464 64",
"output": "NO"
},
{
"input": "-526 -447\n-1000 -526\n-526 -1000\n-131 -131\n-368 106\n185 -526\n-210 -842\n106 -368",
"output": "YES\n1 4 6 7\n2 3 5 8"
},
{
"input": "648 440\n720 -1000\n0 -280\n-120 1520\n-840 2240\n720 488\n672 560\n600 512",
"output": "NO"
},
{
"input": "-1000 568\n-432 639\n278 710\n-929 0\n-361 355\n-361 71\n-219 852\n136 213",
"output": "YES\n1 2 4 6\n3 5 7 8"
},
{
"input": "-520 480\n-40 240\n-1000 240\n240 360\n-400 240\n-160 520\n-880 0\n120 640",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "270 225\n297 387\n315 135\n387 315\n45 0\n0 90\n225 297\n315 225",
"output": "YES\n2 4 7 8\n1 3 5 6"
},
{
"input": "60 30\n0 18\n24 6\n81 36\n75 57\n18 24\n54 51\n6 0",
"output": "YES\n1 4 5 7\n2 3 6 8"
},
{
"input": "134 -496\n-496 -118\n-748 8\n-1000 -748\n8 -244\n-370 134\n-622 260\n-874 -1000",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "1538 -718\n-1000 -718\n3277 -13\n3089 645\n3747 833\n-718 -1000\n3935 175\n1820 -1000",
"output": "NO"
},
{
"input": "116 232\n87 0\n319 116\n203 174\n58 145\n174 0\n203 261\n0 58",
"output": "YES\n3 5 6 7\n1 2 4 8"
},
{
"input": "-912 -296\n672 -560\n-472 -296\n-648 -208\n-648 1288\n-824 -1000\n-1000 -912\n936 1024",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "428 -796\n-592 -1000\n666 3318\n-1000 1856\n190 2842\n462 3454\n394 2706\n20 2060",
"output": "NO"
},
{
"input": "684 399\n0 228\n570 342\n228 285\n342 0\n228 570\n570 855\n114 741",
"output": "YES\n2 3 5 6\n1 4 7 8"
},
{
"input": "-1000 -373\n254 1090\n-791 672\n463 -164\n-373 -373\n-373 -1000\n-164 463\n672 45",
"output": "YES\n2 3 5 8\n1 4 6 7"
},
{
"input": "-536 -304\n-536 508\n-768 -188\n-768 -1000\n-1000 -768\n160 276\n-72 -420\n-304 -536",
"output": "YES\n2 3 6 7\n1 4 5 8"
},
{
"input": "120 30\n200 160\n130 0\n150 40\n40 200\n0 40\n160 10\n160 0",
"output": "YES\n1 3 4 7\n2 5 6 8"
},
{
"input": "595 -159\n421 -565\n-275 -1000\n-275 -420\n189 15\n-1000 -1000\n-1000 -420\n15 -391",
"output": "YES\n1 2 5 8\n3 4 6 7"
},
{
"input": "6 40\n0 35\n4 50\n5 0\n35 40\n40 5\n10 46\n0 44",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "360 300\n210 240\n240 90\n180 210\n150 390\n300 450\n0 120\n60 0",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "434 116\n434 426\n-186 -1000\n-186 -256\n0 116\n434 -628\n62 54\n372 488",
"output": "NO"
},
{
"input": "520 -325\n260 0\n650 -455\n0 195\n130 390\n195 455\n455 260\n260 260",
"output": "NO"
},
{
"input": "189 135\n261 153\n0 54\n81 0\n234 108\n216 180\n135 81\n54 135",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "864 -540\n972 -162\n342 216\n0 -324\n108 54\n468 378\n486 234\n324 360",
"output": "NO"
},
{
"input": "265 220\n30 -60\n330 -420\n140 110\n15 0\n140 200\n15 90\n345 -480",
"output": "NO"
},
{
"input": "94 112\n-190 360\n-280 0\n0 0\n94 84\n74 76\n114 120\n90 360",
"output": "NO"
},
{
"input": "234 104\n0 52\n286 104\n598 624\n208 156\n182 520\n26 0\n702 208",
"output": "YES\n3 4 6 8\n1 2 5 7"
},
{
"input": "0 304\n456 532\n532 304\n456 76\n304 380\n152 0\n608 228\n228 152",
"output": "YES\n3 4 5 8\n1 2 6 7"
},
{
"input": "517 551\n940 786\n376 -13\n799 -1000\n-94 -154\n329 -906\n329 81\n-94 81",
"output": "NO"
},
{
"input": "117 0\n195 312\n312 195\n0 117\n312 663\n195 390\n468 273\n585 546",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "646 102\n238 136\n102 510\n136 0\n578 578\n102 238\n0 102\n170 34",
"output": "YES\n2 4 6 7\n1 3 5 8"
},
{
"input": "-856 -1000\n440 728\n728 296\n-1000 -856\n296 8\n-424 -280\n-280 -424\n8 440",
"output": "YES\n2 3 5 8\n1 4 6 7"
},
{
"input": "160 120\n180 120\n340 140\n20 0\n320 300\n180 40\n160 280\n0 80",
"output": "YES\n2 3 5 7\n1 4 6 8"
},
{
"input": "195 260\n533 390\n455 546\n0 65\n260 195\n65 0\n689 468\n611 624",
"output": "YES\n2 3 7 8\n1 4 5 6"
},
{
"input": "123 0\n-410 123\n902 -123\n-82 369\n123 492\n0 492\n574 -369\n0 0",
"output": "NO"
},
{
"input": "42 -168\n966 252\n462 126\n840 756\n336 630\n0 -588\n-252 -168\n-294 -588",
"output": "NO"
},
{
"input": "280 480\n360 -80\n-1000 -640\n-200 -160\n-760 -1000\n-280 -160\n-280 400\n-40 -520",
"output": "YES\n1 2 4 7\n3 5 6 8"
},
{
"input": "-622 315\n-1000 126\n-937 0\n-55 315\n-559 189\n-433 441\n-307 819\n71 693",
"output": "YES\n4 6 7 8\n1 2 3 5"
},
{
"input": "410 533\n287 41\n615 164\n328 246\n697 451\n246 287\n0 246\n41 0",
"output": "YES\n1 3 4 5\n2 6 7 8"
},
{
"input": "-919 0\n53 648\n-514 405\n-433 729\n-1000 162\n-28 162\n-433 243\n-514 243",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "-1000 276\n-586 828\n-34 414\n104 414\n-862 690\n-448 276\n-34 966\n-172 0",
"output": "YES\n2 4 6 7\n1 3 5 8"
},
{
"input": "-544 -316\n140 368\n-1000 -772\n-316 -544\n-316 596\n-544 140\n-88 -88\n-772 -1000",
"output": "YES\n2 5 6 7\n1 3 4 8"
},
{
"input": "980 -520\n860 -430\n620 -250\n500 -160\n20 1220\n-1000 980\n380 -760\n-640 -1000",
"output": "NO"
},
{
"input": "432 -1000\n0 -1000\n0 -520\n432 -520\n864 104\n192 8\n960 -568\n288 -664",
"output": "YES\n5 6 7 8\n1 2 3 4"
},
{
"input": "872 872\n-766 -1000\n170 -64\n1808 989\n1925 53\n989 -64\n-64 170\n-1000 -766",
"output": "YES\n1 4 5 6\n2 3 7 8"
},
{
"input": "-620 -1000\n-430 -240\n45 -240\n-810 -145\n-145 520\n-715 -430\n-905 330\n-1000 -905",
"output": "YES\n3 5 6 7\n1 2 4 8"
},
{
"input": "-316 684\n-1000 -228\n444 76\n520 152\n1204 380\n-316 0\n-240 0\n368 760",
"output": "NO"
},
{
"input": "364 -688\n-260 248\n-312 40\n0 -532\n0 -792\n104 -792\n260 -428\n-52 -1000",
"output": "NO"
},
{
"input": "96 180\n-204 108\n-144 36\n84 102\n-12 0\n0 6\n-72 72\n12 84",
"output": "NO"
},
{
"input": "357 -1000\n119 190\n714 -48\n0 -643\n833 -524\n952 547\n476 -167\n357 785",
"output": "YES\n2 3 6 8\n1 4 5 7"
},
{
"input": "598 368\n414 92\n0 0\n138 46\n368 322\n644 138\n138 0\n0 46",
"output": "YES\n1 2 5 6\n3 4 7 8"
},
{
"input": "-480 -350\n-1000 -870\n-870 -1000\n-155 495\n-740 -285\n40 -870\n625 -90\n-350 -480",
"output": "YES\n4 5 6 7\n1 2 3 8"
},
{
"input": "-340 1640\n-1000 650\n320 375\n705 485\n815 100\n430 -10\n-340 -10\n-1000 -1000",
"output": "NO"
},
{
"input": "120 120\n105 30\n30 0\n0 75\n75 90\n90 165\n75 105\n45 135",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "840 980\n140 532\n980 840\n588 420\n700 868\n252 980\n140 0\n0 140",
"output": "YES\n2 4 5 6\n1 3 7 8"
},
{
"input": "-244 -730\n512 998\n-460 -946\n728 1214\n-1000 -568\n728 -892\n80 -1000\n-352 -460",
"output": "NO"
},
{
"input": "62 60\n54 50\n6 42\n64 42\n0 6\n36 0\n72 52\n42 36",
"output": "YES\n1 2 4 7\n3 5 6 8"
},
{
"input": "-941 -1000\n-764 -410\n-823 -882\n-882 -823\n-1000 -941\n1006 298\n475 -941\n-233 829",
"output": "YES\n2 6 7 8\n1 3 4 5"
},
{
"input": "360 648\n504 360\n0 360\n648 288\n288 504\n648 576\n288 0\n432 720",
"output": "YES\n1 3 4 7\n2 5 6 8"
},
{
"input": "792 -648\n-352 -142\n704 -1000\n88 -472\n0 -824\n-682 1046\n572 -208\n242 980",
"output": "NO"
},
{
"input": "-1000 176\n100 616\n-824 0\n-780 396\n-252 88\n-780 440\n-428 968\n-604 220",
"output": "YES\n2 5 6 7\n1 3 4 8"
},
{
"input": "-1000 -580\n-1000 -1000\n330 960\n610 260\n-860 -580\n120 470\n-860 -1000\n820 750",
"output": "YES\n3 4 6 8\n1 2 5 7"
},
{
"input": "0 -970\n90 -580\n585 500\n150 -880\n270 -400\n30 -1000\n405 320\n120 -850",
"output": "NO"
},
{
"input": "600 500\n700 200\n600 180\n620 100\n700 120\n100 0\n680 200\n0 300",
"output": "YES\n3 4 5 7\n1 2 6 8"
},
{
"input": "256 496\n304 512\n576 0\n320 464\n272 448\n0 64\n64 640\n640 576",
"output": "YES\n1 2 4 5\n3 6 7 8"
},
{
"input": "128 112\n40 72\n64 96\n72 40\n80 32\n32 0\n0 32\n144 48",
"output": "YES\n1 3 5 8\n2 4 6 7"
},
{
"input": "-1000 1052\n140 -392\n292 -1000\n900 -848\n-12 368\n672 -544\n748 -240\n-316 140",
"output": "NO"
},
{
"input": "-208 -10\n188 -208\n386 188\n-505 -1000\n-505 -703\n-10 386\n-1000 -1000\n-1000 -703",
"output": "YES\n1 2 3 6\n4 5 7 8"
},
{
"input": "153 102\n187 170\n102 153\n153 68\n0 51\n221 102\n51 0\n119 136",
"output": "YES\n2 4 6 8\n1 3 5 7"
},
{
"input": "-1000 -60\n-342 -1000\n1444 -248\n1162 -718\n1538 -624\n1914 -530\n786 692\n2290 -436",
"output": "NO"
},
{
"input": "3368 858\n-1000 -546\n1886 0\n3914 702\n3602 429\n3056 585\n-298 -780\n2588 -234",
"output": "NO"
},
{
"input": "780 68\n424 -466\n68 -110\n246 424\n246 -466\n-110 -110\n-822 -1000\n-1000 -644",
"output": "YES\n1 2 4 6\n3 5 7 8"
},
{
"input": "-372 93\n-403 31\n31 -31\n558 186\n248 434\n279 155\n0 -93\n527 465",
"output": "NO"
},
{
"input": "-859 329\n-1000 141\n81 705\n-906 0\n-577 987\n-718 329\n-624 188\n-201 47",
"output": "YES\n1 3 5 8\n2 4 6 7"
},
{
"input": "-97 -140\n290 -97\n290 935\n935 290\n-1000 -355\n-140 247\n247 290\n-355 -1000",
"output": "YES\n1 2 6 7\n3 4 5 8"
},
{
"input": "426 518\n-609 449\n633 -1000\n-586 2220\n-954 2174\n-632 2588\n-1000 2542\n-816 1967",
"output": "NO"
},
{
"input": "410 -754\n574 312\n82 66\n820 -180\n410 -1000\n0 -1000\n328 -426\n0 -754",
"output": "YES\n2 3 4 7\n1 5 6 8"
},
{
"input": "-700 120\n-370 -90\n-40 510\n-490 150\n-1000 -60\n-670 -270\n-850 600\n-400 960",
"output": "NO"
},
{
"input": "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n0 -10",
"output": "NO"
},
{
"input": "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n6 2",
"output": "NO"
},
{
"input": "100 100\n100 101\n101 100\n101 101\n0 0\n1 5\n11 5\n10 0",
"output": "NO"
},
{
"input": "0 0\n1 0\n0 1\n1 1\n100 100\n100 101\n101 100\n101 101",
"output": "YES\n1 2 3 4\n5 6 7 8"
},
{
"input": "0 8\n-2 0\n-3 0\n0 -8\n2 0\n3 0\n0 2\n0 -2",
"output": "NO"
},
{
"input": "-8 0\n0 -3\n8 0\n10000 10000\n9999 9999\n9999 10000\n0 3\n10000 9999",
"output": "NO"
},
{
"input": "-8 0\n0 -3\n8 0\n10000 10000\n9998 9999\n9998 10000\n0 3\n10000 9999",
"output": "NO"
},
{
"input": "10 10\n15 11\n15 9\n20 10\n100 100\n100 102\n107 102\n107 100",
"output": "NO"
},
{
"input": "0 0\n5 0\n8 4\n3 4\n-2 -2\n-2 -1\n-1 -1\n-1 -2",
"output": "NO"
},
{
"input": "0 0\n1 1\n2 2\n3 3\n4 4\n4 5\n5 4\n5 5",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 0\n1 1\n10 10\n14 10\n12 16\n12 20",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 0\n1 1\n2 0\n2 1\n3 1\n4 0",
"output": "NO"
},
{
"input": "1 1\n1 2\n2 1\n2 2\n100 100\n101 100\n101 102\n102 102",
"output": "NO"
},
{
"input": "0 0\n2 0\n2 2\n0 2\n1 1\n5 0\n5 2\n9 1",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 0\n1 1\n2 2\n3 2\n3 3\n4 3",
"output": "NO"
},
{
"input": "4 1\n7 3\n9 4\n4 5\n1 3\n9 6\n12 4\n12 6",
"output": "NO"
},
{
"input": "0 0\n3 0\n3 4\n6 4\n100 100\n101 100\n100 101\n101 101",
"output": "NO"
},
{
"input": "1 0\n0 4\n2 4\n1 8\n15 15\n15 16\n18 15\n18 16",
"output": "NO"
},
{
"input": "0 0\n0 1\n1 1\n1 0\n1000 1000\n1001 1003\n1004 1004\n1003 1001",
"output": "NO"
},
{
"input": "1 0\n2 2\n0 2\n1 4\n7 0\n9 0\n7 1\n9 1",
"output": "NO"
},
{
"input": "0 0\n1 0\n1 1\n0 1\n5 6\n100 190\n6 7\n10 196",
"output": "NO"
},
{
"input": "0 0\n1 0\n2 0\n1 2\n50 50\n50 51\n51 51\n51 50",
"output": "NO"
}
] | 248 | 0 | 0 | 305 |
|
770 | New Password | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 155 | 6,860,800 | 0 | 306 |
|
493 | Vasya and Chess | [
"constructive algorithms",
"games",
"math"
] | null | null | Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an *n*<=×<=*n* chessboard. We'll denote a cell on the intersection of the *r*-th row and *c*-th column as (*r*,<=*c*). The square (1,<=1) contains the white queen and the square (1,<=*n*) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board *n*<=×<=*n*. | The input contains a single number *n* (2<=≤<=*n*<=≤<=109) — the size of the board. | On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers *r* and *c* representing the cell (*r*,<=*c*), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum *r*. If there are still multiple squares, print the one with the minimum *c*. | [
"2\n",
"3\n"
] | [
"white\n1 2\n",
"black\n"
] | In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | [
{
"input": "2",
"output": "white\n1 2"
},
{
"input": "3",
"output": "black"
},
{
"input": "4",
"output": "white\n1 2"
},
{
"input": "6",
"output": "white\n1 2"
},
{
"input": "10",
"output": "white\n1 2"
},
{
"input": "16",
"output": "white\n1 2"
},
{
"input": "100",
"output": "white\n1 2"
},
{
"input": "10006",
"output": "white\n1 2"
},
{
"input": "99966246",
"output": "white\n1 2"
},
{
"input": "1000000000",
"output": "white\n1 2"
},
{
"input": "999999999",
"output": "black"
},
{
"input": "999999997",
"output": "black"
},
{
"input": "900001",
"output": "black"
},
{
"input": "775681",
"output": "black"
},
{
"input": "666666",
"output": "white\n1 2"
},
{
"input": "12345",
"output": "black"
},
{
"input": "111111",
"output": "black"
},
{
"input": "346367",
"output": "black"
},
{
"input": "13",
"output": "black"
},
{
"input": "11",
"output": "black"
},
{
"input": "9",
"output": "black"
},
{
"input": "7",
"output": "black"
},
{
"input": "5",
"output": "black"
},
{
"input": "19",
"output": "black"
},
{
"input": "939698497",
"output": "black"
},
{
"input": "999999996",
"output": "white\n1 2"
}
] | 108 | 20,172,800 | 3 | 309 |
|
835 | Key races | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game. | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
{
"input": "8 8 1 1 1",
"output": "Second"
},
{
"input": "15 14 32 65 28",
"output": "First"
},
{
"input": "894 197 325 232 902",
"output": "First"
},
{
"input": "1 2 8 8 5",
"output": "Friendship"
},
{
"input": "37 261 207 1 1000",
"output": "Friendship"
},
{
"input": "29 344 406 900 1",
"output": "Friendship"
},
{
"input": "1 2 8 9 8",
"output": "First"
},
{
"input": "2 9 8 8 9",
"output": "Friendship"
},
{
"input": "213 480 811 134 745",
"output": "First"
},
{
"input": "2 313 856 964 421",
"output": "Friendship"
},
{
"input": "1 10 2 6 10",
"output": "Friendship"
},
{
"input": "2 7 6 2 3",
"output": "Friendship"
},
{
"input": "637 324 69 612 998",
"output": "Second"
},
{
"input": "13 849 819 723 918",
"output": "Friendship"
},
{
"input": "9 5 7 8 7",
"output": "First"
},
{
"input": "6 5 7 10 4",
"output": "Friendship"
},
{
"input": "61 464 623 89 548",
"output": "First"
},
{
"input": "641 31 29 161 802",
"output": "Friendship"
},
{
"input": "3 3 1 6 9",
"output": "Friendship"
},
{
"input": "2 3 9 8 2",
"output": "Friendship"
},
{
"input": "485 117 368 567 609",
"output": "First"
},
{
"input": "4 202 512 995 375",
"output": "Friendship"
},
{
"input": "424 41 41 909 909",
"output": "Friendship"
},
{
"input": "884 913 263 641 265",
"output": "Second"
},
{
"input": "12 462 8 311 327",
"output": "Second"
},
{
"input": "436 306 266 493 580",
"output": "Second"
},
{
"input": "69 1 2 1 2",
"output": "First"
}
] | 108 | 0 | 3 | 311 |
|
999 | Alphabetic Removals | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm.
This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters.
Help Polycarp find the resulting string. | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"input": "6 5\naaccdd",
"output": "d"
},
{
"input": "2 1\nzz",
"output": "z"
},
{
"input": "14 5\nhxehmvkybeklnj",
"output": "xmvkyklnj"
}
] | 530 | 36,044,800 | 3 | 312 |
|
66 | Petya and His Friends | [
"constructive algorithms",
"math",
"number theory"
] | D. Petya and His Friends | 2 | 256 | Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*.
Let us remind you the definition of the greatest common divisor: *GCD*(*a*1,<=...,<=*a**k*)<==<=*d*, where *d* represents such a maximal positive number that each *a**i* (1<=≤<=*i*<=≤<=*k*) is evenly divisible by *d*. At that, we assume that all *a**i*'s are greater than zero.
Knowing that Petya is keen on programming, his friends has agreed beforehand that the 1-st friend gives *a*1 sweets, the 2-nd one gives *a*2 sweets, ..., the *n*-th one gives *a**n* sweets. At the same time, for any *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*) they want the *GCD*(*a**i*,<=*a**j*) not to be equal to 1. However, they also want the following condition to be satisfied: *GCD*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=1. One more: all the *a**i* should be distinct.
Help the friends to choose the suitable numbers *a*1,<=...,<=*a**n*. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=50). | If there is no answer, print "-1" without quotes. Otherwise print a set of *n* distinct positive numbers *a*1,<=*a*2,<=...,<=*a**n*. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any of them.
Do not forget, please, that all of the following conditions must be true:
- For every *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*): *GCD*(*a**i*,<=*a**j*)<=≠<=1- *GCD*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=1- For every *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*,<=*i*<=≠<=*j*): *a**i*<=≠<=*a**j*
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"3\n",
"4\n"
] | [
"99\n55\n11115\n",
"385\n360\n792\n8360\n"
] | none | [
{
"input": "3",
"output": "15\n10\n6"
},
{
"input": "4",
"output": "105\n70\n42\n30"
},
{
"input": "5",
"output": "1155\n770\n462\n330\n210"
},
{
"input": "6",
"output": "15015\n10010\n6006\n4290\n2730\n2310"
},
{
"input": "7",
"output": "255255\n170170\n102102\n72930\n46410\n39270\n30030"
},
{
"input": "8",
"output": "4849845\n3233230\n1939938\n1385670\n881790\n746130\n570570\n510510"
},
{
"input": "9",
"output": "111546435\n74364290\n44618574\n31870410\n20281170\n17160990\n13123110\n11741730\n9699690"
},
{
"input": "10",
"output": "3234846615\n2156564410\n1293938646\n924241890\n588153930\n497668710\n380570190\n340510170\n281291010\n223092870"
},
{
"input": "11",
"output": "100280245065\n66853496710\n40112098026\n28651498590\n18232771830\n15427730010\n11797675890\n10555815270\n8720021310\n6915878970\n6469693230"
},
{
"input": "12",
"output": "3710369067405\n2473579378270\n1484147626962\n1060105447830\n674612557710\n570826010370\n436514007930\n390565164990\n322640788470\n255887521890\n239378649510\n200560490130"
},
{
"input": "2",
"output": "-1"
},
{
"input": "13",
"output": "152125131763605\n101416754509070\n60850052705442\n43464323361030\n27659114866110\n23403866425170\n17897074325130\n16013171764590\n13228272327270\n10491388397490\n9814524629910\n8222980095330\n7420738134810"
},
{
"input": "14",
"output": "6541380665835015\n4360920443890010\n2616552266334006\n1868965904524290\n1189341939242730\n1006366256282310\n769574195980590\n688566385877370\n568815710072610\n451129701092070\n422024559086130\n353588144099190\n319091739796830\n304250263527210"
},
{
"input": "15",
"output": "307444891294245705\n204963260862830470\n122977956517698282\n87841397512641630\n55899071144408310\n47299214045268570\n36169987211087730\n32362620136236390\n26734338373412670\n21203095951327290\n19835154277048110\n16618642772661930\n14997311770451010\n14299762385778870\n13082761331670030"
},
{
"input": "16",
"output": "16294579238595022365\n10863052825730014910\n6517831695438008946\n4655594068170006390\n2962650770653640430\n2506858344399234210\n1917009322187649690\n1715218867220528670\n1416919933790871510\n1123764085420346370\n1051263176683549830\n880788066951082290\n794857523833903530\n757887406446280110\n693386350578511590\n614889782588491410"
},
{
"input": "17",
"output": "961380175077106319535\n640920116718070879690\n384552070030842527814\n274680050022030377010\n174796395468564785370\n147904642319554818390\n113103550009071331710\n101197913166011191530\n83598276093661419090\n66302081039800435830\n62024527424329439970\n51966495950113855110\n46896593906200308270\n44715356980330526490\n40909794684132183810\n36278497172720993190\n32589158477190044730"
},
{
"input": "18",
"output": "58644190679703485491635\n39096127119802323661090\n23457676271881394196654\n16755483051343852997610\n10662580123582451907570\n9022183181492843921790\n6899316550553351234310\n6173072703126682683330\n5099494841713346564490\n4044426943427826585630\n3783496172884095838170\n3169956252956945161710\n2860692228278218804470\n2727636775800162115890\n2495497475732063212410\n2212988327535980584590\n1987938667108592728530\n1922760350154212639070"
},
{
"input": "19",
"output": "3929160775540133527939545\n2619440517026755685293030\n1571664310216053411175818\n1122617364440038150839870\n714392868280024277807190\n604486273160020542759930\n462254208887074532698770\n413595871109487739783110\n341666154394794219820830\n270976605209664381237210\n253494243583234421157390\n212387068948115325834570\n191666379294640659899490\n182751663978610861764630\n167198330874048235231470\n148270217944910699167530\n133191890696275712811510\n128824943460332246817690\n117288381359406970983270"
},
{
"input": "20",
"output": "278970415063349480483707695\n185980276708899653655805130\n111588166025339792193483078\n79705832875242708709630770\n50721893647881723724310490\n42918525394361458535955030\n32820048830982291821612670\n29365306848773629524600810\n24258296962030389607278930\n19239338969886171067841910\n17998091294409643902174690\n15079481895316188134254470\n13608312929919486852863790\n12975368142481371185288730\n11871081492057424701434370\n10527185474088659640894630\n9456624239435575609617210\n9146570985683589524055990\n832747..."
},
{
"input": "21",
"output": "20364840299624512075310661735\n13576560199749674716873774490\n8145936119849804830124264694\n5818525799892717735803046210\n3702698236295365831874665770\n3133052353788386473124717190\n2395863564661707302977724910\n2143667399960474955295859130\n1770855678228218441331361890\n1404471744801690487952459430\n1313860664491904004858752370\n1100802178358081733800576310\n993406843884122540259056670\n947201874401140096526077290\n866588948920192003204709010\n768484539608472153785307990\n690333569478797019502056330\n6676..."
},
{
"input": "22",
"output": "1608822383670336453949542277065\n1072548255780224302633028184710\n643528953468134581579816910826\n459663538191524701128440650590\n292513160667333900718098595830\n247511135949282531376852658010\n189273221608274876935240267890\n169349724596877521468372871270\n139897598580029256865177589310\n110953267839333548548244294970\n103794992494860416383841437230\n86963372090288456970245528490\n78479140666845680680465476930\n74828948077690067625560105910\n68460526964695168253172011790\n60710278629069300149039331210\n54..."
},
{
"input": "23",
"output": "133532257844637925677812008996395\n89021505229758617118541339330930\n53412903137855170271124803598558\n38152073669896550193660573998970\n24278592335388713759602183453890\n20543424283790450104278770614830\n15709677393486814785624942234870\n14056027141540834281874948315410\n11611500682142428319809739912730\n9209121230664684529504276482510\n8614984377073414559858839290090\n7217959883493941928530378864670\n6513768675348191496478634585190\n6210802690448275612921488790530\n5682223738069698965013276978570\n503895..."
},
{
"input": "24",
"output": "11884370948172775385325268800679155\n7922913965448516923550179200452770\n4753748379269110154130107520271662\n3395534556620792967235791085908330\n2160794717849595524604594327396210\n1828364761257350059280810584719870\n1398161288020326515920619858903430\n1250986415597134251086870400071490\n1033423560710676120463066852232970\n819611789529156923125880606943390\n766733609559533895827436696818010\n642398429630960831639203718955630\n579725412105989043186598478081910\n552761439449896529550012502357170\n50571791268..."
},
{
"input": "25",
"output": "1152783981972759212376551073665878035\n768522654648506141584367382443918690\n461113592789103684950620429466351214\n329366851992216917821871735333108010\n209597087631410765886645649757432370\n177351381841962955750238626717827390\n135621644937971672044300126313632710\n121345682312922022355426428806934530\n100242085388935583684917484666598090\n79502343584328221543210418873508830\n74373160127274787895261359591346970\n62312647674203200669002760738696110\n56233364974280937189100052373945270\n53617859626639963366..."
},
{
"input": "26",
"output": "116431182179248680450031658440253681535\n77620788119499120300021105626835787690\n46572472871699472180012663376101472614\n33266052051213908700009045268643909010\n21169305850772487354551210625500669370\n17912489566038258530774101298500566390\n13697786138735138876474312757676903710\n12255913913605124257898069309500387530\n10124450624282493952176665951326407090\n8029736702017150375864252306224391830\n7511689172854753577421397318726043970\n6293577415094523267569278834608307110\n567956986240237465609910528976847..."
},
{
"input": "27",
"output": "11992411764462614086353260819346129198105\n7994941176308409390902173879564086132070\n4796964705785045634541304327738451679242\n3426403361275032596100931662670322628030\n2180438502629566197518774694426568945110\n1844986425301940628669732433745558338170\n1410871972289719304276854214040721082130\n1262359133101327798563501138878539915590\n1042818414301096877074196592986619930270\n827062880307766488714017987541112358490\n773703984804039618474403923828782528910\n648238473754735896559635719964655632330\n584995695..."
},
{
"input": "28",
"output": "1283188058797499707239798907670035824197235\n855458705864999804826532605113357216131490\n513275223518999882895919563068014329678894\n366625159656428487782799687905724521199210\n233306919781363583134508892303642877126770\n197413547507307647267661370410774742184190\n150963301034999965557623400902357155787910\n135072427241842074446294621860003770968130\n111581570330217365846939035449568332538890\n88495728192931014292399924666899022358430\n82786326374032239176761219849679730593370\n6936151669175674093188102203..."
},
{
"input": "29",
"output": "139867498408927468089138080936033904837498615\n93244998939284978726092053957355936558332410\n55946999363570987235655232374413561934999446\n39962142402550705168325165981723972810713890\n25430454256168630561661469261097073606817930\n21518076678296533552175089374774446898076710\n16454999812814996245780950698356929980882190\n14722894569360786114646113782740411035526170\n12162391165993692877316354864002948246739010\n9646034373029480557871591788691993437068870\n9023709574769514070266972963615090634677330\n756040..."
},
{
"input": "30",
"output": "15805027320208803894072603145771831246637343495\n10536684880139202596048402097181220831091562330\n6322010928083521557629041258308732498654937398\n4515722091488229684020743755934808927610669570\n2873641330947055253467746026503969317570426090\n2431542664647508291395785099349512499482668230\n1859414978848094575773247428914333087839687470\n1663687086337768830955010857449666447014457210\n1374350201757287295136748099632333151881508130\n1090001884152331303039489872122195258388782310\n10196791819489550899401679448..."
},
{
"input": "31",
"output": "2007238469666518094547220599513022568322942623865\n1338158979777678729698147066342015045548628415910\n802895387866607237818888239805209027329177049546\n573496705619005169870634457003720733806555035390\n364952449030276017190403745366004103331444113430\n308805918410233553007264707617388087434298865210\n236145702313708011123202423472120302155640308690\n211288259964896641531286378896107638770836065670\n174542475623175486482367008653306310288951532510\n138430239287346075486015213759518797815375353370\n129499256..."
},
{
"input": "32",
"output": "262948239526313870385685898536205956450305483726315\n175298826350875913590457265690803970966870322484210\n105179295810525548154274359414482382580122193490526\n75128068436089677253053113867487416128658709636090\n47808770822966158251942890642946537536419178859330\n40453575311740595443951676697877839453893151342510\n30935087003095749457139517474847759582388880438390\n27678762055401460040598515635390100678979524602770\n22865064306635988729190078133583126647852650758810\n1813436134664233588866799300249696251381..."
},
{
"input": "33",
"output": "36023908815105000242838968099460216033691851270505155\n24015939210070000161892645399640144022461234180336770\n14409563526042000097135587239784086413476740508202062\n10292545375744285783668276599845776009626243220144330\n6549801602746363680516176018083675642489427503728210\n5542139817708461575821379707609264005183361733923870\n4238106919424117675628113894054143062787276620059430\n3791990401590000025561996642048443793020194870579490\n3132513810009130455899040704300888350755813153956970\n248440750449000001674..."
},
{
"input": "34",
"output": "5007323325299595033754616565824970028683167326600216545\n3338215550199730022503077710549980019122111551066811030\n2002929330119838013501846626329988011473266930640086618\n1430663807228455723929890447378562865338047807600061870\n910422422781744551591748466513630914306030423018221190\n770357434661476159039171779357687696720487281015417930\n589096861799952356912307831273525885727431450188260770\n527086665821010003553117533244733687229807087010549110\n435419419591269133369966657897823480755058028400018830\n345..."
},
{
"input": "35",
"output": "746091175469639660029437868307920534273791931663432265205\n497394116979759773352958578871947022849194621108954843470\n298436470187855864011775147323168213709516772665372906082\n213168907277039902865553676659405866935369123332409218630\n135652940994479938187170521510531006231598533029714957310\n114783257764559947696836595124295466811352604871297271570\n87775432408192901179933866859755356973387286078050854730\n78535913207330490529414512453465319397241255964571817390\n64877493519099100872125032026775698632503..."
},
{
"input": "36",
"output": "112659767495915588664445118114496000675342581681178272045955\n75106511663943725776296745409664000450228387787452181363970\n45063906998366235465778047245798400270137032672471308818382\n32188504998833025332698605175570285907240737623193792013130\n20483594090166470666262748748090181940971378487486958553810\n17332271922448552102222325863768615488514243335565888007070\n13254090293637128078170013895823058902981480197785679064230\n11858922894306904069941591380473263228983429650650344425890\n9796501521383964231690..."
},
{
"input": "37",
"output": "17687583496858747420317883543975872106028785323944988711214935\n11791722331239164946878589029317248070685856882629992474143290\n7075033398743498968127153417590348842411514129577995484485974\n5053595284816784977233681012564534887436795806841425346061410\n3215924272156135894603251553450158564732506422535452492948170\n2721166691824422680048905160611672631696736203683844417109990\n2080892176101029108272692181644220247768092391052351613084110\n1861850894406183938980829846734302326950398455152104074864730\n15380..."
},
{
"input": "38",
"output": "2883076109987975829511815017668067153282692007803033159928034405\n1922050739991983886341210011778711435521794671868688773285356270\n1153230443995190331804726007067226861313076803121213263971213762\n823736031425135951289090005048019186652197716515152331408009830\n524195656361450150820330003212375846051398546873278756350551710\n443550170767380896847971541179702638966568001200466639988928370\n339185424704467744648448825608007900386199059741533312932709930\n30348169578820798205387526501769127929291494818979296..."
},
{
"input": "39",
"output": "481473710367991963528473107950567214598209565303106537707981745635\n320982473578661309018982071967044809732139710202071025138654497090\n192589484147196785411389243180226885839283826121242615083192698254\n137563917247997703865278030843019204170917018658030439345137641610\n87540674612362175186995110536466766290583557327837552310542135570\n74072878518152609773611247377010340707416856200477928878151037790\n56643965925646113356290953876537319364495242976836063259762558310\n50681443196630733002997169257954443641..."
},
{
"input": "40",
"output": "83294951893662609690425847675448128125490254797437431023480841994855\n55529967929108406460283898450298752083660169864958287348987227996570\n33317980757465043876170339070179251250196101918974972409392336797942\n23798557683903602768693099335842322321568644227839266006708811998530\n15144536707938656307350154122808750568270955417715896549723789453610\n12814607983640401490834745796222788942383116122682681695920129537670\n9799406105136777610638335020640956250057677034992638943938922587630\n8767889673017116809518..."
},
{
"input": "41",
"output": "14909796388965607134586226733905214934462755608741300153203070717079045\n9939864259310404756390817822603476622975170405827533435468713811386030\n5963918555586242853834490693562085973785102243496520061281228286831618\n4259941825418744895596064781115775695560787316783228615200877347736870\n2710872070721019479015677587982766351720501019771145482400558312196190\n2293814829071631866859419497523879220686577785960200023569703187242930\n1754093692819483192304261968694731168760324189263682370965067143185770\n156945..."
},
{
"input": "42",
"output": "2698673146402774891360107038836843903137758765182175327729755799791307145\n1799115430935183260906738025891229268758505843454783551819837199860871430\n1079469258561109956544042815534737561255103506072870131091902319916522858\n771049470400792826102887725381955400896502504337764379351358799940373470\n490667844800504525701837643424880709661410684578577332314501054507510390\n415180484061965367901554929051822138944270579258796204266116276890970330\n3174909584003264578070714163337463415456186782567265091446771529..."
},
{
"input": "43",
"output": "515446570962930004249780444417837185499311924149795487596383357760139664695\n343631047308620002833186962945224790332874616099863658397588905173426443130\n206178628385172001699912177767134874199724769659918195038553343104055865878\n147270448846551429785651555547953481571231978328512996456109530788611332770\n93717558356896364409050989894152215545329440754508270472069701410934484490\n79299472455835385269196991448898028538355680638430075014828208886175333030\n606407730544623534411506405197455512352131675470347..."
},
{
"input": "44",
"output": "99481188195845490820207625772642576801367201360910529106101988047706955286135\n66320792130563660546805083848428384534244800907273686070734658698471303524090\n39792475278338196328083050309057030720546880544364211642440795219082782114454\n28423196627384425948630750220755021943247771817403008316029139442201987224610\n18087488762880998330946841049571377600248582065620096201109452372310355506570\n15304798183976229356955019349637319507902646363217004477861844315031839274790\n1170366919951123421414207362031089138..."
},
{
"input": "45",
"output": "19597794074581561691580902277210587629869338668099374233902091645398270191368595\n13065196049721041127720601518140391753246225778732916155934727763598846794245730\n7839117629832624676632360910884235051947735467239749693560836658159308076547438\n5599369735594731911880257793488739322819811048028392638257740470113791483248170\n3563235286287556671196527686765561387248970666927158951618562117345140034794290\n3015045242243317183320138811878551943056821333553749882138783330061272337133630\n23056228323037131401859..."
},
{
"input": "46",
"output": "3899961020841730776624599553164906938343998394951775472546516237434255768082350405\n2599974013894487184416399702109937958895998929967850315031010824956170512054900270\n1559984408336692310649839821265962775337599357980710189018606494973702307232940162\n1114274577383351650464171300904259125241142398557650135013290353552644505166385830\n709083821971223777568109009666346716062545162718504631372093861351682866924063710\n599994003206420119480707623563831836668307445377196226545617882682193195089592370\n458818943..."
},
{
"input": "47",
"output": "822891775397605193867790505717795363990583661334824624707314926098627967065375935455\n548594516931736795911860337145196909327055774223216416471543284065751978043583956970\n329156710159042077547116202287118145596233464533929849882925970439451186826150374182\n235111935827887198247940144490798675425881046095664178487804264599607990590107410130\n149616686435928217066871001039599157089197029333604477219511804745205084920977442810\n126598734676554645210429308571968517537012870974588403801125373245942764163903990..."
},
{
"input": "48",
"output": "183504865913665958232517282775068366169900156477665891309731228519994036655578833606465\n122336577275777305488344855183378910779933437651777260873154152346662691103719222404310\n73401946365466383293006913110027346467960062591066356523892491407997614662231533442586\n52429961689618845209290652221448104619971473279333111802780351005712581901593952458990\n33364521075211992405912233231830612030890937541393798419951132458180733937377969746630\n282315178328716858819257358115489794107538702273332140476509582338452..."
},
{
"input": "49",
"output": "41655604562402172518781423189940519120567335520430157327308988874038646320816395228667555\n27770403041601448345854282126627012747044890346953438218205992582692430880544263485778370\n16662241824960869007512569275976207648226934208172062930923595549615458528326558091467022\n11901601303543477862508978054268719748733524434408616379231139678296756091661827208190730\n7573746284073122276142076943625548931012242821896392241328907068007026603784799132485010\n640855454806187269519714202922161832624112854160463958881..."
},
{
"input": "50",
"output": "9539133444790097506800945910496378878609919834178506027953758452154850007466954507364870095\n6359422296526731671200630606997585919073279889452337351969172301436566671644636338243246730\n3815653377916039002720378364198551551443967933671402411181503380861940002986781802945948038\n2725466698511456430514555974427536822459977095479573150843930986329957144990558430675677170\n1734387899052745001236535620090250705201803606214273823264319718573609092266719001339067290\n1467558991506168847200145524691750596709218436..."
}
] | 0 | 0 | -1 | 313 |
808 | Array Division | [
"binary search",
"data structures",
"implementation"
] | null | null | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position? | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | [
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4 7 10 7 5 5 1",
"output": "NO"
},
{
"input": "8\n9 5 5 10 4 9 5 8",
"output": "NO"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "YES"
},
{
"input": "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8",
"output": "NO"
},
{
"input": "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13",
"output": "NO"
},
{
"input": "20\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6",
"output": "NO"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14",
"output": "YES"
},
{
"input": "100\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53",
"output": "NO"
},
{
"input": "100\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25",
"output": "NO"
},
{
"input": "100\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19",
"output": "NO"
},
{
"input": "100\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80",
"output": "NO"
},
{
"input": "6\n1 4 3 100 100 6",
"output": "YES"
},
{
"input": "6\n6 100 100 3 4 1",
"output": "YES"
},
{
"input": "6\n4 2 3 7 1 1",
"output": "YES"
},
{
"input": "4\n6 1 4 5",
"output": "NO"
},
{
"input": "3\n228 114 114",
"output": "YES"
},
{
"input": "3\n229 232 444",
"output": "NO"
},
{
"input": "3\n322 324 555",
"output": "NO"
},
{
"input": "3\n69 34 5",
"output": "NO"
},
{
"input": "6\n5 4 1 2 2 2",
"output": "YES"
},
{
"input": "3\n545 237 546",
"output": "NO"
},
{
"input": "5\n2 3 1 1 1",
"output": "YES"
},
{
"input": "6\n2 2 10 2 2 2",
"output": "YES"
},
{
"input": "5\n5 4 6 5 6",
"output": "NO"
},
{
"input": "5\n6 1 1 1 1",
"output": "NO"
},
{
"input": "2\n1 3",
"output": "NO"
},
{
"input": "5\n5 2 2 3 4",
"output": "YES"
},
{
"input": "2\n2 2",
"output": "YES"
},
{
"input": "5\n1 2 6 1 2",
"output": "YES"
},
{
"input": "5\n1 1 8 5 1",
"output": "YES"
},
{
"input": "10\n73 67 16 51 56 71 37 49 90 6",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "5\n8 2 7 5 4",
"output": "YES"
},
{
"input": "1\n2",
"output": "NO"
},
{
"input": "16\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2",
"output": "YES"
},
{
"input": "4\n8 2 2 4",
"output": "YES"
},
{
"input": "19\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3",
"output": "NO"
},
{
"input": "11\n7 2 1 8 8 2 4 10 8 7 1",
"output": "YES"
},
{
"input": "6\n10 20 30 40 99 1",
"output": "YES"
},
{
"input": "10\n3 7 9 2 10 1 9 6 4 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "2\n9 3",
"output": "NO"
},
{
"input": "7\n1 2 3 12 1 2 3",
"output": "YES"
},
{
"input": "6\n2 4 4 5 8 5",
"output": "YES"
},
{
"input": "18\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4",
"output": "YES"
},
{
"input": "20\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9",
"output": "NO"
},
{
"input": "12\n3 8 10 2 4 4 6 9 5 10 10 3",
"output": "YES"
},
{
"input": "11\n9 2 7 7 7 3 7 5 4 10 7",
"output": "NO"
},
{
"input": "5\n1 1 4 1 1",
"output": "YES"
},
{
"input": "2\n4 4",
"output": "YES"
},
{
"input": "2\n7 1",
"output": "NO"
},
{
"input": "5\n10 5 6 7 6",
"output": "YES"
},
{
"input": "11\n4 3 10 3 7 8 4 9 2 1 1",
"output": "YES"
},
{
"input": "6\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "NO"
},
{
"input": "8\n1 5 6 8 3 1 7 3",
"output": "YES"
},
{
"input": "20\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8",
"output": "YES"
},
{
"input": "11\n2 4 8 3 4 7 9 10 5 3 3",
"output": "YES"
},
{
"input": "7\n6 4 2 24 6 4 2",
"output": "YES"
},
{
"input": "17\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5",
"output": "NO"
},
{
"input": "7\n7 10 1 2 6 2 2",
"output": "NO"
},
{
"input": "5\n10 10 40 10 10",
"output": "YES"
},
{
"input": "3\n4 3 13",
"output": "NO"
},
{
"input": "5\n5 2 10 2 1",
"output": "YES"
},
{
"input": "7\n7 4 5 62 20 20 6",
"output": "YES"
},
{
"input": "6\n1 5 2 20 10 2",
"output": "YES"
},
{
"input": "2\n5 6",
"output": "NO"
},
{
"input": "14\n5 2 9 7 5 8 3 2 2 4 9 1 3 10",
"output": "YES"
},
{
"input": "5\n1 2 3 4 2",
"output": "YES"
},
{
"input": "5\n2 2 2 5 5",
"output": "NO"
},
{
"input": "11\n1 1 1 1 1 10 1 1 1 1 1",
"output": "YES"
},
{
"input": "9\n8 4 13 19 11 1 8 2 8",
"output": "YES"
},
{
"input": "6\n14 16 14 14 15 11",
"output": "YES"
},
{
"input": "9\n14 19 1 13 11 3 1 1 7",
"output": "YES"
},
{
"input": "6\n16 13 3 7 4 15",
"output": "YES"
},
{
"input": "4\n11 7 12 14",
"output": "NO"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "5\n2 1 3 6 4",
"output": "YES"
},
{
"input": "5\n3 4 8 11 2",
"output": "YES"
},
{
"input": "5\n1 2 10 3 4",
"output": "YES"
},
{
"input": "6\n8 15 12 14 15 4",
"output": "YES"
},
{
"input": "5\n1 2 4 4 5",
"output": "YES"
},
{
"input": "3\n2 4 2",
"output": "YES"
},
{
"input": "5\n2 3 1 6 4",
"output": "YES"
},
{
"input": "7\n1 2 3 12 3 2 1",
"output": "YES"
},
{
"input": "3\n3 4 13",
"output": "NO"
},
{
"input": "6\n1 1 1 1 1000000000 1000000000",
"output": "YES"
},
{
"input": "6\n19 6 5 13 6 13",
"output": "YES"
},
{
"input": "8\n2 2 2 5 1 2 3 3",
"output": "YES"
}
] | 108 | 6,963,200 | -1 | 314 |
|
699 | One Bomb | [
"implementation"
] | null | null | You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls in the column *y*.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the depot field.
The next *n* lines contain *m* symbols "." and "*" each — the description of the field. *j*-th symbol in *i*-th of them stands for cell (*i*,<=*j*). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | [
"3 4\n.*..\n....\n.*..\n",
"3 3\n..*\n.*.\n*..\n",
"6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n"
] | [
"YES\n1 2\n",
"NO\n",
"YES\n3 3\n"
] | none | [
{
"input": "3 4\n.*..\n....\n.*..",
"output": "YES\n1 2"
},
{
"input": "3 3\n..*\n.*.\n*..",
"output": "NO"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..",
"output": "YES\n3 3"
},
{
"input": "1 10\n**********",
"output": "YES\n1 1"
},
{
"input": "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*",
"output": "YES\n1 1"
},
{
"input": "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*",
"output": "YES\n3 10"
},
{
"input": "10 10\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*",
"output": "YES\n1 10"
},
{
"input": "2 2\n.*\n*.",
"output": "YES\n2 2"
},
{
"input": "4 4\n....\n...*\n....\n*..*",
"output": "YES\n4 4"
},
{
"input": "4 4\n*...\n*...\n....\n****",
"output": "YES\n4 1"
},
{
"input": "1 1\n*",
"output": "YES\n1 1"
},
{
"input": "1 1\n.",
"output": "YES\n1 1"
},
{
"input": "1 2\n.*",
"output": "YES\n1 2"
},
{
"input": "2 1\n.\n*",
"output": "YES\n1 1"
},
{
"input": "2 2\n**\n**",
"output": "NO"
},
{
"input": "3 1\n*\n*\n*",
"output": "YES\n1 1"
},
{
"input": "3 2\n*.\n.*\n.*",
"output": "YES\n1 2"
},
{
"input": "3 3\n***\n***\n***",
"output": "NO"
},
{
"input": "2 2\n..\n.*",
"output": "YES\n1 2"
},
{
"input": "6 5\n..*..\n..*..\n**.**\n..*..\n..*..\n..*..",
"output": "YES\n3 3"
},
{
"input": "3 3\n.*.\n*.*\n.*.",
"output": "YES\n2 2"
},
{
"input": "4 4\n*...\n....\n....\n...*",
"output": "YES\n4 1"
},
{
"input": "2 4\n...*\n...*",
"output": "YES\n1 4"
},
{
"input": "2 2\n..\n..",
"output": "YES\n1 1"
},
{
"input": "3 3\n..*\n.*.\n..*",
"output": "YES\n2 3"
},
{
"input": "2 2\n*.\n.*",
"output": "YES\n2 1"
},
{
"input": "3 2\n.*\n*.\n.*",
"output": "YES\n2 2"
},
{
"input": "3 3\n***\n.*.\n.*.",
"output": "YES\n1 2"
},
{
"input": "4 4\n*.*.\n..*.\n.***\n..*.",
"output": "NO"
},
{
"input": "2 3\n..*\n**.",
"output": "YES\n2 3"
},
{
"input": "3 2\n*.\n.*\n*.",
"output": "YES\n2 1"
},
{
"input": "4 4\n..*.\n**.*\n..*.\n..*.",
"output": "YES\n2 3"
},
{
"input": "3 3\n*..\n*..\n***",
"output": "YES\n3 1"
},
{
"input": "3 3\n...\n*.*\n.*.",
"output": "YES\n2 2"
},
{
"input": "3 2\n..\n..\n**",
"output": "YES\n3 1"
},
{
"input": "3 4\n...*\n...*\n...*",
"output": "YES\n1 4"
},
{
"input": "5 5\n..*..\n..*..\n**.**\n..*..\n..*..",
"output": "YES\n3 3"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.*",
"output": "NO"
},
{
"input": "3 3\n...\n.*.\n..*",
"output": "YES\n3 2"
},
{
"input": "3 5\n....*\n....*\n....*",
"output": "YES\n1 5"
},
{
"input": "3 3\n...\n...\n.*.",
"output": "YES\n1 2"
},
{
"input": "3 3\n*..\n...\n..*",
"output": "YES\n3 1"
},
{
"input": "2 3\n..*\n..*",
"output": "YES\n1 3"
},
{
"input": "2 2\n**\n.*",
"output": "YES\n1 2"
},
{
"input": "3 3\n..*\n*..\n*..",
"output": "YES\n1 1"
},
{
"input": "5 4\n.*..\n*.**\n.*..\n.*..\n.*..",
"output": "YES\n2 2"
},
{
"input": "6 5\n*.*..\n..*..\n*****\n..*..\n..*..\n..*..",
"output": "NO"
},
{
"input": "4 4\n.*..\n*.**\n....\n.*..",
"output": "YES\n2 2"
},
{
"input": "3 5\n....*\n....*\n*****",
"output": "YES\n3 5"
},
{
"input": "3 3\n..*\n*..\n..*",
"output": "YES\n2 3"
},
{
"input": "6 6\n..*...\n......\n......\n......\n......\n*....*",
"output": "YES\n6 3"
},
{
"input": "4 4\n.*..\n*...\n.*..\n.*..",
"output": "YES\n2 2"
},
{
"input": "3 3\n...\n..*\n.*.",
"output": "YES\n3 3"
},
{
"input": "3 2\n.*\n*.\n*.",
"output": "YES\n1 1"
},
{
"input": "4 2\n**\n.*\n.*\n.*",
"output": "YES\n1 2"
},
{
"input": "5 5\n*...*\n.....\n.....\n.....\n..*..",
"output": "YES\n1 3"
},
{
"input": "3 3\n**.\n...\n..*",
"output": "YES\n1 3"
},
{
"input": "3 3\n*.*\n*..\n*.*",
"output": "NO"
},
{
"input": "5 4\n....\n....\n*..*\n....\n.*..",
"output": "YES\n3 2"
},
{
"input": "5 5\n...*.\n...*.\n...*.\n...*.\n***.*",
"output": "YES\n5 4"
},
{
"input": "5 5\n*****\n*****\n*****\n*****\n*****",
"output": "NO"
},
{
"input": "3 3\n.*.\n..*\n.*.",
"output": "YES\n2 2"
},
{
"input": "3 3\n*.*\n...\n*.*",
"output": "NO"
},
{
"input": "2 3\n.*.\n*.*",
"output": "YES\n2 2"
},
{
"input": "3 10\n.......*..\n........*.\n.........*",
"output": "NO"
},
{
"input": "3 3\n.*.\n.*.\n.**",
"output": "YES\n3 2"
},
{
"input": "4 4\n*...\n....\n....\n..**",
"output": "YES\n4 1"
},
{
"input": "4 4\n****\n****\n****\n****",
"output": "NO"
},
{
"input": "3 2\n.*\n.*\n*.",
"output": "YES\n3 2"
},
{
"input": "3 3\n..*\n..*\n**.",
"output": "YES\n3 3"
},
{
"input": "6 3\n...\n...\n...\n...\n**.\n.*.",
"output": "YES\n5 2"
},
{
"input": "3 4\n****\n..*.\n..*.",
"output": "YES\n1 3"
},
{
"input": "5 5\n*..*.\n.....\n.....\n.....\n...*.",
"output": "YES\n1 4"
},
{
"input": "6 5\n..*..\n..*..\n.*...\n..*..\n..*..\n..*..",
"output": "YES\n3 3"
}
] | 919 | 1,433,600 | 3 | 315 |
|
908 | New Year and Counting Cards | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01234567890123456789012345678901234567890123456789",
"output": "25"
},
{
"input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb",
"output": "10"
},
{
"input": "cjw2dwmr10pku4yxohe0wglktd",
"output": "4"
},
{
"input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6",
"output": "13"
},
{
"input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1",
"output": "13"
},
{
"input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs",
"output": "8"
},
{
"input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc",
"output": "14"
},
{
"input": "2222",
"output": "0"
},
{
"input": "13579",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "a",
"output": "1"
},
{
"input": "y",
"output": "0"
},
{
"input": "w",
"output": "0"
},
{
"input": "oo",
"output": "2"
},
{
"input": "oy",
"output": "1"
},
{
"input": "yo",
"output": "1"
},
{
"input": "yy",
"output": "0"
},
{
"input": "a0",
"output": "1"
},
{
"input": "a9",
"output": "2"
},
{
"input": "y0",
"output": "0"
},
{
"input": "y7",
"output": "1"
},
{
"input": "0a",
"output": "1"
},
{
"input": "3a",
"output": "2"
},
{
"input": "06",
"output": "0"
},
{
"input": "07",
"output": "1"
},
{
"input": "70",
"output": "1"
},
{
"input": "77",
"output": "2"
},
{
"input": "13570",
"output": "4"
},
{
"input": "0000000000011111",
"output": "5"
},
{
"input": "1357",
"output": "4"
},
{
"input": "uuuuuuuuuuuuuuuuuu",
"output": "18"
},
{
"input": "gabieurat",
"output": "5"
}
] | 62 | 5,529,600 | 3 | 316 |
|
681 | Economy Game | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*?
Please help Kolya answer this question. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES"
},
{
"input": "999999987",
"output": "YES"
},
{
"input": "27406117",
"output": "NO"
},
{
"input": "27404883",
"output": "NO"
},
{
"input": "27403649",
"output": "NO"
},
{
"input": "27402415",
"output": "NO"
},
{
"input": "27401181",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999244",
"output": "YES"
},
{
"input": "999129999",
"output": "YES"
},
{
"input": "17159199",
"output": "NO"
},
{
"input": "13606913",
"output": "NO"
},
{
"input": "14841529",
"output": "NO"
},
{
"input": "915968473",
"output": "YES"
},
{
"input": "980698615",
"output": "YES"
},
{
"input": "912331505",
"output": "YES"
},
{
"input": "917261049",
"output": "YES"
},
{
"input": "999999997",
"output": "YES"
},
{
"input": "12345",
"output": "NO"
},
{
"input": "1234",
"output": "YES"
},
{
"input": "124690",
"output": "YES"
},
{
"input": "1359257",
"output": "YES"
},
{
"input": "1358023",
"output": "YES"
},
{
"input": "1234",
"output": "YES"
},
{
"input": "1234567",
"output": "YES"
},
{
"input": "124690",
"output": "YES"
},
{
"input": "1358023",
"output": "YES"
},
{
"input": "123456",
"output": "YES"
},
{
"input": "2592590",
"output": "YES"
},
{
"input": "999999998",
"output": "YES"
},
{
"input": "1356789",
"output": "NO"
},
{
"input": "12345670",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "1480800",
"output": "YES"
},
{
"input": "908000000",
"output": "YES"
},
{
"input": "3000",
"output": "NO"
},
{
"input": "1235801",
"output": "YES"
},
{
"input": "991919191",
"output": "YES"
},
{
"input": "25613715",
"output": "YES"
},
{
"input": "13580237",
"output": "YES"
},
{
"input": "14814804",
"output": "YES"
},
{
"input": "11403961",
"output": "YES"
},
{
"input": "999999989",
"output": "YES"
},
{
"input": "1237035",
"output": "YES"
},
{
"input": "81134231",
"output": "YES"
},
{
"input": "1236",
"output": "NO"
},
{
"input": "1359250",
"output": "YES"
},
{
"input": "100",
"output": "NO"
},
{
"input": "987654321",
"output": "YES"
},
{
"input": "122222",
"output": "NO"
},
{
"input": "123458",
"output": "NO"
},
{
"input": "20987639",
"output": "YES"
},
{
"input": "999973333",
"output": "YES"
},
{
"input": "253082",
"output": "YES"
},
{
"input": "1235",
"output": "NO"
},
{
"input": "803219200",
"output": "YES"
},
{
"input": "100000000",
"output": "YES"
},
{
"input": "1485181",
"output": "YES"
}
] | 62 | 6,963,200 | 0 | 317 |
|
60 | Serial Time! | [
"dfs and similar",
"dsu"
] | B. Serial Time! | 2 | 256 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.
Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes. | The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*. | The answer should contain a single number, showing in how many minutes the plate will be filled. | [
"1 1 1\n\n.\n\n1 1\n",
"2 1 1\n\n.\n\n#\n\n1 1\n",
"2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n",
"3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n",
"3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n"
] | [
"1\n",
"1\n",
"5\n",
"7\n",
"13\n"
] | none | [
{
"input": "1 1 1\n\n.\n\n1 1",
"output": "1"
},
{
"input": "2 1 1\n\n.\n\n#\n\n1 1",
"output": "1"
},
{
"input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1",
"output": "5"
},
{
"input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2",
"output": "7"
},
{
"input": "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1",
"output": "13"
},
{
"input": "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1",
"output": "4"
},
{
"input": "4 7 8\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n3 4",
"output": "224"
},
{
"input": "6 5 4\n\n####\n####\n####\n####\n.###\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n5 1",
"output": "1"
},
{
"input": "8 2 6\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n1 2",
"output": "52"
},
{
"input": "9 1 9\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n1 6",
"output": "49"
},
{
"input": "6 8 4\n\n.###\n.#..\n.#..\n####\n....\n.##.\n..#.\n...#\n\n....\n##.#\n....\n....\n##..\n#.##\n#.#.\n#..#\n\n..##\n####\n#...\n..##\n###.\n#..#\n..##\n##..\n\n.##.\n##..\n#.#.\n##..\n####\n####\n.#.#\n###.\n\n#.##\n..#.\n...#\n#.##\n##.#\n##..\n####\n###.\n\n.#.#\n#.#.\n#.##\n#.##\n....\n#.##\n..##\n.##.\n\n6 4",
"output": "88"
},
{
"input": "8 1 8\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n1 3",
"output": "64"
},
{
"input": "1 8 6\n\n######\n######\n.#####\n######\n######\n######\n######\n######\n\n3 1",
"output": "1"
},
{
"input": "6 1 9\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n1 3",
"output": "30"
},
{
"input": "1 1 10\n\n..........\n\n1 6",
"output": "10"
},
{
"input": "5 2 8\n\n.##..#..\n.#.....#\n\n....##..\n#..###.#\n\n#..#.#..\n.#..#...\n\n###.#..#\n#......#\n\n#..#####\n##.....#\n\n1 7",
"output": "45"
},
{
"input": "9 2 1\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n1 1",
"output": "18"
},
{
"input": "5 8 2\n\n##\n##\n##\n#.\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n4 2",
"output": "1"
},
{
"input": "6 10 2\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n2 2",
"output": "63"
},
{
"input": "8 6 2\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n3 1",
"output": "52"
},
{
"input": "4 1 3\n\n...\n\n...\n\n...\n\n...\n\n1 1",
"output": "12"
},
{
"input": "4 6 2\n\n##\n##\n##\n##\n.#\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n5 1",
"output": "1"
},
{
"input": "2 9 2\n\n##\n##\n##\n##\n.#\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n5 1",
"output": "19"
},
{
"input": "10 6 5\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n2 4",
"output": "155"
},
{
"input": "2 3 6\n\n......\n#..#..\n##.#.#\n\n#.##..\n.....#\n##..##\n\n1 3",
"output": "22"
},
{
"input": "8 5 6\n\n######\n######\n######\n###.##\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n4 4",
"output": "1"
},
{
"input": "1 3 10\n\n##########\n####.#####\n##########\n\n2 5",
"output": "1"
},
{
"input": "8 3 3\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n3 3",
"output": "40"
},
{
"input": "5 1 4\n\n#...\n\n####\n\n#.##\n\n.###\n\n###.\n\n1 4",
"output": "3"
},
{
"input": "9 2 2\n\n##\n..\n\n##\n##\n\n#.\n#.\n\n..\n..\n\n##\n..\n\n..\n.#\n\n#.\n#.\n\n.#\n..\n\n#.\n.#\n\n2 1",
"output": "2"
},
{
"input": "1 6 2\n\n##\n..\n##\n.#\n##\n#.\n\n6 2",
"output": "1"
},
{
"input": "5 9 2\n\n##\n##\n##\n#.\n.#\n.#\n..\n##\n#.\n\n##\n..\n##\n##\n#.\n#.\n.#\n#.\n#.\n\n#.\n.#\n##\n.#\n..\n##\n##\n#.\n..\n\n#.\n..\n.#\n#.\n..\n#.\n..\n..\n##\n\n.#\n##\n..\n.#\n#.\n#.\n.#\n##\n##\n\n4 2",
"output": "1"
},
{
"input": "5 8 7\n\n.#.#...\n##.#.##\n...#..#\n#####..\n......#\n..###..\n#.#..#.\n.##..#.\n\n##.....\n.##.#..\n.##.###\n...##..\n.#.###.\n##.#..#\n##..#.#\n.##....\n\n#.#...#\n##.....\n...###.\n...##..\n..#.###\n.#.#...\n.#.#..#\n..###..\n\n#..#...\n.####..\n###.#.#\n#..#.##\n....#..\n.#.#.##\n#.#.###\n.#..###\n\n..#.#.#\n##....#\n.#.####\n#.#.##.\n.#..##.\n##..#.#\n.##.##.\n...###.\n\n4 7",
"output": "132"
},
{
"input": "4 3 2\n\n#.\n#.\n##\n\n.#\n.#\n##\n\n..\n#.\n##\n\n#.\n..\n.#\n\n1 2",
"output": "2"
},
{
"input": "4 10 10\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n8 1",
"output": "400"
},
{
"input": "4 10 10\n\n##########\n##########\n##########\n##########\n##########\n##########\n#########.\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n7 10",
"output": "1"
},
{
"input": "3 10 10\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n1 8",
"output": "102"
},
{
"input": "2 10 10\n\n#..#...#..\n###..#..##\n..#..#..#.\n#..#.#...#\n#####...#.\n#.####..#.\n###..##.##\n.###..#...\n##..##.##.\n..#.#.####\n\n..##..#.#.\n.##....#..\n..#.#.##..\n#.####....\n##..##.#..\n######...#\n..#...###.\n####.###.#\n#...##.#..\n##.#####.#\n\n6 7",
"output": "57"
}
] | 92 | 512,000 | 3.976046 | 319 |
727 | Transformation: from A to B | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them. | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
{
"input": "1 1000000000",
"output": "NO"
},
{
"input": "999999999 1000000000",
"output": "NO"
},
{
"input": "1 2",
"output": "YES\n2\n1 2 "
},
{
"input": "1 536870912",
"output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 "
},
{
"input": "11111 11111111",
"output": "YES\n4\n11111 111111 1111111 11111111 "
},
{
"input": "59139 946224",
"output": "YES\n5\n59139 118278 236556 473112 946224 "
},
{
"input": "9859 19718",
"output": "YES\n2\n9859 19718 "
},
{
"input": "25987 51974222",
"output": "YES\n5\n25987 259871 2598711 25987111 51974222 "
},
{
"input": "9411 188222222",
"output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 "
},
{
"input": "25539 510782222",
"output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 "
},
{
"input": "76259 610072",
"output": "YES\n4\n76259 152518 305036 610072 "
},
{
"input": "92387 184774",
"output": "YES\n2\n92387 184774 "
},
{
"input": "8515 85151111",
"output": "YES\n5\n8515 85151 851511 8515111 85151111 "
},
{
"input": "91939 9193911",
"output": "YES\n3\n91939 919391 9193911 "
},
{
"input": "30518 610361",
"output": "YES\n3\n30518 61036 610361 "
},
{
"input": "46646 373168844",
"output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 "
},
{
"input": "30070 300701",
"output": "YES\n2\n30070 300701 "
},
{
"input": "13494 1079528",
"output": "YES\n5\n13494 134941 269882 539764 1079528 "
},
{
"input": "96918 775344422",
"output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 "
},
{
"input": "13046 260921",
"output": "YES\n3\n13046 26092 260921 "
},
{
"input": "29174 5834811",
"output": "YES\n4\n29174 58348 583481 5834811 "
},
{
"input": "79894 319576421",
"output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 "
},
{
"input": "96022 1920442",
"output": "YES\n3\n96022 960221 1920442 "
},
{
"input": "79446 6355681",
"output": "YES\n5\n79446 158892 317784 635568 6355681 "
},
{
"input": "5440 27853056",
"output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 "
},
{
"input": "250000000 705032705",
"output": "NO"
},
{
"input": "17 35",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
}
] | 140 | 20,172,800 | 3 | 320 |
|
743 | Chloe and the sequence | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step.
The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps.
Please help Chloe to solve the problem! | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 671088640",
"output": "28"
},
{
"input": "38 137438953472",
"output": "38"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "4 12",
"output": "3"
},
{
"input": "8 224",
"output": "6"
},
{
"input": "13 1368",
"output": "4"
},
{
"input": "16 49152",
"output": "15"
},
{
"input": "19 1024",
"output": "11"
},
{
"input": "24 15204352",
"output": "20"
},
{
"input": "27 6586544",
"output": "5"
},
{
"input": "31 536870912",
"output": "30"
},
{
"input": "38 94489280512",
"output": "34"
},
{
"input": "42 215268308020",
"output": "3"
},
{
"input": "42 3452074721280",
"output": "21"
},
{
"input": "46 34394312982528",
"output": "15"
},
{
"input": "48 133865540681728",
"output": "39"
},
{
"input": "49 76541041985542",
"output": "2"
},
{
"input": "49 104822971826176",
"output": "34"
},
{
"input": "49 351843720888320",
"output": "47"
},
{
"input": "50 743042492421629",
"output": "1"
},
{
"input": "50 666266740436818",
"output": "2"
},
{
"input": "50 704239287953456",
"output": "5"
},
{
"input": "50 116938486513664",
"output": "17"
},
{
"input": "50 806423059496960",
"output": "37"
},
{
"input": "50 985162418487296",
"output": "48"
},
{
"input": "50 844424930131968",
"output": "49"
},
{
"input": "50 562949953421312",
"output": "50"
},
{
"input": "50 1",
"output": "1"
},
{
"input": "50 1125899906842623",
"output": "1"
},
{
"input": "50 1125899906842620",
"output": "3"
},
{
"input": "39 549755813887",
"output": "1"
},
{
"input": "50 100000000000",
"output": "12"
}
] | 109 | 6,758,400 | 3 | 321 |
|
46 | Hamsters and Tigers | [
"two pointers"
] | C. Hamsters and Tigers | 2 | 256 | Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. | The first line contains number *n* (2<=≤<=*n*<=≤<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. | Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. | [
"3\nHTH\n",
"9\nHTHTHTHHT\n"
] | [
"0\n",
"2\n"
] | In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7. | [
{
"input": "3\nHTH",
"output": "0"
},
{
"input": "9\nHTHTHTHHT",
"output": "2"
},
{
"input": "2\nTH",
"output": "0"
},
{
"input": "4\nHTTH",
"output": "0"
},
{
"input": "4\nHTHT",
"output": "1"
},
{
"input": "7\nTTTHTTT",
"output": "0"
},
{
"input": "8\nHHTHHTHH",
"output": "1"
},
{
"input": "13\nHTTTHHHTTTTHH",
"output": "3"
},
{
"input": "20\nTTHTHTHHTHTTHHTTTHHH",
"output": "4"
},
{
"input": "35\nTTTTTTHTTHTTTTTHTTTTTTTTTTTHTHTTTTT",
"output": "3"
},
{
"input": "120\nTTTTTTTHTHTHTTTTTHTHTTTTHTTTTTTTTTTTTTTTTTTTTHTTHTTTTHTTHTTTTTTTTTTTTTTTHTTTTTTHTHTTHTTTTTTHTTTTTTTTTHTTHTTTTHTTTHTTTTTH",
"output": "14"
},
{
"input": "19\nHHHHHHHHHHHHHTTTHHH",
"output": "0"
},
{
"input": "87\nHTHHTTHHHHTHHHHHTTTHHTHHHHTTTTHHHTTHHTHTHTHHTTHTHHTHTHTTHHHTTTTTHTTHHHHHHTHHTHHTHTTHTHH",
"output": "17"
},
{
"input": "178\nTHHHTHTTTHTTHTTHHHHHTTTHTTHHTHTTTHTHTTTTTHHHTHTHHHTHHHTTTTTTTTHHHHTTHHTHHHHTHTTTHHHHHHTHHTHTTHTHTTTTTTTTTHHTTHHTHTTHHTHHHHHTTHHTTHHTTHHHTTHHTTTTHTHHHTHTTHTHTTTHHHHTHHTHHHTHTTTTTT",
"output": "40"
}
] | 342 | 0 | 3.9145 | 323 |
690 | Collective Mindsets (easy) | [] | null | null | Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.
They will be *N* guests tonight: *N*<=-<=1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to *N*<=-<=1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, *N*. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:
The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)
You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order:
1. survive the event (they experienced death already once and know it is no fun), 1. get as many brains as possible.
Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.
What is the smallest number of brains that have to be in the chest for this to be possible? | The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109). | Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "4"
},
{
"input": "9",
"output": "5"
},
{
"input": "10",
"output": "5"
},
{
"input": "11",
"output": "6"
},
{
"input": "12",
"output": "6"
},
{
"input": "13",
"output": "7"
},
{
"input": "14",
"output": "7"
},
{
"input": "15",
"output": "8"
},
{
"input": "16",
"output": "8"
},
{
"input": "17",
"output": "9"
},
{
"input": "18",
"output": "9"
},
{
"input": "19",
"output": "10"
},
{
"input": "20",
"output": "10"
},
{
"input": "100",
"output": "50"
},
{
"input": "9999",
"output": "5000"
},
{
"input": "21736",
"output": "10868"
},
{
"input": "873467",
"output": "436734"
},
{
"input": "4124980",
"output": "2062490"
},
{
"input": "536870910",
"output": "268435455"
},
{
"input": "536870912",
"output": "268435456"
},
{
"input": "876543210",
"output": "438271605"
},
{
"input": "987654321",
"output": "493827161"
},
{
"input": "1000000000",
"output": "500000000"
}
] | 62 | 0 | 3 | 325 |
||
114 | Cifera | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 186 | 0 | 0 | 326 |
|
757 | Gotta Catch Em' All! | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different. | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr",
"output": "10"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "20"
},
{
"input": "CeSlSwec",
"output": "0"
},
{
"input": "PnMrWPBGzVcmRcO",
"output": "0"
},
{
"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC",
"output": "6"
},
{
"input": "bulsar",
"output": "0"
},
{
"input": "Bblsar",
"output": "0"
},
{
"input": "Bbusar",
"output": "0"
},
{
"input": "Bbular",
"output": "0"
},
{
"input": "Bbulsr",
"output": "0"
},
{
"input": "Bbulsa",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh",
"output": "2"
},
{
"input": "Bulbasaur",
"output": "1"
},
{
"input": "BulbasaurBulbasaur",
"output": "2"
},
{
"input": "Bulbbasar",
"output": "0"
},
{
"input": "Bulbasur",
"output": "0"
},
{
"input": "Bulbsaur",
"output": "0"
},
{
"input": "BulbsurBulbsurBulbsurBulbsur",
"output": "0"
},
{
"input": "Blbbasar",
"output": "0"
},
{
"input": "Bulbasar",
"output": "0"
},
{
"input": "BBullllbbaassaauurr",
"output": "1"
},
{
"input": "BulbasaurBulbasar",
"output": "1"
},
{
"input": "BulbasaurBulbsaur",
"output": "1"
},
{
"input": "Bubasaur",
"output": "0"
},
{
"input": "ulbasaurulbasaur",
"output": "0"
},
{
"input": "Bulbasr",
"output": "0"
},
{
"input": "BBBuuulllbbbaaasssaaauuurrr",
"output": "3"
},
{
"input": "BBuuuullbbaaaassrr",
"output": "2"
},
{
"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr",
"output": "4"
},
{
"input": "BBuullbbaassaarr",
"output": "1"
},
{
"input": "Bulbasau",
"output": "0"
},
{
"input": "BBuullbbaassaauurr",
"output": "2"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau",
"output": "0"
},
{
"input": "Blbasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasaurd",
"output": "2"
},
{
"input": "ulbasaur",
"output": "0"
},
{
"input": "Bulbaaur",
"output": "0"
},
{
"input": "BBuuuullbbbbbbbbbbbbbbbaassrr",
"output": "1"
},
{
"input": "Bulbasua",
"output": "0"
},
{
"input": "Bubbasaur",
"output": "0"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr",
"output": "3"
},
{
"input": "BulbasaurBubasaur",
"output": "1"
},
{
"input": "Baab",
"output": "0"
},
{
"input": "BulbasaurBulbasau",
"output": "1"
},
{
"input": "Bulbasauu",
"output": "0"
},
{
"input": "BulbasauBulbasau",
"output": "0"
},
{
"input": "BBBBBBBBBBB",
"output": "0"
},
{
"input": "Bulbbasau",
"output": "0"
},
{
"input": "BulbbasaurBulbbasar",
"output": "1"
},
{
"input": "Bulaaaasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasauBulbasauBulbasau",
"output": "1"
}
] | 93 | 1,843,200 | 3 | 327 |
|
369 | Valera and Plates | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally. | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish. | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2",
"output": "132"
},
{
"input": "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1",
"output": "22"
},
{
"input": "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1",
"output": "87"
},
{
"input": "3 1 2\n1 1 1",
"output": "2"
},
{
"input": "3 2 2\n1 1 1",
"output": "1"
},
{
"input": "3 2 1\n1 1 1",
"output": "1"
},
{
"input": "3 1 1\n1 1 1",
"output": "2"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "2"
},
{
"input": "5 2 2\n2 2 2 2 2",
"output": "1"
},
{
"input": "5 2 1\n2 2 2 2 2",
"output": "2"
},
{
"input": "5 1 1\n2 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2\n2",
"output": "0"
},
{
"input": "1 2 2\n2",
"output": "0"
},
{
"input": "1 2 1\n2",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "6 3 1\n1 1 2 2 2 2",
"output": "2"
},
{
"input": "100 40 20\n2 2 2 2 2 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "40"
},
{
"input": "7 5 2\n2 2 1 1 1 1 1",
"output": "0"
},
{
"input": "10 4 4\n2 2 2 2 2 2 1 1 1 1",
"output": "2"
},
{
"input": "3 2 1\n2 1 1",
"output": "0"
},
{
"input": "7 6 1\n2 1 1 1 1 1 1",
"output": "0"
},
{
"input": "7 5 1\n1 1 1 2 2 2 2",
"output": "1"
},
{
"input": "5 3 1\n1 1 2 2 2",
"output": "1"
},
{
"input": "3 1 1\n2 2 2",
"output": "1"
},
{
"input": "5 2 2\n2 2 2 2 2",
"output": "1"
},
{
"input": "3 1 3\n1 1 1",
"output": "2"
},
{
"input": "5 2 1\n1 1 2 2 2",
"output": "2"
},
{
"input": "4 3 2\n2 1 1 1",
"output": "0"
},
{
"input": "4 2 1\n1 2 2 2",
"output": "1"
},
{
"input": "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2",
"output": "3"
},
{
"input": "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1",
"output": "0"
},
{
"input": "5 3 2\n2 2 1 1 1",
"output": "0"
}
] | 109 | 20,172,800 | 3 | 328 |
|
784 | Crunching Numbers Just for You | [
"*special",
"implementation"
] | null | null | You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order. | The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). | Output space-separated elements of the sorted array. | [
"3 3 1 2\n"
] | [
"1 2 3 \n"
] | Remember, this is a very important feature, and you have to make sure the customers appreciate it! | [
{
"input": "3 3 1 2",
"output": "1 2 3 "
},
{
"input": "10 54 100 27 1 33 27 80 49 27 6",
"output": "1 6 27 27 27 33 49 54 80 100 "
}
] | 1,560 | 0 | 3 | 329 |
|
546 | Soldier and Bananas | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 46 | 0 | 3 | 330 |
|
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 | 332 |
|
489 | BerSU Ball | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill. | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{
"input": "4\n4 5 4 4\n5\n5 3 4 2 4",
"output": "4"
},
{
"input": "1\n2\n1\n1",
"output": "1"
},
{
"input": "1\n3\n2\n3 2",
"output": "1"
},
{
"input": "1\n4\n3\n4 4 4",
"output": "1"
},
{
"input": "1\n2\n4\n3 1 4 2",
"output": "1"
},
{
"input": "1\n4\n5\n2 5 5 3 1",
"output": "1"
},
{
"input": "2\n2 2\n1\n2",
"output": "1"
},
{
"input": "2\n4 2\n2\n4 4",
"output": "1"
},
{
"input": "2\n4 1\n3\n2 3 2",
"output": "2"
},
{
"input": "2\n4 3\n4\n5 5 5 6",
"output": "1"
},
{
"input": "2\n5 7\n5\n4 6 7 2 5",
"output": "2"
},
{
"input": "3\n1 2 3\n1\n1",
"output": "1"
},
{
"input": "3\n5 4 5\n2\n2 1",
"output": "0"
},
{
"input": "3\n6 3 4\n3\n4 5 2",
"output": "3"
},
{
"input": "3\n7 7 7\n4\n2 7 2 4",
"output": "1"
},
{
"input": "3\n1 3 3\n5\n1 3 4 1 2",
"output": "3"
},
{
"input": "4\n1 2 1 3\n1\n4",
"output": "1"
},
{
"input": "4\n4 4 6 6\n2\n2 1",
"output": "0"
},
{
"input": "4\n3 1 1 1\n3\n1 6 7",
"output": "1"
},
{
"input": "4\n2 5 1 2\n4\n2 3 3 1",
"output": "3"
},
{
"input": "4\n9 1 7 1\n5\n9 9 9 8 4",
"output": "2"
},
{
"input": "5\n1 6 5 5 6\n1\n2",
"output": "1"
},
{
"input": "5\n5 2 4 5 6\n2\n7 4",
"output": "2"
},
{
"input": "5\n4 1 3 1 4\n3\n6 3 6",
"output": "1"
},
{
"input": "5\n5 2 3 1 4\n4\n1 3 1 7",
"output": "3"
},
{
"input": "5\n9 8 10 9 10\n5\n2 1 5 4 6",
"output": "0"
},
{
"input": "1\n48\n100\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6",
"output": "1"
},
{
"input": "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\n1\n58",
"output": "0"
},
{
"input": "10\n20 87 3 39 20 20 8 40 70 51\n100\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96",
"output": "6"
},
{
"input": "100\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\n10\n66 74 40 67 28 82 99 57 93 64",
"output": "9"
},
{
"input": "100\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\n100\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1",
"output": "76"
},
{
"input": "4\n1 6 9 15\n2\n5 8",
"output": "2"
},
{
"input": "2\n2 4\n2\n3 1",
"output": "2"
},
{
"input": "3\n2 3 5\n3\n3 4 6",
"output": "3"
},
{
"input": "3\n1 3 4\n3\n2 1 5",
"output": "3"
},
{
"input": "2\n5 5\n4\n1 1 1 5",
"output": "1"
},
{
"input": "2\n3 2\n2\n3 4",
"output": "2"
},
{
"input": "2\n3 1\n2\n2 4",
"output": "2"
},
{
"input": "2\n2 3\n2\n2 1",
"output": "2"
},
{
"input": "2\n10 12\n2\n11 9",
"output": "2"
},
{
"input": "3\n1 2 3\n3\n3 2 1",
"output": "3"
},
{
"input": "2\n1 3\n2\n2 1",
"output": "2"
},
{
"input": "2\n4 5\n2\n5 3",
"output": "2"
},
{
"input": "2\n7 5\n2\n6 8",
"output": "2"
},
{
"input": "4\n4 3 2 1\n4\n1 2 3 4",
"output": "4"
},
{
"input": "2\n2 3\n2\n3 1",
"output": "2"
},
{
"input": "2\n2 4\n3\n3 1 8",
"output": "2"
},
{
"input": "3\n3 1 1\n3\n2 4 4",
"output": "2"
},
{
"input": "2\n5 3\n2\n4 6",
"output": "2"
},
{
"input": "4\n1 1 3 3\n4\n2 2 1 1",
"output": "4"
},
{
"input": "3\n3 2 1\n3\n2 4 3",
"output": "3"
},
{
"input": "5\n1 2 3 4 5\n5\n2 3 4 5 1",
"output": "5"
},
{
"input": "3\n3 2 1\n3\n1 2 3",
"output": "3"
},
{
"input": "2\n5 4\n2\n4 6",
"output": "2"
},
{
"input": "4\n3 3 5 5\n4\n4 4 2 2",
"output": "4"
},
{
"input": "3\n2 7 5\n3\n2 4 8",
"output": "3"
},
{
"input": "100\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\n100\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5",
"output": "100"
},
{
"input": "1\n3\n2\n2 3",
"output": "1"
},
{
"input": "2\n5 6\n3\n1 5 100",
"output": "1"
},
{
"input": "2\n2 7\n2\n6 8",
"output": "1"
},
{
"input": "4\n4 10 15 17\n4\n3 12 16 16",
"output": "3"
},
{
"input": "2\n2 3\n2\n1 2",
"output": "2"
}
] | 46 | 0 | 3 | 333 |
|
31 | Sysadmin Bob | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wasd@q,wasd@q,wasd@q,wasd@qw"
},
{
"input": "qwer@ty",
"output": "qwer@ty"
},
{
"input": "@",
"output": "No solution"
},
{
"input": "g",
"output": "No solution"
},
{
"input": "@@",
"output": "No solution"
},
{
"input": "@@@",
"output": "No solution"
},
{
"input": "r@@",
"output": "No solution"
},
{
"input": "@@r",
"output": "No solution"
},
{
"input": "@r@",
"output": "No solution"
},
{
"input": "w@",
"output": "No solution"
},
{
"input": "@e",
"output": "No solution"
},
{
"input": "jj",
"output": "No solution"
},
{
"input": "@gh",
"output": "No solution"
},
{
"input": "n@m",
"output": "n@m"
},
{
"input": "kl@",
"output": "No solution"
},
{
"input": "fpm",
"output": "No solution"
},
{
"input": "@@@@",
"output": "No solution"
},
{
"input": "q@@@",
"output": "No solution"
},
{
"input": "@d@@",
"output": "No solution"
},
{
"input": "@@v@",
"output": "No solution"
},
{
"input": "@@@c",
"output": "No solution"
},
{
"input": "@@zx",
"output": "No solution"
},
{
"input": "@x@a",
"output": "No solution"
},
{
"input": "@pq@",
"output": "No solution"
},
{
"input": "w@@e",
"output": "No solution"
},
{
"input": "e@s@",
"output": "No solution"
},
{
"input": "ec@@",
"output": "No solution"
},
{
"input": "@hjk",
"output": "No solution"
},
{
"input": "e@vb",
"output": "e@vb"
},
{
"input": "tg@q",
"output": "tg@q"
},
{
"input": "jkl@",
"output": "No solution"
},
{
"input": "werb",
"output": "No solution"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No solution"
},
{
"input": "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"output": "No solution"
},
{
"input": "duk@rufrxjzqbwkfrzf@sjp@mdpyrokdfmcmexxtjqaalruvtzwfsqabi@tjkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv",
"output": "duk@r,ufrxjzqbwkfrzf@s,jp@m,dpyrokdfmcmexxtjqaalruvtzwfsqabi@t,jkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv"
},
{
"input": "umegsn@qlmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@ebzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy",
"output": "umegsn@q,lmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@e,bzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy"
},
{
"input": "l@snuoytgflrtuexpx@txzhhdwbakfhfro@syxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs",
"output": "l@s,nuoytgflrtuexpx@t,xzhhdwbakfhfro@s,yxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs"
},
{
"input": "crvjlke@yqsdofatzuuspt@@uumdkiwhtg@crxiabnujfmcquylyklxaedniwnq@@f@@rfnsjtylurexmdaaykvxmgeij@jkjsyi",
"output": "No solution"
},
{
"input": "ukpcivvjubgalr@bdxangokpaxzxuxe@qlemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc",
"output": "ukpcivvjubgalr@b,dxangokpaxzxuxe@q,lemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc"
},
{
"input": "mehxghlvnnazggvpnjdbchdolqguiurrfghwxpwhphdbhloltwnnqovsnsdmfevlikmrlvwvkcqysefvoraorhamchghqaooxaxz",
"output": "No solution"
},
{
"input": "whazbewtogyre@wqlsswhygx@osevwzytuaukqpp@gfjbtwnhpnlxwci@ovaaat@ookd@@o@bss@wyrrwzysubw@utyltkk@hlkx",
"output": "No solution"
},
{
"input": "vpulcessdotvylvmkeonzbpncjxaaigotkyvngsbkicomikyavpsjcphlznjtdmvbqiroxvfcmcczfmqbyedujvrupzlaswbzanv",
"output": "No solution"
},
{
"input": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop",
"output": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop"
},
{
"input": "dxzqftcghawwcwh@iepanbiclstbsxbrsoep@@jwhrptgiu@zfykoravtaykvkzseqfnlsbvjnsgiajgjtgucvewlpxmqwvkghlo",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@",
"output": "No solution"
},
{
"input": "@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d",
"output": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@h@",
"output": "No solution"
},
{
"input": "@r@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@i@rjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierj@g@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@@",
"output": "No solution"
},
{
"input": "@@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierj@@dderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "a@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a",
"output": "a@r,ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a"
},
{
"input": "d@nt@om@zz@ut@tr@ta@ap@ou@sy@sv@fg@el@rp@qr@nl@j",
"output": "d@n,t@o,m@z,z@u,t@t,r@t,a@a,p@o,u@s,y@s,v@f,g@e,l@r,p@q,r@n,l@j"
},
{
"input": "a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q",
"output": "a@m,c@k,s@g,u@r,l@g,q@z,q@i,z@d,a@u,q@m,i@n,f@z,s@h,i@w,e@e,j@k,e@v,b@a,z@y,z@y,l@r,r@g,h@u,m@n,v@q,e@q,q@d,e@d,y@o,p@g,t@v,x@a,k@q"
},
{
"input": "c@ir@xf@ap@fk@sp@wm@ec@qw@vg@by@iu@tr@wu@pv@lj@dd@tc@qj@ok@hm@bs@ul@ez@cg@ht@xf@ag@tr@hz@ap@tx@ly@dg@hu@nd@uv@il@ii@cn@nc@nb@cy@kp@dk@xa@da@ta@yr@yv@qg@db@je@wz@rn@yh@xi@mj@kc@uj@yu@cf@ps@ao@fo@le@d",
"output": "c@i,r@x,f@a,p@f,k@s,p@w,m@e,c@q,w@v,g@b,y@i,u@t,r@w,u@p,v@l,j@d,d@t,c@q,j@o,k@h,m@b,s@u,l@e,z@c,g@h,t@x,f@a,g@t,r@h,z@a,p@t,x@l,y@d,g@h,u@n,d@u,v@i,l@i,i@c,n@n,c@n,b@c,y@k,p@d,k@x,a@d,a@t,a@y,r@y,v@q,g@d,b@j,e@w,z@r,n@y,h@x,i@m,j@k,c@u,j@y,u@c,f@p,s@a,o@f,o@l,e@d"
},
{
"input": "m@us@ru@mg@rq@ed@ot@gt@fo@gs@lm@cx@au@rq@zt@zk@jr@xd@oa@py@kf@lk@zr@ko@lj@wv@fl@yl@gk@cx@px@kl@ic@sr@xn@hm@xs@km@tk@ui@ya@pa@xx@ze@py@ir@xj@cr@dq@lr@cm@zu@lt@bx@kq@kx@fr@lu@vb@rz@hg@iw@dl@pf@pl@wv@z",
"output": "m@u,s@r,u@m,g@r,q@e,d@o,t@g,t@f,o@g,s@l,m@c,x@a,u@r,q@z,t@z,k@j,r@x,d@o,a@p,y@k,f@l,k@z,r@k,o@l,j@w,v@f,l@y,l@g,k@c,x@p,x@k,l@i,c@s,r@x,n@h,m@x,s@k,m@t,k@u,i@y,a@p,a@x,x@z,e@p,y@i,r@x,j@c,r@d,q@l,r@c,m@z,u@l,t@b,x@k,q@k,x@f,r@l,u@v,b@r,z@h,g@i,w@d,l@p,f@p,l@w,v@z"
},
{
"input": "gjkjqjrks@eyqiia@qfijelnmigoditxjrtuhukalfl@nmwancimlqtfekzkxgjioedhtdivqajwbmu@hpdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@neqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb",
"output": "gjkjqjrks@e,yqiia@q,fijelnmigoditxjrtuhukalfl@n,mwancimlqtfekzkxgjioedhtdivqajwbmu@h,pdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@n,eqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb"
},
{
"input": "uakh@chpowdmvdywosakyyknpriverjjgklmdrgwufpawgvhabjbnemimjktgbkx@fzvqcodbceqnihl@kpsslhwwndad@@yavjafrwkqyt@urhnwgnqamn@xkc@vngzlssmtheuxkpzjlbbjq@mwiojmvpilm@hlrmxheszskhxritsieubjjazrngxlqeedfkiuwny",
"output": "No solution"
},
{
"input": "usmjophufnkamnvowbauu@wfoyceknkgeaejlbbqhtucbl@wurukjezj@irhdgrfhyfkz@fbmqgxvtxcebztirvwjf@fnav@@f@paookujny@z@fmcxgvab@@kpqbwuxxwxhsrbivlbunmdjzk@afjznrjjtkq@cafetoinfleecjqvlzpkqlspoufwmidvoblti@jbg",
"output": "No solution"
},
{
"input": "axkxcgcmlxq@v@ynnjximcujikloyls@lqvxiyca@feimaioavacmquasneqbrqftknpbrzpahtcc@ijwqmyzsuidqkm@dffuiitpugbvty@izbnqxhdjasihhlt@gjrol@vy@vnqpxuqbofzzwl@toywomxopbuttczszx@fuowtjmtqy@gypx@la@@tweln@jgyktb",
"output": "No solution"
},
{
"input": "mplxc@crww@gllecngcsbmxmksrgcb@lbrcnkwxclkcgvfeqeoymproppxhxbgm@q@bfxxvuymnnjolqklabcinwpdlxj@jcevvilhmpyiwggvlmdanfhhlgbkobnmei@bvqtdq@osijfdsuouvcqpcjxjqiuhgts@xapp@cpqvlhlfrxtgunbbjwhuafovbcbqyhmlu",
"output": "No solution"
},
{
"input": "aglvesxsmivijisod@mxcnbfcfgqfwjouidlsueaswf@obehqpvbkmukxkicyoknkbol@kutunggpoxxfpbe@qkhv@llddqqoyjeex@byvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@lseltghg@bhuwbfjpsvayzk@fvwow@zapklumefauly",
"output": "aglvesxsmivijisod@m,xcnbfcfgqfwjouidlsueaswf@o,behqpvbkmukxkicyoknkbol@k,utunggpoxxfpbe@q,khv@l,lddqqoyjeex@b,yvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@l,seltghg@b,huwbfjpsvayzk@f,vwow@zapklumefauly"
},
{
"input": "gbllovyerhudm@aluhtnstcp@uwgvejnmqpt@nez@ltzqjrcgwkkpzicb@ihh@wldhvjbrl@efbdzbeg@zyovsta@n@c@jutail@nclsbcihabzr@snowxeyl@jewen@aduffvhr@ifufzzt@i@kptygveumwaknmrn@edsapqpcwsqypmutggztum@ewzakeamobzxt",
"output": "No solution"
},
{
"input": "dokshhqwmtbefrynupvusfxroggoqkjqfyabzkbccjmavumncorbcoairybeknhnpnwftrlbopsvqlgjbrowmfmoeebqseneabvgbcxmujmcqomoawrooixmqmyspfgafudfdfyrnujhgnbtsehgsnvdztjdpnskyquwdtkbfjtvrfjcqzmourvqsnfgjfqjgndydpch",
"output": "No solution"
},
{
"input": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@gjypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf",
"output": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@g,jypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf"
},
{
"input": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc",
"output": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc"
}
] | 31 | 0 | 0 | 335 |
194 | Exams | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"output": "50"
},
{
"input": "50 250",
"output": "0"
},
{
"input": "29 116",
"output": "0"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "46 127",
"output": "11"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "36 99",
"output": "9"
},
{
"input": "45 104",
"output": "31"
},
{
"input": "13 57",
"output": "0"
},
{
"input": "25 106",
"output": "0"
},
{
"input": "8 19",
"output": "5"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "13 32",
"output": "7"
},
{
"input": "47 128",
"output": "13"
},
{
"input": "17 73",
"output": "0"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "38 137",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "36 155",
"output": "0"
},
{
"input": "5 15",
"output": "0"
},
{
"input": "27 75",
"output": "6"
},
{
"input": "21 73",
"output": "0"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "49 177",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "44 173",
"output": "0"
},
{
"input": "49 219",
"output": "0"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "10 28",
"output": "2"
}
] | 248 | 0 | 3 | 336 |
|
954 | Diagonal Walking | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR",
"output": "67"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU",
"output": "99"
},
{
"input": "3\nRUR",
"output": "2"
},
{
"input": "1\nR",
"output": "1"
},
{
"input": "5\nRURUU",
"output": "3"
},
{
"input": "1\nU",
"output": "1"
},
{
"input": "2\nUR",
"output": "1"
},
{
"input": "23\nUUUUUUUUUUUUUUUUUUUUUUU",
"output": "23"
}
] | 62 | 0 | 0 | 337 |
|
797 | Minimal string | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character.
Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal.
You should write a program that will help Petya win the game. | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
"output": "bcmrh"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb"
},
{
"input": "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg",
"output": "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee"
},
{
"input": "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr",
"output": "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn"
},
{
"input": "bcaeaae",
"output": "aaaecbe"
},
{
"input": "edcadcbcdd",
"output": "abccdcddde"
},
{
"input": "a",
"output": "a"
},
{
"input": "a",
"output": "a"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "b",
"output": "b"
},
{
"input": "a",
"output": "a"
},
{
"input": "c",
"output": "c"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "c",
"output": "c"
},
{
"input": "b",
"output": "b"
},
{
"input": "a",
"output": "a"
},
{
"input": "e",
"output": "e"
},
{
"input": "b",
"output": "b"
},
{
"input": "b",
"output": "b"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "ca",
"output": "ac"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "cb",
"output": "bc"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "da",
"output": "ad"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "cd",
"output": "cd"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aab",
"output": "aab"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "baa",
"output": "aab"
},
{
"input": "bab",
"output": "abb"
},
{
"input": "baa",
"output": "aab"
},
{
"input": "ccc",
"output": "ccc"
},
{
"input": "ddd",
"output": "ddd"
},
{
"input": "ccd",
"output": "ccd"
},
{
"input": "bca",
"output": "acb"
},
{
"input": "cde",
"output": "cde"
},
{
"input": "ece",
"output": "cee"
},
{
"input": "bdd",
"output": "bdd"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "abaa",
"output": "aaab"
},
{
"input": "abab",
"output": "aabb"
},
{
"input": "bbbb",
"output": "bbbb"
},
{
"input": "bbba",
"output": "abbb"
},
{
"input": "caba",
"output": "aabc"
},
{
"input": "ccbb",
"output": "bbcc"
},
{
"input": "abac",
"output": "aabc"
},
{
"input": "daba",
"output": "aabd"
},
{
"input": "cdbb",
"output": "bbdc"
},
{
"input": "bddd",
"output": "bddd"
},
{
"input": "dacb",
"output": "abcd"
},
{
"input": "abcc",
"output": "abcc"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "baaab",
"output": "aaabb"
},
{
"input": "aabbb",
"output": "aabbb"
},
{
"input": "aabaa",
"output": "aaaab"
},
{
"input": "abcba",
"output": "aabcb"
},
{
"input": "bacbc",
"output": "abbcc"
},
{
"input": "bacba",
"output": "aabcb"
},
{
"input": "bdbda",
"output": "adbdb"
},
{
"input": "accbb",
"output": "abbcc"
},
{
"input": "dbccc",
"output": "bcccd"
},
{
"input": "decca",
"output": "acced"
},
{
"input": "dbbdd",
"output": "bbddd"
},
{
"input": "accec",
"output": "accce"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "bbbbab",
"output": "abbbbb"
},
{
"input": "bbbbab",
"output": "abbbbb"
},
{
"input": "aaaaba",
"output": "aaaaab"
},
{
"input": "cbbbcc",
"output": "bbbccc"
},
{
"input": "aaacac",
"output": "aaaacc"
},
{
"input": "bacbbc",
"output": "abbbcc"
},
{
"input": "cacacc",
"output": "aacccc"
},
{
"input": "badbdc",
"output": "abbcdd"
},
{
"input": "ddadad",
"output": "aadddd"
},
{
"input": "ccdece",
"output": "cccede"
},
{
"input": "eecade",
"output": "acdeee"
},
{
"input": "eabdcb",
"output": "abbcde"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaabbaa",
"output": "aaaaabb"
},
{
"input": "baaabab",
"output": "aaaabbb"
},
{
"input": "bbababa",
"output": "aaabbbb"
},
{
"input": "bcccacc",
"output": "acccbcc"
},
{
"input": "cbbcccc",
"output": "bbccccc"
},
{
"input": "abacaaa",
"output": "aaaaacb"
},
{
"input": "ccdbdac",
"output": "acdbdcc"
},
{
"input": "bbacaba",
"output": "aaabcbb"
},
{
"input": "abbaccc",
"output": "aabbccc"
},
{
"input": "bdcbcab",
"output": "abcbcdb"
},
{
"input": "dabcbce",
"output": "abbccde"
},
{
"input": "abaaabe",
"output": "aaaabbe"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ababbbba",
"output": "aaabbbbb"
},
{
"input": "aaaaaaba",
"output": "aaaaaaab"
},
{
"input": "babbbaab",
"output": "aaabbbbb"
},
{
"input": "bcaccaab",
"output": "aaabcccb"
},
{
"input": "bbccaabc",
"output": "aabccbbc"
},
{
"input": "cacaaaac",
"output": "aaaaaccc"
},
{
"input": "daacbddc",
"output": "aabccddd"
},
{
"input": "cdbdcdaa",
"output": "aadcdbdc"
},
{
"input": "bccbdacd",
"output": "acdbccbd"
},
{
"input": "abbeaade",
"output": "aaadebbe"
},
{
"input": "ccabecba",
"output": "aabcebcc"
},
{
"input": "ececaead",
"output": "aadecece"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aabaaabbb",
"output": "aaaaabbbb"
},
{
"input": "abbbbbaab",
"output": "aaabbbbbb"
},
{
"input": "bbbaababb",
"output": "aaabbbbbb"
},
{
"input": "babcaaccb",
"output": "aaabcccbb"
},
{
"input": "ccbcabaac",
"output": "aaabcbccc"
},
{
"input": "caaaccccb",
"output": "aaabccccc"
},
{
"input": "abbcdbddb",
"output": "abbbbdddc"
},
{
"input": "dbcaacbbb",
"output": "aabbbccbd"
},
{
"input": "cadcbddac",
"output": "aacddbcdc"
},
{
"input": "ecebadadb",
"output": "aabddbece"
},
{
"input": "bdbeeccdd",
"output": "bbccddeed"
},
{
"input": "daaedecda",
"output": "aaadceded"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "abaaaaabbb",
"output": "aaaaaabbbb"
},
{
"input": "bbaaaabaaa",
"output": "aaaaaaabbb"
},
{
"input": "bbabbaaaaa",
"output": "aaaaaabbbb"
},
{
"input": "cbaabcaacc",
"output": "aaaacbbccc"
},
{
"input": "aaaaccccab",
"output": "aaaaabcccc"
},
{
"input": "bccaccaacc",
"output": "aaaccccbcc"
},
{
"input": "dbdccdcacd",
"output": "accdccdbdd"
},
{
"input": "caaddaaccb",
"output": "aaaabccddc"
},
{
"input": "adbbabcbdc",
"output": "aabbbbccdd"
},
{
"input": "cdeabdbbad",
"output": "aabbdbdedc"
},
{
"input": "eeddcbeeec",
"output": "bcceeeddee"
},
{
"input": "bbcebddeba",
"output": "abeddbecbb"
}
] | 61 | 0 | 0 | 338 |
|
990 | Commentary Boxes | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "5000000000020"
},
{
"input": "1000000000000 750000000001 100 10",
"output": "2499999999990"
},
{
"input": "42 1 1 1",
"output": "0"
},
{
"input": "1 1000000000000 1 100",
"output": "100"
},
{
"input": "7 2 3 7",
"output": "3"
},
{
"input": "999999999 2 1 1",
"output": "1"
},
{
"input": "999999999999 10000000007 100 100",
"output": "70100"
},
{
"input": "10000000001 2 1 1",
"output": "1"
},
{
"input": "29 6 1 2",
"output": "1"
},
{
"input": "99999999999 6 100 100",
"output": "300"
},
{
"input": "1000000000000 7 3 8",
"output": "8"
},
{
"input": "99999999999 2 1 1",
"output": "1"
},
{
"input": "1 2 1 1",
"output": "1"
},
{
"input": "999999999999 2 1 1",
"output": "1"
},
{
"input": "9 2 1 1",
"output": "1"
},
{
"input": "17 4 5 5",
"output": "5"
},
{
"input": "100000000000 3 1 1",
"output": "1"
},
{
"input": "100 7 1 1",
"output": "2"
},
{
"input": "1000000000000 3 100 100",
"output": "100"
},
{
"input": "70 3 10 10",
"output": "10"
},
{
"input": "1 2 5 1",
"output": "1"
},
{
"input": "1000000000000 3 1 1",
"output": "1"
},
{
"input": "804289377 846930887 78 16",
"output": "3326037780"
},
{
"input": "1000000000000 9 55 55",
"output": "55"
},
{
"input": "957747787 424238336 87 93",
"output": "10162213695"
},
{
"input": "25 6 1 2",
"output": "2"
},
{
"input": "22 7 3 8",
"output": "8"
},
{
"input": "10000000000 1 1 1",
"output": "0"
},
{
"input": "999999999999 2 10 10",
"output": "10"
},
{
"input": "999999999999 2 100 100",
"output": "100"
},
{
"input": "100 3 3 8",
"output": "6"
},
{
"input": "99999 2 1 1",
"output": "1"
},
{
"input": "100 3 2 5",
"output": "4"
},
{
"input": "1000000000000 13 10 17",
"output": "17"
},
{
"input": "7 2 1 2",
"output": "1"
},
{
"input": "10 3 1 2",
"output": "2"
},
{
"input": "5 2 2 2",
"output": "2"
},
{
"input": "100 3 5 2",
"output": "2"
},
{
"input": "7 2 1 1",
"output": "1"
},
{
"input": "70 4 1 1",
"output": "2"
},
{
"input": "10 4 1 1",
"output": "2"
},
{
"input": "6 7 41 42",
"output": "41"
},
{
"input": "10 3 10 1",
"output": "1"
},
{
"input": "5 5 2 3",
"output": "0"
},
{
"input": "1000000000000 3 99 99",
"output": "99"
},
{
"input": "7 3 100 1",
"output": "1"
},
{
"input": "7 2 100 5",
"output": "5"
},
{
"input": "1000000000000 1 23 33",
"output": "0"
},
{
"input": "30 7 1 1",
"output": "2"
},
{
"input": "100 3 1 1",
"output": "1"
},
{
"input": "90001 300 100 1",
"output": "1"
},
{
"input": "13 4 1 2",
"output": "2"
},
{
"input": "1000000000000 6 1 3",
"output": "2"
},
{
"input": "50 4 5 100",
"output": "10"
},
{
"input": "999 2 1 1",
"output": "1"
},
{
"input": "5 2 5 5",
"output": "5"
},
{
"input": "20 3 3 3",
"output": "3"
},
{
"input": "3982258181 1589052704 87 20",
"output": "16083055460"
},
{
"input": "100 3 1 3",
"output": "2"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "19 10 100 100",
"output": "100"
},
{
"input": "23 3 100 1",
"output": "2"
},
{
"input": "25 7 100 1",
"output": "4"
},
{
"input": "100 9 1 2",
"output": "2"
},
{
"input": "9999999999 2 1 100",
"output": "1"
},
{
"input": "1000000000000 2 1 1",
"output": "0"
},
{
"input": "10000 3 1 1",
"output": "1"
},
{
"input": "22 7 1 6",
"output": "6"
},
{
"input": "100000000000 1 1 1",
"output": "0"
},
{
"input": "18 7 100 1",
"output": "4"
},
{
"input": "10003 4 1 100",
"output": "1"
},
{
"input": "3205261341 718648876 58 11",
"output": "3637324207"
},
{
"input": "8 3 100 1",
"output": "2"
},
{
"input": "15 7 1 1",
"output": "1"
},
{
"input": "1000000000000 1 20 20",
"output": "0"
},
{
"input": "16 7 3 2",
"output": "4"
},
{
"input": "1000000000000 1 1 1",
"output": "0"
},
{
"input": "7 3 1 100",
"output": "2"
},
{
"input": "16 3 1 100",
"output": "2"
},
{
"input": "13 4 1 10",
"output": "3"
},
{
"input": "10 4 5 5",
"output": "10"
},
{
"input": "14 3 1 100",
"output": "1"
},
{
"input": "100 33 100 1",
"output": "1"
},
{
"input": "22 7 1 8",
"output": "6"
},
{
"input": "10 4 2 1",
"output": "2"
},
{
"input": "6 4 2 2",
"output": "4"
},
{
"input": "17 4 2 1",
"output": "1"
},
{
"input": "7 3 100 10",
"output": "10"
},
{
"input": "702 7 3 2",
"output": "4"
},
{
"input": "8 3 1 5",
"output": "1"
},
{
"input": "3 2 5 2",
"output": "2"
},
{
"input": "99 19 1 7",
"output": "15"
},
{
"input": "16 3 100 1",
"output": "1"
},
{
"input": "100 34 1 100",
"output": "2"
},
{
"input": "100 33 1 1",
"output": "1"
},
{
"input": "2 3 4 3",
"output": "4"
},
{
"input": "15 4 4 10",
"output": "4"
},
{
"input": "1144108931 470211273 45 79",
"output": "11993619960"
},
{
"input": "2 3 3 4",
"output": "3"
},
{
"input": "29 5 4 9",
"output": "4"
},
{
"input": "15 7 1 5",
"output": "5"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "1 1 3 4",
"output": "0"
},
{
"input": "10 12 2 1",
"output": "4"
},
{
"input": "1 2 3 4",
"output": "3"
}
] | 77 | 0 | 3 | 341 |
|
629 | Babaei and Birthday Cake | [
"data structures",
"dp"
] | null | null | As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has *n* simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number *i* can be placed only on the table or on some cake number *j* where *j*<=<<=*i*. Moreover, in order to impress friends Babaei will put the cake *i* on top of the cake *j* only if the volume of the cake *i* is strictly greater than the volume of the cake *j*.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of simple cakes Babaei has.
Each of the following *n* lines contains two integers *r**i* and *h**i* (1<=≤<=*r**i*,<=*h**i*<=≤<=10<=000), giving the radius and height of the *i*-th cake. | Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"2\n100 30\n40 10\n",
"4\n1 1\n9 7\n1 4\n10 7\n"
] | [
"942477.796077000\n",
"3983.539484752\n"
] | In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | [
{
"input": "2\n100 30\n40 10",
"output": "942477.796077000"
},
{
"input": "4\n1 1\n9 7\n1 4\n10 7",
"output": "3983.539484752"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "109.955742876"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "109.955742876"
},
{
"input": "3\n3 3\n1 1\n2 2",
"output": "84.823001647"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "113.097335529"
},
{
"input": "3\n1 1\n3 3\n2 2",
"output": "87.964594301"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "84.823001647"
},
{
"input": "1\n1 1",
"output": "3.141592654"
},
{
"input": "2\n1 1\n2 2",
"output": "28.274333882"
},
{
"input": "2\n2 2\n1 1",
"output": "25.132741229"
},
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "314.159265359"
},
{
"input": "4\n1 1\n2 2\n4 4\n3 3",
"output": "229.336263712"
},
{
"input": "4\n1 1\n3 3\n2 2\n4 4",
"output": "289.026524130"
},
{
"input": "4\n1 1\n3 3\n4 4\n2 2",
"output": "289.026524130"
},
{
"input": "4\n1 1\n4 4\n2 2\n3 3",
"output": "204.203522483"
},
{
"input": "4\n1 1\n4 4\n3 3\n2 2",
"output": "204.203522483"
},
{
"input": "4\n2 2\n1 1\n3 3\n4 4",
"output": "311.017672705"
},
{
"input": "4\n2 2\n1 1\n4 4\n3 3",
"output": "226.194671058"
},
{
"input": "4\n2 2\n3 3\n1 1\n4 4",
"output": "311.017672705"
},
{
"input": "4\n2 2\n3 3\n4 4\n1 1",
"output": "311.017672705"
},
{
"input": "4\n2 2\n4 4\n1 1\n3 3",
"output": "226.194671058"
},
{
"input": "4\n2 2\n4 4\n3 3\n1 1",
"output": "226.194671058"
},
{
"input": "4\n3 3\n1 1\n2 2\n4 4",
"output": "285.884931477"
},
{
"input": "4\n3 3\n1 1\n4 4\n2 2",
"output": "285.884931477"
},
{
"input": "4\n3 3\n2 2\n1 1\n4 4",
"output": "285.884931477"
},
{
"input": "4\n3 3\n2 2\n4 4\n1 1",
"output": "285.884931477"
},
{
"input": "4\n3 3\n4 4\n1 1\n2 2",
"output": "285.884931477"
},
{
"input": "4\n3 3\n4 4\n2 2\n1 1",
"output": "285.884931477"
},
{
"input": "4\n4 4\n1 1\n2 2\n3 3",
"output": "201.061929830"
},
{
"input": "4\n4 4\n1 1\n3 3\n2 2",
"output": "201.061929830"
},
{
"input": "4\n4 4\n2 2\n1 1\n3 3",
"output": "201.061929830"
},
{
"input": "4\n4 4\n2 2\n3 3\n1 1",
"output": "201.061929830"
},
{
"input": "4\n4 4\n3 3\n1 1\n2 2",
"output": "201.061929830"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "201.061929830"
},
{
"input": "24\n14 3600\n105 64\n40 441\n15 3136\n24 1225\n42 400\n84 100\n12 4900\n120 49\n56 225\n140 36\n70 144\n168 25\n60 196\n30 784\n280 9\n10 7056\n21 1600\n28 900\n210 16\n420 4\n840 1\n35 576\n20 1764",
"output": "2216707.776373104"
},
{
"input": "15\n40 9\n12 100\n60 4\n20 36\n24 25\n15 64\n120 1\n4 900\n6 400\n5 576\n10 144\n30 16\n3 1600\n2 3600\n8 225",
"output": "45238.934211696"
},
{
"input": "14\n8 324\n12 144\n72 4\n144 1\n48 9\n3 2304\n24 36\n2 5184\n9 256\n36 16\n6 576\n4 1296\n18 64\n16 81",
"output": "65144.065264842"
},
{
"input": "15\n4 1764\n24 49\n84 4\n21 64\n28 36\n6 784\n7 576\n2 7056\n168 1\n56 9\n3 3136\n8 441\n14 144\n42 16\n12 196",
"output": "88668.311054924"
},
{
"input": "15\n3 3200\n2 7200\n20 72\n8 450\n60 8\n15 128\n4 1800\n5 1152\n24 50\n40 18\n120 2\n6 800\n30 32\n12 200\n10 288",
"output": "90477.868423392"
},
{
"input": "17\n6 900\n20 81\n45 16\n4 2025\n15 144\n9 400\n2 8100\n3 3600\n10 324\n30 36\n5 1296\n12 225\n36 25\n18 100\n90 4\n60 9\n180 1",
"output": "101787.601976316"
},
{
"input": "13\n24 72\n3 4608\n18 128\n72 8\n48 18\n144 2\n4 2592\n16 162\n9 512\n6 1152\n12 288\n36 32\n8 648",
"output": "130288.130529684"
},
{
"input": "14\n60 12\n20 108\n24 75\n120 3\n3 4800\n5 1728\n6 1200\n8 675\n12 300\n4 2700\n30 48\n15 192\n40 27\n10 432",
"output": "135716.802635088"
},
{
"input": "14\n105 4\n14 225\n6 1225\n7 900\n35 36\n10 441\n30 49\n5 1764\n21 100\n70 9\n42 25\n3 4900\n210 1\n15 196",
"output": "138544.236023319"
},
{
"input": "14\n6 1296\n216 1\n18 144\n3 5184\n8 729\n4 2916\n72 9\n12 324\n9 576\n54 16\n36 36\n27 64\n108 4\n24 81",
"output": "146574.146845895"
},
{
"input": "14\n4 3528\n12 392\n24 98\n84 8\n14 288\n42 32\n168 2\n56 18\n6 1568\n8 882\n3 6272\n21 128\n28 72\n7 1152",
"output": "177336.622109848"
},
{
"input": "18\n3 6400\n4 3600\n20 144\n8 900\n24 100\n15 256\n30 64\n16 225\n10 576\n48 25\n5 2304\n80 9\n60 16\n240 1\n6 1600\n40 36\n12 400\n120 4",
"output": "180955.736846784"
},
{
"input": "13\n3 6912\n144 3\n24 108\n18 192\n16 243\n36 48\n9 768\n12 432\n4 3888\n48 27\n72 12\n8 972\n6 1728",
"output": "195432.195794527"
},
{
"input": "16\n126 4\n21 144\n3 7056\n14 324\n42 36\n63 16\n28 81\n36 49\n7 1296\n84 9\n252 1\n4 3969\n6 1764\n9 784\n12 441\n18 196",
"output": "199503.699873579"
},
{
"input": "16\n45 32\n12 450\n60 18\n9 800\n180 2\n6 1800\n4 4050\n36 50\n3 7200\n18 200\n15 288\n30 72\n20 162\n90 8\n10 648\n5 2592",
"output": "203575.203952632"
},
{
"input": "14\n22 144\n24 121\n264 1\n6 1936\n132 4\n33 64\n4 4356\n12 484\n66 16\n3 7744\n44 36\n11 576\n88 9\n8 1089",
"output": "218956.441584609"
},
{
"input": "14\n30 80\n5 2880\n4 4500\n3 8000\n10 720\n12 500\n8 1125\n6 2000\n60 20\n120 5\n24 125\n15 320\n40 45\n20 180",
"output": "226194.671058480"
},
{
"input": "14\n27 100\n135 4\n3 8100\n45 36\n90 9\n30 81\n6 2025\n270 1\n54 25\n18 225\n10 729\n15 324\n5 2916\n9 900",
"output": "229022.104446711"
},
{
"input": "14\n28 100\n140 4\n20 196\n5 3136\n56 25\n4 4900\n40 49\n7 1600\n35 64\n70 16\n10 784\n280 1\n14 400\n8 1225",
"output": "246300.864041456"
},
{
"input": "16\n32 81\n96 9\n12 576\n3 9216\n18 256\n144 4\n36 64\n16 324\n72 16\n4 5184\n48 36\n288 1\n8 1296\n6 2304\n24 144\n9 1024",
"output": "260576.261059369"
},
{
"input": "14\n3 9408\n12 588\n4 5292\n24 147\n42 48\n7 1728\n168 3\n84 12\n6 2352\n28 108\n56 27\n8 1323\n21 192\n14 432",
"output": "266004.933164772"
},
{
"input": "14\n20 216\n12 600\n5 3456\n10 864\n15 384\n3 9600\n4 5400\n30 96\n8 1350\n6 2400\n24 150\n60 24\n120 6\n40 54",
"output": "271433.605270176"
},
{
"input": "14\n35 72\n21 200\n6 2450\n5 3528\n70 18\n30 98\n10 882\n15 392\n105 8\n210 2\n42 50\n3 9800\n14 450\n7 1800",
"output": "277088.472046638"
},
{
"input": "16\n100 9\n3 10000\n60 25\n15 400\n75 16\n10 900\n50 36\n150 4\n25 144\n6 2500\n12 625\n5 3600\n20 225\n30 100\n4 5625\n300 1",
"output": "282743.338823100"
},
{
"input": "13\n72 18\n24 162\n36 72\n4 5832\n18 288\n54 32\n12 648\n9 1152\n108 8\n216 2\n8 1458\n27 128\n6 2592",
"output": "293148.293691790"
},
{
"input": "15\n36 75\n45 48\n6 2700\n9 1200\n30 108\n18 300\n12 675\n20 243\n5 3888\n4 6075\n60 27\n90 12\n10 972\n180 3\n15 432",
"output": "305362.805928948"
},
{
"input": "13\n12 676\n39 64\n6 2704\n8 1521\n52 36\n312 1\n13 576\n104 9\n4 6084\n156 4\n24 169\n78 16\n26 144",
"output": "305815.195271065"
},
{
"input": "9\n4 2\n2 2\n4 1\n3 1\n1 1\n4 3\n5 1\n4 3\n4 1",
"output": "304.734487398"
},
{
"input": "5\n8 3\n6 3\n4 2\n7 3\n6 3",
"output": "801.106126665"
},
{
"input": "2\n1 1\n1 1",
"output": "3.141592654"
},
{
"input": "3\n10 10\n10 10\n10 10",
"output": "3141.592653590"
},
{
"input": "2\n100 30\n100 30",
"output": "942477.796077000"
}
] | 2,000 | 7,680,000 | 0 | 343 |
|
285 | Find Marble | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*. | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*. | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1 5 6 2 9 4 3",
"output": "-1"
},
{
"input": "10 3 6\n5 6 7 3 8 4 2 1 10 9",
"output": "3"
},
{
"input": "10 10 4\n4 2 6 9 5 3 8 1 10 7",
"output": "4"
},
{
"input": "100 90 57\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "-1"
},
{
"input": "100 11 20\n80 25 49 55 22 98 35 59 88 14 91 20 68 66 53 50 77 45 82 63 96 93 85 46 37 74 84 9 7 95 41 86 23 36 33 27 81 39 18 13 12 92 24 71 3 48 83 61 31 87 28 79 75 38 11 21 29 69 44 100 72 62 32 43 30 16 47 56 89 60 42 17 26 70 94 99 4 6 2 73 8 52 65 1 15 90 67 51 78 10 5 76 57 54 34 58 19 64 40 97",
"output": "26"
},
{
"input": "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23 66 76 59 79 40 86 63 44 82 32 48 16 50 100 28 96 46 12 27 13 24 9 19 84 73 69 71 42 56 33 34 95",
"output": "71"
},
{
"input": "100 6 93\n74 62 67 81 40 85 35 42 59 72 80 28 79 41 16 19 33 63 13 10 69 76 70 93 49 84 89 94 8 37 11 90 26 52 47 7 36 95 86 75 56 15 61 99 88 12 83 21 20 3 100 17 32 82 6 5 43 25 66 68 73 78 18 77 92 27 23 2 4 39 60 48 22 24 14 97 29 34 54 64 71 57 87 38 9 50 30 53 51 45 44 31 58 91 98 65 55 1 46 96",
"output": "-1"
},
{
"input": "100 27 56\n58 18 50 41 33 37 14 87 77 73 61 53 15 8 70 68 45 96 54 78 39 67 51 60 80 12 93 99 20 92 17 79 4 13 62 91 69 29 49 36 98 34 90 35 84 64 38 83 28 89 97 94 9 16 26 48 10 57 23 75 27 88 44 21 72 76 30 43 32 2 71 24 100 1 31 81 42 40 47 55 86 85 66 5 52 22 95 74 11 19 7 82 6 25 56 63 65 59 46 3",
"output": "20"
},
{
"input": "87 42 49\n45 55 24 44 56 72 74 23 4 7 37 67 22 6 58 76 40 36 3 20 26 87 64 75 49 70 62 42 31 1 80 33 25 59 78 27 32 2 41 61 66 28 19 85 15 69 52 77 50 14 16 34 18 43 73 83 11 39 29 9 35 13 81 54 79 21 60 46 71 57 12 17 5 47 38 30 10 84 53 63 68 8 51 65 48 86 82",
"output": "-1"
},
{
"input": "2 1 2\n1 2",
"output": "-1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
},
{
"input": "2 2 2\n1 2",
"output": "0"
},
{
"input": "2 2 2\n2 1",
"output": "0"
},
{
"input": "2 1 1\n2 1",
"output": "0"
}
] | 280 | 7,270,400 | 0 | 344 |
|
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"
}
] | 233 | 21,504,000 | 3 | 345 |
|
120 | Put Knight! | [
"games",
"math"
] | null | null | Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=*c*<=-<=2), (*r*<=+<=1,<=*c*<=+<=2), (*r*<=+<=1,<=*c*<=-<=2), (*r*<=-<=2,<=*c*<=+<=1), (*r*<=-<=2,<=*c*<=-<=1), (*r*<=+<=2,<=*c*<=+<=1) and (*r*<=+<=2,<=*c*<=-<=1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts. | The first line contains integer *T* (1<=≤<=*T*<=≤<=100) — the number of boards, for which you should determine the winning player. Next *T* lines contain *T* integers *n**i* (1<=≤<=*n**i*<=≤<=10000) — the sizes of the chessboards. | For each *n**i*<=×<=*n**i* board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1". | [
"2\n2\n1\n"
] | [
"1\n0\n"
] | none | [
{
"input": "2\n2\n1",
"output": "1\n0"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "0\n1\n0\n1\n0\n1\n0\n1\n0\n1"
},
{
"input": "15\n10\n4\n7\n8\n9\n6\n2\n1\n3\n1\n5\n2\n3\n4\n5",
"output": "1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0"
},
{
"input": "6\n10\n7\n10\n8\n5\n1",
"output": "1\n0\n1\n1\n0\n0"
},
{
"input": "100\n5\n6\n8\n7\n5\n7\n10\n2\n8\n3\n10\n3\n7\n3\n2\n7\n10\n3\n7\n3\n9\n5\n1\n1\n1\n5\n7\n5\n4\n8\n7\n3\n2\n10\n5\n10\n1\n10\n5\n2\n10\n6\n4\n10\n7\n6\n10\n8\n8\n5\n5\n7\n5\n7\n8\n6\n7\n8\n5\n8\n7\n9\n1\n1\n1\n5\n10\n6\n3\n3\n2\n7\n5\n2\n4\n4\n10\n1\n5\n2\n9\n1\n9\n9\n8\n2\n6\n9\n8\n2\n6\n2\n1\n10\n10\n8\n9\n7\n8\n8",
"output": "0\n1\n1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n0\n0\n1\n1"
},
{
"input": "100\n59\n95\n11\n67\n65\n90\n93\n53\n29\n63\n74\n47\n5\n67\n70\n67\n56\n66\n10\n33\n81\n63\n41\n77\n62\n58\n19\n95\n68\n2\n99\n85\n85\n94\n52\n87\n20\n85\n74\n58\n74\n85\n76\n95\n46\n1\n28\n89\n100\n75\n94\n46\n29\n21\n89\n42\n95\n72\n18\n65\n73\n99\n98\n59\n59\n74\n80\n47\n68\n58\n94\n1\n63\n90\n74\n77\n36\n9\n13\n100\n64\n55\n63\n70\n97\n50\n48\n7\n81\n25\n31\n64\n57\n12\n42\n61\n95\n83\n79\n84",
"output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1"
},
{
"input": "100\n62\n25\n86\n34\n47\n37\n38\n18\n42\n48\n39\n59\n74\n41\n58\n96\n50\n19\n40\n42\n43\n80\n100\n64\n54\n2\n36\n56\n80\n77\n29\n21\n87\n58\n87\n92\n30\n73\n87\n8\n30\n98\n52\n47\n67\n95\n12\n87\n98\n18\n16\n52\n36\n1\n100\n23\n49\n60\n89\n14\n100\n6\n34\n27\n30\n81\n33\n10\n59\n64\n74\n33\n28\n19\n78\n79\n87\n98\n30\n78\n42\n77\n80\n87\n34\n72\n19\n86\n36\n19\n15\n94\n61\n11\n32\n91\n44\n33\n32\n48",
"output": "1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1"
},
{
"input": "100\n17\n6\n14\n53\n81\n33\n31\n31\n4\n34\n4\n70\n94\n64\n46\n25\n92\n19\n70\n4\n57\n45\n59\n51\n47\n45\n2\n69\n91\n3\n10\n4\n89\n71\n21\n46\n87\n60\n100\n59\n37\n12\n75\n98\n88\n89\n49\n38\n44\n14\n39\n57\n95\n82\n11\n56\n51\n97\n9\n14\n27\n14\n17\n43\n2\n88\n37\n21\n98\n70\n55\n66\n93\n47\n30\n30\n87\n86\n46\n56\n67\n99\n98\n3\n23\n42\n90\n18\n91\n14\n46\n73\n65\n10\n70\n72\n45\n31\n84\n59",
"output": "0\n1\n1\n0\n0\n0\n0\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n0"
},
{
"input": "100\n20\n36\n41\n21\n15\n80\n24\n44\n18\n20\n17\n82\n63\n38\n34\n53\n85\n20\n48\n13\n19\n11\n18\n86\n39\n89\n20\n30\n3\n30\n39\n40\n91\n35\n56\n52\n97\n48\n12\n9\n93\n25\n50\n50\n9\n32\n85\n89\n42\n9\n14\n15\n54\n14\n70\n37\n5\n86\n80\n63\n6\n74\n1\n11\n22\n96\n89\n85\n37\n76\n83\n47\n58\n28\n83\n32\n38\n75\n63\n33\n45\n70\n16\n20\n59\n63\n62\n97\n46\n56\n30\n52\n17\n60\n61\n54\n94\n29\n37\n71",
"output": "1\n1\n0\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0"
},
{
"input": "100\n24\n18\n68\n40\n49\n27\n17\n9\n31\n6\n81\n93\n31\n12\n22\n82\n27\n20\n78\n23\n33\n76\n78\n73\n83\n32\n37\n91\n15\n4\n20\n75\n93\n48\n91\n58\n7\n36\n25\n59\n1\n38\n73\n1\n31\n26\n69\n40\n40\n53\n36\n21\n12\n95\n81\n17\n6\n23\n52\n11\n33\n81\n84\n80\n94\n3\n42\n48\n76\n81\n64\n79\n23\n56\n87\n82\n89\n63\n80\n11\n71\n92\n33\n37\n48\n33\n33\n77\n1\n50\n13\n82\n21\n59\n51\n83\n96\n27\n89\n83",
"output": "1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n0\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0"
},
{
"input": "100\n27\n47\n95\n7\n82\n22\n9\n21\n45\n40\n46\n5\n52\n34\n10\n11\n21\n73\n8\n85\n95\n41\n37\n8\n75\n24\n3\n52\n26\n31\n49\n11\n95\n12\n25\n12\n17\n71\n37\n10\n56\n51\n97\n100\n52\n20\n5\n91\n86\n48\n59\n26\n19\n27\n92\n50\n8\n60\n23\n11\n12\n89\n68\n96\n66\n58\n94\n59\n15\n39\n92\n12\n36\n85\n39\n84\n41\n52\n97\n89\n48\n14\n51\n53\n85\n54\n4\n9\n56\n44\n45\n61\n25\n58\n41\n65\n45\n25\n42\n94",
"output": "0\n0\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1"
},
{
"input": "100\n30\n29\n70\n26\n16\n70\n2\n34\n59\n26\n11\n16\n20\n8\n98\n39\n14\n73\n38\n94\n9\n6\n96\n95\n67\n68\n21\n13\n38\n57\n30\n95\n97\n25\n60\n17\n75\n59\n98\n60\n64\n64\n72\n52\n73\n15\n42\n41\n84\n91\n34\n32\n78\n7\n51\n31\n62\n49\n43\n60\n40\n49\n51\n64\n38\n66\n46\n23\n6\n45\n73\n92\n1\n65\n91\n86\n92\n40\n14\n19\n74\n36\n68\n70\n22\n76\n75\n88\n11\n86\n28\n39\n29\n9\n31\n47\n46\n23\n94\n6",
"output": "1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n1\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n0\n1\n0\n1\n1"
},
{
"input": "100\n34\n58\n97\n93\n50\n17\n95\n47\n72\n11\n76\n28\n89\n82\n86\n68\n56\n74\n68\n4\n72\n24\n3\n82\n60\n11\n39\n74\n50\n32\n59\n30\n99\n89\n94\n71\n84\n46\n10\n10\n19\n30\n95\n3\n94\n57\n26\n40\n82\n87\n56\n38\n37\n40\n62\n64\n64\n86\n14\n8\n19\n57\n87\n80\n58\n73\n99\n86\n45\n51\n53\n25\n66\n94\n95\n36\n43\n29\n31\n97\n52\n58\n86\n87\n10\n45\n46\n68\n66\n80\n60\n70\n33\n8\n22\n28\n96\n21\n47\n18",
"output": "1\n1\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n1"
},
{
"input": "100\n37\n88\n24\n60\n84\n12\n40\n12\n86\n97\n88\n39\n9\n4\n74\n97\n50\n75\n46\n65\n86\n89\n62\n17\n52\n55\n4\n88\n61\n58\n88\n66\n1\n2\n29\n77\n94\n34\n23\n9\n27\n43\n71\n55\n67\n52\n62\n91\n80\n82\n79\n95\n95\n20\n73\n45\n18\n23\n85\n9\n46\n64\n70\n48\n30\n80\n51\n97\n84\n57\n82\n57\n31\n22\n47\n39\n95\n17\n96\n74\n30\n81\n4\n3\n47\n67\n17\n99\n21\n74\n43\n49\n37\n6\n12\n58\n97\n20\n51\n30",
"output": "0\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n1"
},
{
"input": "100\n91\n83\n93\n95\n65\n56\n2\n7\n85\n42\n28\n26\n84\n62\n65\n23\n78\n49\n15\n100\n72\n86\n71\n19\n5\n71\n49\n100\n29\n59\n92\n82\n41\n53\n50\n57\n98\n80\n5\n65\n58\n68\n58\n72\n8\n64\n67\n44\n5\n79\n3\n59\n19\n22\n33\n85\n63\n23\n62\n50\n67\n52\n9\n14\n29\n31\n46\n3\n60\n82\n60\n12\n89\n87\n95\n51\n87\n54\n16\n36\n67\n90\n72\n77\n10\n14\n9\n76\n92\n82\n85\n59\n87\n75\n52\n76\n79\n24\n33\n76",
"output": "0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1"
}
] | 154 | 2,764,800 | -1 | 348 |
|
355 | Vasya and Digital Root | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=<<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10.
For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3.
Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000).
Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220..."
},
{
"input": "22 9",
"output": "1583569962049529809017"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "13 5",
"output": "1381199538344"
},
{
"input": "100 4",
"output": "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478"
},
{
"input": "123 6",
"output": "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343"
},
{
"input": "1000 1",
"output": "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878..."
},
{
"input": "2 0",
"output": "No solution"
},
{
"input": "734 9",
"output": "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981..."
},
{
"input": "678 8",
"output": "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310..."
},
{
"input": "955 7",
"output": "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421..."
},
{
"input": "893 3",
"output": "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702..."
},
{
"input": "998 2",
"output": "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966..."
},
{
"input": "960 6",
"output": "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..."
}
] | 108 | 0 | 0 | 349 |
|
174 | Problem About Equation | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
"input": "3 5\n1 2 1",
"output": "2.000000\n1.000000\n2.000000"
},
{
"input": "10 95\n0 0 0 0 0 1 1 1 1 1",
"output": "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000"
},
{
"input": "3 5\n1 2 3",
"output": "2.666667\n1.666667\n0.666667"
},
{
"input": "3 5\n1 3 2",
"output": "2.666667\n0.666667\n1.666667"
},
{
"input": "3 5\n2 1 3",
"output": "1.666667\n2.666667\n0.666667"
},
{
"input": "3 5\n2 3 1",
"output": "1.666667\n0.666667\n2.666667"
},
{
"input": "3 5\n3 1 2",
"output": "0.666667\n2.666667\n1.666667"
},
{
"input": "3 5\n3 2 1",
"output": "0.666667\n1.666667\n2.666667"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "2 1\n2 2",
"output": "0.500000\n0.500000"
},
{
"input": "3 2\n2 1 2",
"output": "0.333333\n1.333333\n0.333333"
},
{
"input": "3 3\n2 2 1",
"output": "0.666667\n0.666667\n1.666667"
},
{
"input": "3 3\n3 1 2",
"output": "0.000000\n2.000000\n1.000000"
},
{
"input": "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72",
"output": "-1"
},
{
"input": "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6",
"output": "-1"
},
{
"input": "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92",
"output": "-1"
},
{
"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": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99",
"output": "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0..."
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100",
"output": "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0..."
},
{
"input": "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99",
"output": "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1..."
},
{
"input": "10 100\n52 52 51 52 52 52 51 51 52 52",
"output": "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000"
},
{
"input": "10 100\n13 13 13 13 12 13 12 13 12 12",
"output": "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000"
},
{
"input": "10 100\n50 51 47 51 48 46 49 51 46 51",
"output": "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000"
},
{
"input": "10 100\n13 13 9 12 12 11 13 8 10 13",
"output": "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000"
},
{
"input": "93 91\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",
"output": "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0..."
},
{
"input": "93 97\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",
"output": "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1..."
},
{
"input": "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99",
"output": "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1..."
},
{
"input": "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0..."
},
{
"input": "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99",
"output": "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1..."
},
{
"input": "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52",
"output": "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923"
},
{
"input": "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13",
"output": "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118"
},
{
"input": "9 91\n52 51 50 52 52 51 50 48 51",
"output": "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889"
},
{
"input": "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12",
"output": "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529"
},
{
"input": "2 3\n1 1",
"output": "1.500000\n1.500000"
},
{
"input": "2 90\n0 89",
"output": "89.500000\n0.500000"
},
{
"input": "4 17\n3 4 8 1",
"output": "5.250000\n4.250000\n0.250000\n7.250000"
},
{
"input": "2 9\n5 5",
"output": "4.500000\n4.500000"
},
{
"input": "7 28\n1 3 9 10 9 6 10",
"output": "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143"
},
{
"input": "5 11\n1 2 3 4 5",
"output": "4.200000\n3.200000\n2.200000\n1.200000\n0.200000"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0.600000\n0.600000\n0.600000\n0.600000\n0.600000"
},
{
"input": "3 1\n100 100 100",
"output": "0.333333\n0.333333\n0.333333"
},
{
"input": "5 50\n2 2 3 2 2",
"output": "10.200000\n10.200000\n9.200000\n10.200000\n10.200000"
},
{
"input": "3 3\n2 2 3",
"output": "1.333333\n1.333333\n0.333333"
},
{
"input": "2 52\n2 100",
"output": "-1"
},
{
"input": "3 2\n2 2 3",
"output": "1.000000\n1.000000\n0.000000"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0.200000\n0.200000\n0.200000\n0.200000\n0.200000"
},
{
"input": "2 4\n1 2",
"output": "2.500000\n1.500000"
},
{
"input": "5 49\n1 2 3 4 5",
"output": "11.800000\n10.800000\n9.800000\n8.800000\n7.800000"
}
] | 280 | 0 | 3 | 350 |
|
886 | Petya and Catacombs | [
"dsu",
"greedy",
"implementation",
"trees"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*:
- If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13",
"output": "66"
},
{
"input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12",
"output": "71"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6",
"output": "8"
},
{
"input": "2\n0 1",
"output": "1"
}
] | 61 | 0 | 0 | 351 |
|
595 | Vitaly and Night | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'. | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 109 | 307,200 | 3 | 352 |
|
420 | Start Up | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO",
"output": "YES"
},
{
"input": "YYHUIUGYI",
"output": "NO"
},
{
"input": "TT",
"output": "YES"
},
{
"input": "UUU",
"output": "YES"
},
{
"input": "WYYW",
"output": "YES"
},
{
"input": "MITIM",
"output": "YES"
},
{
"input": "VO",
"output": "NO"
},
{
"input": "WWS",
"output": "NO"
},
{
"input": "VIYMAXXAVM",
"output": "NO"
},
{
"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM",
"output": "NO"
},
{
"input": "CC",
"output": "NO"
},
{
"input": "QOQ",
"output": "NO"
},
{
"input": "AEEA",
"output": "NO"
},
{
"input": "OQQQO",
"output": "NO"
},
{
"input": "HNCMEEMCNH",
"output": "NO"
},
{
"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ",
"output": "NO"
},
{
"input": "A",
"output": "YES"
},
{
"input": "B",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "D",
"output": "NO"
},
{
"input": "E",
"output": "NO"
},
{
"input": "F",
"output": "NO"
},
{
"input": "G",
"output": "NO"
},
{
"input": "H",
"output": "YES"
},
{
"input": "I",
"output": "YES"
},
{
"input": "J",
"output": "NO"
},
{
"input": "K",
"output": "NO"
},
{
"input": "L",
"output": "NO"
},
{
"input": "M",
"output": "YES"
},
{
"input": "N",
"output": "NO"
},
{
"input": "O",
"output": "YES"
},
{
"input": "P",
"output": "NO"
},
{
"input": "Q",
"output": "NO"
},
{
"input": "R",
"output": "NO"
},
{
"input": "S",
"output": "NO"
},
{
"input": "T",
"output": "YES"
},
{
"input": "U",
"output": "YES"
},
{
"input": "V",
"output": "YES"
},
{
"input": "W",
"output": "YES"
},
{
"input": "X",
"output": "YES"
},
{
"input": "Y",
"output": "YES"
},
{
"input": "JL",
"output": "NO"
},
{
"input": "AAAKTAAA",
"output": "NO"
},
{
"input": "AKA",
"output": "NO"
},
{
"input": "AAJAA",
"output": "NO"
},
{
"input": "ABA",
"output": "NO"
},
{
"input": "AAAAAABAAAAAA",
"output": "NO"
},
{
"input": "ZZ",
"output": "NO"
},
{
"input": "ADA",
"output": "NO"
},
{
"input": "N",
"output": "NO"
},
{
"input": "P",
"output": "NO"
},
{
"input": "LAL",
"output": "NO"
},
{
"input": "AABAA",
"output": "NO"
},
{
"input": "AZA",
"output": "NO"
},
{
"input": "V",
"output": "YES"
},
{
"input": "SSS",
"output": "NO"
},
{
"input": "NNN",
"output": "NO"
},
{
"input": "S",
"output": "NO"
},
{
"input": "I",
"output": "YES"
},
{
"input": "SS",
"output": "NO"
},
{
"input": "E",
"output": "NO"
}
] | 171 | 614,400 | 0 | 355 |
|
151 | Soft Drinking | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
"input": "2 6 4 5 6 5 1 3",
"output": "0"
},
{
"input": "1 7 3 5 3 6 2 1",
"output": "6"
},
{
"input": "2 4 5 4 5 7 3 2",
"output": "1"
},
{
"input": "2 3 6 5 7 8 2 1",
"output": "4"
},
{
"input": "1 4 5 5 3 10 3 1",
"output": "6"
},
{
"input": "1 4 6 7 3 5 1 3",
"output": "1"
},
{
"input": "1 6 5 5 5 8 3 1",
"output": "8"
},
{
"input": "1 7 5 3 3 9 2 1",
"output": "9"
},
{
"input": "3 5 3 7 6 10 3 1",
"output": "1"
},
{
"input": "3 6 3 5 3 6 3 1",
"output": "2"
},
{
"input": "1 7 5 5 5 5 2 2",
"output": "2"
},
{
"input": "2 5 3 5 6 9 2 1",
"output": "3"
},
{
"input": "3 4 3 5 3 6 2 1",
"output": "2"
},
{
"input": "1 5 5 4 7 6 3 1",
"output": "6"
},
{
"input": "2 3 7 6 5 9 3 1",
"output": "3"
},
{
"input": "2 6 5 3 3 8 1 1",
"output": "4"
},
{
"input": "2 4 7 3 4 10 2 1",
"output": "5"
},
{
"input": "1 1000 1000 1000 1000 1000 1 1",
"output": "1000"
},
{
"input": "17 1000 1000 1000 1000 1000 3 7",
"output": "8"
},
{
"input": "115 1000 1000 1000 1000 1000 17 15",
"output": "0"
},
{
"input": "1 587 981 1 2 1 1 1",
"output": "1"
},
{
"input": "1 1 2 1 2 2 1 1",
"output": "2"
}
] | 62 | 0 | 3 | 357 |
|
459 | Pashmak and Graph | [
"dp",
"sortings"
] | null | null | Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.
You are given a weighted directed graph with *n* vertices and *m* edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.
Help Pashmak, print the number of edges in the required path. | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=*min*(*n*·(*n*<=-<=1),<=3·105)). Then, *m* lines follows. The *i*-th line contains three space separated integers: *u**i*, *v**i*, *w**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 1<=≤<=*w**i*<=≤<=105) which indicates that there's a directed edge with weight *w**i* from vertex *u**i* to vertex *v**i*.
It's guaranteed that the graph doesn't contain self-loops and multiple edges. | Print a single integer — the answer to the problem. | [
"3 3\n1 2 1\n2 3 1\n3 1 1\n",
"3 3\n1 2 1\n2 3 2\n3 1 3\n",
"6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | In the first sample the maximum trail can be any of this trails: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1534088dd4d998a9bcc7e17dba96f7c213c54fc6.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample the maximum trail is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9b1d1f66686c43090329870c208942499764a73b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample the maximum trail is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1db1cef44580d43663d6896f0190e5ccee9502c9.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "3 3\n1 2 1\n2 3 1\n3 1 1",
"output": "1"
},
{
"input": "3 3\n1 2 1\n2 3 2\n3 1 3",
"output": "3"
},
{
"input": "6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4",
"output": "6"
},
{
"input": "2 2\n1 2 1\n2 1 2",
"output": "2"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 4 2",
"output": "2"
},
{
"input": "4 12\n1 2 2\n2 1 2\n1 3 1\n3 1 1\n1 4 1\n4 1 1\n2 3 1\n3 2 1\n2 4 1\n4 2 1\n3 4 2\n4 3 2",
"output": "2"
},
{
"input": "3 4\n1 2 1\n2 1 2\n2 3 2\n3 1 3",
"output": "3"
},
{
"input": "4 3\n1 2 1\n3 4 1\n2 1 2",
"output": "2"
},
{
"input": "5 8\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n1 5 1\n1 3 2\n2 4 2\n3 5 3",
"output": "2"
},
{
"input": "3 6\n1 2 1\n2 3 1\n3 1 1\n2 1 2\n3 2 4\n1 3 3",
"output": "4"
},
{
"input": "3 3\n1 2 1\n1 3 2\n3 2 3",
"output": "2"
},
{
"input": "6 7\n1 2 1\n1 5 1\n5 2 3\n2 3 3\n3 4 4\n1 6 1\n6 2 3",
"output": "3"
},
{
"input": "5 5\n1 2 3\n1 3 3\n2 3 4\n3 4 4\n4 5 5",
"output": "3"
}
] | 46 | 3,891,200 | 0 | 358 |
|
141 | Amusing Joke | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": "YES"
},
{
"input": "ONDOL\nJNPB\nONLNJBODP",
"output": "YES"
},
{
"input": "Y\nW\nYW",
"output": "YES"
},
{
"input": "OI\nM\nIMO",
"output": "YES"
},
{
"input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF",
"output": "YES"
},
{
"input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB",
"output": "NO"
},
{
"input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH",
"output": "NO"
},
{
"input": "IQ\nOQ\nQOQIGGKFNHJSGCGM",
"output": "NO"
},
{
"input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR",
"output": "YES"
},
{
"input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY",
"output": "YES"
},
{
"input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX",
"output": "YES"
},
{
"input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW",
"output": "YES"
},
{
"input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU",
"output": "YES"
},
{
"input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK",
"output": "YES"
},
{
"input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE",
"output": "NO"
},
{
"input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ",
"output": "NO"
},
{
"input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI",
"output": "NO"
},
{
"input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT",
"output": "NO"
},
{
"input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY",
"output": "NO"
},
{
"input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT",
"output": "NO"
},
{
"input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY",
"output": "NO"
},
{
"input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI",
"output": "NO"
},
{
"input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE",
"output": "NO"
},
{
"input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH",
"output": "NO"
},
{
"input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU",
"output": "NO"
},
{
"input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG",
"output": "NO"
},
{
"input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM",
"output": "NO"
},
{
"input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW",
"output": "NO"
},
{
"input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ",
"output": "YES"
},
{
"input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS",
"output": "YES"
},
{
"input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH",
"output": "YES"
},
{
"input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB",
"output": "YES"
},
{
"input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP",
"output": "YES"
},
{
"input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR",
"output": "YES"
},
{
"input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT",
"output": "YES"
},
{
"input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH",
"output": "YES"
},
{
"input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG",
"output": "YES"
},
{
"input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF",
"output": "YES"
},
{
"input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA",
"output": "NO"
},
{
"input": "IXFDY\nJRMOU\nDF",
"output": "NO"
},
{
"input": "JPSPZ\nUGCUB\nJMZZZZZZZZ",
"output": "NO"
},
{
"input": "AC\nA\nBBA",
"output": "NO"
},
{
"input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB",
"output": "NO"
},
{
"input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW",
"output": "NO"
},
{
"input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE",
"output": "NO"
},
{
"input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH",
"output": "NO"
},
{
"input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ",
"output": "NO"
},
{
"input": "GIO\nPRL\nPRL",
"output": "NO"
},
{
"input": "A\nB\nABC",
"output": "NO"
},
{
"input": "KKK\nKKK\nZZZZZ",
"output": "NO"
},
{
"input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA",
"output": "NO"
}
] | 62 | 0 | 3 | 359 |
|
762 | k-th divisor | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"output": "-1"
},
{
"input": "1000000000000000 1000000000",
"output": "-1"
},
{
"input": "1000000000000000 100",
"output": "1953125"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "9 3",
"output": "9"
},
{
"input": "21 3",
"output": "7"
},
{
"input": "67280421310721 1",
"output": "1"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "16 3",
"output": "4"
},
{
"input": "1 1000",
"output": "-1"
},
{
"input": "16 4",
"output": "8"
},
{
"input": "36 8",
"output": "18"
},
{
"input": "49 4",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "16 1",
"output": "1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "16 5",
"output": "16"
},
{
"input": "25 4",
"output": "-1"
},
{
"input": "4010815561 2",
"output": "63331"
},
{
"input": "49 3",
"output": "49"
},
{
"input": "36 6",
"output": "9"
},
{
"input": "36 10",
"output": "-1"
},
{
"input": "25 3",
"output": "25"
},
{
"input": "22876792454961 28",
"output": "7625597484987"
},
{
"input": "1234 2",
"output": "2"
},
{
"input": "179458711 2",
"output": "179458711"
},
{
"input": "900104343024121 100000",
"output": "-1"
},
{
"input": "8 3",
"output": "4"
},
{
"input": "100 6",
"output": "20"
},
{
"input": "15500 26",
"output": "-1"
},
{
"input": "111111 1",
"output": "1"
},
{
"input": "100000000000000 200",
"output": "160000000000"
},
{
"input": "1000000000000 100",
"output": "6400000"
},
{
"input": "100 10",
"output": "-1"
},
{
"input": "1000000000039 2",
"output": "1000000000039"
},
{
"input": "64 5",
"output": "16"
},
{
"input": "999999961946176 33",
"output": "63245552"
},
{
"input": "376219076689 3",
"output": "376219076689"
},
{
"input": "999999961946176 63",
"output": "999999961946176"
},
{
"input": "1048576 12",
"output": "2048"
},
{
"input": "745 21",
"output": "-1"
},
{
"input": "748 6",
"output": "22"
},
{
"input": "999999961946176 50",
"output": "161082468097"
},
{
"input": "10 3",
"output": "5"
},
{
"input": "1099511627776 22",
"output": "2097152"
},
{
"input": "1000000007 100010",
"output": "-1"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "100 8",
"output": "50"
},
{
"input": "100 7",
"output": "25"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "999999961946176 64",
"output": "-1"
},
{
"input": "20 5",
"output": "10"
},
{
"input": "999999999999989 2",
"output": "999999999999989"
},
{
"input": "100000000000000 114",
"output": "10240000"
},
{
"input": "99999640000243 3",
"output": "9999991"
},
{
"input": "999998000001 566",
"output": "333332666667"
},
{
"input": "99999820000081 2",
"output": "9999991"
},
{
"input": "49000042000009 3",
"output": "49000042000009"
},
{
"input": "151491429961 4",
"output": "-1"
},
{
"input": "32416190071 2",
"output": "32416190071"
},
{
"input": "1000 8",
"output": "25"
},
{
"input": "1999967841 15",
"output": "1999967841"
},
{
"input": "26880 26880",
"output": "-1"
},
{
"input": "151491429961 3",
"output": "151491429961"
},
{
"input": "90000000000 300",
"output": "100000000"
},
{
"input": "98765004361 10",
"output": "-1"
},
{
"input": "15 2",
"output": "3"
},
{
"input": "16 2",
"output": "2"
},
{
"input": "1996 2",
"output": "2"
},
{
"input": "1997 2",
"output": "1997"
},
{
"input": "1999 2",
"output": "1999"
},
{
"input": "1998 2",
"output": "2"
},
{
"input": "1998 1",
"output": "1"
},
{
"input": "1998 7",
"output": "27"
},
{
"input": "1998 8",
"output": "37"
},
{
"input": "100000380000361 2",
"output": "10000019"
},
{
"input": "15 1",
"output": "1"
},
{
"input": "100000000000000 226",
"output": "-1"
},
{
"input": "844030857550613 517",
"output": "-1"
},
{
"input": "4567890 14",
"output": "430"
},
{
"input": "123123123 123123123",
"output": "-1"
},
{
"input": "24 4",
"output": "4"
},
{
"input": "999999993568952 17",
"output": "31622777"
},
{
"input": "99999999994190 9",
"output": "241656799"
},
{
"input": "999997874844049 4",
"output": "-1"
},
{
"input": "99999999999931 2",
"output": "99999999999931"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "67280421310721 2",
"output": "67280421310721"
}
] | 2,000 | 5,324,800 | 0 | 360 |
|
798 | Mike and palindrome | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input": "gqrk",
"output": "NO"
},
{
"input": "glxlg",
"output": "YES"
},
{
"input": "czhfc",
"output": "YES"
},
{
"input": "broon",
"output": "NO"
},
{
"input": "rmggmr",
"output": "NO"
},
{
"input": "wvxxzw",
"output": "YES"
},
{
"input": "ukvciu",
"output": "NO"
},
{
"input": "vrnwnrv",
"output": "YES"
},
{
"input": "vlkjkav",
"output": "YES"
},
{
"input": "guayhmg",
"output": "NO"
},
{
"input": "lkvhhvkl",
"output": "NO"
},
{
"input": "ffdsslff",
"output": "YES"
},
{
"input": "galjjtyw",
"output": "NO"
},
{
"input": "uosgwgsou",
"output": "YES"
},
{
"input": "qjwmjmljq",
"output": "YES"
},
{
"input": "ustrvrodf",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "qjfyjjyfjq",
"output": "NO"
},
{
"input": "ysxibbixsq",
"output": "YES"
},
{
"input": "howfslfwmh",
"output": "NO"
},
{
"input": "ekhajrjahke",
"output": "YES"
},
{
"input": "ucnolsloncw",
"output": "YES"
},
{
"input": "jrzsfrrkrtj",
"output": "NO"
},
{
"input": "typayzzyapyt",
"output": "NO"
},
{
"input": "uwdhkzokhdwu",
"output": "YES"
},
{
"input": "xokxpyyuafij",
"output": "NO"
},
{
"input": "eusneioiensue",
"output": "YES"
},
{
"input": "fuxpuajabpxuf",
"output": "YES"
},
{
"input": "guvggtfhlgruy",
"output": "NO"
},
{
"input": "cojhkhxxhkhjoc",
"output": "NO"
},
{
"input": "mhifbmmmmbmihm",
"output": "YES"
},
{
"input": "kxfqqncnebpami",
"output": "NO"
},
{
"input": "scfwrjevejrwfcs",
"output": "YES"
},
{
"input": "thdaonpepdoadht",
"output": "YES"
},
{
"input": "jsfzcbnhsccuqsj",
"output": "NO"
},
{
"input": "nn",
"output": "NO"
},
{
"input": "nm",
"output": "YES"
},
{
"input": "jdj",
"output": "YES"
},
{
"input": "bbcaa",
"output": "NO"
},
{
"input": "abcde",
"output": "NO"
},
{
"input": "abcdf",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "abecd",
"output": "NO"
},
{
"input": "abccacb",
"output": "NO"
},
{
"input": "aabc",
"output": "NO"
},
{
"input": "anpqb",
"output": "NO"
},
{
"input": "c",
"output": "YES"
},
{
"input": "abcdefg",
"output": "NO"
},
{
"input": "aanbb",
"output": "NO"
},
{
"input": "aabbb",
"output": "NO"
},
{
"input": "aaabbab",
"output": "NO"
},
{
"input": "ab",
"output": "YES"
},
{
"input": "aabbc",
"output": "NO"
},
{
"input": "ecabd",
"output": "NO"
},
{
"input": "abcdrty",
"output": "NO"
},
{
"input": "abcdmnp",
"output": "NO"
},
{
"input": "bbbbbb",
"output": "NO"
},
{
"input": "abcxuio",
"output": "NO"
},
{
"input": "abcdabcde",
"output": "NO"
},
{
"input": "abcxpoi",
"output": "NO"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "aacbb",
"output": "NO"
},
{
"input": "abcedca",
"output": "NO"
},
{
"input": "abcdd",
"output": "NO"
},
{
"input": "abbcs",
"output": "NO"
},
{
"input": "aaabccc",
"output": "NO"
},
{
"input": "paxkxbq",
"output": "NO"
},
{
"input": "z",
"output": "YES"
},
{
"input": "b",
"output": "YES"
},
{
"input": "abcdefghi",
"output": "NO"
},
{
"input": "abcqr",
"output": "NO"
},
{
"input": "abcdc",
"output": "NO"
},
{
"input": "abcb",
"output": "NO"
},
{
"input": "aabcd",
"output": "NO"
},
{
"input": "abbba",
"output": "YES"
},
{
"input": "aaabbb",
"output": "NO"
},
{
"input": "bb",
"output": "NO"
},
{
"input": "aaacbbb",
"output": "NO"
},
{
"input": "abbzcca",
"output": "NO"
},
{
"input": "abxab",
"output": "NO"
},
{
"input": "bbb",
"output": "YES"
},
{
"input": "abcrtyu",
"output": "NO"
},
{
"input": "cbacb",
"output": "NO"
},
{
"input": "acbb",
"output": "NO"
},
{
"input": "ww",
"output": "NO"
},
{
"input": "aaaaaa",
"output": "NO"
},
{
"input": "jizzz",
"output": "NO"
},
{
"input": "aaakcba",
"output": "NO"
},
{
"input": "acbak",
"output": "NO"
},
{
"input": "bddeffd",
"output": "NO"
},
{
"input": "aaa",
"output": "YES"
},
{
"input": "afghqwe",
"output": "NO"
},
{
"input": "abcdfga",
"output": "NO"
}
] | 46 | 0 | 0 | 361 |
|
10 | Power Consumption Calculation | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work. | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "52870"
},
{
"input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245",
"output": "46995"
},
{
"input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434",
"output": "85540"
},
{
"input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357",
"output": "67147"
},
{
"input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422",
"output": "85876"
},
{
"input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282",
"output": "38570"
},
{
"input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431",
"output": "11134"
},
{
"input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424",
"output": "59043"
},
{
"input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369",
"output": "53608"
},
{
"input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438",
"output": "84067"
},
{
"input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439",
"output": "79844"
},
{
"input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437",
"output": "82686"
},
{
"input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437",
"output": "92356"
},
{
"input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434",
"output": "107490"
},
{
"input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401",
"output": "25258"
},
{
"input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419",
"output": "23992"
}
] | 280 | 20,172,800 | 3.822425 | 362 |
245 | Internet Address | [
"implementation",
"strings"
] | null | null | Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
where:
- <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), - <domain> is a non-empty string, consisting of lowercase English letters, - the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters.
If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context).
When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".".
Help Vasya to restore the possible address of the recorded Internet resource. | The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.
It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. | Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. | [
"httpsunrux\n",
"ftphttprururu\n"
] | [
"http://sun.ru/x\n",
"ftp://http.ru/ruru\n"
] | In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". | [
{
"input": "httpsunrux",
"output": "http://sun.ru/x"
},
{
"input": "ftphttprururu",
"output": "ftp://http.ru/ruru"
},
{
"input": "httpuururrururruruurururrrrrurrurrurruruuruuu",
"output": "http://uu.ru/rrururruruurururrrrrurrurrurruruuruuu"
},
{
"input": "httpabuaruauabbaruru",
"output": "http://abua.ru/auabbaruru"
},
{
"input": "httpuurrruurruuruuruuurrrurururuurruuuuuuruurr",
"output": "http://uurr.ru/urruuruuruuurrrurururuurruuuuuuruurr"
},
{
"input": "httpruhhphhhpuhruruhhpruhhphruhhru",
"output": "http://ruhhphhhpuh.ru/ruhhpruhhphruhhru"
},
{
"input": "httpftprftprutprururftruruftptp",
"output": "http://ftprftp.ru/tprururftruruftptp"
},
{
"input": "httpfttpftpfttftpftpftppfrurururu",
"output": "http://fttpftpfttftpftpftppf.ru/rururu"
},
{
"input": "httpruhttttpruhttprupruhttpruhtturuhttphtruuru",
"output": "http://ruhttttp.ru/httprupruhttpruhtturuhttphtruuru"
},
{
"input": "httpsjkazaaghasjkasjkabruru",
"output": "http://sjkazaaghasjkasjkab.ru/ru"
},
{
"input": "httpftphttptphttphrururuhpftphtpftphtpftphtptpft",
"output": "http://ftphttptphttph.ru/ruruhpftphtpftphtpftphtptpft"
},
{
"input": "httpppppru",
"output": "http://pppp.ru"
},
{
"input": "ftprrurururrurururuurrururruuru",
"output": "ftp://r.ru/rururrurururuurrururruuru"
},
{
"input": "ftpabaruru",
"output": "ftp://aba.ru/ru"
},
{
"input": "ftpruurruurururururuuruuur",
"output": "ftp://ruur.ru/urururururuuruuur"
},
{
"input": "ftphhphruhhpruhhpuhhpuruhhphruhhruhhpuhhru",
"output": "ftp://hhph.ru/hhpruhhpuhhpuruhhphruhhruhhpuhhru"
},
{
"input": "ftparua",
"output": "ftp://a.ru/a"
},
{
"input": "httpzru",
"output": "http://z.ru"
},
{
"input": "httprrur",
"output": "http://r.ru/r"
},
{
"input": "ftprru",
"output": "ftp://r.ru"
}
] | 92 | 5,632,000 | 0 | 365 |
|
725 | Food on the Plane | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch. | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integer — the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d",
"output": "3999999999999999994"
},
{
"input": "999999999999999997a",
"output": "3999999999999999988"
},
{
"input": "1c",
"output": "6"
},
{
"input": "1d",
"output": "3"
},
{
"input": "1e",
"output": "2"
},
{
"input": "1a",
"output": "4"
},
{
"input": "2a",
"output": "11"
},
{
"input": "2b",
"output": "12"
},
{
"input": "2e",
"output": "9"
},
{
"input": "2f",
"output": "8"
},
{
"input": "3a",
"output": "4"
},
{
"input": "3b",
"output": "5"
},
{
"input": "3c",
"output": "6"
},
{
"input": "3d",
"output": "3"
},
{
"input": "3e",
"output": "2"
},
{
"input": "3f",
"output": "1"
},
{
"input": "4b",
"output": "12"
},
{
"input": "4c",
"output": "13"
},
{
"input": "4d",
"output": "10"
},
{
"input": "4e",
"output": "9"
},
{
"input": "4f",
"output": "8"
},
{
"input": "999999997a",
"output": "3999999988"
},
{
"input": "999999997b",
"output": "3999999989"
},
{
"input": "999999997c",
"output": "3999999990"
},
{
"input": "999999997d",
"output": "3999999987"
},
{
"input": "999999997e",
"output": "3999999986"
},
{
"input": "999999997f",
"output": "3999999985"
},
{
"input": "999999998a",
"output": "3999999995"
},
{
"input": "999999998b",
"output": "3999999996"
},
{
"input": "999999998c",
"output": "3999999997"
},
{
"input": "999999998d",
"output": "3999999994"
},
{
"input": "999999998e",
"output": "3999999993"
},
{
"input": "999999998f",
"output": "3999999992"
},
{
"input": "999999999a",
"output": "3999999988"
},
{
"input": "999999999b",
"output": "3999999989"
},
{
"input": "999999999c",
"output": "3999999990"
},
{
"input": "999999999d",
"output": "3999999987"
},
{
"input": "999999999e",
"output": "3999999986"
},
{
"input": "999999999f",
"output": "3999999985"
},
{
"input": "1000000000a",
"output": "3999999995"
},
{
"input": "1000000000b",
"output": "3999999996"
},
{
"input": "1000000000c",
"output": "3999999997"
},
{
"input": "1000000000d",
"output": "3999999994"
},
{
"input": "1000000000e",
"output": "3999999993"
},
{
"input": "1000000000f",
"output": "3999999992"
},
{
"input": "100000b",
"output": "399996"
},
{
"input": "100000f",
"output": "399992"
},
{
"input": "100001d",
"output": "400003"
},
{
"input": "100001e",
"output": "400002"
},
{
"input": "100001f",
"output": "400001"
},
{
"input": "100002a",
"output": "400011"
},
{
"input": "100002b",
"output": "400012"
},
{
"input": "100002d",
"output": "400010"
},
{
"input": "1231273a",
"output": "4925092"
},
{
"input": "82784f",
"output": "331128"
},
{
"input": "88312c",
"output": "353245"
},
{
"input": "891237e",
"output": "3564946"
},
{
"input": "999999999999999997b",
"output": "3999999999999999989"
},
{
"input": "999999999999999997c",
"output": "3999999999999999990"
},
{
"input": "999999999999999997d",
"output": "3999999999999999987"
},
{
"input": "999999999999999997e",
"output": "3999999999999999986"
},
{
"input": "999999999999999997f",
"output": "3999999999999999985"
},
{
"input": "999999999999999998a",
"output": "3999999999999999995"
},
{
"input": "999999999999999998b",
"output": "3999999999999999996"
},
{
"input": "999999999999999998c",
"output": "3999999999999999997"
},
{
"input": "999999999999999998d",
"output": "3999999999999999994"
},
{
"input": "999999999999999998e",
"output": "3999999999999999993"
},
{
"input": "999999999999999998f",
"output": "3999999999999999992"
},
{
"input": "999999999999999999a",
"output": "3999999999999999988"
},
{
"input": "999999999999999999b",
"output": "3999999999999999989"
},
{
"input": "999999999999999999c",
"output": "3999999999999999990"
},
{
"input": "999999999999999999d",
"output": "3999999999999999987"
},
{
"input": "1000000000000000000a",
"output": "3999999999999999995"
},
{
"input": "1000000000000000000e",
"output": "3999999999999999993"
},
{
"input": "1000000000000000000f",
"output": "3999999999999999992"
},
{
"input": "1000000000000000000c",
"output": "3999999999999999997"
},
{
"input": "97a",
"output": "388"
},
{
"input": "6f",
"output": "24"
},
{
"input": "7f",
"output": "17"
},
{
"input": "7e",
"output": "18"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "7a",
"output": "20"
},
{
"input": "8f",
"output": "24"
},
{
"input": "999999999999999992a",
"output": "3999999999999999963"
},
{
"input": "999999999999999992b",
"output": "3999999999999999964"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "999999999999999992d",
"output": "3999999999999999962"
},
{
"input": "999999999999999992e",
"output": "3999999999999999961"
},
{
"input": "999999999999999992f",
"output": "3999999999999999960"
},
{
"input": "999999999999999993a",
"output": "3999999999999999972"
},
{
"input": "999999999999999993b",
"output": "3999999999999999973"
},
{
"input": "999999999999999993c",
"output": "3999999999999999974"
},
{
"input": "999999999999999993d",
"output": "3999999999999999971"
},
{
"input": "999999999999999993e",
"output": "3999999999999999970"
},
{
"input": "999999999999999993f",
"output": "3999999999999999969"
},
{
"input": "999999999999999994a",
"output": "3999999999999999979"
},
{
"input": "999999999999999994b",
"output": "3999999999999999980"
},
{
"input": "999999999999999994c",
"output": "3999999999999999981"
},
{
"input": "999999999999999994d",
"output": "3999999999999999978"
},
{
"input": "999999999999999994e",
"output": "3999999999999999977"
},
{
"input": "999999999999999994f",
"output": "3999999999999999976"
},
{
"input": "999999999999999995a",
"output": "3999999999999999972"
},
{
"input": "999999999999999995b",
"output": "3999999999999999973"
},
{
"input": "999999999999999995c",
"output": "3999999999999999974"
},
{
"input": "999999999999999995d",
"output": "3999999999999999971"
},
{
"input": "999999999999999995e",
"output": "3999999999999999970"
},
{
"input": "999999999999999995f",
"output": "3999999999999999969"
},
{
"input": "10a",
"output": "43"
},
{
"input": "11f",
"output": "33"
},
{
"input": "681572647b",
"output": "2726290581"
},
{
"input": "23f",
"output": "81"
},
{
"input": "123a",
"output": "484"
},
{
"input": "999999888888777777a",
"output": "3999999555555111108"
}
] | 109 | 0 | 3 | 366 |
|
181 | Number of Triplets | [
"binary search",
"brute force"
] | null | null | You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C*) and (*C*,<=*B*,<=*A*) are considered the same. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points.
Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000).
It is guaranteed that all given points are different. | Print the single number — the answer to the problem. | [
"3\n1 1\n2 2\n3 3\n",
"3\n0 0\n-1 0\n0 1\n"
] | [
"1\n",
"0\n"
] | none | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "1"
},
{
"input": "3\n0 0\n-1 0\n0 1",
"output": "0"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0",
"output": "2"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5",
"output": "4"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 0",
"output": "3"
},
{
"input": "9\n1 1\n1 0\n0 1\n0 0\n-1 0\n-1 1\n-1 -1\n1 -1\n0 -1",
"output": "8"
},
{
"input": "10\n2 1\n-1 0\n-2 -1\n-1 1\n0 2\n2 -2\n0 0\n-2 -2\n0 -2\n-2 1",
"output": "4"
},
{
"input": "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2",
"output": "4"
},
{
"input": "10\n0 1\n-1 -1\n1 1\n-1 0\n1 -1\n-2 -1\n-2 2\n-2 0\n0 -2\n0 -1",
"output": "5"
},
{
"input": "10\n2 1\n-1 1\n0 0\n-3 1\n-2 -3\n-1 -2\n-1 -1\n1 2\n3 -2\n0 -2",
"output": "1"
},
{
"input": "20\n-3 -3\n0 4\n-3 1\n1 1\n-1 2\n-4 4\n3 -1\n-3 0\n0 2\n4 0\n2 3\n2 4\n4 -3\n-4 3\n-1 1\n1 3\n-2 4\n1 -2\n1 -1\n3 0",
"output": "10"
},
{
"input": "20\n-3 -3\n0 4\n-3 1\n1 1\n-1 2\n-4 4\n3 -1\n-3 0\n0 2\n4 0\n2 3\n2 4\n4 -3\n-4 3\n-1 1\n1 3\n-2 4\n1 -2\n1 -1\n3 0",
"output": "10"
},
{
"input": "20\n-1 18\n-2 5\n-5 4\n2 -33\n9 -18\n0 0\n11 -22\n2 0\n-1 2\n-4 41\n1 6\n1 -2\n6 -12\n0 1\n-3 6\n3 -6\n3 -8\n-1 4\n2 -5\n1 0",
"output": "21"
},
{
"input": "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-4 5\n181 -262\n76 -118\n0 0\n-7 18\n-58 104\n-5 6\n-6 12\n-3 4\n1 0\n11 -10\n-86 130\n-3 6\n153 -236\n-183 270\n-33 64",
"output": "57"
},
{
"input": "3\n3 3\n1 2\n1 1",
"output": "0"
},
{
"input": "3\n0 0\n0 -1\n0 1",
"output": "1"
}
] | 60 | 0 | 0 | 367 |
|
186 | Comparing Strings | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "YES"
},
{
"input": "qxolmbkkt\naovlajmlf",
"output": "NO"
},
{
"input": "b\ng",
"output": "NO"
},
{
"input": "ab\naba",
"output": "NO"
},
{
"input": "ba\na",
"output": "NO"
},
{
"input": "a\nab",
"output": "NO"
},
{
"input": "a\naa",
"output": "NO"
},
{
"input": "a\nz",
"output": "NO"
},
{
"input": "aabb\nbbaa",
"output": "NO"
},
{
"input": "ab\nbd",
"output": "NO"
},
{
"input": "bac\ndae",
"output": "NO"
},
{
"input": "abc\nakl",
"output": "NO"
},
{
"input": "cb\naa",
"output": "NO"
},
{
"input": "abaab\naabba",
"output": "NO"
},
{
"input": "aab\naaa",
"output": "NO"
},
{
"input": "abcde\nedcba",
"output": "NO"
},
{
"input": "abab\nbaba",
"output": "NO"
},
{
"input": "ab\nbac",
"output": "NO"
},
{
"input": "abcd\naqcb",
"output": "NO"
},
{
"input": "abc\nbad",
"output": "NO"
},
{
"input": "ab\nca",
"output": "NO"
},
{
"input": "abc\nab",
"output": "NO"
},
{
"input": "ab\nbae",
"output": "NO"
},
{
"input": "aaaabcccca\naaaadccccb",
"output": "NO"
},
{
"input": "acaa\nabca",
"output": "NO"
},
{
"input": "aba\naab",
"output": "YES"
},
{
"input": "ah\nla",
"output": "NO"
},
{
"input": "aab\naa",
"output": "NO"
},
{
"input": "abab\nabcd",
"output": "NO"
},
{
"input": "ed\nab",
"output": "NO"
}
] | 280 | 409,600 | 0 | 368 |
Subsets and Splits