Search is not available for this dataset
problem_id
stringlengths 32
32
| name
stringlengths 2
112
| problem
stringlengths 200
14k
| test_cases
stringlengths 33
79.2M
| difficulty
stringclasses 33
values | language
sequencelengths 1
1
| source
stringclasses 14
values | num_solutions
int64 2
1.9M
| starter_code
stringlengths 0
1.47k
| subset
stringclasses 3
values |
---|---|---|---|---|---|---|---|---|---|
a619d42eed633f3050df62f94d10b7c1 | King's Path | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the *i*-th row and *j*-th column as (*i*,<=*j*).
You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as *n* segments. Each segment is described by three integers *r**i*,<=*a**i*,<=*b**i* (*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed.
Your task is to find the minimum number of moves the king needs to get from square (*x*0,<=*y*0) to square (*x*1,<=*y*1), provided that he only moves along the allowed cells. In other words, the king can be located only on allowed cells on his way.
Let us remind you that a chess king can move to any of the neighboring cells in one move. Two cells of a chess field are considered neighboring if they share at least one point.
The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contain the descriptions of these segments. The *i*-th line contains three space-separated integers *r**i*,<=*a**i*,<=*b**i* (1<=≤<=*r**i*,<=*a**i*,<=*b**i*<=≤<=109,<=*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed. Note that the segments of the allowed cells can intersect and embed arbitrarily.
It is guaranteed that the king's initial and final position are allowed cells. It is guaranteed that the king's initial and the final positions do not coincide. It is guaranteed that the total length of all given segments doesn't exceed 105.
If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one.
Sample Input
5 7 6 11
3
5 3 8
6 7 11
5 2 5
3 4 3 10
3
3 1 4
4 5 9
3 10 10
1 1 2 10
2
1 1 3
2 6 10
Sample Output
4
6
-1
| {"inputs": ["5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5", "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10", "1 1 2 10\n2\n1 1 3\n2 6 10", "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10 10", "6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15\n7 14 14\n8 15 15", "13 16 20 10\n18\n13 16 16\n20 10 10\n19 10 10\n12 15 15\n20 10 10\n18 11 11\n19 10 10\n19 10 10\n20 10 10\n19 10 10\n20 10 10\n20 10 10\n19 10 10\n18 11 11\n13 16 16\n12 15 15\n19 10 10\n19 10 10", "89 29 88 30\n16\n87 31 31\n14 95 95\n98 88 89\n96 88 88\n14 97 97\n13 97 98\n100 88 88\n88 32 32\n99 88 89\n90 29 29\n87 31 31\n15 94 96\n89 29 29\n88 32 32\n97 89 89\n88 29 30", "30 14 39 19\n31\n35 7 11\n37 11 12\n32 13 13\n37 5 6\n46 13 13\n37 14 14\n31 13 13\n43 13 19\n45 15 19\n46 13 13\n32 17 17\n41 14 19\n30 14 14\n43 13 17\n34 16 18\n44 11 19\n38 13 13\n40 12 20\n37 16 18\n46 16 18\n34 10 14\n36 9 10\n36 15 19\n38 15 19\n42 13 19\n33 14 15\n35 15 19\n33 17 18\n39 12 20\n36 5 7\n45 12 12", "2 1 1 1\n2\n1 1 2\n2 1 2", "1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200", "1 1 1000000000 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200"], "outputs": ["4", "6", "-1", "2", "1", "-1", "1", "9", "1", "1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 68 | codeforces |
|
a645e12baf8641d60fc64287c60ce752 | Trains | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106).
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Sample Input
3 7
5 3
2 3
Sample Output
Dasha
Masha
Equal
| {"inputs": ["3 7", "5 3", "2 3", "31 88", "8 75", "32 99", "77 4", "27 1", "84 11", "4 6", "52 53", "397 568", "22 332", "419 430", "638 619", "393 325", "876 218", "552 551", "906 912", "999 996", "652 653", "3647 7698", "2661 8975", "251 9731", "9886 8671", "8545 7312", "4982 2927", "7660 7658", "9846 9844", "9632 9640", "5036 5037", "64854 77725", "4965 85708", "20393 86640", "99207 30728", "77545 13842", "30362 10712", "51291 51292", "55381 55382", "91560 91550", "99087 99090", "983794 986389", "779183 786727", "450766 610961", "664690 630787", "461363 256765", "638067 409048", "929061 929052", "996219 996216", "716249 716248", "782250 782252", "1 2", "2 1", "999999 1000000", "999997 1000000", "1000000 999993", "999983 999979"], "outputs": ["Dasha", "Masha", "Equal", "Dasha", "Dasha", "Dasha", "Masha", "Masha", "Masha", "Equal", "Equal", "Dasha", "Dasha", "Dasha", "Masha", "Masha", "Masha", "Equal", "Equal", "Equal", "Equal", "Dasha", "Dasha", "Dasha", "Masha", "Masha", "Masha", "Equal", "Equal", "Equal", "Equal", "Dasha", "Dasha", "Dasha", "Masha", "Masha", "Masha", "Equal", "Equal", "Equal", "Equal", "Dasha", "Dasha", "Dasha", "Masha", "Masha", "Masha", "Equal", "Equal", "Equal", "Equal", "Equal", "Equal", "Equal", "Dasha", "Masha", "Masha"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 91 | codeforces |
|
a64bde11b9445dc1e39be04d2fceef00 | Modified GCD | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Sample Input
9 27
3
1 5
10 11
9 11
Sample Output
3
-1
9
| {"inputs": ["9 27\n3\n1 5\n10 11\n9 11", "48 72\n2\n8 29\n29 37", "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90", "84 36\n1\n18 32", "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36", "84 90\n18\n10 75\n2 40\n30 56\n49 62\n19 33\n5 79\n61 83\n13 56\n73 78\n1 18\n23 35\n14 72\n22 33\n1 21\n8 38\n54 82\n6 80\n57 75", "84 100\n16\n10 64\n3 61\n19 51\n42 67\n51 68\n12 40\n10 47\n52 53\n37 67\n2 26\n23 47\n17 75\n49 52\n3 83\n63 81\n8 43", "36 60\n2\n17 25\n16 20", "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57", "90 36\n8\n1 19\n10 12\n14 28\n21 24\n8 8\n33 34\n10 26\n15 21", "48 80\n19\n1 1\n16 16\n1 16\n16 48\n16 80\n16 1000000000\n1000000000 1000000000\n1 1000000000\n500000000 1000000000\n15 17\n17 17\n15 15\n8 8\n8 15\n8 16\n8 17\n7 17\n7 15\n9 15", "31607 999002449\n18\n31607 31607\n31606 31608\n31607 31608\n31606 31607\n31606 31606\n31608 31608\n1 31607\n1 31606\n1 31608\n1 1000000000\n31607 1000000000\n31606 1000000000\n31608 1000000000\n1000000000 1000000000\n1 1\n2 31606\n2 31607\n2 31608", "999999937 999999929\n12\n999999929 999999937\n1 1\n1 1000000000\n2 1000000000\n1 2\n999999937 999999937\n999999929 999999929\n2 2\n3 3\n1 100\n1 999999937\n1 999999929"], "outputs": ["3\n-1\n9", "24\n-1", "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1", "-1", "-1\n18\n18\n-1\n6\n-1\n9\n9\n18\n-1\n18\n18\n9\n2\n-1\n18", "-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n6\n-1", "-1\n4\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n4\n-1\n-1\n-1\n4\n-1\n-1", "-1\n-1", "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1", "18\n-1\n18\n-1\n-1\n-1\n18\n18", "1\n16\n16\n16\n16\n16\n-1\n16\n-1\n16\n-1\n-1\n8\n8\n16\n16\n16\n8\n-1", "31607\n31607\n31607\n31607\n-1\n-1\n31607\n1\n31607\n31607\n31607\n31607\n-1\n-1\n1\n-1\n31607\n31607", "-1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 62 | codeforces |
|
a65a8ddec22e98a4bdf4fef23ccebc2e | Animals | Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.
DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly *n* days in DravDe’s dream and the animal that came on the *i*-th day, ate exactly *c**i* tons of food daily starting from day *i*. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly *X* tons of food on the farm.
DravDe woke up terrified...
When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the *n*-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.
It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the *n*-th.
The first input line contains integers *n* and *X* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*X*<=≤<=104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers *c**i* (1<=≤<=*c**i*<=≤<=300). Numbers in the second line are divided by a space.
Output the only number — the maximum possible amount of animals on the farm by the end of the *n*-th day given that the food was enough for everybody.
Sample Input
3 4
1 1 1
3 6
1 1 1
Sample Output
2
3
| {"inputs": ["3 4\n1 1 1", "3 6\n1 1 1", "1 12\n1", "3 100\n1 1 1", "5 75\n1 1 1 1 1", "7 115\n1 1 1 1 1 1 1", "10 1055\n7 1 1 2 8 7 8 2 5 8", "7 3623\n20 14 24 4 14 14 24", "10 3234\n24 2 28 18 6 15 31 2 28 16", "15 402\n3 3 3 3 2 2 3 3 3 3 3 3 2 2 1", "25 5523\n24 29 6 35 11 7 24 10 17 43 2 25 15 36 31 8 22 40 23 23 7 24 5 16 24", "50 473\n3 2 2 1 1 3 3 2 1 3 2 3 1 1 3 1 3 2 2 1 2 3 1 3 2 2 1 1 1 3 1 3 4 4 1 3 4 4 4 1 1 3 1 3 1 2 2 1 4 2", "100 4923\n21 5 18 2 9 4 22 17 8 25 20 11 17 25 18 14 25 12 21 13 22 4 6 21 1 12 12 7 20 16 12 17 28 4 17 14 6 2 5 20 20 14 6 30 4 24 18 24 7 18 24 23 33 16 16 24 21 22 11 18 34 19 32 21 1 34 8 9 9 13 4 7 18 8 33 24 9 2 24 35 8 35 35 38 11 23 14 42 43 44 7 43 37 21 8 17 3 9 33 43", "25 101\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", "45 9343\n36 16 13 20 48 5 45 48 54 16 42 40 66 31 18 59 24 66 72 32 65 54 55 72 1 1 36 13 59 16 42 2 72 70 7 40 85 65 40 20 68 89 37 16 46", "75 8333\n27 41 40 42 1 23 25 25 9 12 36 20 19 13 8 49 16 11 17 7 19 25 46 6 33 27 48 37 46 44 5 5 33 8 49 20 49 51 42 2 43 26 4 60 50 25 41 60 53 25 49 28 45 66 26 39 60 58 53 64 44 50 18 29 67 10 63 44 55 26 20 60 35 43 65", "100 115\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", "100 1150\n5 3 1 4 2 4 1 1 3 2 1 5 6 3 1 6 3 4 1 3 3 5 2 3 1 5 3 1 3 5 3 1 6 2 3 2 3 2 3 6 3 5 4 6 4 5 3 6 1 2 3 2 1 2 5 1 6 7 4 8 4 4 6 1 6 5 6 7 8 2 5 6 6 2 1 1 9 1 5 6 7 7 2 9 5 1 7 1 2 2 7 6 4 2 1 8 11 8 6 6", "100 3454\n9 3 3 15 14 8 8 14 13 2 16 4 16 4 13 8 14 1 15 7 19 12 9 19 17 17 18 16 10 1 20 8 16 5 12 18 6 5 5 13 12 15 18 4 20 16 3 18 13 22 5 1 23 20 10 21 20 8 9 5 7 23 24 20 1 25 7 19 1 6 14 8 23 26 18 14 11 26 12 11 8 5 10 28 22 8 5 12 28 8 7 8 22 31 31 30 28 33 24 31", "100 8777\n38 4 2 14 30 45 20 17 25 14 12 44 11 11 5 30 16 3 48 14 42 48 9 4 1 30 9 13 23 15 24 31 16 12 23 20 1 4 20 18 41 47 27 5 50 12 41 33 25 16 1 46 41 59 27 57 24 6 33 62 27 50 54 28 48 11 37 23 31 29 21 32 25 47 15 9 41 26 70 26 58 62 42 10 39 38 25 55 69 72 5 31 30 21 43 59 39 83 67 45", "100 10\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", "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100 1000\n3 2 4 5 3 4 5 3 2 5 3 3 1 1 1 3 5 1 2 2 5 3 2 4 4 1 5 1 1 3 4 4 1 4 3 5 2 1 1 6 6 2 2 6 5 1 6 4 5 2 1 2 2 5 5 2 1 5 7 4 4 1 4 4 5 3 4 4 1 6 3 2 4 5 2 6 3 6 5 5 2 4 6 3 7 1 5 4 7 2 5 5 6 3 8 5 9 9 3 3", "100 10000\n9 24 4 16 15 28 18 5 16 52 19 12 52 31 6 53 20 44 17 3 51 51 21 53 27 3 40 15 42 34 54 6 55 24 32 53 35 25 38 2 19 7 26 8 46 32 10 25 24 50 65 6 21 26 25 62 12 67 45 34 50 46 59 40 18 55 41 36 48 13 29 76 52 46 57 30 10 60 43 26 73 21 19 68 20 76 67 29 8 46 27 33 22 74 58 91 27 89 50 42", "100 9999\n31 26 2 16 41 42 44 30 28 9 15 49 19 8 34 52 19 36 30 43 53 53 43 18 38 3 56 3 4 51 6 44 41 46 43 43 14 44 37 53 3 39 25 63 22 14 40 36 40 45 44 14 54 29 56 39 42 65 59 28 34 53 16 14 31 33 28 9 42 43 41 54 27 1 60 47 79 52 72 55 1 16 56 75 81 46 50 58 32 34 73 26 19 25 2 31 18 40 91 17", "100 1234\n1 5 6 5 6 5 2 3 2 1 4 1 6 6 4 5 3 6 5 1 1 5 2 2 3 3 6 1 1 4 6 2 1 3 5 2 7 6 6 2 2 1 1 2 1 4 1 2 1 2 2 5 1 8 8 8 2 2 4 8 1 8 4 1 1 5 5 9 9 2 6 4 7 2 5 3 7 6 7 10 9 9 1 2 5 8 5 7 1 1 8 10 2 6 7 9 5 2 10 6", "100 4321\n7 2 18 4 10 1 11 12 4 22 2 10 5 19 12 3 6 16 20 22 12 2 1 3 15 2 1 13 4 14 11 1 24 12 6 23 18 20 10 7 23 15 24 16 3 15 24 14 18 22 27 18 9 9 10 21 14 21 23 5 5 25 4 23 9 17 16 30 7 14 3 25 23 21 7 19 12 8 14 29 28 21 28 24 29 32 27 10 16 8 3 8 40 3 18 28 23 24 42 40", "100 2222\n10 4 1 2 7 1 2 8 10 6 5 9 9 5 6 5 9 3 4 6 5 7 6 6 11 4 10 6 3 2 5 9 13 2 6 3 4 10 7 7 1 9 7 14 13 13 6 3 12 5 13 9 15 2 5 10 3 4 7 7 5 11 8 15 14 11 4 4 7 3 3 15 4 13 1 13 7 12 4 7 1 4 16 1 9 5 16 14 2 4 7 17 7 4 7 20 11 2 15 9", "5 54\n3 3 2 6 9", "7 102\n2 6 1 3 4 8 7", "4 43\n3 4 9 2", "6 131\n2 9 7 9 7 6", "11 362\n4 5 4 8 10 6 3 2 7 7 4", "85 1121\n6 4 1 3 2 5 1 6 1 3 3 2 1 2 3 2 1 4 1 6 1 1 6 4 5 4 1 5 1 6 2 3 6 5 3 6 7 3 4 7 7 2 1 3 1 8 2 8 7 4 5 7 4 8 6 8 2 6 4 5 5 1 3 7 3 2 4 3 1 9 9 5 9 2 9 1 10 2 10 10 2 10 8 5 8", "85 5801\n14 28 19 29 19 6 17 22 15 17 24 1 5 26 28 11 20 5 1 5 30 30 17 9 31 13 21 13 12 31 3 21 12 5 7 35 27 26 1 18 7 36 18 4 24 21 36 38 20 42 15 20 33 31 25 8 31 33 39 2 11 32 34 9 26 24 16 22 13 31 38 8 17 40 52 51 6 33 53 22 33 19 19 16 41", "95 1191\n3 6 4 3 5 1 6 1 4 4 3 6 5 2 3 6 2 4 5 5 2 5 5 5 2 1 6 2 4 2 3 1 1 5 7 1 6 4 3 6 6 1 1 5 5 4 6 5 8 1 3 1 3 6 4 6 5 4 3 4 4 7 1 3 3 2 5 7 5 5 7 3 5 8 5 9 3 1 7 9 8 9 1 2 7 3 5 3 8 7 1 7 11 9 11", "95 5201\n26 1 1 18 22 8 3 10 18 14 21 17 9 1 22 13 9 27 5 14 28 14 25 3 9 28 3 19 28 7 28 21 25 13 18 5 29 16 1 32 18 4 19 28 31 5 9 27 6 29 19 20 20 19 4 21 20 34 7 2 5 36 27 22 8 3 10 28 37 9 18 36 38 9 23 43 2 6 3 35 9 20 42 45 37 12 29 19 45 22 48 3 13 40 45", "80 8101\n17 23 11 5 11 27 22 5 31 23 24 6 34 44 22 25 10 44 10 42 42 6 3 24 31 43 10 5 27 36 36 51 27 12 45 39 15 29 30 54 14 22 25 6 33 36 16 4 12 20 54 17 2 61 2 38 33 56 34 4 16 15 60 31 41 21 58 66 46 59 2 33 20 20 37 50 61 33 69 38", "90 4411\n11 1 23 12 22 23 17 3 22 4 22 18 23 23 4 15 7 11 14 4 22 11 14 20 4 17 18 14 9 20 7 12 14 18 22 17 25 8 1 15 17 1 27 11 27 13 20 29 29 29 20 1 24 13 10 30 31 33 9 15 29 18 19 4 4 14 23 11 31 15 3 28 19 37 18 24 32 12 26 31 36 12 10 24 4 32 25 30 37 2", "100 9898\n13 16 40 32 21 21 50 18 5 35 44 18 38 31 12 42 29 30 13 51 50 36 37 48 8 56 16 36 15 39 48 37 26 18 8 15 15 2 44 28 20 29 7 36 30 62 31 50 59 37 58 26 37 23 21 31 14 12 58 55 30 9 66 64 55 23 59 54 54 29 36 72 41 36 68 42 17 16 65 71 35 72 43 6 53 79 26 51 1 16 55 36 65 72 43 20 78 86 42 52"], "outputs": ["2", "3", "1", "3", "5", "7", "10", "7", "10", "15", "23", "22", "29", "13", "25", "26", "14", "28", "27", "30", "4", "13", "24", "30", "29", "28", "31", "30", "5", "7", "3", "5", "11", "25", "29", "27", "33", "30", "27", "26"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 23 | codeforces |
|
a6681f6a24b6e413486938d1b52f3fae | Log Stream Analysis | You've got a list of program warning logs. Each record of a log stream is a string in this format:
String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the year of 2012. String "HH:MM:SS" determines a correct time in the 24 hour format.
The described record of a log stream means that at a certain time the record has got some program warning (string "MESSAGE" contains the warning's description).
Your task is to print the first moment of time, when the number of warnings for the last *n* seconds was not less than *m*.
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=10000).
The second and the remaining lines of the input represent the log stream. The second line of the input contains the first record of the log stream, the third line contains the second record and so on. Each record of the log stream has the above described format. All records are given in the chronological order, that is, the warning records are given in the order, in which the warnings appeared in the program.
It is guaranteed that the log has at least one record. It is guaranteed that the total length of all lines of the log stream doesn't exceed 5·106 (in particular, this means that the length of some line does not exceed 5·106 characters). It is guaranteed that all given dates and times are correct, and the string 'MESSAGE" in all records is non-empty.
If there is no sought moment of time, print -1. Otherwise print a string in the format "2012-MM-DD HH:MM:SS" (without the quotes) — the first moment of time when the number of warnings for the last *n* seconds got no less than *m*.
Sample Input
60 3
2012-03-16 16:15:25: Disk size is
2012-03-16 16:15:25: Network failute
2012-03-16 16:16:29: Cant write varlog
2012-03-16 16:16:42: Unable to start process
2012-03-16 16:16:43: Disk size is too small
2012-03-16 16:16:53: Timeout detected
1 2
2012-03-16 23:59:59:Disk size
2012-03-17 00:00:00: Network
2012-03-17 00:00:01:Cant write varlog
2 2
2012-03-16 23:59:59:Disk size is too sm
2012-03-17 00:00:00:Network failute dete
2012-03-17 00:00:01:Cant write varlogmysq
Sample Output
2012-03-16 16:16:43
-1
2012-03-17 00:00:00
| {"inputs": ["60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected", "1 2\n2012-03-16 23:59:59:Disk size\n2012-03-17 00:00:00: Network\n2012-03-17 00:00:01:Cant write varlog", "2 2\n2012-03-16 23:59:59:Disk size is too sm\n2012-03-17 00:00:00:Network failute dete\n2012-03-17 00:00:01:Cant write varlogmysq", "10 30\n2012-02-03 10:01:10: qQsNeHR.BLmZVMsESEKKDvqcQHHzBeddbKiIb,aDQnBKNtdcvitwtpUDGVFSh.Lx,FPBZXdSrsSDZtIJDgx!mSovndGiqHlCwCFAHy", "2 3\n2012-02-20 16:15:00: Dis\n2012-03-16 16:15:01: Net\n2012-03-16 16:15:02: Cant write varlog\n2012-03-16 16:15:02: Unable to start process\n2012-03-16 16:16:43: Dis\n2012-03-16 16:16:53: Timeout detected", "2 4\n2012-02-20 16:15:00: Dis\n2012-03-16 16:15:01: Net\n2012-03-16 16:15:02: Cant write varlog\n2012-03-16 16:15:02: Unable to start process\n2012-03-16 16:16:43: Dis\n2012-03-16 16:16:53: Timeout detected"], "outputs": ["2012-03-16 16:16:43", "-1", "2012-03-17 00:00:00", "-1", "2012-03-16 16:15:02", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a67247ddc642337fb665ffad33a5c619 | Lunch Rush | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy.
Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant.
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
Sample Input
2 5
3 3
4 5
4 6
5 8
3 6
2 3
2 2
1 5
1 7
Sample Output
4
3
-1
| {"inputs": ["2 5\n3 3\n4 5", "4 6\n5 8\n3 6\n2 3\n2 2", "1 5\n1 7", "4 9\n10 13\n4 18\n13 3\n10 6", "1 1\n1 1000000000", "1 1\n1000000000 1000000000", "1 1\n1000000000 1", "2 3\n1000000000 1\n2 2", "2 5\n1 7\n1 1000000000"], "outputs": ["4", "3", "-1", "13", "-999999998", "1", "1000000000", "1000000000", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 208 | codeforces |
|
a67a70733c91214a0387239b6c5f3b0b | The Great Game | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team.
Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie.
Sample Input
[]()[]8<
8<[]()8<
8<8<()
[]8<[]
Sample Output
TEAM 2 WINS
TIE
| {"inputs": ["[]()[]8<\n8<[]()8<", "8<8<()\n[]8<[]", "()\n[]", "()\n8<", "8<\n[]", "[]8<()()()()8<8<8<[]\n()()[][][]8<[]()8<8<", "()[]()()()\n[]()[][]8<", "()\n8<", "()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()", "()[][]8<\n8<()8<()", "8<()8<8<8<8<()8<\n[]()()8<()[][][]", "[][]8<8<8<8<\n8<[][]()8<()", "[]\n()", "8<8<8<[]\n[][][][]", "[][]8<[][]8<[]()()()\n()()[][]8<[]()8<[][]", "[]8<8<[]\n[]8<()[]", "[]\n[]", "[]8<[]()()()[]\n8<[]8<()8<()8<", "[]()()()8<[]8<[]\n[][]8<[]()[][][]", "8<()8<[]\n()[][]()", "()[]()()8<[]8<[]\n()()()8<8<()8<[]", "8<()()()8<8<\n[]8<()()[][]", "()[]()()\n()()[]()", "[]8<[]8<[]()\n8<[]8<8<[]8<", "8<()()[]()[]\n8<8<8<8<[][]", "[][]()[]\n[]8<8<[]", "[]()\n()()", "()()()()8<()()()8<\n()[][][]8<()[][][]", "[]8<\n8<()", "8<8<8<\n[]()8<", "[]\n[]", "()\n()", "8<\n8<", "()\n[]", "8<\n[]"], "outputs": ["TEAM 2 WINS", "TIE", "TEAM 2 WINS", "TEAM 1 WINS", "TEAM 1 WINS", "TEAM 2 WINS", "TEAM 2 WINS", "TEAM 1 WINS", "TEAM 2 WINS", "TIE", "TIE", "TEAM 2 WINS", "TEAM 1 WINS", "TEAM 1 WINS", "TEAM 1 WINS", "TEAM 2 WINS", "TIE", "TEAM 2 WINS", "TEAM 2 WINS", "TIE", "TEAM 1 WINS", "TEAM 1 WINS", "TIE", "TIE", "TIE", "TIE", "TEAM 1 WINS", "TEAM 2 WINS", "TEAM 2 WINS", "TIE", "TIE", "TIE", "TIE", "TEAM 2 WINS", "TEAM 1 WINS"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 18 | codeforces |
|
a67ea2cda7f0cc20730deba2efa225e7 | Chocolate | Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is *a*1<=×<=*b*1 segments large and the second one is *a*2<=×<=*b*2 segments large.
Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares.
To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following:
- he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, - or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar.
In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar.
Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is 16<=×<=23, then Polycarpus can chip off a half, but not a third. If the bar is 20<=×<=18, then Polycarpus can chip off both a half and a third. If the bar is 5<=×<=7, then Polycarpus cannot chip off a half nor a third.
What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process.
The first line of the input contains integers *a*1,<=*b*1 (1<=≤<=*a*1,<=*b*1<=≤<=109) — the initial sizes of the first chocolate bar. The second line of the input contains integers *a*2,<=*b*2 (1<=≤<=*a*2,<=*b*2<=≤<=109) — the initial sizes of the second bar.
You can use the data of type int64 (in Pascal), long long (in С++), long (in Java) to process large integers (exceeding 231<=-<=1).
In the first line print *m* — the sought minimum number of minutes. In the second and third line print the possible sizes of the bars after they are leveled in *m* minutes. Print the sizes using the format identical to the input format. Print the sizes (the numbers in the printed pairs) in any order. The second line must correspond to the first bar and the third line must correspond to the second bar. If there are multiple solutions, print any of them.
If there is no solution, print a single line with integer -1.
Sample Input
2 6
2 3
36 5
10 16
3 5
2 1
Sample Output
1
1 6
2 3
3
16 5
5 16
-1
| {"inputs": ["2 6\n2 3", "36 5\n10 16", "3 5\n2 1", "36 5\n10 12", "1 1\n1 1", "2 1\n1 2", "3 6\n2 1", "1 27\n1 1", "2 5\n20 2", "40 5\n150 36", "60 1080\n60 45", "2160 3240\n7200 384", "51840 900\n48 27000", "100 200\n7200 25", "112500 96\n375 2400", "432000 3000\n4800 10000", "7 1\n1 7", "12 39\n13 3", "906992640 544195584\n906992640 725594112", "859963392 644972544\n725594112 967458816", "644972544 886837248\n725594112 886837248", "243 216\n6 1", "400 2500000\n1000000 1000", "10000 100000\n2 1000000000", "25000000 80\n128 23437500", "62500000 96\n256 7812500", "1280 2343750\n25600 312500", "15625 1152000\n1562500 5760", "9000000 12000\n6250 480000", "1920 50000000\n78125 25600", "5625000 19200\n1125000 96000", "45 800000000\n288000000 500", "750000000 725594112\n716636160 675000000", "10000079 1\n10000079 1", "1 30000237\n10000079 1", "10000079 1\n6 10000079", "3 540004266\n60000474 27", "720005688 725594112\n816293376 960007584", "859963392 816293376\n967458816 859963392", "644972544 816293376\n544195584 816293376", "99999989 1\n1 99999989", "99999989 9\n1 99999989", "199999978 2\n599999934 3", "544195584 899999901\n599999934 967458816", "8 8\n1 1", "31 15\n36 25", "68 34\n84 78", "894 197\n325 232", "41764 97259\n54586 18013", "333625 453145\n800800 907251", "4394826 2233224\n609367 3364334", "13350712 76770926\n61331309 8735000", "844212449 863672439\n410956265 742052168", "22295873 586964387\n4736819 472714349", "905412001 865545936\n598517372 498343827", "378462721 734062076\n42554822 374230201", "261578849 307610920\n636335376 399859678", "144694977 881159765\n80372825 425489156", "35135676 3879\n841304242 18", "57946752 619939008\n114816 331164", "171 162\n9 57", "2592 4950\n60 2970", "90315 96\n48 30105", "5832 45693720\n10154160 108", "5832 45693720\n10154160 108", "1 911953772\n39650164 23", "3 707552887\n6 707552887", "806410824 11\n2 369604961", "144 980783074\n24786 461544976", "614363206 2\n2 307181603", "1336608 1650\n18711 3182400", "472586400 448\n1050192 8400", "497664 367567200\n3304800 55351296", "916090560 291133440\n628176384 424569600", "556792704 718502400\n640493568 832809600", "320 162162\n8736 1980", "25740 6048\n38918880 81", "90720 35582976\n294840 9237888", "870912 1924560\n544195584 35925120", "846526464 537477120\n806215680 952342272", "862202880 967458816\n595213920 886837248", "564350976 623557440\n775982592 604661760", "775982592 716636160\n906992640 919683072", "806215680 940584960\n627056640 537477120", "537477120 560431872\n627056640 720555264", "564350976 906992640\n836075520 816293376", "591224832 529079040\n574801920 725594112", "816293376 881798400\n612220032 783820800", "862202880 764411904\n997691904 836075520", "766402560 725594112\n680244480 689762304", "766402560 816293376\n680244480 581986944", "952342272 554273280\n646652160 725594112", "739031040 564350976\n644972544 862202880", "831409920 564350976\n574801920 725594112", "1 1\n774840978 774840978", "725594112 725594112\n1 1", "1 1\n536870912 536870912", "573308928 573308928\n1 1", "1 1\n918330048 918330048", "1 1\n688747536 688747536", "536870912 536870912\n387420489 387420489", "967458816 967458816\n967458816 967458816", "1 1\n65536 65536", "387420489 387420489\n536870912 536870912", "999999937 999999937\n999999937 999999937", "387420489 774840978\n774840978 645700815"], "outputs": ["1\n1 6\n2 3", "3\n16 5\n5 16", "-1", "1\n24 5\n10 12", "0\n1 1\n1 1", "0\n2 1\n1 2", "4\n1 2\n2 1", "6\n1 1\n1 1", "2\n2 5\n5 2", "6\n40 5\n25 8", "5\n5 540\n60 45", "5\n640 2160\n3600 384", "6\n1440 900\n48 27000", "4\n100 200\n800 25", "4\n9375 96\n375 2400", "6\n16000 3000\n4800 10000", "0\n7 1\n1 7", "4\n1 39\n13 3", "2\n604661760 544195584\n453496320 725594112", "6\n214990848 644972544\n143327232 967458816", "3\n322486272 886837248\n322486272 886837248", "16\n1 6\n6 1", "0\n400 2500000\n1000000 1000", "1\n10000 100000\n1 1000000000", "1\n25000000 80\n128 15625000", "2\n31250000 64\n256 7812500", "3\n1280 1562500\n6400 312500", "1\n15625 576000\n1562500 5760", "6\n250000 12000\n6250 480000", "6\n40 50000000\n78125 25600", "0\n5625000 19200\n1125000 96000", "2\n45 800000000\n72000000 500", "3\n500000000 483729408\n358318080 675000000", "0\n10000079 1\n10000079 1", "2\n1 10000079\n10000079 1", "3\n10000079 1\n1 10000079", "0\n3 540004266\n60000474 27", "1\n720005688 725594112\n544195584 960007584", "5\n254803968 816293376\n241864704 859963392", "5\n161243136 816293376\n161243136 816293376", "0\n99999989 1\n1 99999989", "4\n99999989 1\n1 99999989", "3\n199999978 2\n199999978 2", "5\n161243136 899999901\n299999967 483729408", "6\n1 1\n1 1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "4\n3903964 3879\n841304242 18", "24\n92 413292672\n114816 331164", "7\n19 27\n9 57", "7\n36 4950\n60 2970", "3\n30105 48\n48 30105", "10\n24 45693720\n10154160 108", "10\n24 45693720\n10154160 108", "0\n1 911953772\n39650164 23", "1\n3 707552887\n3 707552887", "4\n67200902 11\n2 369604961", "8\n144 980783074\n306 461544976", "1\n307181603 2\n2 307181603", "6\n1336608 1650\n693 3182400", "5\n19691100 448\n1050192 8400", "0\n497664 367567200\n3304800 55351296", "0\n916090560 291133440\n628176384 424569600", "2\n371195136 718502400\n320246784 832809600", "2\n160 108108\n8736 1980", "6\n25740 6048\n1921920 81", "5\n22680 35582976\n87360 9237888", "16\n870912 1924560\n46656 35925120", "4\n423263232 537477120\n238878720 952342272", "7\n107775360 967458816\n117573120 886837248", "2\n376233984 623557440\n387991296 604661760", "1\n775982592 716636160\n604661760 919683072", "2\n358318080 940584960\n627056640 537477120", "1\n537477120 560431872\n418037760 720555264", "2\n376233984 906992640\n418037760 816293376", "2\n394149888 529079040\n287400960 725594112", "1\n544195584 881798400\n612220032 783820800", "6\n215550720 764411904\n197074944 836075520", "5\n191600640 725594112\n201553920 689762304", "7\n95800320 816293376\n134369280 581986944", "3\n423263232 554273280\n323326080 725594112", "2\n492687360 564350976\n322486272 862202880", "3\n369515520 564350976\n287400960 725594112", "74\n1 1\n1 1", "68\n1 1\n1 1", "58\n1 1\n1 1", "64\n1 1\n1 1", "72\n1 1\n1 1", "72\n1 1\n1 1", "58\n128 536870912\n262144 262144", "0\n967458816 967458816\n967458816 967458816", "32\n1 1\n1 1", "58\n262144 262144\n128 536870912", "0\n999999937 999999937\n999999937 999999937", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a6836333c0cd74c9f9fb81e34f53cab5 | Testing Robots | The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (*x*0,<=*y*0) of a rectangular squared field of size *x*<=×<=*y*, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly *x*·*y* tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same.
After placing the objects on the field the robot will have to run a sequence of commands given by string *s*, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code.
Moving to the left decreases coordinate *y*, and moving to the right increases it. Similarly, moving up decreases the *x* coordinate, and moving down increases it.
The tests can go on for very long, so your task is to predict their results. For each *k* from 0 to *length*(*s*) your task is to find in how many tests the robot will run exactly *k* commands before it blows up.
The first line of the input contains four integers *x*, *y*, *x*0, *y*0 (1<=≤<=*x*,<=*y*<=≤<=500,<=1<=≤<=*x*0<=≤<=*x*,<=1<=≤<=*y*0<=≤<=*y*) — the sizes of the field and the starting coordinates of the robot. The coordinate axis *X* is directed downwards and axis *Y* is directed to the right.
The second line contains a sequence of commands *s*, which should be fulfilled by the robot. It has length from 1 to 100<=000 characters and only consists of characters 'L', 'R', 'U', 'D'.
Print the sequence consisting of (*length*(*s*)<=+<=1) numbers. On the *k*-th position, starting with zero, print the number of tests where the robot will run exactly *k* commands before it blows up.
Sample Input
3 4 2 2
UURDRDRL
2 2 2 2
ULD
Sample Output
1 1 0 1 1 1 1 0 6
1 1 1 1
| {"inputs": ["3 4 2 2\nUURDRDRL", "2 2 2 2\nULD", "1 1 1 1\nURDLUURRDDLLURDL", "15 17 8 9\nURRDLUULLDD", "15 17 8 9\nURRDLUULLDDDRRUR", "15 17 8 9\nURRDLUULLDDDRRURR", "1 2 1 1\nR", "2 1 1 1\nD", "1 2 1 2\nLR", "2 1 2 1\nUD", "4 4 2 2\nDRUL", "4 4 3 3\nLUDRUL", "15 17 8 9\nURRDLU", "15 17 8 9\nURRDLUULLDDR", "15 17 8 9\nURRDLUULLDDRR", "15 17 8 9\nURRDLUULLDDRRR", "15 17 8 9\nURRDLUULLDDRRRR", "15 17 8 9\nURRDLUULLDDRRRRU"], "outputs": ["1 1 0 1 1 1 1 0 6", "1 1 1 1", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "1 1 1 1 1 1 0 1 1 1 1 245", "1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 241", "1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 241", "1 1", "1 1", "1 1 0", "1 1 0", "1 1 1 1 12", "1 1 1 0 0 1 12", "1 1 1 1 1 1 249", "1 1 1 1 1 1 0 1 1 1 1 1 244", "1 1 1 1 1 1 0 1 1 1 1 1 0 244", "1 1 1 1 1 1 0 1 1 1 1 1 0 0 244", "1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 244", "1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 243"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 31 | codeforces |
|
a6be5c5b3f940ae34740357bd4512ea4 | Petya and Strings | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
Sample Input
aaaa
aaaA
abs
Abz
abcdefg
AbCdEfF
Sample Output
0
-1
1
| {"inputs": ["aaaa\naaaA", "abs\nAbz", "abcdefg\nAbCdEfF", "asadasdasd\nasdwasdawd", "aslkjlkasdd\nasdlkjdajwi", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "UG\nak", "JZR\nVae", "a\nZ", "rk\nkv", "RvuT\nbJzE", "PPS\nydq", "q\nq", "peOw\nIgSJ", "PyK\noKN", "O\ni", "NmGY\npDlP", "nG\nZf", "m\na", "MWyB\nWZEV", "Gre\nfxc", "Ooq\nwap", "XId\nlbB", "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "abac\nadaa", "Bbc\nabc", "aaaba\naaaab"], "outputs": ["0", "-1", "1", "-1", "1", "0", "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", "0", "1", "1", "1", "-1", "-1", "1", "-1", "1", "-1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "-1", "1", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 534 | codeforces |
|
a6c0ec0f94b080801d3e32b45ed8ec9c | How Many Squares? | You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2<=×<=2. We are only interested in two types of squares:
1. squares with each side parallel to a side of the matrix; 1. squares with each side parallel to a diagonal of the matrix.
Regardless of type, a square must contain at least one 1 and can't touch (by side or corner) any foreign 1. Of course, the lengths of the sides of each square should be equal.
How many squares are in the given matrix?
The first line contains integer *t* (1<=≤<=*t*<=≤<=10000), where *t* is the number of test cases in the input. Then test cases follow. Each case starts with a line containing integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=250), where *n* is the number of rows and *m* is the number of columns. The following *n* lines contain *m* characters each (0 or 1).
The total number of characters in all test cases doesn't exceed 106 for any input file.
You should output exactly *t* lines, with the answer to the *i*-th test case on the *i*-th line.
Sample Input
2
8 8
00010001
00101000
01000100
10000010
01000100
00101000
11010011
11000011
10 10
1111111000
1000001000
1011001000
1011001010
1000001101
1001001010
1010101000
1001001000
1000001000
1111111000
1
12 11
11111111111
10000000001
10111111101
10100000101
10101100101
10101100101
10100000101
10100000101
10111111101
10000000001
11111111111
00000000000
Sample Output
1
2
3
| {"inputs": ["2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000", "1\n12 11\n11111111111\n10000000001\n10111111101\n10100000101\n10101100101\n10101100101\n10100000101\n10100000101\n10111111101\n10000000001\n11111111111\n00000000000"], "outputs": ["1\n2", "3"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a6c41ea9c9ce50b21113df8a612d7106 | Nearest Minimums | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Print the only number — distance between two nearest minimums in the array.
Sample Input
2
3 3
3
5 6 5
9
2 1 3 5 4 1 2 3 1
Sample Output
1
2
3
| {"inputs": ["2\n3 3", "3\n5 6 5", "9\n2 1 3 5 4 1 2 3 1", "6\n4 6 7 8 6 4", "2\n1000000000 1000000000", "42\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", "2\n10000000 10000000", "5\n100000000 100000001 100000000 100000001 100000000", "9\n4 3 4 3 4 1 3 3 1", "3\n10000000 1000000000 10000000", "12\n5 6 6 5 6 1 9 9 9 9 9 1", "5\n5 5 1 2 1", "5\n2 2 1 3 1", "3\n1000000000 1000000000 1000000000", "3\n100000005 1000000000 100000005", "5\n1 2 2 2 1", "3\n10000 1000000 10000", "3\n999999999 999999998 999999998", "6\n2 1 1 2 3 4", "4\n1000000000 900000000 900000000 1000000000", "5\n7 7 2 7 2", "6\n10 10 1 20 20 1", "2\n999999999 999999999", "10\n100000 100000 1 2 3 4 5 6 7 1", "10\n3 3 1 2 2 1 10 10 10 10", "5\n900000000 900000001 900000000 900000001 900000001", "5\n3 3 2 5 2", "2\n100000000 100000000", "10\n10 15 10 2 54 54 54 54 2 10", "2\n999999 999999", "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "5\n1000000000 100000000 1000000000 1000000000 100000000", "4\n10 9 10 9", "5\n1 3 2 3 1", "5\n2 2 1 4 1", "6\n1 2 2 2 2 1", "7\n3 7 6 7 6 7 3", "8\n1 2 2 2 2 1 2 2", "10\n2 2 2 3 3 1 3 3 3 1", "2\n88888888 88888888", "3\n100000000 100000000 100000000", "10\n1 3 2 4 5 5 4 3 2 1", "5\n2 2 1 2 1", "6\n900000005 900000000 900000001 900000000 900000001 900000001", "5\n41 41 1 41 1", "6\n5 5 1 3 3 1", "8\n1 2 2 2 1 2 2 2", "7\n6 6 6 6 1 8 1", "3\n999999999 1000000000 999999999", "5\n5 5 4 10 4", "11\n2 2 3 4 1 5 3 4 2 5 1", "5\n3 5 4 5 3", "6\n6 6 6 6 1 1", "7\n11 1 3 2 3 1 11", "5\n3 3 1 2 1", "5\n4 4 2 5 2", "4\n10000099 10000567 10000099 10000234", "4\n100000009 100000011 100000012 100000009", "2\n1000000 1000000", "2\n10000010 10000010", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "8\n2 6 2 8 1 9 8 1", "5\n7 7 1 8 1", "7\n1 3 2 3 2 3 1", "7\n2 3 2 1 3 4 1", "5\n1000000000 999999999 1000000000 1000000000 999999999", "4\n1000000000 1000000000 1000000000 1000000000", "5\n5 5 3 5 3", "6\n2 3 3 3 3 2", "4\n1 1 2 2", "5\n1 1 2 2 2", "6\n2 1 1 2 2 2", "5\n1000000000 1000000000 100000000 1000000000 100000000", "7\n2 2 1 1 2 2 2", "8\n2 2 2 1 1 2 2 2", "10\n2 2 2 2 2 1 1 2 2 2", "11\n2 2 2 2 2 2 1 1 2 2 2", "12\n2 2 2 2 2 2 2 1 1 2 2 2", "13\n2 2 2 2 2 2 2 2 1 1 2 2 2", "14\n2 2 2 2 2 2 2 2 2 1 1 2 2 2", "15\n2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "16\n2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "17\n2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "18\n2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "4\n1000000000 100000000 100000000 1000000000", "21\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "4\n1 2 3 1", "8\n5 5 5 5 3 5 5 3", "7\n2 3 2 1 4 4 1", "6\n3 3 1 2 4 1", "3\n2 1 1", "5\n3 3 2 8 2", "5\n1 2 1 2 2", "4\n1 2 1 2", "5\n3 1 1 3 2", "4\n1 1 2 1", "4\n2 2 1 1", "5\n1 2 2 1 2", "7\n2 1 2 1 1 2 1", "9\n200000 500000 500000 500000 200000 500000 500000 500000 500000", "3\n1 1 2", "85\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1", "5\n1000000000 1000000000 999999999 1000000000 999999999", "5\n2 1 2 2 1", "3\n1 1 1", "4\n1 2 1 1", "6\n1 3 4 2 4 1", "9\n2 2 5 1 6 8 7 9 1", "10\n1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 999999999", "7\n3 3 1 2 4 1 2", "7\n3 3 1 2 3 4 1", "8\n10 5 10 1 10 10 10 1"], "outputs": ["1", "2", "3", "5", "1", "1", "1", "2", "3", "2", "6", "2", "2", "1", "2", "4", "2", "1", "1", "1", "2", "3", "1", "7", "3", "2", "2", "1", "5", "1", "1", "3", "2", "4", "2", "5", "6", "5", "4", "1", "1", "9", "2", "2", "2", "3", "4", "2", "2", "2", "6", "4", "1", "4", "2", "2", "2", "3", "1", "1", "1", "3", "2", "6", "3", "3", "1", "2", "5", "1", "1", "1", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "3", "3", "3", "3", "1", "2", "2", "2", "1", "1", "1", "3", "1", "4", "1", "84", "2", "3", "1", "1", "5", "5", "6", "3", "4", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 217 | codeforces |
|
a6cab46b8ce1e78c5fa12073774b1b7d | Alyona and Strings | After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and because she is too small, *k* does not exceed 10. The girl wants now to choose *k* disjoint non-empty substrings of string *s* such that these strings appear as disjoint substrings of string *t* and in the same order as they do in string *s*. She is also interested in that their length is maximum possible among all variants.
Formally, Alyona wants to find a sequence of *k* non-empty strings *p*1,<=*p*2,<=*p*3,<=...,<=*p**k* satisfying following conditions:
- *s* can be represented as concatenation *a*1*p*1*a*2*p*2... *a**k**p**k**a**k*<=+<=1, where *a*1,<=*a*2,<=...,<=*a**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - *t* can be represented as concatenation *b*1*p*1*b*2*p*2... *b**k**p**k**b**k*<=+<=1, where *b*1,<=*b*2,<=...,<=*b**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - sum of the lengths of strings in sequence is maximum possible.
Please help Alyona solve this complicated problem and find at least the sum of the lengths of the strings in a desired sequence.
A substring of a string is a subsequence of consecutive characters of the string.
In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The third line of the input contains string *t*, consisting of lowercase English letters.
In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists.
Sample Input
3 2 2
abc
ab
9 12 4
bbaaababb
abbbabbaaaba
Sample Output
2
7
| {"inputs": ["3 2 2\nabc\nab", "9 12 4\nbbaaababb\nabbbabbaaaba", "11 11 4\naaababbabbb\nbbbaaaabaab", "15 9 4\nababaaabbaaaabb\nbbaababbb", "2 7 1\nbb\nbbaabaa", "13 4 3\nabbaababaaaab\naaab", "2 3 2\nab\naab", "13 9 1\noaflomxegekyv\nbgwwqizfo", "5 9 1\nbabcb\nabbcbaacb", "8 12 2\nbccbbaac\nabccbcaccaaa", "11 2 2\nbcbcbbabaaa\nca", "12 7 6\naabbccaccbcb\ncabcccc", "15 10 1\nabbccbaaaabaabb\nbbaabaacca", "127 266 4\nbaaabaababaaabbabbbbaababbbabaabbaaaaaabbababaabababaaaabaaaabbabaaababaabaabbbbbaabaabbbbbaaabbaabaabbbbaaaaababaaabaaabbaabaa\nabbababaaaabbbabbbbaabbbbaaabbabbaaaabaabaabababbbabbaabbabaaaaaabbbbbbbbaaabaababbbabababbabaaaababaabaaabaaabaaabaabbbabbbbabbaaabaaaaaabbaaabababbababaaaaaabaaabbbabbbabbbbabaabbabababbabbabbaababbbabbbbabbabaabbbaababbaaababaabbabbaaabbabbaabaabaabbaabbabaababba", "132 206 2\nababaababaaaabbaabbaabaababbaaabbabababbbbabbbaaaaaaabbabaaaabbabbbbbbbbbabbbbaabbaaabaaaabbabaaaababbbbaaaaabababbbbabababbbabbabab\nabbbababbbaaababaaaababbbaababaaababbbbbbaaabbbabbbaabbbbabbbababbaaabbaaabaabababbaabbbbbaabaabaaababababaaaababbabaaaabbabaaabbbbabbbbaabbbbaaaabbabbbaababbbbaabbbbbabaabbababbaaabaabbabbbaabbabbbaabbaaab", "290 182 2\nbababbbabaabbbababbaaaabbbabbababbbbbbabbbaaaaabaaabbaabbbaaabaabaaaabbbaaabbaabbbbbbbbbbabbabbabaaaaaaaabaaaabababaabbabaabaaaaababaabbbbbbabbabbbbabaababbabbaaabbbbbaaabbbbaaababaabbbbababbbabbababbabbabbbaaabaaabbbbaabaaaaabbaabbbabbbbbabbbaaaabbaaababbaabbbbbbbbbbabaaabbaaabaababbbbaaa\nbabbaababaaaaaaabbaabbabaaaaaaaabbabaabbbaabaababbaaaababaaaabaabbababbabaaabbbaaabaabababbbbababaaabbbaababbbbaabbabbaabaaaaabaaabbbbbbabaabbababbbaabbaaaaabaaaabaaabaaaabbbaabaabab", "279 89 9\nbbbbaabbbbabaaaabbbababbaabbaabaaabababaabbaaaaabaababbbaababaaaaaabaababababbaaaababaaaabaaaaabaaaaaababbabaaababaaabbbabaaabaaabbbaabbaabaababbaaaaabaaabbabababababbaabbabbbaaababbbabbaaabaaabaaababaaabbaaaabababbabbabaabaabbbabbbabbbaababbabaaabaabbaabaabaaaaaaaabbbaabbbbabba\nabaaaabbabbbbaabaaaabbbbbbbbbbaaababaabaabbaaabbaabababababbbabaaabaaababbbbbbabbaabbbaba", "421 53 2\nbaaaaaabaaababaaaabbabaaabaabaaaabaabbaaababababbbbbabaaaaabbabbbaabbabbbbabaabbbababbbbabaaaababaabaabbbbaabaaaabbbaaaabababbbabbbbaabbabbabbbaabaaabbbabbabbababaaaaabbbabbbbbabbaaababbaababbbbbaaaabaabbabaaababbaabaaaaabbbbaabbbbaabaabbabbaabbaababbbaabaaaaabaabbaaabbababaaaabbabbbaaaabbbaabaabbaababababababaabbaaaabababaabaabaabbbaababbbaaaabaaababaabbabbabbaaaaaaaaaabbbbbabbaabbaabbabbbbbbbaabaabbaaaaabbbabbbbbbab\naababaaabbaaaabaaabbaabbabbbaaabbbababbbbbbaababbbbaa", "274 102 7\nbccabbbcbcababaacacaccbbcabbccbbacabccbaacabacacbcacaccaabacacccabbcccccabacbacbcaacacacbccaaacccaacacbbbcccccccbcaaacbcacaccbccacccacbbbbbbaabcbbbbbacbcacacaacbbbcbcbbaacacbaabcbbbaccbcccbbaacccabaabbcccccacbccbccbacbacbbbaccbabcbabbcbbccabaacccbaccaccaaaacacabcaacbabcabbc\nabbcabbabacaccacaaaabcacbbcbbaccccbcccacaacabacabccbbbbaaaaccbbccaabcabbacbabbcabbbcaccaccaabbbcabcacb", "120 362 6\ncaaccbbbabbbcbaacbaccacaaccacaaababccaccaabaccacccbbaaaaababbccbbacccaacabacbaaacabbacbabcccbccbcbbcaabaaabaabcccaabacbb\nabcbbaaccbbcabbcbbcacbabaacbaaacabcbabcabbabccbcaaacaccaaabbcbaacccccbcabacaacabbbcabaabcbbccabacbaaaacbbbbbccabccccbababcbacbbbcbbaabcaabcacbaaaaaccbaabbabacbcbbbaabbbcabcaacbcccbcbbacababbcaababcbbbbbbcbbaaaababacabcbbcbbaccccbcacccabbbabccabcabacccbbbcaccaccaacacaabacaabccccaabccccaabaccbabcaabbcbbccccbbabccbbccbaacaccabbacacabbacccbbaaacaabacccbcbacbcbcaca", "103 54 5\nbccabcbcabcbacbbacccbaccacacccacaaabbbabaccbcbcacbaaccaccaacabaaccbbbabccbacbcbaccbcabbbaacaabbcbbbcaab\nbabbccbcbcbbbbcabcbbccbabbbbcacbcbbbaccbbccbacaacaaaca", "14 14 1\ngeoskjkdvmxlnu\nfaqyereihjimnu", "8 8 3\nabbbcccd\nayyycccz"], "outputs": ["2", "7", "7", "8", "2", "4", "2", "1", "3", "6", "2", "6", "5", "41", "26", "25", "71", "22", "44", "43", "27", "2", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
a6dbb69f10ce63f83e7b2804af0bd856 | The Golden Age | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as there is no such representation for it.
Such interval of years that there are no unlucky years in it is called The Golden Age.
You should write a program which will find maximum length of The Golden Age which starts no earlier than the year *l* and ends no later than the year *r*. If all years in the interval [*l*,<=*r*] are unlucky then the answer is 0.
The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0.
Sample Input
2 3 1 10
3 5 10 22
2 3 3 5
Sample Output
1
8
0
| {"inputs": ["2 3 1 10", "3 5 10 22", "2 3 3 5", "2 2 1 10", "2 2 1 1000000", "2 2 1 1000000000000000000", "2 3 1 1000000", "2 3 1 1000000000000000000", "12345 54321 1 1000000", "54321 12345 1 1000000000000000000", "2 3 100000000 1000000000000", "2 14 732028847861235712 732028847861235712", "14 2 732028847861235713 732028847861235713", "3 2 6 7", "16 5 821690667 821691481", "1000000000000000000 2 1 1000000000000000000", "2 1000000000000000000 1000000000000000 1000000000000000000", "2 2 1000000000000000000 1000000000000000000", "3 3 1 1", "2 3 626492297402423196 726555387600422608", "4 4 1 1", "304279187938024110 126610724244348052 78460471576735729 451077737144268785", "510000000000 510000000000 1 1000000000000000000", "2 10000000000000000 1 1000000000000000000", "84826654960259 220116531311479700 375314289098080160 890689132792406667", "1001 9999 1 1000000000000000000", "106561009498593483 3066011339919949 752858505287719337 958026822891358781", "650233444262690661 556292951587380938 715689923804218376 898772439356652923", "4294967297 4294967297 1 1000000000000000000", "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000", "2 2 1 1", "73429332516742239 589598864615747534 555287238606698050 981268715519611449", "282060925969693883 446418005951342865 709861829378794811 826972744183396568", "97958277744315833 443452631396066615 33878596673318768 306383421710156519", "40975442958818854 7397733549114401 299774870238987084 658001214206968260", "699 700 1 1000", "483076744475822225 425097332543006422 404961220953110704 826152774360856248", "4294967297 4294967297 1 999999999999999999", "702012794 124925148 2623100012 1000000000000000000", "433333986179614514 1000000000000000000 433333986179614515 726628630292055493", "999999999999999999 364973116927770629 4 4", "4 2 40 812", "2 3 1 1", "1556368728 1110129598 120230736 1258235681", "7 9 164249007852879073 459223650245359577", "324693328712373699 541961409169732375 513851377473048715 873677521504257312", "370083000139673112 230227213530985315 476750241623737312 746365058930029530", "4 3 584 899", "4 3 286 581", "304045744870965151 464630021384225732 142628934177558000 844155070300317027", "195627622825327857 666148746663834172 1 1000000000000000000", "459168731438725410 459955118458373596 410157890472128901 669197645706452507", "999999999999999999 999999999999999999 1 1000000000000000000", "752299248283963354 680566564599126819 73681814274367577 960486443362068685", "20373217421623606 233158243228114207 97091516440255589 395722640217125926", "203004070900 20036005000 1 1000000000000000000", "565269817339236857 318270460838647700 914534538271870694 956123707310168659", "2 5 330 669", "9 9 91 547", "9 4 866389615074294253 992899492208527253", "3037000500 3037000500 1 1000000000000000000", "4294967297 4294967297 12 1000000000000000000", "5 3 78510497842978003 917156799600023483", "749206377024033575 287723056504284448 387669391392789697 931234393488075794", "999999999999999999 454135 1000000000000000000 1000000000000000000", "759826429841877401 105086867783910112 667080043736858072 797465019478234768", "1000000000000000000 1000000000000000000 5 7", "440968000218771383 43378854522801881 169393324037146024 995429539593716237", "15049917793417622 113425474361704411 87565655389309185 803955352361026671", "4 6 264626841724745187 925995096479842591", "4294967297 4294967297 13 1000000000000000000", "315729630349763416 22614591055604717 66895291338255006 947444311481017774", "3 10 173 739", "161309010783040325 128259041753158864 5843045875031294 854024306926137845", "239838434825939759 805278168279318096 202337849919104640 672893754916863788", "9 9 435779695685310822 697902619874412541", "967302429573451368 723751675006196376 143219686319239751 266477897142546404", "10 8 139979660652061677 941135332855173888", "4294967297 1000000000000000000 4294967296 17179869184", "100914030314340517 512922595840756536 812829791042966971 966156272123068006", "288230376151711744 288230376151711744 1 1000000000000000000", "6 9 681 750", "880356874212472951 178538501711453307 162918237570625233 224969951233811739", "2 7 405373082004080437 771991379629433514", "10 11 10 11"], "outputs": ["1", "8", "0", "1", "213568", "144115188075855871", "206415", "261485717957290893", "933334", "976614248345331214", "188286357653", "0", "1", "1", "815", "423539247696576511", "423539247696576511", "1", "1", "100063090197999413", "1", "177668463693676057", "999998980000000000", "413539247696576512", "515374843694326508", "988998989390034998", "205168317603639445", "183082515552434548", "999999991410065406", "1", "1", "318240518387121676", "98493812262359820", "208425143965840685", "358226343967981177", "697", "343076029885034022", "999999991410065405", "491571744457491660", "293294644112440978", "1", "191", "1", "989898863", "229336748650748455", "324693328712373697", "146054845259371103", "146", "161", "304045744870965149", "470521123838506314", "209242527248078910", "999999999999999997", "606884750324759243", "142191179567388113", "999999776959924100", "41589169038297966", "131", "385", "126509877134233001", "999999993925999000", "999999991410065406", "238418579101562499", "361536985631243879", "0", "92746386105019330", "3", "511082684852142973", "675479960205904638", "369878143059623936", "999999991410065406", "609100090075649641", "386", "564456254389938656", "433055320090924028", "262122924189101720", "123258210823306654", "697020144779318016", "12884901886", "153326481080101036", "423539247696576512", "49", "46431449522358431", "153172782079203571", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 93 | codeforces |
|
a70764fb4fd16794e40aeac14235d364 | Berland National Library | Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:
- "+ *r**i*" — the reader with registration number *r**i* entered the room; - "- *r**i*" — the reader with registration number *r**i* left the room.
The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.
Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.
Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of records in the system log. Next follow *n* events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ *r**i*" or "- *r**i*", where *r**i* is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).
It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.
Print a single integer — the minimum possible capacity of the reading room.
Sample Input
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
2
- 1
- 2
2
+ 1
- 1
Sample Output
321 | {"inputs": ["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1", "5\n+ 1\n- 1\n+ 2\n+ 3\n- 4", "3\n- 1\n- 2\n- 3", "4\n+ 1\n+ 2\n- 1\n+ 3", "6\n+ 1\n+ 2\n- 1\n+ 3\n- 2\n+ 4", "3\n+ 1\n+ 2\n- 3", "3\n- 1\n+ 2\n- 2", "4\n- 1\n- 2\n+ 3\n+ 4", "1\n+ 1", "1\n- 1", "3\n- 1\n+ 1\n- 1", "10\n+ 1\n+ 2\n+ 3\n+ 4\n+ 5\n+ 6\n+ 7\n+ 8\n+ 9\n+ 10", "5\n+ 5\n+ 4\n- 4\n- 5\n+ 5", "50\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100", "10\n- 8\n- 4\n+ 8\n+ 10\n+ 6\n- 8\n+ 9\n- 2\n- 7\n+ 4", "20\n+ 3\n- 3\n- 2\n+ 2\n+ 3\n- 5\n- 1\n+ 1\n- 3\n+ 4\n- 1\n+ 1\n+ 3\n- 3\n+ 5\n- 2\n- 1\n+ 2\n+ 1\n- 5", "50\n+ 4\n+ 5\n+ 3\n+ 2\n- 2\n- 3\n- 4\n+ 3\n+ 2\n- 3\n+ 4\n- 2\n- 4\n+ 2\n+ 3\n- 3\n- 5\n- 1\n+ 4\n+ 5\n- 5\n+ 3\n- 4\n- 3\n- 2\n+ 4\n+ 3\n+ 2\n- 2\n- 4\n+ 5\n+ 1\n+ 4\n+ 2\n- 2\n+ 2\n- 3\n- 5\n- 4\n- 1\n+ 5\n- 2\n- 5\n+ 5\n+ 3\n- 3\n+ 1\n+ 3\n+ 2\n- 1", "10\n- 2\n+ 1\n- 1\n+ 2\n- 2\n+ 2\n+ 1\n- 1\n- 2\n+ 1", "50\n+ 1\n+ 2\n+ 3\n+ 4\n+ 5\n+ 6\n+ 7\n+ 8\n+ 9\n+ 10\n+ 11\n+ 12\n+ 13\n+ 14\n+ 15\n+ 16\n+ 17\n+ 18\n+ 19\n+ 20\n+ 21\n+ 22\n+ 23\n+ 24\n+ 25\n+ 26\n+ 27\n+ 28\n+ 29\n+ 30\n+ 31\n+ 32\n+ 33\n+ 34\n+ 35\n+ 36\n+ 37\n+ 38\n+ 39\n+ 40\n+ 41\n+ 42\n+ 43\n+ 44\n+ 45\n+ 46\n+ 47\n+ 48\n+ 49\n+ 50", "50\n- 1\n- 2\n- 3\n- 4\n- 5\n- 6\n- 7\n- 8\n- 9\n- 10\n- 11\n- 12\n- 13\n- 14\n- 15\n- 16\n- 17\n- 18\n- 19\n- 20\n- 21\n- 22\n- 23\n- 24\n- 25\n- 26\n- 27\n- 28\n- 29\n- 30\n- 31\n- 32\n- 33\n- 34\n- 35\n- 36\n- 37\n- 38\n- 39\n- 40\n- 41\n- 42\n- 43\n- 44\n- 45\n- 46\n- 47\n- 48\n- 49\n- 50"], "outputs": ["3", "2", "1", "3", "3", "2", "2", "3", "1", "2", "1", "1", "1", "10", "2", "1", "5", "4", "5", "2", "50", "50"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 37 | codeforces |
|
a7154105f6f9c9c7b051cbe3640e655a | Mobile Communications | A sum of *p* rubles is charged from Arkady's mobile phone account every day in the morning. Among the following *m* days, there are *n* days when Arkady will top up the account: in the day *d**i* he will deposit *t**i* rubles on his mobile phone account. Arkady will always top up the account before the daily payment will be done. There will be no other payments nor tops up in the following *m* days.
Determine the number of days starting from the 1-st to the *m*-th such that the account will have a negative amount on it after the daily payment (i. e. in evening). Initially the account's balance is zero rubles.
The first line contains three integers *n*, *p* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109, 1<=≤<=*m*<=≤<=109, *n*<=≤<=*m*) — the number of days Arkady will top up the account, the amount of the daily payment, and the number of days you should check.
The *i*-th of the following *n* lines contains two integers *d**i* and *t**i* (1<=≤<=*d**i*<=≤<=*m*, 1<=≤<=*t**i*<=≤<=109) — the index of the day when Arkady will make the *i*-th top up, and the amount he will deposit on this day. It is guaranteed that the indices of the days are distinct and are given in increasing order, i. e. *d**i*<=><=*d**i*<=-<=1 for all *i* from 2 to *n*.
Print the number of days from the 1-st to the *m*-th such that the account will have a negative amount on it after the daily payment.
Sample Input
3 6 7
2 13
4 20
7 9
5 4 100
10 70
15 76
21 12
30 100
67 85
Sample Output
3
26
| {"inputs": ["3 6 7\n2 13\n4 20\n7 9", "5 4 100\n10 70\n15 76\n21 12\n30 100\n67 85", "14 25 100\n1 209\n2 224\n3 58\n4 31\n5 135\n6 16\n7 130\n8 113\n9 230\n10 60\n11 209\n12 185\n13 118\n14 16", "1 1 1\n1 1", "1 2 1\n1 1", "1 2 1\n1 3", "1 1000000000 1\n1 1000000000", "1 100000000 1\n1 99999999", "10 1 10\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 1000000000\n7 1000000000\n8 1000000000\n9 1000000000\n10 1000000000", "8 518 10\n1 1\n2 650\n3 436\n4 525\n6 1163\n7 416\n8 512\n9 500", "14 4115 100\n18 85238\n20 1\n28 38150\n32 16316\n33 269\n42 47018\n48 18222\n53 22346\n57 13571\n58 1717\n65 40035\n90 93955\n93 10747\n96 15415", "8 518 10\n1 1\n2 581\n3 638\n4 420\n6 1447\n7 31\n8 574\n9 689", "14 4115 100\n18 96022\n20 1\n28 28266\n32 18061\n33 2\n42 46869\n48 20282\n53 22181\n57 14156\n58 1415\n65 29530\n90 122045\n93 5\n96 23547", "8 518 10\n1 1\n2 528\n3 668\n4 459\n6 1103\n7 413\n8 549\n9 550", "14 4115 100\n18 72959\n20 5578\n28 36578\n32 12797\n33 4242\n42 42918\n48 21810\n53 19442\n57 14274\n58 5036\n65 34539\n90 98082\n93 12170\n96 13730", "8 518 10\n1 1\n2 820\n3 378\n4 513\n6 915\n7 692\n8 398\n9 538", "14 4115 100\n18 136900\n20 1\n28 2\n32 79818\n33 2\n42 8712\n48 21894\n53 28023\n57 14205\n58 5\n65 40631\n90 154277\n93 5\n96 3", "8 518 10\n1 1\n2 524\n3 676\n4 389\n6 1013\n7 623\n8 529\n9 606", "14 4115 100\n18 103373\n20 1\n28 20482\n32 14482\n33 2321\n42 43952\n48 19687\n53 24828\n57 9584\n58 6392\n65 28693\n90 102250\n93 15860\n96 11260"], "outputs": ["3", "26", "31", "0", "1", "0", "0", "1", "0", "10", "70", "10", "59", "10", "98", "10", "26", "10", "66"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 6 | codeforces |
|
a7575a52a521f677485b619b19b3277a | Toy Army | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.
The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.
You are asked to calculate the maximum total number of soldiers that may be killed during the game.
The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields.
Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.
Sample Input
2
4
Sample Output
3
6
| {"inputs": ["2", "4", "6", "8", "10", "140", "500", "1000", "2000", "50000", "10000", "25460", "54646", "59790", "578456", "56798056", "8457980", "5687986", "10984932", "99999994", "99999996", "99999998", "100000000"], "outputs": ["3", "6", "9", "12", "15", "210", "750", "1500", "3000", "75000", "15000", "38190", "81969", "89685", "867684", "85197084", "12686970", "8531979", "16477398", "149999991", "149999994", "149999997", "150000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 270 | codeforces |
|
a75c2796222c96034eb516cffb9cd766 | Yet Another Number Game | Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games.
BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn:
- Take one of the integers (we'll denote it as *a**i*). Choose integer *x* (1<=≤<=*x*<=≤<=*a**i*). And then decrease *a**i* by *x*, that is, apply assignment: *a**i*<==<=*a**i*<=-<=*x*. - Choose integer *x* . And then decrease all *a**i* by *x*, that is, apply assignment: *a**i*<==<=*a**i*<=-<=*x*, for all *i*.
The player who cannot make a move loses.
You're given the initial sequence *a*1,<=*a*2,<=...,<=*a**n*. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=3).
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=300).
Write the name of the winner (provided that both players play optimally well). Either "BitLGM" or "BitAryo" (without the quotes).
Sample Input
2
1 1
2
1 2
3
1 2 1
Sample Output
BitLGM
BitAryo
BitLGM
| {"inputs": ["2\n1 1", "2\n1 2", "3\n1 2 1", "2\n1 3", "2\n3 5", "2\n9 10", "2\n6 8", "3\n0 0 0", "2\n223 58", "2\n106 227", "2\n125 123", "3\n31 132 7", "2\n41 29", "3\n103 286 100", "3\n9 183 275", "3\n19 88 202", "3\n234 44 69", "3\n244 241 295", "1\n6", "1\n231", "2\n241 289", "2\n200 185", "2\n218 142", "3\n124 47 228", "3\n134 244 95", "1\n0", "1\n10", "1\n2", "1\n1", "1\n99", "2\n44 27", "2\n280 173", "2\n29 47", "2\n16 26", "2\n58 94", "2\n17 28", "2\n59 96", "2\n164 101", "2\n143 88", "2\n69 112", "2\n180 111", "2\n159 98", "2\n183 113", "2\n162 100", "2\n230 142", "2\n298 184", "2\n144 233", "2\n0 0", "2\n173 280", "2\n180 111", "2\n251 155", "2\n114 185", "2\n156 253", "2\n144 233", "2\n0 0", "2\n14 23", "2\n2 1", "2\n70 43", "2\n49 30", "2\n150 243", "2\n6 10", "2\n152 246", "2\n13 8", "2\n293 181", "2\n15 9", "2\n295 182", "2\n62 38", "2\n80 130", "2\n40 65", "1\n248", "1\n10", "2\n216 91", "1\n234", "2\n140 193", "3\n151 97 120", "1\n213", "3\n119 251 222", "3\n129 148 141", "1\n147", "2\n124 194", "3\n184 222 102", "3\n101 186 223", "3\n0 87 87", "3\n144 33 177", "3\n49 252 205", "3\n49 126 79", "3\n152 66 218", "3\n181 232 93", "3\n15 150 153", "3\n191 50 141", "3\n162 230 68", "3\n4 19 23", "3\n222 129 95", "3\n38 16 54", "3\n254 227 29", "3\n196 45 233", "3\n70 45 107", "3\n190 61 131", "3\n0 173 173", "3\n50 69 119", "1\n108", "1\n15", "1\n85", "1\n291", "1\n1", "2\n11 222", "2\n218 127", "2\n280 24", "2\n298 281", "3\n275 70 60", "3\n299 299 298", "3\n299 299 299", "3\n299 299 299", "2\n298 299", "2\n299 299", "1\n299", "3\n299 290 288"], "outputs": ["BitLGM", "BitAryo", "BitLGM", "BitLGM", "BitAryo", "BitLGM", "BitLGM", "BitAryo", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitAryo", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitAryo", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM", "BitLGM"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a769601d5a0746ed3aedd5004fa7c43c | The Door Problem | Moriarty has trapped *n* people in *n* distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are *m* switches. Each switch control doors of some rooms, but each door is controlled by exactly two switches.
You are given the initial configuration of the doors. Toggling any switch, that is, turning it ON when it is OFF, or turning it OFF when it is ON, toggles the condition of the doors that this switch controls. Say, we toggled switch 1, which was connected to room 1, 2 and 3 which were respectively locked, unlocked and unlocked. Then, after toggling the switch, they become unlocked, locked and locked.
You need to tell Sherlock, if there exists a way to unlock all doors at the same time.
First line of input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105, 2<=≤<=*m*<=≤<=105) — the number of rooms and the number of switches.
Next line contains *n* space-separated integers *r*1,<=*r*2,<=...,<=*r**n* (0<=≤<=*r**i*<=≤<=1) which tell the status of room doors. The *i*-th room is locked if *r**i*<==<=0, otherwise it is unlocked.
The *i*-th of next *m* lines contains an integer *x**i* (0<=≤<=*x**i*<=≤<=*n*) followed by *x**i* distinct integers separated by space, denoting the number of rooms controlled by the *i*-th switch followed by the room numbers that this switch controls. It is guaranteed that the room numbers are in the range from 1 to *n*. It is guaranteed that each door is controlled by exactly two switches.
Output "YES" without quotes, if it is possible to open all doors at the same time, otherwise output "NO" without quotes.
Sample Input
3 3
1 0 1
2 1 3
2 1 2
2 2 3
3 3
1 0 1
3 1 2 3
1 2
2 1 3
3 3
1 0 1
3 1 2 3
2 1 2
1 3
Sample Output
NOYESNO | {"inputs": ["3 3\n1 0 1\n2 1 3\n2 1 2\n2 2 3", "3 3\n1 0 1\n3 1 2 3\n1 2\n2 1 3", "3 3\n1 0 1\n3 1 2 3\n2 1 2\n1 3", "11 10\n0 0 1 0 0 0 0 1 1 0 1\n3 2 3 11\n1 3\n2 6 7\n1 5\n1 11\n1 10\n5 4 6 8 9 10\n2 1 5\n1 7\n5 1 2 4 8 9", "10 9\n1 0 1 1 0 1 0 0 1 0\n4 2 3 9 10\n4 3 4 5 8\n2 1 6\n2 7 8\n1 7\n1 5\n1 10\n2 2 4\n3 1 6 9", "13 11\n0 1 1 0 1 0 0 0 1 0 0 1 1\n6 2 8 9 11 12 13\n3 1 3 11\n1 12\n1 7\n3 6 10 13\n3 1 3 8\n2 7 9\n1 4\n1 2\n2 5 10\n3 4 5 6", "7 6\n0 0 1 0 1 0 0\n1 7\n4 1 2 5 7\n2 4 6\n2 4 5\n3 1 3 6\n2 2 3", "2 2\n1 0\n2 1 2\n2 1 2", "2 2\n0 0\n2 1 2\n2 1 2", "4 4\n0 1 0 1\n2 1 2\n2 2 3\n2 3 4\n2 1 4", "2 2\n1 1\n2 1 2\n2 1 2", "4 4\n0 0 1 1\n2 1 3\n2 2 3\n2 1 4\n2 2 4", "4 4\n0 1 0 1\n2 1 2\n2 2 3\n2 3 4\n2 4 1", "2 3\n1 0\n1 1\n2 1 2\n1 2", "4 5\n0 0 0 1\n2 1 2\n1 1\n2 2 3\n2 3 4\n1 4", "3 6\n0 0 0\n0\n0\n0\n2 1 2\n2 2 3\n2 1 3", "3 3\n1 0 0\n2 1 2\n2 1 3\n2 2 3", "4 4\n0 0 0 0\n2 1 2\n2 1 2\n2 3 4\n2 3 4", "3 3\n0 1 0\n2 1 3\n2 1 2\n2 2 3", "3 3\n0 1 0\n2 1 3\n2 2 3\n2 1 2", "4 4\n1 1 1 0\n2 1 2\n2 1 2\n2 3 4\n2 3 4", "3 4\n1 1 0\n2 1 2\n2 1 2\n1 3\n1 3", "2 4\n0 0\n1 1\n1 1\n1 2\n1 2", "3 3\n0 0 0\n2 1 2\n2 2 3\n2 1 3"], "outputs": ["NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 13 | codeforces |
|
a776432a650f3bf651bc2f3fd6206d17 | Volatile Kite | You are given a convex polygon *P* with *n* distinct vertices *p*1,<=*p*2,<=...,<=*p**n*. Vertex *p**i* has coordinates (*x**i*,<=*y**i*) in the 2D plane. These vertices are listed in clockwise order.
You can choose a real number *D* and move each vertex of the polygon a distance of at most *D* from their original positions.
Find the maximum value of *D* such that no matter how you move the vertices, the polygon does not intersect itself and stays convex.
The first line has one integer *n* (4<=≤<=*n*<=≤<=1<=000) — the number of vertices.
The next *n* lines contain the coordinates of the vertices. Line *i* contains two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th vertex. These points are guaranteed to be given in clockwise order, and will form a strictly convex polygon (in particular, no three consecutive points lie on the same straight line).
Print one real number *D*, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex.
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 .
Sample Input
4
0 0
0 1
1 1
1 0
6
5 0
10 0
12 -4
10 -8
5 -8
3 -4
Sample Output
0.3535533906
1.0000000000
| {"inputs": ["4\n0 0\n0 1\n1 1\n1 0", "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4", "19\n449447997 711296339\n530233434 692216537\n535464528 613140435\n535533467 100893188\n530498867 -265063956\n519107979 -271820709\n482156929 -287792333\n-303730271 -287970295\n-416935204 -263348201\n-443613873 -249980523\n-453444829 -173903413\n-462102798 -80789280\n-462064673 -13220755\n-461368561 482595837\n-457749751 687048095\n-448625206 709399396\n-145117181 710688825\n159099640 711650577\n400454061 711503381", "4\n0 0\n0 10\n10 10\n6 4", "4\n-1000000000 -1000000000\n-999999999 -999999999\n1000000000 999999999\n0 -1", "4\n-1000000000 -1000000000\n-1000000000 1000000000\n1000000000 1000000000\n1000000000 -1000000000", "4\n-100000 -100000\n-99999 -99999\n100000 99999\n0 -100", "4\n-10000 -10000\n-9999 -9999\n10000 9999\n0 -1000", "5\n0 0\n0 10\n10 10\n20 0\n10 -1", "5\n10 -1\n0 0\n0 10\n10 10\n20 0", "4\n1000000000 1000000000\n1000000000 -1000000000\n-1000000000 -1000000000\n-1000000000 1000000000", "4\n2 0\n0 0\n0 14\n8 14", "4\n0 0\n1 100\n100 0\n1 -100", "4\n-1000000000 1000000000\n1000000000 500000000\n1000000000 -1000000000\n-500000000 -1000000000"], "outputs": ["0.3535533906", "1.0000000000", "24967.1394973334", "0.7071067812", "0.0000000000", "707106781.1865475000", "0.0000017678", "0.0000176781", "0.5000000000", "0.5000000000", "707106781.1865475000", "0.8682431421", "0.5000000000", "530330085.8899106400"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 23 | codeforces |
|
a797ac3b124c17d4c2c31ee0aba85c2c | The Way to Home | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
Sample Input
8 4
10010101
4 2
1001
8 4
11100101
12 3
101111100101
Sample Output
2
-1
3
4
| {"inputs": ["8 4\n10010101", "4 2\n1001", "8 4\n11100101", "12 3\n101111100101", "5 4\n11011", "5 4\n10001", "10 7\n1101111011", "10 9\n1110000101", "10 9\n1100000001", "20 5\n11111111110111101001", "20 11\n11100000111000011011", "20 19\n10100000000000000001", "50 13\n10011010100010100111010000010000000000010100000101", "50 8\n11010100000011001100001100010001110000101100110011", "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111", "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111", "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111", "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111", "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111", "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111", "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111", "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111", "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001", "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101", "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111", "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001", "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011", "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001", "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101", "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001", "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001", "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001", "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001", "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001", "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111", "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111", "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111", "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111", "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111", "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111", "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011", "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101", "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001", "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111", "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101", "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101", "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001", "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001", "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001", "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001", "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001", "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001", "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "43 30\n1001000001111111010100100100110101011101101", "7 1\n1111111", "9 3\n101000001", "10 3\n1100000001", "8 2\n10000101", "2 1\n11"], "outputs": ["2", "-1", "3", "4", "1", "1", "2", "1", "1", "4", "2", "1", "5", "8", "25", "1", "20", "25", "25", "34", "13", "15", "12", "18", "16", "10", "13", "18", "12", "9", "12", "7", "3", "3", "3", "2", "1", "99", "50", "-1", "33", "-1", "17", "-1", "14", "11", "-1", "-1", "13", "9", "-1", "-1", "-1", "2", "3", "2", "-1", "2", "6", "-1", "-1", "-1", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 553 | codeforces |
|
a7ac01ff36356b6ef5d9d6b3571169af | Approximating a Constant Range | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
Sample Input
5
1 2 3 3 2
11
5 4 5 5 6 7 8 8 8 7 6
Sample Output
4
5
| {"inputs": ["5\n1 2 3 3 2", "11\n5 4 5 5 6 7 8 8 8 7 6", "2\n3 2", "4\n1001 1000 1000 1001", "4\n1 1 2 3", "3\n1 2 1", "3\n1 2 3", "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9", "3\n1 2 2", "4\n10 9 10 9", "4\n4 3 2 3", "4\n8 8 7 7", "3\n99998 99999 100000", "3\n100000 99999 99998", "3\n1 1 1", "2\n99999 100000", "2\n100000 100000", "2\n1 1", "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000"], "outputs": ["4", "5", "2", "4", "3", "3", "2", "3", "3", "4", "3", "4", "2", "2", "3", "2", "2", "2", "15"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 188 | codeforces |
|
a7b83f74c9b94bdf5a673fec7894c3ad | Down the Hatch! | 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.
Sample Input
4
abbba
4
abbab
Sample Output
1
0
| {"inputs": ["4\nabbba", "4\nabbab", "4\naaa", "4\naab", "4\naabaabbba", "6\naaaaaaaaaaaaaaaa", "7\nabbbaaabbbaaaab", "9\naaaabaaaaa", "4\na", "4\nb", "4\nab", "4\nbb", "4\naba", "4\nbbb", "4\nabab", "4\nabaa", "4\nabbbaaabba", "4\nababba", "4\naaaaaa", "5\nbbbbaabaaa", "2000\na", "2000\naabaaabaabababbbbbbabbbbb", "4\nabbb", "5\nbbbbb"], "outputs": ["1", "0", "0", "0", "1", "2", "2", "1", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "1", "0", "0", "0", "0", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 38 | codeforces |
|
a7b9003851fc4cb8632f1823cb585985 | Clear The Matrix | You are given a matrix *f* with 4 rows and *n* columns. Each element of the matrix is either an asterisk (*) or a dot (.).
You may perform the following operation arbitrary number of times: choose a square submatrix of *f* with size *k*<=×<=*k* (where 1<=≤<=*k*<=≤<=4) and replace each element of the chosen submatrix with a dot. Choosing a submatrix of size *k*<=×<=*k* costs *a**k* coins.
What is the minimum number of coins you have to pay to replace all asterisks with dots?
The first line contains one integer *n* (4<=≤<=*n*<=≤<=1000) — the number of columns in *f*.
The second line contains 4 integers *a*1, *a*2, *a*3, *a*4 (1<=≤<=*a**i*<=≤<=1000) — the cost to replace the square submatrix of size 1<=×<=1, 2<=×<=2, 3<=×<=3 or 4<=×<=4, respectively.
Then four lines follow, each containing *n* characters and denoting a row of matrix *f*. Each character is either a dot or an asterisk.
Print one integer — the minimum number of coins to replace all asterisks with dots.
Sample Input
4
1 10 8 20
***.
***.
***.
...*
7
2 1 8 2
.***...
.***..*
.***...
....*..
4
10 10 1 10
***.
*..*
*..*
.***
Sample Output
9
3
2
| {"inputs": ["4\n1 10 8 20\n***.\n***.\n***.\n...*", "7\n2 1 8 2\n.***...\n.***..*\n.***...\n....*..", "4\n10 10 1 10\n***.\n*..*\n*..*\n.***", "5\n4 3 4 4\n.....\n****.\n..***\n...**", "6\n15 3 18 16\n.*.***\n...**.\n*.....\n**..*.", "5\n2 1 2 1\n*.***\n***.*\n.*..*\n***..", "4\n2 23 19 1\n..**\n*...\n**.*\n.*.*", "4\n18 17 3 15\n**..\n***.\n*..*\n****", "4\n13 12 20 12\n**.*\n....\n***.\n*.**", "6\n8 2 11 9\n.*.***\n..**.*\n.**.**\n*.****", "6\n1 2 2 1\n...*.*\n.**...\n*.*.*.\n**...*", "6\n2 2 2 1\n*.****\n.*....\n.*.***\n*.***.", "5\n9 19 10 7\n.....\n*.*.*\n.*.**\n..**.", "10\n1 1 1 1\n.**.*.****\n.*.**..***\n.*...*..**\n*.*.**..*.", "4\n1 1 1 1\n****\n****\n****\n****", "10\n433 514 452 478\n**********\n**********\n**********\n**********", "4\n1000 1000 1000 1000\n****\n****\n****\n****", "4\n1 4 9 16\n****\n**.*\n*.**\n..**", "4\n1 4 9 15\n****\n****\n****\n****", "33\n548 102 31 730\n.**..**.**...******.*.**....**.**\n**..******...*.*...*.....*....*.*\n.**..*...*.**.*.....*..*..**.*..*\n.....**.....*..*...***.***..**.**"], "outputs": ["9", "3", "2", "7", "15", "2", "1", "9", "12", "12", "2", "2", "14", "3", "1", "1434", "1000", "12", "15", "527"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a7ca291de9a1aed7fcf65c7aebaaddd9 | Photographer | Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is *d* megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes *a* megabytes of memory, one high quality photo take *b* megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the *i*-th client asks to make *x**i* low quality photos and *y**i* high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the *i*-th client, Valera needs to give him everything he wants, that is, to make *x**i* low quality photos and *y**i* high quality photos. To make one low quality photo, the camera must have at least *a* megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least *b* megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*d*<=≤<=109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=104) — the size of one low quality photo and of one high quality photo, correspondingly.
Next *n* lines describe the clients. The *i*-th line contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=105) — the number of low quality photos and high quality photos the *i*-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Sample Input
3 10
2 3
1 4
2 1
1 0
3 6
6 6
1 1
1 0
1 0
Sample Output
2
3 2 1
2 | {"inputs": ["3 10\n2 3\n1 4\n2 1\n1 0", "3 6\n6 6\n1 1\n1 0\n1 0", "4 5\n6 8\n1 2\n3 0\n10 2\n0 4", "4 10\n6 6\n1 2\n2 2\n0 0\n0 0", "10 10\n1 1\n0 3\n6 4\n3 3\n6 3\n5 2\n6 4\n1 3\n5 5\n2 6\n6 4", "5 5\n1 1\n2 0\n3 2\n4 4\n10 0\n0 1", "4 10\n1 2\n1 0\n0 0\n2 0\n1 3", "1 22\n3 5\n1 3", "10 20\n3 5\n3 0\n0 3\n1 2\n1 3\n1 1\n3 0\n0 3\n0 3\n3 1\n3 1", "10 50\n1 1\n7 10\n6 6\n1 0\n2 5\n2 6\n9 7\n3 5\n7 6\n7 10\n7 7", "15 30\n13 19\n10 20\n9 0\n11 15\n10 8\n18 3\n13 15\n2 14\n9 16\n8 4\n13 10\n19 2\n13 19\n6 17\n16 4\n15 6", "30 50\n1 3\n2 2\n3 2\n3 3\n0 1\n0 2\n1 3\n1 3\n1 1\n0 1\n0 2\n1 3\n1 0\n1 0\n2 1\n0 1\n0 0\n0 3\n2 3\n2 2\n0 1\n2 3\n2 3\n0 3\n0 3\n3 3\n1 2\n2 1\n1 3\n3 1\n0 3", "50 50\n6 10\n10 0\n1 9\n8 2\n4 9\n0 7\n2 0\n7 5\n4 8\n10 7\n2 4\n5 6\n6 8\n3 2\n4 6\n7 8\n6 9\n7 7\n7 3\n9 5\n3 10\n7 2\n4 3\n2 0\n6 5\n5 3\n1 7\n1 7\n9 1\n10 4\n10 5\n4 2\n10 10\n0 7\n1 2\n10 1\n1 7\n3 7\n8 7\n5 2\n6 1\n3 1\n4 7\n7 10\n1 5\n10 8\n5 5\n5 1\n3 3\n1 6\n2 1", "1 100\n6 10\n14 19", "2 160\n6 9\n11 9\n6 6", "2 1000000000\n10000 10000\n50000 50000\n100000 100000", "2 1000000000\n10000 10000\n100000 0\n100000 100000", "1 1000000000\n1 1\n1 1", "6 1000000000\n9999 10000\n10000 9998\n10000 10000\n10000 10000\n70000 70000\n10000 10000\n10000 10000", "3 10\n1 10\n0 1\n3 0\n3 0", "2 1000000000\n10000 10000\n0 100000\n100000 100000", "3 3\n1 1\n3 0\n1 0\n1 0", "2 1000000000\n10000 10000\n100000 100000\n50000 50000", "2 1000000000\n10000 10000\n0 90000\n100000 100000", "3 1000000000\n10000 10000\n100000 0\n100000 100000\n0 0", "2 1000000000\n10000 10000\n10000 10000\n100000 100000", "2 1000000000\n10000 10000\n100000 100000\n100000 0", "3 1000000000\n10000 10000\n99999 0\n100000 100000\n100000 100000"], "outputs": ["2\n3 2 ", "1\n2 ", "0", "2\n3 4 ", "2\n1 7 ", "2\n5 1 ", "4\n2 1 3 4 ", "1\n1 ", "2\n5 1 ", "6\n3 4 5 7 2 8 ", "0", "13\n16 12 13 4 9 15 20 8 14 27 5 10 29 ", "3\n6 23 50 ", "0", "1\n2 ", "1\n1 ", "1\n1 ", "1\n1 ", "5\n1 2 3 5 6 ", "2\n2 3 ", "1\n1 ", "2\n2 3 ", "1\n2 ", "1\n1 ", "2\n3 1 ", "1\n1 ", "1\n2 ", "1\n1 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 43 | codeforces |
|
a7f405ddb27670ecb47318df840304fc | Bus Video System | The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, the system records the number $y-x$. So the system records show how number of passengers changed.
The test run was made for single bus and $n$ bus stops. Thus, the system recorded the sequence of integers $a_1, a_2, \dots, a_n$ (exactly one number for each bus stop), where $a_i$ is the record for the bus stop $i$. The bus stops are numbered from $1$ to $n$ in chronological order.
Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$ (that is, at any time in the bus there should be from $0$ to $w$ passengers inclusive).
The first line contains two integers $n$ and $w$ $(1 \le n \le 1\,000, 1 \le w \le 10^{9})$ — the number of bus stops and the capacity of the bus.
The second line contains a sequence $a_1, a_2, \dots, a_n$ $(-10^{6} \le a_i \le 10^{6})$, where $a_i$ equals to the number, which has been recorded by the video system after the $i$-th bus stop.
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
Sample Input
3 5
2 1 -3
2 4
-1 1
4 10
2 4 1 2
Sample Output
3
4
2
| {"inputs": ["3 5\n2 1 -3", "2 4\n-1 1", "4 10\n2 4 1 2", "2 10\n-1 2", "3 4\n-3 -4 4", "10 1\n-1 -1 3 -4 2 3 0 -3 3 2", "5 21\n-3 2 -4 -1 -5", "5 9\n-2 -1 2 -1 -2", "8 7\n-5 0 -3 1 -1 5 0 -6", "3 4\n-2 -1 0", "1 1000000000\n0", "2 1000000000\n-1000000 -1000000", "2 1000000000\n1000000 -1000000", "2 1000000000\n-1000000 1000000", "2 1000000000\n1000000 1000000", "102 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 1 1", "1 1234564\n1", "3 4\n1 2 3"], "outputs": ["3", "4", "2", "9", "0", "0", "11", "6", "0", "2", "1000000001", "998000001", "999000001", "999000001", "998000001", "0", "1234564", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 20 | codeforces |
|
a81e7d7125035b8f7bdaadf1cc9b1c92 | ACM ICPC | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Sample Input
1 3 2 1 2 1
1 1 1 1 1 99
Sample Output
YES
NO
| {"inputs": ["1 3 2 1 2 1", "1 1 1 1 1 99", "1000 1000 1000 1000 1000 1000", "0 0 0 0 0 0", "633 609 369 704 573 416", "353 313 327 470 597 31", "835 638 673 624 232 266", "936 342 19 398 247 874", "417 666 978 553 271 488", "71 66 124 199 67 147", "54 26 0 171 239 12", "72 8 186 92 267 69", "180 179 188 50 75 214", "16 169 110 136 404 277", "101 400 9 200 300 10", "101 400 200 9 300 10", "101 200 400 9 300 10", "101 400 200 300 9 10", "101 200 400 300 9 10", "4 4 4 4 5 4", "2 2 2 2 2 1", "1000 1000 999 1000 1000 1000", "129 1 10 29 8 111", "1000 1000 1000 999 999 1000", "101 200 300 400 9 10", "101 400 200 300 10 9", "101 200 400 300 10 9", "101 200 300 400 10 9", "101 200 300 10 400 9", "1 1 1 1 1 5", "8 1 1 3 3 0", "1 1 2 2 3 3", "1 2 2 5 2 5", "1 2 3 6 6 6", "36 91 7 86 51 89", "10 1 1 1 23 24", "1 1 1 10 23 24", "20 10 1 2 3 44", "7 0 14 11 8 6", "100 496 1 1 1 1", "5 4 2 5 11 3", "1 3 7 8 8 9", "1 3 4 5 18 19", "5 5 1 2 2 15", "2 1 0 0 0 5", "1 6 6 1 20 2", "2 10 0 0 0 0", "1 1 3 1 1 11", "10 10 1 1 1 37", "1 1 0 0 0 4", "1 1 10 1 1 28", "1 5 5 5 6 8", "0 2 3 4 4 5"], "outputs": ["YES", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 279 | codeforces |
|
a83d76638f25ffd2fcd9c09cc652d2c2 | Artem and Array | Artem has an array of *n* positive integers. Artem decided to play with it. The game consists of *n* moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets *min*(*a*,<=*b*) points, where *a* and *b* are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points.
After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of elements in the array. The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the values of the array elements.
In a single line print a single integer — the maximum number of points Artem can get.
Sample Input
5
3 1 5 2 6
5
1 2 3 4 5
5
1 100 101 100 1
Sample Output
11
6
102
| {"inputs": ["5\n3 1 5 2 6", "5\n1 2 3 4 5", "5\n1 100 101 100 1", "10\n96 66 8 18 30 48 34 11 37 42", "1\n87", "2\n93 51", "3\n31 19 5", "4\n86 21 58 60", "5\n21 6 54 69 32", "6\n46 30 38 9 65 23", "7\n82 60 92 4 2 13 15", "8\n77 84 26 34 17 56 76 3", "9\n72 49 39 50 68 35 75 94 56", "10\n4 2 2 4 1 2 2 4 2 1", "1\n4", "2\n3 1", "3\n1 2 1", "4\n2 3 1 2", "5\n2 6 2 1 2", "6\n1 7 3 1 6 2", "7\n2 1 2 2 2 2 2", "8\n3 4 3 1 1 3 4 1", "9\n4 5 2 2 3 1 3 3 5"], "outputs": ["11", "6", "102", "299", "0", "0", "5", "118", "74", "145", "129", "279", "435", "21", "0", "0", "1", "4", "6", "12", "10", "15", "23"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 3 | codeforces |
|
a83f8b46df13927157fecc78b46a9e07 | Phone Numbers | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.
Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account.
The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.
Read the examples to understand statement and format of the output better.
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.
Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.
Sample Input
2
ivan 1 00123
masha 1 00123
3
karl 2 612 12
petr 1 12
katya 1 612
4
ivan 3 123 123 456
ivan 2 456 456
ivan 8 789 3 23 6 56 9 89 2
dasha 2 23 789
Sample Output
2
masha 1 00123
ivan 1 00123
3
katya 1 612
petr 1 12
karl 1 612
2
dasha 2 23 789
ivan 4 789 123 2 456
| {"inputs": ["2\nivan 1 00123\nmasha 1 00123", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "20\nnxj 6 7 6 6 7 7 7\nnxj 10 8 5 1 7 6 1 0 7 0 6\nnxj 2 6 5\nnxj 10 6 7 6 6 5 8 3 6 6 8\nnxj 10 6 1 7 6 7 1 8 7 8 6\nnxj 10 8 5 8 6 5 6 1 9 6 3\nnxj 10 8 1 6 4 8 0 4 6 0 1\nnxj 9 2 6 6 8 1 1 3 6 6\nnxj 10 8 9 0 9 1 3 2 3 2 3\nnxj 6 6 7 0 8 1 2\nnxj 7 7 7 8 1 3 6 9\nnxj 10 2 7 0 1 5 1 9 1 2 6\nnxj 6 9 6 9 6 3 7\nnxj 9 0 1 7 8 2 6 6 5 6\nnxj 4 0 2 3 7\nnxj 10 0 4 0 6 1 1 8 8 4 7\nnxj 8 4 6 2 6 6 1 2 7\nnxj 10 5 3 4 2 1 0 7 0 7 6\nnxj 10 9 6 0 6 1 6 2 1 9 6\nnxj 4 2 9 0 1", "20\nl 6 02 02 2 02 02 2\nl 8 8 8 8 2 62 13 31 3\ne 9 0 91 0 0 60 91 60 2 44\ne 9 69 2 1 44 2 91 66 1 70\nl 9 7 27 27 3 1 3 7 80 81\nl 9 2 1 13 7 2 10 02 3 92\ne 9 0 15 3 5 5 15 91 09 44\nl 7 2 50 4 5 98 31 98\nl 3 26 7 3\ne 6 7 5 0 62 65 91\nl 8 80 0 4 0 2 2 0 13\nl 9 19 13 02 2 1 4 19 26 02\nl 10 7 39 7 9 22 22 26 2 90 4\ne 7 65 2 36 0 34 57 9\ne 8 13 02 09 91 73 5 36 62\nl 9 75 0 10 8 76 7 82 8 34\nl 7 34 0 19 80 6 4 7\ne 5 4 2 5 7 2\ne 7 4 02 69 7 07 20 2\nl 4 8 2 1 63", "20\no 10 6 6 97 45 6 6 6 6 5 6\nl 8 5 5 5 19 59 5 8 5\nj 9 2 30 58 2 2 1 0 30 4\nc 10 1 1 7 51 7 7 51 1 1 1\no 9 7 97 87 70 2 19 2 14 6\ne 6 26 6 6 6 26 5\ng 9 3 3 3 3 3 78 69 8 9\nl 8 8 01 1 5 8 41 72 3\nz 10 1 2 2 2 9 1 9 1 6 7\ng 8 7 78 05 36 7 3 67 9\no 5 6 9 9 7 7\ne 10 30 2 1 1 2 5 04 0 6 6\ne 9 30 30 2 2 0 26 30 79 8\nt 10 2 2 9 29 7 7 7 9 2 9\nc 7 7 51 1 31 2 7 4\nc 9 83 1 6 78 94 74 54 8 32\ng 8 4 1 01 9 39 28 6 6\nt 7 9 2 01 4 4 9 58\nj 5 0 1 58 02 4\nw 10 80 0 91 91 06 91 9 9 27 7", "1\negew 5 3 123 23 1234 134"], "outputs": ["2\nmasha 1 00123 \nivan 1 00123 ", "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 ", "2\ndasha 2 789 23 \nivan 4 2 123 456 789 ", "1\nnxj 10 4 1 8 7 5 3 6 9 0 2 ", "2\ne 18 70 07 62 36 20 69 66 57 02 65 34 44 73 60 91 15 09 13 \nl 21 02 80 27 63 19 50 81 76 34 90 98 92 31 26 22 75 39 13 10 82 62 ", "9\nw 5 91 06 27 9 80 \nt 6 01 29 4 58 2 7 \ne 8 2 8 30 04 26 5 79 1 \nl 8 8 41 72 01 19 59 3 5 \nj 5 58 02 1 4 30 \nz 5 7 9 6 2 1 \ng 10 39 67 3 01 36 4 05 69 78 28 \no 8 19 2 45 6 87 14 97 70 \nc 10 7 94 32 6 78 74 31 83 51 54 ", "1\negew 3 134 123 1234 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 28 | codeforces |
|
a84f6423a5d54508f5988f076c9607ab | Magical Array | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.
He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Sample Input
4
2 1 1 4
5
-2 -2 -2 0 1
Sample Output
5
8
| {"inputs": ["4\n2 1 1 4", "5\n-2 -2 -2 0 1", "1\n10", "2\n5 6", "5\n5 5 4 5 5", "8\n1 2 0 0 0 0 3 3", "12\n-4 3 3 2 3 3 3 -4 2 -4 -4 -4", "10\n7 1 0 10 0 -5 -3 -2 0 0", "20\n6 0 0 -3 1 -3 0 -8 1 3 5 2 -1 -5 -1 9 0 6 -2 4", "100\n0 -18 -9 -15 3 16 -28 0 -28 0 28 -20 -9 9 -11 0 18 -15 -18 -26 0 -27 -25 -22 6 -5 8 14 -17 24 20 3 -6 24 -27 1 -23 0 4 12 -20 0 -10 30 22 -6 13 16 0 15 17 -8 -2 0 -5 13 11 23 -17 -29 10 15 -28 0 -23 4 20 17 -7 -5 -16 -17 16 2 20 19 -8 0 8 -5 12 0 0 -14 -15 -28 -10 20 0 8 -1 10 14 9 0 4 -16 15 13 -10", "50\n2 0 2 0 0 0 0 -1 -2 -2 -2 1 1 2 2 0 2 0 2 -3 0 0 0 0 3 1 -2 0 -1 0 -2 3 -1 2 0 2 0 0 0 0 2 0 1 0 0 3 0 0 -2 0", "2\n-510468670 0", "150\n0 -2 1 -2 0 0 0 0 -2 0 -2 -1 0 0 2 0 1 -2 1 -1 0 0 0 2 -2 2 -1 0 0 0 -2 0 2 0 1 0 -2 0 -2 -1 -1 -2 -2 2 0 0 1 -2 -2 -1 -2 0 2 1 1 -1 1 0 -2 2 0 0 0 1 -1 0 -2 -1 0 -2 2 1 1 0 0 2 0 0 2 -1 0 0 2 0 2 0 -2 -1 1 -2 1 0 0 -2 -1 -1 0 0 2 -1 -1 -1 -1 -2 0 0 2 -1 -1 1 0 0 1 -1 0 0 -1 2 2 0 0 0 -1 -2 0 1 0 -1 0 -1 -1 0 2 0 1 2 0 0 2 0 0 1 2 0 2 -2 2 0 2 2"], "outputs": ["5", "8", "1", "2", "7", "15", "19", "11", "21", "101", "75", "2", "196"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 96 | codeforces |
|
a850a1bcad64de860c139cea3c8ba010 | Zoo | The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has *n* observation binoculars located at the *OX* axis. For each *i* between 1 and *n*, inclusive, there exists a single binocular located at the point with coordinates (*i*,<=0). There are *m* flamingos in the Zoo, located at points with positive coordinates. The flamingos are currently sleeping and you can assume that they don't move.
In order to get a good view over the flamingos, each of the binoculars can be independently rotated to face any angle (not necessarily integer). Then, the binocular can be used to observe all flamingos that is located at the straight line passing through the binocular at the angle it is set. In other words, you can assign each binocular a direction corresponding to any straight line passing through the binocular, and the binocular will be able to see all flamingos located on that line.
Today, some kids from the prestigious Codeforces kindergarten went on a Field Study to the Zoo. Their teacher would like to set each binocular an angle to maximize the number of flamingos that can be seen by the binocular. The teacher is very interested in the sum of these values over all binoculars. Please help him find this sum.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*m*<=≤<=250), denoting the number of binoculars and the number of flamingos, respectively.
Then *m* lines follow, the *i*-th line will contain two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=109), which means that the *i*-th flamingo is located at point (*x**i*,<=*y**i*).
All flamingos will be located at distinct points.
Print a single integer denoting the maximum total number of flamingos that can be seen by all the binoculars.
Sample Input
5 5
2 1
4 1
3 2
4 3
4 4
Sample Output
11
| {"inputs": ["5 5\n2 1\n4 1\n3 2\n4 3\n4 4", "3 3\n1 1\n2 10\n3 100", "1 2\n450000001 500000000\n900000001 1000000000", "3 6\n1 1\n1 2\n1 3\n2 1\n2 2\n3 1", "3 3\n227495634 254204506\n454991267 508409012\n715803819 799841973", "3 3\n96684705 23204141\n193369409 46408282\n217792636 52269809", "1000000 2\n136395332 110293751\n568110113 459392523", "3 3\n227495634 254204506\n454991267 508409012\n217792637 799841973", "3 3\n333333334 1\n666666667 2\n1000000000 3", "3 3\n333333334 1\n666666667 2\n999999999 3", "3 3\n2 333333333\n3 666666666\n4 999999999", "3 3\n2 333333333\n3 666666666\n4 1000000000", "3 3\n2 333333333\n3 666666666\n4 999999998", "1000000 2\n136395332 110293751\n568110113 459392523", "1000000 2\n881456674 979172365\n878302062 975668042", "3 10\n1000000000 1000000000\n1000000000 999999999\n1000000000 999999998\n1000000000 999999997\n1000000000 999999996\n1000000000 999999995\n1000000000 999999994\n1000000000 999999993\n1000000000 999999992\n1000000000 999999991", "1000000 2\n194305 1024\n4388610 1023", "4 5\n1 3\n2 2\n3 1\n4 2\n4 3", "5 5\n2 1\n1 1\n3 1\n4 1\n4 4"], "outputs": ["11", "3", "2", "7", "4", "4", "1000000", "4", "5", "5", "5", "4", "4", "1000000", "1000000", "3", "1000000", "7", "6"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a855c7679049814a0a06cbf78812c973 | Greg and Caves | Greg has a pad. The pad's screen is an *n*<=×<=*m* rectangle, each cell can be either black or white. We'll consider the pad rows to be numbered with integers from 1 to *n* from top to bottom. Similarly, the pad's columns are numbered with integers from 1 to *m* from left to right.
Greg thinks that the pad's screen displays a cave if the following conditions hold:
- There is a segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), such that each of the rows *l*,<=*l*<=+<=1,<=...,<=*r* has exactly two black cells and all other rows have only white cells. - There is a row number *t* (*l*<=≤<=*t*<=≤<=*r*), such that for all pairs of rows with numbers *i* and *j* (*l*<=≤<=*i*<=≤<=*j*<=≤<=*t*) the set of columns between the black cells in row *i* (with the columns where is these black cells) is the subset of the set of columns between the black cells in row *j* (with the columns where is these black cells). Similarly, for all pairs of rows with numbers *i* and *j* (*t*<=≤<=*i*<=≤<=*j*<=≤<=*r*) the set of columns between the black cells in row *j* (with the columns where is these black cells) is the subset of the set of columns between the black cells in row *i* (with the columns where is these black cells).
Greg wondered, how many ways there are to paint a cave on his pad. Two ways can be considered distinct if there is a cell that has distinct colors on the two pictures.
Help Greg.
The first line contains two integers *n*, *m* — the pad's screen size (1<=≤<=*n*,<=*m*<=≤<=2000).
In the single line print the remainder after dividing the answer to the problem by 1000000007 (109<=+<=7).
Sample Input
1 1
4 4
3 5
Sample Output
0
485
451
| {"inputs": ["1 1", "4 4", "3 5", "5 3", "5 5", "7 8", "9 8", "10 10", "100 100", "100 110", "100 200", "1 1000", "1000 1", "1000 3", "3 1000", "10 1000", "10 500", "250 250", "500 1000", "1000 500", "1000 1000", "1 2", "2000 2000", "1500 2000", "2000 1777", "1999 1994", "1994 1995", "1 2000", "2000 1", "2 2000", "2000 2", "3 1999", "1998 4"], "outputs": ["0", "485", "451", "185", "6751", "5898445", "72459477", "33937168", "631601096", "257801865", "852627600", "499500", "0", "1333331", "977762109", "298998986", "659024105", "331145635", "169229174", "900561408", "950299696", "1", "627008355", "294292096", "20685302", "785234759", "854486105", "1999000", "0", "668322662", "2001000", "583178527", "542192517"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a8695a151c7d1fee85c1c1e62cc8f6c1 | Jeff and Furik | Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of *n* numbers: *p*1, *p*2, ..., *p**n*. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent permutation elements and then the boy swaps them. During his move, Furic tosses a coin and if the coin shows "heads" he chooses a random pair of adjacent elements with indexes *i* and *i*<=+<=1, for which an inequality *p**i*<=><=*p**i*<=+<=1 holds, and swaps them. But if the coin shows "tails", Furik chooses a random pair of adjacent elements with indexes *i* and *i*<=+<=1, for which the inequality *p**i*<=<<=*p**i*<=+<=1 holds, and swaps them. If the coin shows "heads" or "tails" and Furik has multiple ways of adjacent pairs to take, then he uniformly takes one of the pairs. If Furik doesn't have any pair to take, he tosses a coin one more time. The game ends when the permutation is sorted in the increasing order.
Jeff wants the game to finish as quickly as possible (that is, he wants both players to make as few moves as possible). Help Jeff find the minimum mathematical expectation of the number of moves in the game if he moves optimally well.
You can consider that the coin shows the heads (or tails) with the probability of 50 percent.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3000). The next line contains *n* distinct integers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation *p*. The numbers are separated by spaces.
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Sample Input
2
1 2
5
3 5 2 4 1
Sample Output
0.000000
13.000000
| {"inputs": ["2\n1 2", "5\n3 5 2 4 1", "16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12", "9\n1 7 8 5 3 4 6 9 2", "5\n2 3 4 5 1", "9\n4 1 8 6 7 5 2 9 3", "10\n3 4 1 5 7 9 8 10 6 2", "13\n3 1 11 12 4 5 8 10 13 7 9 2 6", "10\n8 4 1 7 6 10 9 5 3 2", "2\n2 1", "95\n68 56 24 89 79 20 74 69 49 59 85 67 95 66 15 34 2 13 92 25 84 77 70 71 17 93 62 81 1 87 76 38 75 31 63 51 35 33 37 11 36 52 23 10 27 90 12 6 45 32 86 26 60 47 91 65 58 80 78 88 50 9 44 4 28 29 22 8 48 7 19 57 14 54 55 83 5 30 72 18 82 94 43 46 41 3 61 53 73 39 40 16 64 42 21"], "outputs": ["0.000000", "13.000000", "108.000000", "33.000000", "8.000000", "33.000000", "29.000000", "69.000000", "53.000000", "1.000000", "5076.000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 7 | codeforces |
|
a875c5dded52170798e08effa7cb6695 | Vasya and Socks | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
Sample Input
2 2
9 3
Sample Output
3
13
| {"inputs": ["2 2", "9 3", "1 2", "2 3", "1 99", "4 4", "10 2", "10 9", "100 100", "2 27", "99 100", "99 2", "100 3", "98 3", "4 4", "100 2", "62 4", "99 10", "100 5", "80 80", "95 16", "75 16", "99 74", "20 21", "52 96", "24 5"], "outputs": ["3", "13", "1", "2", "1", "5", "19", "11", "101", "2", "99", "197", "149", "146", "5", "199", "82", "109", "124", "81", "101", "79", "100", "20", "52", "29"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 468 | codeforces |
|
a8970e2b436e94ec4bcc241534b45bd6 | Tiling with Hexagons | Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has *a*, *b*, *c*, *a*, *b* and *c* adjacent tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for *a*<==<=2, *b*<==<=3 and *c*<==<=4.
According to the legend, as the King of Berland obtained the values *a*, *b* and *c*, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?
The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000).
Print a single number — the total number of tiles on the hall floor.
Sample Input
2 3 4
Sample Output
18 | {"inputs": ["2 3 4", "2 2 2", "7 8 13", "14 7 75", "201 108 304", "999 998 996", "2 2 3", "2 3 2", "3 2 2", "2 3 3", "3 2 3", "3 3 2", "3 3 3", "4 5 3", "2 2 856", "2 986 2", "985 2 2", "2 958 983", "992 2 912", "789 894 2", "1000 1000 1000", "384 458 284", "709 14 290", "485 117 521", "849 333 102", "998 999 1000", "2 2 1000", "2 1000 2", "1000 2 2", "1000 2 1000", "865 291 383", "41 49 28", "34 86 90", "39 23 56", "14 99 81", "48 38 193", "395 85 22", "38 291 89", "7 23 595", "948 48 3"], "outputs": ["18", "7", "224", "1578", "115032", "2983022", "10", "10", "10", "14", "14", "14", "19", "36", "2569", "2959", "2956", "943654", "906607", "707048", "2997001", "413875", "218584", "369265", "401998", "2991006", "3001", "3001", "3001", "1001999", "692925", "4412", "13515", "4252", "10346", "18144", "43634", "39922", "17387", "47494"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 64 | codeforces |
|
a89c8820cafbc7a9c6e3baacc9ad9840 | Wilbur and Points | Wilbur is playing with a set of *n* points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (*x*, *y*) belongs to the set, then all points (*x*', *y*'), such that 0<=≤<=*x*'<=≤<=*x* and 0<=≤<=*y*'<=≤<=*y* also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to *n*. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (*x*, *y*) gets number *i*, then all (*x*',*y*') from the set, such that *x*'<=≥<=*x* and *y*'<=≥<=*y* must be assigned a number not less than *i*. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as *s*(*x*,<=*y*)<==<=*y*<=-<=*x*. Now he gives Wilbur some *w*1, *w*2,..., *w**n*, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number *i* has it's special value equal to *w**i*, that is *s*(*x**i*,<=*y**i*)<==<=*y**i*<=-<=*x**i*<==<=*w**i*.
Now Wilbur asks you to help him with this challenge.
The first line of the input consists of a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of points in the set Wilbur is playing with.
Next follow *n* lines with points descriptions. Each line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=100<=000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (*x*, *y*) is present in the input, then all points (*x*', *y*'), such that 0<=≤<=*x*'<=≤<=*x* and 0<=≤<=*y*'<=≤<=*y*, are also present in the input.
The last line of the input contains *n* integers. The *i*-th of them is *w**i* (<=-<=100<=000<=≤<=*w**i*<=≤<=100<=000) — the required special value of the point that gets number *i* in any aesthetically pleasing numbering.
If there exists an aesthetically pleasant numbering of points in the set, such that *s*(*x**i*,<=*y**i*)<==<=*y**i*<=-<=*x**i*<==<=*w**i*, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with *n* lines. On the *i*-th of these lines print the point of the set that gets number *i*. If there are multiple solutions, print any of them.
Sample Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
3
1 0
0 0
2 0
0 1 2
Sample Output
YES
0 0
1 0
2 0
0 1
1 1
NO
| {"inputs": ["5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0", "3\n1 0\n0 0\n2 0\n0 1 2", "9\n0 0\n1 0\n2 0\n0 1\n1 1\n2 1\n1 2\n2 2\n0 2\n0 0 0 -1 -1 -2 1 1 2", "18\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n1 0\n0 1 2 3 4 5 6 7 8 9 -1 10 11 12 13 14 15 16", "1\n0 0\n0", "37\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n1 0\n0 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 -1 26 27 28 29 30 31 32 33 34 35", "31\n0 0\n0 1\n0 2\n0 3\n1 0\n1 1\n2 0\n2 1\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n24 0\n25 0\n0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 1 -15 2 -16 -17 -18 3 -19 -20 0 -21 -22 -23 -24 -25 -1", "40\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n1 0\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n0 1 2 -1 -2 3 4 -3 5 6 7 8 0 -4 -5 1 -6 -7 -8 -9 -10 -11 9 2 -12 -13 -14 3 10 -15 11 4 -16 -17 -18 -19 5 6 12 -20", "21\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n1 0\n1 1\n1 2\n1 3\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n86174 -26039 -13726 25840 85990 -62633 -29634 -68400 39255 1313 77388 830 -45558 -90862 97867 46376 58592 17103 32820 27220 94751", "31\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n1 0\n1 1\n1 2\n1 3\n1 4\n1 5\n2 0\n2 1\n2 2\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n-8 1 4 -11 0 -4 -10 3 4 -5 -9 8 7 6 2 -2 -1 9 -3 -14 2 3 -6 0 -7 -1 5 0 -13 -12 1", "1\n0 0\n-9876", "16\n0 0\n0 1\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 1 -11 -12 -13 -14", "5\n1 1\n0 1\n2 0\n1 0\n0 0\n0 -1 -2 1 0", "2\n0 0\n1 0\n-1 0"], "outputs": ["YES\n0 0\n1 0\n2 0\n0 1\n1 1", "NO", "NO", "YES\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n1 0\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16", "YES\n0 0", "YES\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n1 0\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35", "YES\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n0 1\n15 0\n0 2\n16 0\n17 0\n18 0\n0 3\n19 0\n20 0\n1 1\n21 0\n22 0\n23 0\n24 0\n25 0\n2 1", "YES\n0 0\n0 1\n0 2\n1 0\n2 0\n0 3\n0 4\n3 0\n0 5\n0 6\n0 7\n0 8\n1 1\n4 0\n5 0\n1 2\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n0 9\n1 3\n12 0\n13 0\n14 0\n1 4\n0 10\n15 0\n0 11\n1 5\n16 0\n17 0\n18 0\n19 0\n1 6\n1 7\n0 12\n20 0", "NO", "NO", "NO", "YES\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n0 1\n11 0\n12 0\n13 0\n14 0", "YES\n0 0\n1 0\n2 0\n0 1\n1 1", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 12 | codeforces |
|
a8b1aab3a22f8405c79e530a2a79375e | Christmas Spruce | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a parent.
Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.
The definition of a rooted tree can be found [here](https://goo.gl/1dqvzz).
The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*).
Vertex 1 is the root. It's guaranteed that the root has at least 2 children.
Print "Yes" if the tree is a spruce and "No" otherwise.
Sample Input
4
1
1
1
7
1
1
1
2
2
2
8
1
1
1
1
3
3
3
Sample Output
Yes
No
Yes
| {"inputs": ["4\n1\n1\n1", "7\n1\n1\n1\n2\n2\n2", "8\n1\n1\n1\n1\n3\n3\n3", "3\n1\n1", "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10", "7\n1\n2\n2\n1\n1\n1", "7\n1\n1\n1\n1\n2\n2", "8\n1\n1\n1\n1\n5\n5\n5", "9\n1\n1\n1\n1\n2\n6\n6\n6", "12\n1\n1\n1\n2\n5\n5\n5\n5\n1\n2\n2", "20\n1\n1\n1\n1\n2\n2\n2\n3\n3\n3\n4\n4\n4\n5\n5\n5\n1\n1\n1", "7\n1\n1\n1\n3\n3\n3"], "outputs": ["Yes", "No", "Yes", "No", "No", "No", "No", "Yes", "No", "No", "Yes", "No"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 122 | codeforces |
|
a8b9f0bb25f28f00fcfd1efbbfb86d8e | Paper Work | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. If *a**i* is negative, then the company suffered losses on the *i*-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the *n* days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (*a**i*<=<<=0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence *a**i*, will print the minimum number of folders.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*.
Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them.
Sample Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
5
0 -1 100 -1 0
Sample Output
3
5 3 3 1
5 | {"inputs": ["11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "5\n0 -1 100 -1 0", "1\n0", "1\n-1", "2\n0 0", "2\n-2 2", "2\n-2 -1", "12\n1 -12 -5 -8 0 -8 -1 -1 -6 12 -9 12", "4\n1 2 0 3", "4\n4 -3 3 3", "4\n0 -3 4 -3", "4\n-3 -2 4 -3", "4\n-3 -2 -1 -4", "5\n-2 -2 4 0 -1", "5\n-5 -3 -1 2 -1", "5\n-3 -2 -3 -2 -3", "10\n0 5 2 3 10 9 4 9 9 3", "10\n10 2 1 2 9 10 7 4 -4 5", "10\n1 -3 1 10 -7 -6 7 0 -5 3", "10\n6 5 -10 -4 -3 -7 5 -2 -6 -10", "10\n-2 -4 -1 -6 -5 -5 -7 0 -7 -8", "100\n48 36 10 85 15 57 100 70 14 82 15 75 67 44 40 83 12 94 80 77 92 40 39 80 11 10 2 22 71 31 93 51 22 29 98 90 33 91 66 64 87 70 46 86 62 13 85 15 37 3 49 11 21 57 26 14 5 80 33 82 9 75 26 76 50 32 48 100 62 11 97 47 67 81 86 80 51 51 44 97 2 22 18 52 43 54 65 91 94 54 22 80 23 63 44 7 52 98 80 69", "100\n7 51 31 14 17 0 72 29 77 6 32 94 70 94 1 64 85 29 67 66 56 -90 38 85 51 5 69 36 62 99 99 43 43 40 68 88 62 39 45 75 50 95 51 96 69 60 65 27 63 89 23 43 49 39 92 90 1 49 22 78 13 90 97 87 5 100 60 82 50 49 0 11 87 34 67 7 35 65 20 92 89 29 73 48 41 8 14 76 91 34 13 18 42 75 36 14 78 80 74 9", "100\n83 71 43 50 61 54 -45 44 36 35 44 21 34 65 23 32 73 36 70 17 46 47 10 30 48 25 84 58 63 96 44 88 24 93 26 24 70 69 90 75 20 42 63 11 0 41 54 23 95 99 17 27 43 20 46 100 65 -79 15 72 78 0 13 94 76 72 69 35 61 3 65 83 28 12 27 48 8 37 30 37 40 87 30 76 81 78 71 44 79 92 10 60 5 7 9 33 79 31 86 51", "100\n78 96 4 24 -66 42 28 16 42 -48 89 0 74 19 12 86 75 21 42 100 2 43 11 -76 85 24 12 51 26 48 22 74 68 73 22 39 53 42 37 -78 100 5 9 58 10 63 19 89 76 42 10 -96 76 49 67 59 86 37 13 66 75 92 48 80 37 59 49 -4 83 1 82 25 0 31 73 40 52 3 -47 17 68 94 51 84 47 76 73 -65 83 72 56 50 62 -5 40 12 81 75 84 -6", "100\n-63 20 79 73 18 82 23 -93 55 8 -31 37 33 24 30 41 70 77 14 34 84 79 -94 88 54 81 7 90 74 35 29 3 75 71 14 28 -61 63 90 79 71 97 -90 74 -33 10 27 34 46 31 9 90 100 -73 58 2 73 51 5 46 -27 -9 30 65 73 28 15 14 1 59 96 21 100 78 12 97 72 37 -28 52 12 0 -42 84 88 8 88 8 -48 39 13 -78 20 56 38 82 32 -87 45 39", "100\n21 40 60 28 85 10 15 -3 -27 -7 26 26 9 93 -3 -65 70 88 68 -85 24 75 24 -69 53 56 44 -53 -15 -74 12 22 37 22 77 90 9 95 40 15 -76 7 -81 65 83 51 -57 59 19 78 34 40 11 17 99 75 56 67 -81 39 22 86 -78 61 19 25 53 13 -91 91 17 71 45 39 63 32 -57 83 70 26 100 -53 7 95 67 -47 84 84 28 56 94 72 48 58 21 -89 91 73 16 93", "100\n39 -70 7 7 11 27 88 16 -3 94 94 -2 23 91 41 49 69 61 53 -99 98 54 87 44 48 73 62 80 86 -33 34 -87 56 48 4 18 92 14 -37 84 7 42 9 70 0 -78 17 68 54 -82 65 -21 59 90 72 -19 -81 8 92 88 -68 65 -42 -60 98 -39 -2 2 88 24 9 -95 17 75 12 -32 -9 85 7 88 59 14 90 69 19 -88 -73 1 2 72 15 -83 65 18 26 25 -71 3 -51 95", "100\n-47 -28 -90 -35 28 32 63 77 88 3 -48 18 48 22 47 47 89 2 88 46 25 60 65 44 100 28 73 71 19 -55 44 47 30 -25 50 15 -98 5 73 -56 61 15 15 77 67 59 -64 22 17 70 67 -12 26 -81 -58 -20 1 22 34 52 -45 56 78 29 47 -11 -10 70 -57 -2 62 85 -84 -54 -67 67 85 23 6 -65 -6 -79 -13 -1 12 68 1 71 73 77 48 -48 90 70 52 100 45 38 -43 -93", "100\n-34 -61 96 14 87 33 29 64 -76 7 47 -41 54 60 79 -28 -18 88 95 29 -89 -29 52 39 8 13 68 13 15 46 -34 -49 78 -73 64 -56 83 -16 45 17 40 11 -86 55 56 -35 91 81 38 -77 -41 67 16 -37 -56 -84 -42 99 -83 45 46 -56 -14 -15 79 77 -48 -87 94 46 77 18 -32 16 -18 47 67 35 89 95 36 -32 51 46 40 78 0 58 81 -47 41 5 -48 65 89 6 -79 -56 -25 74", "100\n14 36 94 -66 24 -24 14 -87 86 94 44 88 -68 59 4 -27 -74 12 -75 92 -31 29 18 -69 -47 45 -85 67 95 -77 7 -56 -80 -46 -40 73 40 71 41 -86 50 87 94 16 43 -96 96 -63 66 24 3 90 16 42 50 41 15 -45 72 32 -94 -93 91 -31 -30 -73 -88 33 45 9 71 18 37 -26 43 -82 87 67 62 -9 29 -70 -34 99 -30 -25 -86 -91 -70 -48 24 51 53 25 90 69 -17 -53 87 -62", "100\n-40 87 -68 72 -49 48 -62 73 95 27 80 53 76 33 -95 -53 31 18 -61 -75 84 40 35 -82 49 47 -13 22 -81 -65 -17 47 -61 21 9 -12 52 67 31 -86 -63 42 18 -25 70 45 -3 -18 94 -62 -28 16 -100 36 -96 -73 83 -65 9 -51 83 36 65 -24 77 38 81 -84 32 -34 75 -50 -92 11 -73 -17 81 -66 -61 33 -47 -50 -72 -95 -58 54 68 -46 -41 8 76 28 58 87 88 100 61 -61 75 -1", "100\n-61 56 1 -37 61 -77 -6 -5 28 36 27 -32 -10 -44 -89 -26 67 100 -94 80 -18 -5 -92 94 81 -38 -76 4 -77 2 79 55 -93 54 -19 10 -35 -12 -42 -32 -23 -67 -95 -62 -16 23 -25 41 -16 -51 3 -45 -1 53 20 0 0 21 87 28 15 62 64 -21 6 45 -19 95 -23 87 15 -35 21 -88 47 -81 89 68 66 -65 95 54 18 -97 65 -7 75 -58 -54 -3 99 -95 -57 -84 98 -6 33 44 81 -56", "100\n-21 61 -52 47 -25 -42 -48 -46 58 -13 75 -65 52 88 -59 68 -12 -25 33 14 -2 78 32 -41 -79 17 0 85 -39 -80 61 30 -27 -92 -100 66 -53 -11 -59 65 -5 92 -2 -85 87 -72 19 -50 -24 32 -27 -92 -100 14 72 13 67 -22 -27 -56 -84 -90 -74 -70 44 -92 70 -49 -50 11 57 -73 23 68 65 99 82 -18 -93 -34 85 45 89 -58 -80 5 -57 -98 -11 -96 28 30 29 -71 47 50 -15 30 -96 -53", "100\n-61 15 -88 52 -75 -71 -36 29 93 99 -73 -97 -69 39 -78 80 -28 -20 -36 -89 88 -82 56 -37 -13 33 2 -6 -88 -9 8 -24 40 5 8 -33 -83 -90 -48 55 69 -12 -49 -41 -4 92 42 57 -17 -68 -41 -68 77 -17 -45 -64 -39 24 -78 -3 -49 77 3 -23 84 -36 -19 -16 -72 74 -19 -81 65 -79 -57 64 89 -29 49 69 88 -18 16 26 -86 -58 -91 69 -43 -28 86 6 -87 47 -71 18 81 -55 -42 -30", "100\n-21 -98 -66 26 3 -5 86 99 96 -22 78 -16 20 -3 93 22 -67 -37 -27 12 -97 43 -46 -48 -58 -4 -19 26 -87 -61 67 -76 -42 57 -87 -50 -24 -79 -6 43 -68 -42 13 -1 -82 81 -32 -88 -6 -99 46 42 19 -17 89 14 -98 -24 34 -37 -17 49 76 81 -61 23 -46 -79 -48 -5 87 14 -97 -67 -31 94 -77 15 -44 38 -44 -67 -69 -84 -58 -59 -17 -54 3 -15 79 -28 -10 -26 34 -73 -37 -57 -42 -44", "100\n-63 -62 -88 -14 -58 -75 -28 19 -71 60 -38 77 98 95 -49 -64 -87 -97 2 -37 -37 -41 -47 -96 -58 -42 -88 12 -90 -65 0 52 -59 87 -79 -68 -66 -90 -19 -4 86 -65 -49 -94 67 93 -61 100 68 -40 -35 -67 -4 -100 -90 -86 15 -3 -75 57 65 -91 -80 -57 51 -88 -61 -54 -13 -46 -64 53 -87 -54 -69 29 -67 -23 -96 -93 -3 -77 -10 85 55 -44 17 24 -78 -82 -33 14 85 79 84 -91 -81 54 -89 -86", "100\n30 -47 -87 -49 -4 -58 -10 -10 -37 -15 -12 -85 4 24 -3 -2 57 57 -60 94 -21 82 1 -54 -39 -98 -72 57 84 -6 -41 82 93 -81 -61 -30 18 -68 -88 17 87 -6 43 -26 72 -14 -40 -75 -69 60 -91 -70 -26 -62 -13 -19 -97 -14 -59 -17 -44 -15 -65 60 -60 74 26 -6 12 -83 -49 82 -76 -96 -31 -98 -100 49 -50 -42 -43 92 -56 -79 -38 -86 -99 -37 -75 -26 -79 -12 -9 -87 -63 -62 -25 -3 -5 -92", "100\n-58 -18 -94 -96 -18 -2 -35 -49 47 69 96 -46 -88 -91 -9 -95 -12 -46 -12 16 44 -53 -96 71 -11 -98 -62 -27 -89 -88 -28 -11 -14 -47 67 -69 -33 -64 15 -24 67 53 -93 -10 -75 -98 -8 -97 -62 67 -52 -59 -9 -89 -39 -23 -37 -61 -83 -89 23 -47 -67 18 -38 -63 -73 -98 -65 -70 -20 13 -33 -46 -50 -30 -33 85 -93 -42 -37 48 -8 -11 -32 0 -58 -70 -27 -79 -52 82 22 -62 -100 -12 -5 -82 88 -74", "100\n-60 -62 -19 -42 -50 -22 -90 -82 -56 40 87 -1 -30 -76 -8 -32 -57 38 -14 -39 84 -60 -28 -82 -62 -83 -37 -59 -61 -86 -13 48 18 -8 50 -27 -47 -100 -42 -88 -19 -45 30 -93 -46 3 -26 -80 -61 -13 -20 76 -95 -51 -26 -1 39 -92 -41 -76 -67 26 -23 30 79 -26 -51 -40 -29 -14 -2 -43 -30 -19 -62 -65 -1 -90 -66 -38 -50 89 -17 -53 -6 -13 -41 -54 -1 -23 -31 -88 -59 -44 -67 -11 -83 -16 -23 -71", "100\n-1 -65 76 -28 -58 -63 -86 -54 -62 -66 -39 -3 -62 -35 -2 -86 -6 -16 -85 -30 -6 -41 -88 38 -8 -78 -6 -73 -83 -12 40 -99 -78 -51 -97 -15 81 -76 -1 -78 -38 -14 -24 -2 -70 -80 -24 -28 -51 -50 61 -64 -81 -32 -59 -60 -58 -10 -24 -81 -42 -7 58 -23 -11 -14 -84 -27 -45 2 -31 -32 -20 -72 -2 -81 -31 -6 -8 -91 55 -76 -93 -65 -94 -8 -57 -20 -75 -20 -27 -37 -82 97 -37 -8 -16 49 -90 -3", "100\n-75 -29 -14 -2 99 -94 -75 82 -17 -19 -61 -18 -14 -94 -17 16 -16 -4 -41 -8 -81 -26 -65 24 -7 -87 -85 -22 -74 -21 46 -31 -39 -82 -88 -20 -2 -13 -46 -1 -78 -66 -83 -50 -13 -15 -60 -56 36 -79 -99 -52 -96 -80 -97 -74 80 -90 -52 -33 -1 -78 73 -45 -3 -77 62 -4 -85 -44 -62 -74 -33 -35 -44 -14 -80 -20 -17 -83 -32 -40 -74 -13 -90 -62 -15 -16 -59 -15 -40 -50 -98 -33 -73 -25 -86 -35 -84 -41", "100\n-43 -90 -65 -70 -7 -49 -90 -93 -43 -80 -2 -47 -13 -5 -70 -42 -71 -68 -60 -71 -27 -84 82 -74 -75 -65 -32 -32 -50 -74 62 -96 -85 -95 -65 -51 -69 49 3 -19 -92 -61 -33 -7 -70 -51 -3 -1 -48 -48 -64 -7 -4 -46 -11 -36 -80 -69 -67 -1 -39 -40 66 -9 -40 -8 -58 -74 -27 66 -52 -26 -62 -72 -48 -25 -41 -13 -65 -82 -50 -68 -94 -52 -77 -91 -37 -18 -8 -51 -19 -22 -52 -95 35 -32 59 -41 -54 -88", "100\n-67 -100 -7 -13 -9 -78 -55 -68 -31 -18 -92 -23 -4 -99 -54 -97 -45 -24 -33 -95 -42 -20 -63 -24 -89 -25 -55 -35 -84 -30 -1 57 -88 -94 -67 -27 -91 -14 -13 -20 -7 -8 -33 -95 -1 -75 -80 -49 -15 -64 -73 -49 -87 -19 -44 -50 -19 -10 -90 -51 -74 90 -42 -18 -93 -99 -43 51 -96 95 -97 -36 -21 -13 -73 -37 -33 -22 -83 -33 -44 -84 -20 -78 -34 -70 -83 -83 -85 -17 -36 62 83 -73 -6 51 -77 -82 -83 -68", "100\n-30 -40 -64 -50 -13 -69 -87 -54 -7 -32 -38 30 -79 -31 57 -50 -3 -6 -13 -94 -28 -57 -95 -67 -82 -49 -83 -39 -41 -12 -73 -20 -17 -46 -92 -31 -36 -31 -80 -47 -37 -67 -41 -65 -7 -95 -85 -53 -87 -18 -52 -61 -98 -85 -6 -80 -96 -95 -72 -9 -19 -49 74 84 -60 -69 -64 -39 -82 -28 -24 -82 -13 -7 -15 -28 -26 -48 -88 -9 -36 -38 -75 -1 9 -15 -12 -47 -11 -45 -3 -10 -60 -62 -54 -60 45 -8 -43 -89", "100\n-78 -77 -84 -29 -99 -15 -60 97 -56 -9 -19 -21 -5 -29 -20 -41 -56 -15 -77 -22 -87 -75 -56 -96 -46 -24 -35 -64 63 -5 -16 -27 34 -77 84 -30 -9 -73 -58 -93 -20 -20 -69 -16 -42 -40 -44 -66 -42 -90 -47 -35 -87 -55 -37 -48 -34 -3 -40 -3 -46 -25 -80 -55 -12 -62 -46 -99 -38 -33 -72 -60 -18 -12 -52 -3 -75 -5 -48 -30 -59 -56 99 -52 -59 -72 -41 -15 -19 -19 -26 -28 -16 -23 -46 -93 -92 -38 -12 -75", "100\n22 -83 -95 -61 -100 -53 -50 -19 -24 -85 -45 -43 -3 -74 -6 -24 -78 -54 -58 -52 -42 -16 -18 -56 -93 -45 -97 -67 -88 -27 83 -7 -72 -85 -24 -45 -22 -82 -83 -94 -75 -79 -22 -44 -22 -44 -42 -44 -61 85 -11 -16 -91 -12 -15 -3 -15 -82 -1 -2 -28 -24 -68 -22 -25 -46 -40 -21 -67 -90 -31 -33 -54 -83 -91 -74 -56 -67 -87 -36 -8 -100 -76 -88 -90 -45 -64 -25 -55 -15 -84 -67 -57 -73 -78 86 -28 -41 -63 -57", "100\n-13 -43 -95 -61 -62 -94 -97 -48 -16 -88 -96 -74 -26 -58 -79 -44 -72 -22 -18 -66 -8 85 -98 -3 -36 -17 -80 -82 -77 -41 -24 -86 -62 -1 -22 -29 -30 -18 -25 -90 -66 -58 -86 -81 -34 -76 -67 -72 -77 -29 -66 -67 -34 3 -16 -90 -9 -14 -28 -60 -26 -99 75 -74 -94 -55 -54 -23 -30 -34 -4 -92 -88 -46 -52 -63 -98 -6 -89 -99 -80 -100 -97 -62 -70 -97 -75 -85 -22 -2 -32 -47 -85 -44 -23 -4 -21 -30 -6 -34", "100\n-5 -37 -22 -85 -63 -46 -44 -43 -23 -77 -75 -64 -84 -46 -78 -94 -67 -19 -5 -59 -32 -92 -10 -92 -58 -73 -72 -16 99 -58 -94 -49 -60 -3 -60 -74 -12 -8 -32 -94 -63 -53 -24 -29 -6 -46 -30 -32 -87 -41 -58 -70 -53 -20 -73 -42 -54 -5 -84 -45 -11 -9 -84 -7 -68 -100 -11 -2 -87 -27 -65 -45 -17 -33 -88 -55 90 -58 -89 -13 -66 -1 -46 -90 -69 -74 -84 -90 -50 -32 -62 -37 -44 -51 -25 -94 -73 -43 -1 -44", "100\n-76 -48 -63 -62 -94 -37 -54 -67 -9 -52 -83 -1 -87 -36 -94 -10 -19 -55 -93 -23 -2 -87 -15 -59 -60 -87 -63 -18 -62 -92 -10 -61 -12 -89 -85 -38 -37 -3 -71 -22 -94 -96 -100 -47 -20 -93 -28 77 -35 -74 -50 -72 -38 -29 -58 -80 -24 -9 -59 -4 -93 -65 -31 -47 -36 -13 -89 -96 -99 -83 -99 -36 -45 -58 -22 -93 -51 -26 -93 -36 -85 -72 -49 -27 -69 -29 -51 -84 -35 -26 -41 -43 -45 -87 -65 -100 -45 -69 -69 -73", "100\n-77 -6 -71 -86 -42 -1 -40 -41 -31 -67 -75 -49 -62 -21 -2 -40 -2 -82 -90 -42 -43 -14 -72 -50 -33 -37 -58 -51 -67 -96 -63 -39 -56 -22 -17 -69 -88 -60 -18 -47 -16 -41 -32 -59 -82 -48 -22 -46 -29 -69 -21 -2 -41 -52 -83 -3 -49 -39 -31 -78 -60 -100 -12 -64 -28 -72 -43 -68 -60 -98 -21 -29 -72 -82 -5 -4 -65 -76 -60 -40 -37 -17 -77 -21 -19 -98 -39 -67 -49 -75 -7 -45 -11 -13 -45 -19 -83 -38 -14 -89", "4\n1 2 3 4", "4\n1 2 3 -4", "4\n-4 2 1 2", "1\n-1", "2\n2 -1", "2\n-100 100", "3\n-100 0 -100", "5\n1 2 3 -1 -1", "5\n-1 -1 2 3 4", "3\n-3 -4 -5", "4\n-3 -4 1 -3", "1\n-1", "2\n-1 0", "4\n0 0 0 0", "3\n-1 -1 -1", "6\n-1 -1 0 -1 -1 -1", "2\n0 0", "6\n0 0 -1 -1 -1 0"], "outputs": ["3\n5 3 3 ", "1\n5 ", "1\n1 ", "1\n1 ", "1\n2 ", "1\n2 ", "1\n2 ", "4\n3 3 2 4 ", "1\n4 ", "1\n4 ", "1\n4 ", "2\n1 3 ", "2\n2 2 ", "2\n1 4 ", "2\n2 3 ", "3\n1 2 2 ", "1\n10 ", "1\n10 ", "2\n5 5 ", "4\n3 2 3 2 ", "5\n1 2 2 2 3 ", "1\n100 ", "1\n100 ", "1\n100 ", "5\n10 30 28 20 12 ", "8\n1 10 26 8 16 18 10 11 ", "10\n9 6 5 8 2 13 16 10 13 18 ", "13\n2 10 18 9 11 6 5 3 3 9 10 6 8 ", "15\n2 2 26 7 10 7 2 10 3 4 2 6 2 9 8 ", "18\n1 8 7 5 10 3 4 8 5 4 2 5 2 4 7 15 7 3 ", "20\n6 7 4 4 4 5 3 2 11 12 4 3 2 9 6 3 2 2 8 3 ", "23\n1 4 10 4 5 5 2 5 5 6 3 3 3 4 8 4 3 3 3 2 2 4 11 ", "25\n4 3 5 2 2 5 2 4 6 4 2 2 2 2 4 3 12 5 5 6 6 3 3 2 6 ", "28\n1 4 2 3 5 3 6 5 4 2 3 3 3 4 3 2 6 2 2 3 3 9 2 5 3 2 7 3 ", "30\n3 3 5 2 4 2 3 3 4 3 5 2 4 2 5 2 3 2 3 4 3 2 3 3 7 4 3 4 5 2 ", "33\n1 2 7 4 4 3 3 2 3 3 3 2 2 3 3 3 2 7 3 5 3 2 4 3 4 2 2 2 3 3 3 2 2 ", "35\n2 2 2 3 6 2 3 2 2 2 3 4 3 2 2 3 4 4 2 2 3 4 2 3 2 2 3 3 2 2 2 6 2 6 3 ", "38\n2 2 2 2 2 2 4 5 4 2 4 4 3 4 4 2 3 2 2 2 2 2 2 5 3 3 2 3 2 3 2 2 2 2 2 2 2 2 ", "40\n2 2 2 2 5 2 2 2 4 3 2 2 2 2 3 3 4 2 2 3 2 2 2 2 3 3 2 2 2 3 2 3 2 3 3 2 2 4 2 3 ", "43\n1 2 2 2 2 4 2 2 3 3 2 2 2 2 5 2 2 2 3 3 2 3 2 3 2 3 4 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 ", "45\n2 3 2 2 2 2 2 2 2 2 2 3 2 2 3 2 3 2 2 2 2 2 2 3 2 2 2 2 3 2 2 3 2 2 2 2 3 2 2 2 2 2 3 2 3 ", "46\n1 2 3 3 2 2 2 3 2 2 3 2 2 3 2 2 2 2 2 2 2 2 3 2 2 3 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ", "46\n2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 4 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 2 2 4 2 ", "47\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 4 2 2 2 2 2 2 2 2 2 2 4 3 2 ", "47\n2 2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 3 2 2 2 2 3 2 ", "48\n1 2 2 2 3 2 2 2 2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 ", "48\n3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 ", "49\n1 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ", "49\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 ", "50\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ", "50\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ", "1\n4 ", "1\n4 ", "1\n4 ", "1\n1 ", "1\n2 ", "1\n2 ", "1\n3 ", "1\n5 ", "1\n5 ", "2\n1 2 ", "2\n1 3 ", "1\n1 ", "1\n2 ", "1\n4 ", "2\n1 2 ", "3\n1 3 2 ", "1\n2 ", "2\n3 3 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 100 | codeforces |
|
a8bdd009f7ce1f2f44c150ad8504bc9a | Lipshitz Sequence | A function is called Lipschitz continuous if there is a real constant *K* such that the inequality |*f*(*x*)<=-<=*f*(*y*)|<=≤<=*K*·|*x*<=-<=*y*| holds for all . We'll deal with a more... discrete version of this term.
For an array , we define it's Lipschitz constant as follows:
- if *n*<=<<=2, - if *n*<=≥<=2, over all 1<=≤<=*i*<=<<=*j*<=≤<=*n*
In other words, is the smallest non-negative integer such that |*h*[*i*]<=-<=*h*[*j*]|<=≤<=*L*·|*i*<=-<=*j*| holds for all 1<=≤<=*i*,<=*j*<=≤<=*n*.
You are given an array of size *n* and *q* queries of the form [*l*,<=*r*]. For each query, consider the subarray ; determine the sum of Lipschitz constants of all subarrays of .
The first line of the input contains two space-separated integers *n* and *q* (2<=≤<=*n*<=≤<=100<=000 and 1<=≤<=*q*<=≤<=100) — the number of elements in array and the number of queries respectively.
The second line contains *n* space-separated integers ().
The following *q* lines describe queries. The *i*-th of those lines contains two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Print the answers to all queries in the order in which they are given in the input. For the *i*-th query, print one line containing a single integer — the sum of Lipschitz constants of all subarrays of .
Sample Input
10 4
1 5 2 9 1 3 4 2 1 7
2 4
3 8
7 10
1 9
7 6
5 7 7 4 6 6 2
1 2
2 3
2 6
1 7
4 7
3 5
Sample Output
17
82
23
210
2
0
22
59
16
8
| {"inputs": ["10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9", "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5", "2 2\n0 0\n1 2\n1 2", "2 2\n0 100000000\n1 2\n1 2", "4 6\n1 2 3 2\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "3 6\n10 20 30\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3", "3 6\n48261735 26888803 75904937\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3", "3 6\n100000000 99999999 0\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3", "2 2\n100000000 0\n1 2\n1 2"], "outputs": ["17\n82\n23\n210", "2\n0\n22\n59\n16\n8", "0\n0", "100000000\n100000000", "1\n3\n6\n1\n3\n1", "10\n30\n10\n10\n10\n30", "21372932\n119405200\n49016134\n21372932\n49016134\n119405200", "1\n199999999\n99999999\n1\n99999999\n199999999", "100000000\n100000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a8d9c374dc35bbbb2575ed30d529d3b7 | Little Elephant and Sorting | The Little Elephant loves sortings.
He has an array *a* consisting of *n* integers. Let's number the array elements from 1 to *n*, then the *i*-th element will be denoted as *a**i*. The Little Elephant can make one move to choose an arbitrary pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) and increase *a**i* by 1 for all *i* such that *l*<=≤<=*i*<=≤<=*r*.
Help the Little Elephant find the minimum number of moves he needs to convert array *a* to an arbitrary array sorted in the non-decreasing order. Array *a*, consisting of *n* elements, is sorted in the non-decreasing order if for any *i* (1<=≤<=*i*<=<<=*n*) *a**i*<=≤<=*a**i*<=+<=1 holds.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* integers, separated by single spaces — array *a* (1<=≤<=*a**i*<=≤<=109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem.
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.
Sample Input
3
1 2 3
3
3 2 1
4
7 4 1 47
Sample Output
0
2
6
| {"inputs": ["3\n1 2 3", "3\n3 2 1", "4\n7 4 1 47", "10\n1 2 3 4 5 6 7 8 9 1000000000", "10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1", "7\n47 47 47 47 47 47 48", "47\n479793446 951468508 89486286 338446715 32648506 624498057 608503040 669251062 922459299 753303599 15471514 633954104 726178809 25774434 239818174 886000554 86565563 340322990 233160987 244152140 400122002 267331289 113220645 554372347 628491411 141545764 72472415 172718507 818323067 524691081 273905810 540908460 264978418 971408123 336064021 681508839 387880395 446312618 486187013 687624992 335098176 259987774 832741771 604233011 459307319 378796313 520655387", "47\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3", "74\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\n940259367", "2\n710095427 879909817", "3\n39740000 928596641 251625421", "47\n3 999999997 5 999999991 9 999999996 1 999999991 6 999999996 4 999999998 6 999999994 4 999999994 7 999999990 1 999999993 6 999999997 4 999999996 1 999999990 7 1000000000 3 999999994 5 999999997 3 999999991 2 999999997 4 999999992 8 999999994 10 999999992 2 999999995 2 999999990 2", "47\n703599938 780784195 912005704 957182560 961181825 964876912 996677776 997012583 999004240 999888999 999980718 999997556 999997940 999999989 999999991 999999991 999999999 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"], "outputs": ["0", "2", "6", "0", "4999999995", "0", "7171587476", "76", "0", "0", "0", "676971220", "22999999763", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 54 | codeforces |
|
a9142d7a0d07b86b7e2a3da2f1ed8549 | Rumor | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
Sample Input
5 2
2 5 3 4 8
1 4
4 5
10 0
1 2 3 4 5 6 7 8 9 10
10 5
1 6 2 7 3 8 4 9 5 10
1 2
3 4
5 6
7 8
9 10
Sample Output
10
55
15
| {"inputs": ["5 2\n2 5 3 4 8\n1 4\n4 5", "10 0\n1 2 3 4 5 6 7 8 9 10", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "1 0\n0", "1 0\n1000000000", "2 0\n0 0", "2 0\n1000000000 0", "2 0\n0 1000000000", "2 0\n1000000000 1000000000", "2 1\n0 0\n1 2"], "outputs": ["10", "55", "15", "0", "1000000000", "0", "1000000000", "1000000000", "2000000000", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 104 | codeforces |
|
a92dfe19131f642079f8c1857648c0f3 | Warehouse | Once upon a time, when the world was more beautiful, the sun shone brighter, the grass was greener and the sausages tasted better Arlandia was the most powerful country. And its capital was the place where our hero DravDe worked. He couldn’t program or make up problems (in fact, few people saw a computer those days) but he was nevertheless happy. He worked in a warehouse where a magical but non-alcoholic drink Ogudar-Olok was kept. We won’t describe his work in detail and take a better look at a simplified version of the warehouse.
The warehouse has one set of shelving. It has *n* shelves, each of which is divided into *m* sections. The shelves are numbered from top to bottom starting from 1 and the sections of each shelf are numbered from left to right also starting from 1. Each section can contain exactly one box of the drink, and try as he might, DravDe can never put a box in a section that already has one. In the course of his work DravDe frequently notices that he has to put a box in a filled section. In that case his solution is simple. DravDe ignores that section and looks at the next one to the right. If it is empty, he puts the box there. Otherwise he keeps looking for the first empty section to the right. If no empty section is found by the end of the shelf, he looks at the shelf which is under it, then the next one, etc. Also each time he looks at a new shelf he starts from the shelf’s beginning. If DravDe still can’t find an empty section for the box, he immediately drinks it all up and throws the empty bottles away not to be caught.
After one great party with a lot of Ogudar-Olok drunk DravDe asked you to help him. Unlike him, you can program and therefore modeling the process of counting the boxes in the warehouse will be easy work for you.
The process of counting contains two types of query messages:
- «+1 x y id» (where *x*, *y* are integers, 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m*, and *id* is a string of lower case Latin letters — from 1 to 10 characters long). That query means that the warehouse got a box identified as *id*, which should be put in the section *y* on the shelf *x*. If the section is full, use the rules described above. It is guaranteed that every moment of the process the identifiers of all the boxes in the warehouse are different. You don’t have to answer this query. - «-1 id» (where *id* is a string of lower case Latin letters — from 1 to 10 characters long). That query means that a box identified as *id* is removed from the warehouse. You have to answer this query (see output format).
The first input line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=30, 1<=≤<=*k*<=≤<=2000) — the height, the width of shelving and the amount of the operations in the warehouse that you need to analyze. In the following *k* lines the queries are given in the order of appearance in the format described above.
For each query of the «-1 id» type output two numbers in a separate line — index of the shelf and index of the section where the box with this identifier lay. If there was no such box in the warehouse when the query was made, output «-1 -1» without quotes.
Sample Input
2 2 9
+1 1 1 cola
+1 1 1 fanta
+1 1 1 sevenup
+1 1 1 whitekey
-1 cola
-1 fanta
-1 sevenup
-1 whitekey
-1 cola
2 2 8
+1 1 1 cola
-1 cola
+1 1 1 fanta
-1 fanta
+1 1 1 sevenup
-1 sevenup
+1 1 1 whitekey
-1 whitekey
Sample Output
1 1
1 2
2 1
2 2
-1 -1
1 1
1 1
1 1
1 1
| {"inputs": ["2 2 9\n+1 1 1 cola\n+1 1 1 fanta\n+1 1 1 sevenup\n+1 1 1 whitekey\n-1 cola\n-1 fanta\n-1 sevenup\n-1 whitekey\n-1 cola", "2 2 8\n+1 1 1 cola\n-1 cola\n+1 1 1 fanta\n-1 fanta\n+1 1 1 sevenup\n-1 sevenup\n+1 1 1 whitekey\n-1 whitekey", "2 2 5\n-1 ywesjzsdk\n-1 aaew\n+1 1 2 wk\n-1 wk\n-1 wk", "3 5 5\n-1 vpotlzzxu\n-1 ucdpqnechl\n-1 ykphisxph\n-1 buppgmurvz\n-1 rjhowqxmv", "4 6 7\n+1 2 3 psj\n+1 4 5 vpjghrat\n+1 1 2 edvffw\n+1 4 2 lvmfvxowzz\n+1 3 6 hqiyvevtll\n+1 4 4 unfpiingsi\n-1 unfpiingsi", "6 5 10\n+1 2 5 gw\n+1 3 4 mbgrh\n-1 gw\n+1 3 3 abcs\n-1 mbgrh\n+1 4 1 yna\n+1 3 3 fmhjovjklc\n+1 1 3 mcdspppmrv\n+1 2 4 ohiefjcq\n+1 3 1 jpk", "7 6 10\n-1 e\n-1 kzbdpeckem\n-1 esi\n-1 jgsokv\n-1 serkq\n-1 ipczknkye\n-1 bawktukez\n-1 wvw\n-1 jm\n+1 5 2 i", "8 9 20\n+1 1 5 dsszh\n+1 6 3 xggbssovef\n+1 8 4 ura\n+1 8 4 l\n+1 6 6 jxszipfobb\n-1 l\n+1 6 7 ib\n+1 3 1 sxwnv\n+1 7 2 zattgyj\n+1 4 7 kvzatjkftd\n-1 dsszh\n+1 3 1 wsqbde\n+1 5 9 otwlz\n+1 2 3 hpaatle\n+1 2 9 evp\n+1 5 6 v\n-1 hpaatle\n-1 hpaatle\n-1 ura\n-1 otwlz", "5 1 10\n+1 2 1 t\n-1 t\n-1 t\n+1 5 1 prcle\n-1 t\n+1 3 1 epkbtyjk\n+1 3 1 kwqzwt\n-1 epkbtyjk\n+1 3 1 v\n+1 2 1 xib", "1 7 25\n-1 rwej\n+1 1 5 v\n-1 v\n-1 aoqq\n-1 ekyqnk\n-1 qhsguruyme\n-1 hnaro\n-1 xccmrodgx\n-1 t\n-1 oasftssp\n-1 hvacacmdff\n-1 wjmti\n-1 s\n-1 pekyyriywk\n-1 vxnz\n+1 1 7 xgfcnftep\n+1 1 7 vexyo\n-1 xgfcnftep\n-1 vexyo\n-1 fxygf\n+1 1 5 yyklyiul\n-1 yyklyiul\n-1 tknmop\n-1 dch\n-1 m", "2 10 27\n+1 1 1 axxhgy\n+1 2 2 vhhmrgppzf\n+1 2 5 bvycznpbx\n-1 bvycznpbx\n+1 1 6 kdfmydiy\n+1 2 8 qad\n+1 1 7 mvvyza\n+1 1 6 i\n-1 mvvyza\n-1 vhhmrgppzf\n-1 axxhgy\n-1 qad\n-1 i\n-1 kdfmydiy\n+1 2 3 bjust\n+1 2 1 f\n-1 f\n-1 bjust\n+1 2 5 mrgryhbg\n+1 1 1 eaonus\n-1 eaonus\n+1 2 2 zavxcoam\n-1 mrgryhbg\n-1 zavxcoam\n+1 2 3 mqrwhwdbzg\n+1 2 9 rwby\n+1 2 2 wfgkuiapxq", "1 30 10\n+1 1 16 kqqpjfkhg\n-1 kqqpjfkhg\n+1 1 26 jmvcacxdc\n+1 1 16 xh\n-1 jmvcacxdc\n-1 xh\n+1 1 23 gbra\n+1 1 25 k\n+1 1 22 nctorw\n-1 gbra", "30 5 20\n+1 30 2 drzlg\n-1 drzlg\n+1 20 3 e\n+1 18 2 tip\n+1 1 5 jap\n-1 jap\n+1 19 2 jadnylbug\n+1 12 3 fcuhloenmz\n-1 tip\n+1 2 1 ut\n+1 26 2 unts\n+1 5 2 vbep\n+1 28 4 anacba\n-1 ut\n+1 23 1 urrmf\n+1 10 3 atbqvnlcg\n-1 unts\n-1 jadnylbug\n+1 25 2 kwzhnqzwuc\n+1 9 3 ppyzv"], "outputs": ["1 1\n1 2\n2 1\n2 2\n-1 -1", "1 1\n1 1\n1 1\n1 1", "-1 -1\n-1 -1\n1 2\n-1 -1", "-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1", "4 4", "2 5\n3 4", "-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1", "8 5\n1 5\n2 3\n-1 -1\n8 4\n5 9", "2 1\n-1 -1\n-1 -1\n3 1", "-1 -1\n1 5\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n1 7\n-1 -1\n-1 -1\n1 5\n-1 -1\n-1 -1\n-1 -1", "2 5\n1 7\n2 2\n1 1\n2 8\n1 8\n1 6\n2 1\n2 3\n1 1\n2 5\n2 2", "1 16\n1 26\n1 16\n1 23", "30 2\n1 5\n18 2\n2 1\n26 2\n19 2"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 6 | codeforces |
|
a9334ecfe4eda493c86d67d26b117c09 | Random Query | You are given an array *a* consisting of *n* positive integers. You pick two integer numbers *l* and *r* from 1 to *n*, inclusive (numbers are picked randomly, equiprobably and independently). If *l*<=><=*r*, then you swap values of *l* and *r*. You have to calculate the expected value of the number of unique elements in segment of the array from index *l* to index *r*, inclusive (1-indexed).
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integer numbers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array.
Print one number — the expected number of unique elements in chosen segment.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=4 — formally, the answer is correct if , where *x* is jury's answer, and *y* is your answer.
Sample Input
2
1 2
2
2 2
Sample Output
1.500000
1.000000
| {"inputs": ["2\n1 2", "2\n2 2", "10\n9 6 8 5 5 2 8 9 2 2", "20\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21", "1\n1000000"], "outputs": ["1.500000", "1.000000", "3.100000", "7.010000", "1.000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 8 | codeforces |
|
a954c9b3c7a84fd96eda0a8f7520b89c | Painting Eggs | The Bitlandians are quite weird people. They have very peculiar customs.
As is customary, Uncle J. wants to have *n* eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.
The kids are excited because just as is customary, they're going to be paid for the job!
Overall uncle J. has got *n* eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.
Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.
Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.
The first line contains integer *n* (1<=≤<=*n*<=≤<=106) — the number of eggs.
Next *n* lines contain two integers *a**i* and *g**i* each (0<=≤<=*a**i*,<=*g**i*<=≤<=1000; *a**i*<=+<=*g**i*<==<=1000): *a**i* is the price said by A. for the *i*-th egg and *g**i* is the price said by G. for the *i*-th egg.
If it is impossible to assign the painting, print "-1" (without quotes).
Otherwise print a string, consisting of *n* letters "G" and "A". The *i*-th letter of this string should represent the child who will get the *i*-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as *S**a*, and the money Uncle J. must pay G. for the painting as *S**g*, then this inequality must hold: |*S**a*<=<=-<=<=*S**g*|<=<=≤<=<=500.
If there are several solutions, you are allowed to print any of them.
Sample Input
2
1 999
999 1
3
400 600
400 600
400 600
Sample Output
AG
AGA
| {"inputs": ["2\n1 999\n999 1", "3\n400 600\n400 600\n400 600", "2\n500 500\n500 500", "1\n1 999", "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999", "2\n499 501\n501 499", "3\n500 500\n1 999\n400 600", "1\n0 1000", "1\n500 500", "1\n1000 0"], "outputs": ["AG", "AGA", "AG", "A", "AAAAAAAAAA", "AG", "AGA", "A", "A", "G"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 3 | codeforces |
|
a979154b5b2a8175788285841d9e28d3 | Game With Sticks | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9.
The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).
Assume that both players play optimally. Who will win the game?
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
Sample Input
2 2
2 3
3 3
Sample Output
Malvika
Malvika
Akshat
| {"inputs": ["2 2", "2 3", "3 3", "20 68", "1 1", "1 2", "1 3", "2 1", "2 2", "3 1", "3 2", "68 42", "1 35", "25 70", "59 79", "65 63", "46 6", "28 82", "98 98", "98 99", "98 100", "99 98", "99 99", "99 100", "100 98", "100 99", "100 100", "3 4"], "outputs": ["Malvika", "Malvika", "Akshat", "Malvika", "Akshat", "Akshat", "Akshat", "Akshat", "Malvika", "Akshat", "Malvika", "Malvika", "Akshat", "Akshat", "Akshat", "Akshat", "Malvika", "Malvika", "Malvika", "Malvika", "Malvika", "Malvika", "Akshat", "Akshat", "Malvika", "Akshat", "Malvika", "Akshat"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 254 | codeforces |
|
a98bb4e313d9676809393673a356aec7 | Deletion of Repeats | Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length *x* is such a substring of length 2*x*, that its first half coincides character by character with its second half. Bob started deleting all the repeats from the string. He does it as follows: while it's possible, Bob takes the shortest repeat, if it is not unique, he takes the leftmost one, and deletes its left half and everything that is to the left of this repeat.
You're given the string seen by Bob. Find out, what it will look like after Bob deletes all the repeats in the way described above.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — length of the string. The following line contains *n* space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.
In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.
Sample Input
6
1 2 3 1 2 3
7
4 5 6 5 6 7 7
Sample Output
3
1 2 3
1
7
| {"inputs": ["6\n1 2 3 1 2 3", "7\n4 5 6 5 6 7 7", "10\n5 7 2 1 8 8 5 10 2 5", "10\n0 1 1 1 0 3 0 1 4 0", "10\n0 1 0 2 0 0 1 1 1 0", "30\n17 17 2 4 13 21 17 11 15 0 9 2 23 10 24 21 23 17 5 11 25 1 16 6 11 22 19 2 12 16", "100\n8 43 55 27 70 81 66 10 49 67 24 61 53 0 2 76 96 16 16 1 78 1 69 69 4 59 6 87 98 14 98 20 12 48 20 41 67 90 20 96 44 8 77 94 84 2 61 27 90 42 66 84 5 19 68 13 5 53 13 87 70 41 48 40 19 61 72 31 4 4 59 100 50 64 84 10 96 16 73 3 63 85 67 91 74 63 22 34 6 96 78 42 61 85 3 95 98 84 66 78", "100\n5 4 8 2 4 7 6 6 9 0 5 9 9 8 2 1 10 7 1 0 0 6 3 5 3 7 8 0 0 10 6 7 10 5 4 10 7 6 7 5 1 5 0 10 3 10 5 7 4 10 0 9 1 2 6 3 3 6 10 6 9 1 6 3 4 6 2 8 8 9 5 2 3 3 10 7 4 1 10 1 8 5 4 3 2 2 0 4 4 1 4 5 7 2 8 7 1 1 2 8", "100\n19 17 16 6 4 13 7 12 4 16 2 2 12 15 20 17 3 13 14 2 4 20 14 10 11 17 7 17 12 18 17 14 10 16 20 16 19 12 9 15 2 13 5 6 9 3 14 6 20 3 15 16 0 12 5 11 3 19 5 2 11 18 20 20 11 4 1 10 20 10 19 0 4 10 1 11 4 11 8 19 3 14 6 1 14 2 13 20 8 3 19 19 6 19 19 20 20 8 13 14", "10\n1 2 1 2 1 2 1 2 1 2", "10\n1 2 3 4 5 1 2 3 4 5", "10\n1 1 1 1 1 1 1 1 1 1", "21\n16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296", "22\n823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040", "23\n482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044", "1\n0", "2\n1 2", "2\n1000000000 1000000000", "3\n1000000000 1000000000 1000000000", "4\n1000000000 1000000000 1000000000 1000000000", "7\n1 2 3 1 2 3 1", "30\n0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2", "10\n0 0 0 0 0 0 0 0 0 0", "20\n0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1"], "outputs": ["3\n1 2 3 ", "1\n7 ", "5\n8 5 10 2 5 ", "7\n1 0 3 0 1 4 0 ", "2\n1 0 ", "29\n17 2 4 13 21 17 11 15 0 9 2 23 10 24 21 23 17 5 11 25 1 16 6 11 22 19 2 12 16 ", "31\n4 59 100 50 64 84 10 96 16 73 3 63 85 67 91 74 63 22 34 6 96 78 42 61 85 3 95 98 84 66 78 ", "3\n1 2 8 ", "4\n20 8 13 14 ", "2\n1 2 ", "5\n1 2 3 4 5 ", "1\n1 ", "3\n16417014 805849548 385039296 ", "4\n823078040 389511796 683819000 823078040 ", "5\n482255418 973174044 835115058 482255418 973174044 ", "1\n0 ", "2\n1 2 ", "1\n1000000000 ", "1\n1000000000 ", "1\n1000000000 ", "4\n1 2 3 1 ", "1\n2 ", "1\n0 ", "1\n1 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a9b139efa7de061f69403d9289843020 | Happy Farm 5 | The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them.
For that a young player Vasya decided to make the shepherd run round the cows along one and the same closed path. It is very important that the cows stayed strictly inside the area limited by the path, as otherwise some cows will sooner or later be eaten. To be absolutely sure in the cows' safety, Vasya wants the path completion time to be minimum.
The new game is launched for different devices, including mobile phones. That's why the developers decided to quit using the arithmetics with the floating decimal point and use only the arithmetics of integers. The cows and the shepherd in the game are represented as points on the plane with integer coordinates. The playing time is modeled by the turns. During every turn the shepherd can either stay where he stands or step in one of eight directions: horizontally, vertically, or diagonally. As the coordinates should always remain integer, then the length of a horizontal and vertical step is equal to 1, and the length of a diagonal step is equal to . The cows do not move. You have to minimize the number of moves the shepherd needs to run round the whole herd.
The first line contains an integer *N* which represents the number of cows in the herd (1<=≤<=*N*<=≤<=105). Each of the next *N* lines contains two integers *X**i* and *Y**i* which represent the coordinates of one cow of (|*X**i*|,<=|*Y**i*|<=≤<=106). Several cows can stand on one point.
Print the single number — the minimum number of moves in the sought path.
Sample Input
4
1 1
5 1
5 3
1 3
Sample Output
16
| {"inputs": ["4\n1 1\n5 1\n5 3\n1 3", "3\n0 0\n5 0\n0 5", "5\n0 0\n7 7\n7 5\n5 7\n1 1", "5\n1 0\n-1 0\n1 0\n-1 0\n0 0", "9\n1 0\n-1 0\n1 0\n-1 0\n0 0\n1 1\n-1 -1\n1 -1\n-1 1", "5\n-10 10\n-10 -10\n10 -10\n9 8\n1 2", "1\n7 -10", "3\n7 -10\n7 -10\n7 -10", "2\n-10 0\n-10 7", "5\n-10 0\n-10 7\n-10 0\n-10 7\n-10 0", "11\n0 0\n3 0\n1 0\n2 0\n1 0\n5 0\n3 0\n10 0\n6 0\n-1 0\n2 0", "10\n1 0\n1 -3\n1 5\n1 -2\n1 5\n1 -2\n1 -2\n1 -2\n1 -2\n1 -2", "6\n1 0\n2 1\n10 9\n-1 -2\n2 1\n-1 -2", "6\n5 0\n0 5\n10 -5\n-5 10\n2 3\n3 2", "3\n0 0\n2 0\n0 2", "3\n0 0\n1 0\n0 2", "3\n0 0\n2 0\n0 1", "3\n0 0\n2 1\n0 2", "3\n0 0\n2 0\n1 2", "3\n0 0\n2 1\n1 2", "3\n0 0\n3 1\n2 3", "3\n10 0\n0 20\n33 30", "4\n0 2\n2 0\n3 5\n5 3", "5\n0 2\n2 0\n3 5\n5 3\n6 3", "8\n0 2\n3 0\n5 3\n2 5\n2 2\n3 3\n2 2\n2 2", "4\n0 3\n3 0\n5 3\n2 5", "10\n2 0\n1 1\n0 2\n4 0\n0 4\n3 8\n5 8\n7 8\n8 7\n8 4", "4\n-1000000 -1000000\n1000000 1000000\n-1000000 1000000\n1000000 -1000000", "4\n-1000000 -999993\n999991 999997\n-999998 999996\n999994 -1000000", "11\n-1000000 -999993\n999991 999997\n1 3\n1 3\n0 0\n-999998 999996\n-1 3\n4 5\n-999998 999996\n6 7\n999994 -1000000", "2\n-1000000 -1000000\n999999 999999", "2\n-1000000 -1000000\n999999 1000000", "3\n1 -1\n-1 -1\n-1 1", "3\n2 2\n1 -2\n0 2", "3\n1 -1\n1 2\n-2 -2", "3\n0 2\n-1 1\n2 -1", "3\n2 1\n1 2\n-2 0", "3\n0 2\n2 1\n2 1", "3\n1 1\n0 2\n0 -1", "4\n-1 -2\n2 -1\n-1 -1\n-1 0", "4\n2 1\n1 1\n-1 2\n-2 -2", "4\n1 2\n0 1\n0 3\n-1 -3", "4\n1 -1\n0 -2\n0 1\n-1 0", "5\n-2 2\n2 -3\n2 3\n2 1\n2 -3", "5\n-3 -3\n-3 3\n1 0\n-2 2\n0 -1", "6\n2 -1\n-2 1\n-1 -1\n0 2\n2 -2\n-2 0", "8\n3 -1\n1 -1\n0 2\n-2 -2\n1 -2\n1 -2\n3 2\n3 2", "20\n9 0\n11 6\n13 4\n7 3\n9 0\n10 4\n11 4\n11 2\n9 0\n9 1\n9 0\n10 4\n13 4\n10 6\n10 6\n9 0\n9 1\n10 2\n10 4\n12 3", "30\n-4 0\n-4 0\n-5 2\n-1 3\n-3 3\n-3 4\n-1 2\n-3 3\n-2 4\n-4 0\n-1 -1\n-2 2\n-2 2\n-5 1\n-1 3\n-1 -1\n-5 1\n-1 -1\n-3 1\n-3 0\n-5 2\n-2 -1\n-4 0\n-1 4\n-5 2\n-1 -1\n-1 3\n-4 1\n-3 4\n-3 -1", "40\n6 -14\n12 -13\n13 -16\n12 -13\n12 -13\n7 -13\n13 -16\n11 -15\n6 -14\n5 -14\n13 -14\n8 -17\n9 -13\n10 -10\n6 -13\n6 -15\n7 -12\n10 -11\n14 -14\n12 -12\n6 -14\n6 -14\n9 -15\n12 -13\n5 -14\n13 -16\n7 -12\n11 -17\n12 -13\n14 -14\n10 -11\n10 -18\n6 -15\n9 -14\n10 -14\n15 -15\n8 -13\n13 -15\n8 -17\n13 -13", "50\n-10 4\n5 4\n-4 4\n0 4\n-11 2\n-10 6\n-3 2\n-2 -3\n-2 -5\n5 -4\n0 -3\n5 -4\n-13 3\n-9 3\n1 -4\n-1 3\n0 5\n-7 2\n-9 5\n0 4\n4 5\n-2 -5\n4 4\n-9 1\n-9 6\n3 -2\n2 -4\n-10 6\n-2 -3\n-7 2\n2 5\n-2 6\n-2 6\n2 5\n2 -4\n5 2\n-5 -2\n4 4\n2 -4\n2 -4\n5 3\n5 1\n3 -1\n-10 4\n4 -5\n-4 2\n-5 -2\n-2 2\n-1 4\n3 5", "60\n22 -7\n25 -2\n21 5\n21 2\n26 1\n19 1\n21 0\n21 2\n29 -5\n18 -3\n27 -3\n29 -5\n23 -4\n29 -5\n22 0\n19 -1\n23 0\n21 -5\n24 -1\n21 -4\n19 1\n24 3\n19 3\n25 -7\n24 -3\n30 -5\n24 -3\n27 -7\n20 -5\n16 -1\n25 -5\n19 -3\n18 -1\n17 -1\n19 1\n18 2\n28 -5\n24 0\n25 2\n22 1\n29 -5\n22 -1\n19 1\n28 -2\n29 -2\n22 -4\n21 0\n22 -4\n21 -5\n19 3\n22 -1\n21 5\n27 -4\n30 -3\n30 -5\n22 3\n19 2\n26 -1\n23 3\n22 -4", "20\n-118 -4\n-114 -8\n-86 40\n-77 38\n-128 24\n-114 -8\n-107 24\n-63 15\n-114 -8\n-138 34\n-136 53\n-116 37\n-62 14\n-116 37\n-112 10\n-146 25\n-83 42\n-62 14\n-107 11\n-138 34", "30\n220065 650176\n-85645 309146\n245761 474510\n297068 761230\n39280 454823\n65372 166746\n316557 488319\n220065 650176\n245761 474510\n65372 166746\n-8475 -14722\n327177 312018\n371695 397843\n343097 243895\n-113462 117273\n-8189 440841\n327177 312018\n-171241 288713\n-147691 268033\n265028 425605\n208512 456240\n97333 6791\n-109657 297156\n-109657 297156\n-176591 87288\n-120815 31512\n120019 546293\n3773 19061\n161901 442125\n-50681 429871", "50\n139 201\n115 37\n206 8\n115 37\n167 201\n189 1\n167 201\n141 201\n141 201\n115 37\n78 81\n167 201\n126 201\n78 91\n103 186\n208 169\n85 67\n208 153\n78 97\n208 89\n126 26\n141 201\n208 42\n166 41\n78 124\n156 1\n181 201\n78 129\n208 169\n208 52\n78 85\n128 201\n167 201\n208 23\n100 52\n148 4\n116 199\n208 122\n173 201\n167 201\n153 1\n176 1\n170 194\n78 132\n206 8\n208 23\n208 67\n208 116\n78 161\n142 160", "60\n-20 179\n-68 0\n-110 68\n-22 177\n47 140\n-49 -4\n-106 38\n-23 22\n20 193\n47 173\n-23 22\n-100 32\n-97 29\n47 124\n-49 -4\n20 193\n-20 179\n-50 149\n-59 -7\n4 193\n-23 22\n-97 29\n-23 22\n-66 133\n47 167\n-61 138\n-49 -4\n-91 108\n-110 84\n47 166\n-110 77\n-99 100\n-23 22\n-59 -7\n47 128\n46 91\n9 193\n-110 86\n-49 -4\n8 193\n2 47\n-35 164\n-100 32\n47 114\n-56 -7\n47 148\n14 193\n20 65\n47 171\n47 171\n-110 53\n47 93\n20 65\n-35 164\n-50 149\n-25 174\n9 193\n47 150\n-49 -4\n-110 44", "54\n-2 0\n-2 0\n3 -3\n-3 -6\n-5 -5\n-1 -4\n2 5\n-4 2\n2 5\n-5 5\n5 3\n3 1\n-2 1\n4 4\n-4 4\n-3 2\n-5 -4\n2 4\n4 2\n-2 1\n4 -1\n5 4\n-2 1\n-5 5\n-3 -1\n-4 -1\n1 -4\n-2 -2\n3 -3\n2 6\n-5 3\n-1 4\n5 -1\n2 -4\n2 -2\n1 4\n-5 5\n0 4\n-5 3\n-4 -2\n3 -2\n3 -1\n-4 -1\n5 5\n4 5\n3 -3\n1 2\n2 5\n-2 -4\n-5 5\n-4 1\n2 4\n-3 -4\n1 6", "35\n3 -3\n1 4\n-3 -3\n2 -2\n0 -1\n-1 -1\n2 5\n0 -1\n1 3\n-3 -5\n1 -1\n3 5\n1 -3\n3 -5\n-1 3\n2 -3\n1 -1\n-3 5\n-3 -2\n2 -2\n1 -6\n-3 5\n-1 1\n1 -3\n1 4\n3 4\n-1 -1\n0 -5\n3 -2\n-3 -4\n3 6\n1 4\n-2 1\n2 -3\n2 -6", "43\n-1 2\n2 -3\n-2 0\n2 -1\n0 1\n0 0\n1 -3\n0 -2\n0 2\n2 0\n-1 2\n2 -3\n1 2\n1 0\n1 -3\n-2 -3\n2 -3\n-2 0\n0 -3\n1 -2\n-2 -3\n1 1\n2 -3\n2 1\n-1 -3\n1 2\n1 -3\n-1 2\n0 1\n0 -1\n0 -3\n2 1\n1 0\n-2 -3\n0 -2\n1 1\n-2 2\n-2 -3\n-2 3\n-1 0\n1 -1\n2 2\n-1 -2", "61\n0 -5\n0 3\n0 -1\n0 -4\n0 6\n0 -1\n0 -3\n0 6\n0 5\n0 -5\n0 1\n0 2\n0 5\n0 -3\n0 1\n0 -6\n0 -3\n0 3\n0 -3\n0 -5\n0 2\n0 1\n0 5\n0 3\n0 -2\n0 -2\n0 -3\n0 -6\n0 -4\n0 -2\n0 0\n0 -1\n0 -5\n0 -6\n0 6\n0 0\n0 -5\n0 1\n0 2\n0 -2\n0 -5\n0 6\n0 -3\n0 4\n0 5\n0 2\n0 -6\n0 -3\n0 2\n0 1\n0 -2\n0 -4\n0 -2\n0 4\n0 -1\n0 6\n0 0\n0 -1\n0 -3\n0 -4\n0 -3", "57\n-8 0\n-2 0\n-2 0\n-7 0\n-8 0\n0 0\n8 0\n8 0\n3 0\n-2 0\n-3 0\n6 0\n-7 0\n-9 0\n-2 0\n-4 0\n-8 0\n0 0\n6 0\n7 0\n3 0\n0 0\n9 0\n0 0\n-9 0\n3 0\n8 0\n0 0\n6 0\n-4 0\n8 0\n10 0\n-7 0\n3 0\n-1 0\n8 0\n3 0\n1 0\n6 0\n3 0\n-8 0\n4 0\n-8 0\n-2 0\n1 0\n6 0\n7 0\n-6 0\n-2 0\n-2 0\n-8 0\n-8 0\n2 0\n0 0\n10 0\n4 0\n-8 0"], "outputs": ["16", "19", "22", "8", "12", "81", "4", "4", "18", "18", "26", "20", "26", "34", "10", "9", "9", "10", "10", "9", "12", "87", "14", "16", "16", "15", "26", "8000004", "7999973", "7999973", "4000002", "4000004", "10", "14", "14", "11", "12", "8", "10", "12", "15", "16", "10", "19", "18", "15", "19", "17", "18", "24", "48", "35", "200", "1727359", "515", "446", "40", "37", "23", "28", "42"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a9e7f39b20cf005323eea47e365c2890 | Encrypting Messages | The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.
A message is a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Encryption uses a key which is a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (*m*<=≤<=*n*). All numbers from the message and from the key belong to the interval from 0 to *c*<=-<=1, inclusive, and all the calculations are performed modulo *c*.
Encryption is performed in *n*<=-<=*m*<=+<=1 steps. On the first step we add to each number *a*1,<=*a*2,<=...,<=*a**m* a corresponding number *b*1,<=*b*2,<=...,<=*b**m*. On the second step we add to each number *a*2,<=*a*3,<=...,<=*a**m*<=+<=1 (changed on the previous step) a corresponding number *b*1,<=*b*2,<=...,<=*b**m*. And so on: on step number *i* we add to each number *a**i*,<=*a**i*<=+<=1,<=...,<=*a**i*<=+<=*m*<=-<=1 a corresponding number *b*1,<=*b*2,<=...,<=*b**m*. The result of the encryption is the sequence *a*1,<=*a*2,<=...,<=*a**n* after *n*<=-<=*m*<=+<=1 steps.
Help the Beaver to write a program that will encrypt messages in the described manner.
The first input line contains three integers *n*, *m* and *c*, separated by single spaces.
The second input line contains *n* integers *a**i* (0<=≤<=*a**i*<=<<=*c*), separated by single spaces — the original message.
The third input line contains *m* integers *b**i* (0<=≤<=*b**i*<=<<=*c*), separated by single spaces — the encryption key.
The input limitations for getting 30 points are:
- 1<=≤<=*m*<=≤<=*n*<=≤<=103 - 1<=≤<=*c*<=≤<=103
The input limitations for getting 100 points are:
- 1<=≤<=*m*<=≤<=*n*<=≤<=105 - 1<=≤<=*c*<=≤<=103
Print *n* space-separated integers — the result of encrypting the original message.
Sample Input
4 3 2
1 1 1 1
1 1 1
3 1 5
1 2 3
4
Sample Output
0 1 1 0
0 1 2
| {"inputs": ["4 3 2\n1 1 1 1\n1 1 1", "3 1 5\n1 2 3\n4", "5 2 7\n0 0 1 2 4\n3 5", "20 15 17\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15", "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n47 92 59 85 73 38"], "outputs": ["0 1 1 0", "0 1 2", "3 1 2 3 2", "10 1 3 8 3 15 7 14 1 12 3 10 15 16 16 5 4 15 13 11", "95 38 9 63 33 19 84 76 46 3 69 14 40 65 88 25 28 50 39 84 51 2 58 15 64 36 92 44 49 49 68 9 98 14 72 51 15 10 80 93 49 31 81 68 43 25 88 55 65 0 66 13 18 59 45 88 9 3 93 31 67 33 77 49 93 43 8 15 10 86 91 41 29 29 83 19 43 79 82 81"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 32 | codeforces |
|
a9ec43cedd74ecc2200cd993ccce7067 | Generate Login | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
Sample Input
harry potter
tom riddle
Sample Output
hap
tomr
| {"inputs": ["harry potter", "tom riddle", "a qdpinbmcrf", "wixjzniiub ssdfodfgap", "z z", "ertuyivhfg v", "asdfghjkli ware", "udggmyop ze", "fapkdme rtzxovx", "mybiqxmnqq l", "dtbqya fyyymv", "fyclu zokbxiahao", "qngatnviv rdych", "ttvnhrnng lqkfulhrn", "fya fgx", "nuis zvjjqlre", "ly qtsmze", "d kgfpjsurfw", "lwli ewrpu", "rr wldsfubcs", "h qart", "vugvblnzx kqdwdulm", "xohesmku ef", "twvvsl wtcyawv", "obljndajv q", "jjxwj kxccwx", "sk fftzmv", "cgpegngs aufzxkyyrw", "reyjzjdvq skuch", "ardaae mxgdulijf", "bgopsdfji uaps", "amolfed pun", "badkiln yort", "aaaaaaaaaz york", "bbbbcbbbbd c", "aa ab", "ab b", "aaaaa ab", "aa a", "aba b", "aaaaaaa aaaaaa", "a a", "a aa", "a b", "b a", "z a", "aaa a", "aa aa", "a aaa", "aaaaaaaaaa aaaaaaaaaa", "aaaaaaaaaa a", "a aaaaaaaaaa", "zzaa b", "ca cf", "abhi ia", "aaaa aaaab", "aar raa", "harry hotter", "aaaaaaa a", "apple pie", "aaa aaa", "kabc buba", "asd ss", "bbb b"], "outputs": ["hap", "tomr", "aq", "wis", "zz", "ertuv", "asdfghjkliw", "udggmyopz", "fapkdmer", "ml", "df", "fycluz", "qngar", "tl", "ff", "nuisz", "lq", "dk", "le", "rrw", "hq", "vk", "xe", "tw", "obljndajq", "jjk", "sf", "ca", "res", "am", "bgopsdfjiu", "amolfedp", "badkilny", "aaaaaaaaay", "bbbbc", "aa", "ab", "aa", "aa", "ab", "aa", "aa", "aa", "ab", "ba", "za", "aa", "aa", "aa", "aa", "aa", "aa", "zb", "cac", "abhi", "aa", "aar", "hah", "aa", "ap", "aa", "kab", "as", "bb"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 253 | codeforces |
|
a9edd7e23c7a56dec735305f3eb667a2 | Cyclic Cipher | You are given *n* sequences. Each sequence consists of positive integers, not exceeding *m*. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the *i*-th sequence is *k**i*.
Each second integers in each of the sequences are shifted by one to the left, i.e. integers at positions *i*<=><=1 go to positions *i*<=-<=1, while the first integers becomes the last.
Each second we take the first integer of each sequence and write it down to a new array. Then, for each value *x* from 1 to *m* we compute the longest segment of the array consisting of element *x* only.
The above operation is performed for 10100 seconds. For each integer from 1 to *m* find out the longest segment found at this time.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the number of sequences and the maximum integer that can appear in the sequences.
Then follow *n* lines providing the sequences. Each of them starts with an integer *k**i* (1<=≤<=*k**i*<=≤<=40) — the number of integers in the sequence, proceeded by *k**i* positive integers — elements of the sequence. It's guaranteed that all integers in each sequence are pairwise distinct and do not exceed *m*.
The total length of all sequences doesn't exceed 200<=000.
Print *m* integers, the *i*-th of them should be equal to the length of the longest segment of the array with all its values equal to *i* during the first 10100 seconds.
Sample Input
3 4
3 3 4 1
4 1 3 4 2
3 3 1 4
5 5
2 3 1
4 5 1 3 2
4 2 1 3 5
1 3
2 5 3
4 6
3 4 5 3
2 6 3
2 3 6
3 3 6 5
Sample Output
2
1
3
2
3
1
4
0
1
0
0
2
1
1
2
| {"inputs": ["3 4\n3 3 4 1\n4 1 3 4 2\n3 3 1 4", "5 5\n2 3 1\n4 5 1 3 2\n4 2 1 3 5\n1 3\n2 5 3", "4 6\n3 4 5 3\n2 6 3\n2 3 6\n3 3 6 5", "10 5\n2 2 4\n2 4 5\n2 1 2\n4 3 1 5 2\n4 1 3 2 5\n5 3 4 5 2 1\n3 3 5 4\n1 1\n2 4 1\n1 5", "10 10\n2 1 5\n2 3 4\n4 7 1 10 4\n4 6 3 9 7\n2 3 5\n3 4 9 7\n3 6 5 9\n5 8 5 4 10 6\n3 5 7 1\n1 5", "10 100\n1 76\n3 86 1 85\n1 96\n5 48 54 32 71 90\n2 27 18\n1 38\n1 73\n3 60 40 4\n4 92 77 37 80\n4 61 24 67 82"], "outputs": ["2\n1\n3\n2", "3\n1\n4\n0\n1", "0\n0\n2\n1\n1\n2", "2\n2\n3\n2\n3", "1\n0\n1\n2\n3\n2\n1\n1\n1\n1", "1\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
a9f1db41bf78794ebd59fce0b08f9ad0 | Expression | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
Sample Input
1
2
3
2
10
3
Sample Output
9
60
| {"inputs": ["1\n2\n3", "2\n10\n3", "1\n1\n1", "1\n2\n1", "10\n10\n10", "5\n1\n3", "3\n1\n5", "6\n7\n1", "1\n8\n3", "9\n7\n2", "1\n1\n10", "9\n1\n1", "10\n5\n6", "8\n9\n7", "4\n2\n10", "2\n8\n3", "3\n5\n7", "1\n10\n1", "2\n2\n2", "5\n6\n1", "10\n1\n1", "1\n6\n1", "1\n9\n1", "2\n1\n2", "2\n6\n1", "9\n2\n1", "1\n9\n2", "1\n3\n1", "2\n1\n1"], "outputs": ["9", "60", "3", "4", "1000", "20", "20", "48", "27", "126", "20", "18", "300", "504", "80", "48", "105", "12", "8", "35", "20", "8", "11", "6", "14", "27", "20", "5", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 341 | codeforces |
|
a9f7eb841627ede770d54ac50ad4486b | Collective Mindsets (easy) | 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.
Sample Input
1
4
Sample Output
1
2
| {"inputs": ["1", "4", "2", "3", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "100", "9999", "21736", "873467", "4124980", "536870910", "536870912", "876543210", "987654321", "1000000000"], "outputs": ["1", "2", "1", "2", "3", "3", "4", "4", "5", "5", "6", "6", "7", "7", "8", "8", "9", "9", "10", "10", "50", "5000", "10868", "436734", "2062490", "268435455", "268435456", "438271605", "493827161", "500000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 41 | codeforces |
|
aa0e79b94b0ba6e8643b2b44c935d9eb | Random Task | One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer *n*, that among numbers *n*<=+<=1, *n*<=+<=2, ..., 2·*n* there are exactly *m* numbers which binary representation contains exactly *k* digits one".
The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018.
The first line contains two space-separated integers, *m* and *k* (0<=≤<=*m*<=≤<=1018; 1<=≤<=*k*<=≤<=64).
Print the required number *n* (1<=≤<=*n*<=≤<=1018). If there are multiple answers, print any of them.
Sample Input
1 1
3 2
Sample Output
1
5
| {"inputs": ["1 1", "3 2", "3 3", "1 11", "4 20", "45902564 24", "330 8", "10 10", "0 2", "1000000 55", "1 60", "1000000000 52", "101628400788615604 30", "101628400798615604 31", "55 55", "14240928 10", "1000000000 10", "1111111 11", "10000000000000000 35", "0 19", "768 10", "3691 6", "16 15", "427 4", "669 9", "0 16", "286 11", "6 16", "13111 8", "17 2", "440 4", "5733 6", "3322 6", "333398 7", "19027910 20", "73964712 13", "33156624 15", "406 3", "3600 4", "133015087 16", "14065439 11", "135647 6", "613794 8", "79320883 13", "433 3", "142129 6", "20074910 16", "27712 4", "109197403264830 17", "1767 3", "2518095982 9", "16184825266581 15", "60 2", "51908921235703 16", "373301530 8", "51140330728306 16", "78015012688021 17", "360651917262546 18", "15619605006173 15", "296851618 8", "1651507249349341 20", "234217752433205 18", "5004844 6", "820882585293 13", "0 64"], "outputs": ["1", "5", "7", "1024", "983040", "6406200698", "2033", "1023", "1", "504262282264444927", "576460752303423488", "542648557841154044", "999999999999995905", "981546175132942729", "36028797018963967", "999948289", "38209103398929", "7734675", "247948501945678280", "1", "9471", "39105", "40960", "18561", "5535", "1", "8185", "64512", "73033", "65537", "20993", "96257", "34441", "142974977", "530210696", "808934145", "217957249", "402653185", "310378497", "903250260", "277820673", "612761601", "47611905", "877746562", "603979777", "893386753", "156957897", "54078379900534785", "530824147803045889", "612489549322387457", "835136255900516353", "753750817529397249", "576460752303423489", "927684967108968449", "628568807366983681", "880672956240363521", "237668409087623169", "866841191969193985", "676897611185127425", "208581753835618305", "660934198681731073", "333773758789582849", "488640559569698817", "167167411424854017", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
aa3049696d389bffae6f06d2bf84bfeb | Liebig's Barrels | You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Sample Input
4 2 1
2 2 1 2 3 2 2 3
2 1 0
10 10
1 2 1
5 2
3 2 1
1 2 3 4 5 6
Sample Output
7
20
2
0
| {"inputs": ["4 2 1\n2 2 1 2 3 2 2 3", "2 1 0\n10 10", "1 2 1\n5 2", "3 2 1\n1 2 3 4 5 6", "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71", "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834 962 521 463 740 520 494", "10 3 795\n398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104", "6 2 29\n1 2 3 3 4 5 5 6 7 7 8 9", "2 1 2\n1 2"], "outputs": ["7", "20", "2", "0", "0", "2979", "5045", "28", "3"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 63 | codeforces |
|
aa38306070eb8e4093e1bf4283d68da4 | Bubble Sort Graph | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with *n* elements *a*1, *a*2, ..., *a**n* in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it *G*) initially has *n* vertices and 0 edges. During Bubble Sort execution, edges appear as described in the following algorithm (pseudocode).
For a graph, an independent set is a set of vertices in a graph, no two of which are adjacent (so there are no edges between vertices of an independent set). A maximum independent set is an independent set which has maximum cardinality. Given the permutation, find the size of the maximum independent set of graph *G*, if we use such permutation as the premutation *a* in procedure bubbleSortGraph.
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=105). The next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*).
Output a single integer — the answer to the problem.
Sample Input
3
3 1 2
Sample Output
2
| {"inputs": ["3\n3 1 2", "5\n4 2 1 3 5", "10\n1 9 8 10 2 3 4 6 5 7", "50\n12 24 42 43 36 3 40 29 7 34 10 13 28 9 35 23 25 21 19 4 20 18 11 38 41 48 6 46 33 17 31 37 2 30 32 44 45 5 47 49 16 15 50 27 26 14 39 22 1 8", "100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 20 63 77 80 12 53 5 25 58 90 68 24 64 23 95 32 55 47"], "outputs": ["2", "3", "6", "13", "16"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 22 | codeforces |
|
aa3c1b41277165391ffdeec88676f3de | Leaving Auction | There are *n* people taking part in auction today. The rules of auction are classical. There were *n* bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all.
Each bid is define by two integers (*a**i*,<=*b**i*), where *a**i* is the index of the person, who made this bid and *b**i* is its size. Bids are given in chronological order, meaning *b**i*<=<<=*b**i*<=+<=1 for all *i*<=<<=*n*. Moreover, participant never makes two bids in a row (no one updates his own bid), i.e. *a**i*<=≠<=*a**i*<=+<=1 for all *i*<=<<=*n*.
Now you are curious with the following question: who (and which bid) will win the auction if some participants were absent? Consider that if someone was absent, all his bids are just removed and no new bids are added.
Note, that if during this imaginary exclusion of some participants it happens that some of the remaining participants makes a bid twice (or more times) in a row, only first of these bids is counted. For better understanding take a look at the samples.
You have several questions in your mind, compute the answer for each of them.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of participants and bids.
Each of the following *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*n*,<=1<=≤<=*b**i*<=≤<=109,<=*b**i*<=<<=*b**i*<=+<=1) — the number of participant who made the *i*-th bid and the size of this bid.
Next line contains an integer *q* (1<=≤<=*q*<=≤<=200<=000) — the number of question you have in mind.
Each of next *q* lines contains an integer *k* (1<=≤<=*k*<=≤<=*n*), followed by *k* integers *l**j* (1<=≤<=*l**j*<=≤<=*n*) — the number of people who are not coming in this question and their indices. It is guarenteed that *l**j* values are different for a single question.
It's guaranteed that the sum of *k* over all question won't exceed 200<=000.
For each question print two integer — the index of the winner and the size of the winning bid. If there is no winner (there are no remaining bids at all), print two zeroes.
Sample Input
6
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
3
1 3
2 2 3
2 1 2
3
1 10
2 100
1 1000
2
2 1 2
2 2 3
Sample Output
2 100000
1 10
3 1000
0 0
1 10
| {"inputs": ["6\n1 10\n2 100\n3 1000\n1 10000\n2 100000\n3 1000000\n3\n1 3\n2 2 3\n2 1 2", "3\n1 10\n2 100\n1 1000\n2\n2 1 2\n2 2 3", "1\n1 1\n1\n1 1", "2\n1 1\n2 2\n3\n1 1\n1 2\n2 1 2", "4\n1 3\n2 7\n1 8\n3 10\n15\n1 1\n1 2\n1 3\n1 4\n2 1 2\n2 1 3\n2 1 4\n2 2 3\n2 2 4\n2 3 4\n3 1 2 3\n3 1 2 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4", "3\n1 3\n2 5\n3 7\n7\n1 1\n1 2\n1 3\n2 1 2\n2 1 3\n2 2 3\n3 1 2 3", "4\n1 3\n2 4\n3 5\n1 7\n15\n1 1\n1 2\n1 3\n1 4\n2 1 2\n2 1 3\n2 1 4\n2 2 3\n2 2 4\n2 3 4\n3 1 2 3\n3 1 2 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4", "3\n2 7\n1 13\n2 22\n7\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3", "3\n2 6\n3 10\n2 14\n7\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3", "4\n4 10\n3 12\n1 20\n4 28\n15\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3\n1 4\n2 1 4\n2 2 4\n3 1 2 4\n2 3 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4", "4\n2 8\n1 14\n3 24\n1 30\n15\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3\n1 4\n2 1 4\n2 2 4\n3 1 2 4\n2 3 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4", "5\n3 4\n1 14\n4 20\n3 22\n5 28\n31\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3\n1 4\n2 1 4\n2 2 4\n3 1 2 4\n2 3 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4\n1 5\n2 1 5\n2 2 5\n3 1 2 5\n2 3 5\n3 1 3 5\n3 2 3 5\n4 1 2 3 5\n2 4 5\n3 1 4 5\n3 2 4 5\n4 1 2 4 5\n3 3 4 5\n4 1 3 4 5\n4 2 3 4 5\n5 1 2 3 4 5", "5\n1 5\n3 7\n2 17\n3 24\n1 28\n31\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3\n1 4\n2 1 4\n2 2 4\n3 1 2 4\n2 3 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4\n1 5\n2 1 5\n2 2 5\n3 1 2 5\n2 3 5\n3 1 3 5\n3 2 3 5\n4 1 2 3 5\n2 4 5\n3 1 4 5\n3 2 4 5\n4 1 2 4 5\n3 3 4 5\n4 1 3 4 5\n4 2 3 4 5\n5 1 2 3 4 5"], "outputs": ["2 100000\n1 10\n3 1000", "0 0\n1 10", "0 0", "2 2\n1 1\n0 0", "3 10\n3 10\n1 8\n3 10\n3 10\n2 7\n3 10\n1 3\n3 10\n1 8\n0 0\n3 10\n2 7\n1 3\n0 0", "3 7\n3 7\n2 5\n3 7\n2 5\n1 3\n0 0", "3 5\n1 7\n1 7\n1 7\n3 5\n2 4\n3 5\n1 3\n1 7\n1 7\n0 0\n3 5\n2 4\n1 3\n0 0", "2 7\n1 13\n0 0\n2 22\n2 7\n1 13\n0 0", "2 14\n3 10\n3 10\n2 6\n2 6\n0 0\n0 0", "4 28\n4 28\n4 28\n4 28\n4 10\n4 28\n4 10\n1 20\n3 12\n1 20\n3 12\n1 20\n0 0\n1 20\n0 0", "3 24\n1 30\n3 24\n1 14\n2 8\n1 14\n0 0\n1 30\n3 24\n1 30\n3 24\n1 14\n2 8\n1 14\n0 0", "5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n5 28\n3 22\n3 22\n3 22\n3 22\n4 20\n4 20\n4 20\n4 20\n3 22\n3 4\n3 22\n3 4\n1 14\n0 0\n1 14\n0 0", "3 24\n1 28\n3 7\n1 28\n2 17\n1 5\n0 0\n1 28\n3 24\n1 28\n3 7\n1 28\n2 17\n1 5\n0 0\n1 28\n3 24\n1 28\n3 7\n1 28\n2 17\n1 5\n0 0\n1 28\n3 24\n1 28\n3 7\n1 28\n2 17\n1 5\n0 0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
aa58cc23ec95ad4e4034fc6ce173c19c | Hamsters and Tigers | 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.
Sample Input
3
HTH
9
HTHTHTHHT
Sample Output
0
2
| {"inputs": ["3\nHTH", "9\nHTHTHTHHT", "2\nTH", "4\nHTTH", "4\nHTHT", "7\nTTTHTTT", "8\nHHTHHTHH", "13\nHTTTHHHTTTTHH", "20\nTTHTHTHHTHTTHHTTTHHH", "35\nTTTTTTHTTHTTTTTHTTTTTTTTTTTHTHTTTTT", "120\nTTTTTTTHTHTHTTTTTHTHTTTTHTTTTTTTTTTTTTTTTTTTTHTTHTTTTHTTHTTTTTTTTTTTTTTTHTTTTTTHTHTTHTTTTTTHTTTTTTTTTHTTHTTTTHTTTHTTTTTH", "19\nHHHHHHHHHHHHHTTTHHH", "87\nHTHHTTHHHHTHHHHHTTTHHTHHHHTTTTHHHTTHHTHTHTHHTTHTHHTHTHTTHHHTTTTTHTTHHHHHHTHHTHHTHTTHTHH", "178\nTHHHTHTTTHTTHTTHHHHHTTTHTTHHTHTTTHTHTTTTTHHHTHTHHHTHHHTTTTTTTTHHHHTTHHTHHHHTHTTTHHHHHHTHHTHTTHTHTTTTTTTTTHHTTHHTHTTHHTHHHHHTTHHTTHHTTHHHTTHHTTTTHTHHHTHTTHTHTTTHHHHTHHTHHHTHTTTTTT"], "outputs": ["0", "2", "0", "0", "1", "0", "1", "3", "4", "3", "14", "0", "17", "40"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 72 | codeforces |
|
aa6ceb741b91e022653c4ce5b955f3ff | Bus | There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct).
We shall assume that the stop is located on the coordinate axis *Ox*, at point *x*<==<=0, and the bus goes along the ray *Ox*, that is, towards the positive direction of the coordinate axis, and back. The *i*-th student needs to get to the point with coordinate *x**i* (*x**i*<=><=0).
The bus moves by the following algorithm. Initially it is at point 0. The students consistently come to the stop and get on it. The bus has a seating capacity which is equal to *m* passengers. At the moment when *m* students get on the bus, it starts moving in the positive direction of the coordinate axis. Also it starts moving when the last (*n*-th) student gets on the bus. The bus is moving at a speed of 1 unit of distance per 1 unit of time, i.e. it covers distance *y* in time *y*.
Every time the bus passes the point at which at least one student needs to get off, it stops and these students get off the bus. The students need 1<=+<=[*k*<=/<=2] units of time to get off the bus, where *k* is the number of students who leave at this point. Expression [*k*<=/<=2] denotes rounded down *k*<=/<=2. As soon as the last student leaves the bus, the bus turns around and goes back to the point *x*<==<=0. It doesn't make any stops until it reaches the point. At the given point the bus fills with students once more, and everything is repeated.
If students come to the stop when there's no bus, they form a line (queue) and get on the bus in the order in which they came. Any number of students get on the bus in negligible time, you should assume that it doesn't take any time. Any other actions also take no time. The bus has no other passengers apart from the students.
Write a program that will determine for each student the time when he got off the bus. The moment a student got off the bus is the moment the bus stopped at the student's destination stop (despite the fact that the group of students need some time to get off).
The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of students and the number of passengers the bus can transport, correspondingly. Next *n* lines contain descriptions of the students, one per line. Each line contains a pair of integers *t**i*,<=*x**i* (1<=≤<=*t**i*<=≤<=105,<=1<=≤<=*x**i*<=≤<=104). The lines are given in the order of strict increasing of *t**i*. Values of *x**i* can coincide.
Print *n* numbers *w*1,<=*w*2,<=...,<=*w**n*, *w**i* — the moment of time when the *i*-th student got off the bus. Print the numbers on one line and separate them with single spaces.
Sample Input
1 10
3 5
2 1
3 5
4 5
5 4
3 5
4 5
5 5
6 5
7 1
20 4
28 13
31 13
35 6
36 4
52 6
53 4
83 2
84 4
87 1
93 6
108 4
113 6
116 1
125 2
130 2
136 13
162 2
166 4
184 1
192 2
Sample Output
8
8 19
11 11 11 11 20
51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195
| {"inputs": ["1 10\n3 5", "2 1\n3 5\n4 5", "5 4\n3 5\n4 5\n5 5\n6 5\n7 1", "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2", "1 1\n109 15", "2 1\n43 5\n102 1", "4 2\n7 1\n12 14\n90 15\n176 1", "8 8\n48 14\n74 12\n94 4\n127 14\n151 11\n173 4\n190 14\n191 9", "16 1\n29 10\n48 13\n53 10\n54 5\n59 6\n67 9\n68 10\n95 13\n132 5\n148 6\n150 6\n154 6\n169 10\n171 10\n185 6\n198 6", "32 3\n9 2\n12 4\n13 7\n14 7\n15 4\n19 10\n20 10\n29 2\n38 7\n58 4\n59 1\n61 4\n73 4\n90 1\n92 4\n95 7\n103 4\n107 7\n119 4\n121 4\n122 10\n123 10\n127 2\n134 10\n142 7\n144 7\n151 10\n160 7\n165 10\n191 1\n197 1\n199 7", "32 4\n4 6\n7 5\n13 6\n27 6\n39 5\n48 5\n57 11\n62 13\n64 11\n68 11\n84 9\n86 5\n89 6\n91 6\n107 13\n108 13\n113 11\n120 13\n126 5\n130 6\n134 9\n136 6\n137 5\n139 9\n143 5\n154 9\n155 5\n157 13\n171 11\n179 11\n185 13\n190 5", "32 5\n12 11\n17 14\n21 2\n24 2\n35 7\n41 15\n51 11\n52 2\n53 2\n61 14\n62 14\n75 2\n89 15\n90 14\n95 7\n102 7\n104 2\n105 14\n106 14\n109 2\n133 2\n135 2\n143 14\n151 11\n155 14\n168 15\n169 15\n179 14\n180 7\n181 15\n186 7\n198 14", "32 6\n15 12\n24 6\n30 13\n35 6\n38 6\n46 6\n47 12\n60 6\n66 9\n71 15\n74 6\n76 15\n104 6\n105 6\n110 15\n124 12\n126 12\n129 9\n131 12\n134 15\n135 15\n141 12\n154 13\n167 9\n171 9\n179 15\n181 15\n185 12\n189 12\n191 6\n192 6\n196 12", "32 7\n4 14\n6 14\n17 4\n22 3\n29 4\n32 4\n39 10\n40 11\n44 11\n51 11\n57 10\n76 4\n82 4\n87 14\n88 10\n118 10\n121 10\n136 14\n141 3\n143 4\n159 10\n162 10\n163 11\n165 10\n171 4\n172 10\n175 4\n176 3\n179 10\n196 10\n197 3\n198 10", "32 8\n12 9\n26 8\n27 8\n29 9\n43 11\n44 9\n45 5\n48 5\n50 8\n53 8\n57 9\n69 8\n76 11\n86 1\n88 9\n103 5\n116 9\n131 8\n139 8\n142 5\n148 1\n152 8\n154 8\n167 1\n170 5\n172 5\n173 5\n181 8\n183 1\n185 1\n190 1\n200 5"], "outputs": ["8", "8 19", "11 11 11 11 20", "51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195", "124", "48 103", "13 27 192 177", "210 207 195 210 205 195 210 202", "39 63 87 103 115 131 151 175 194 206 219 232 249 270 287 300", "15 18 22 38 34 42 65 55 61 81 77 81 97 93 97 115 111 115 128 128 136 158 149 158 177 177 182 201 205 194 217 224", "34 32 34 34 67 67 75 78 105 105 102 97 124 124 133 133 161 164 153 155 189 185 183 189 205 211 205 216 242 242 246 235", "49 53 37 37 44 87 81 70 70 85 119 105 122 119 111 147 140 155 155 140 173 173 188 184 188 221 221 219 211 221 245 253", "61 52 63 52 52 52 92 83 88 96 83 96 135 135 149 144 144 140 180 186 186 180 183 176 213 222 222 217 217 209 245 252", "57 57 44 42 44 44 52 101 101 101 99 91 91 106 171 171 171 178 162 164 171 206 209 206 198 206 198 196 232 232 224 232", "61 58 58 61 65 61 53 53 113 113 116 113 120 104 116 109 182 178 178 174 168 178 178 168 207 207 207 213 201 201 201 207"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
aa87f34e616f70cb9788a76c5f75ea43 | HDD is Outdated Technology | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.
Find the time need to read file split to *n* fragments. The *i*-th sector contains the *f**i*-th fragment of the file (1<=≤<=*f**i*<=≤<=*n*). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the *n*-th fragment is read. The fragments are read in the order from the first to the *n*-th.
It takes |*a*<=-<=*b*| time units to move the magnetic head from the sector *a* to the sector *b*. Reading a fragment takes no time.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector.
Print the only integer — the number of time units needed to read the file.
Sample Input
3
3 1 2
5
1 3 5 4 2
Sample Output
3
10
| {"inputs": ["3\n3 1 2", "5\n1 3 5 4 2", "1\n1", "1\n1", "1\n1", "10\n8 2 10 3 4 6 1 7 9 5", "10\n1 2 3 4 5 6 7 8 9 10", "10\n1 3 5 7 9 10 8 6 4 2", "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "100\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2"], "outputs": ["3", "10", "0", "0", "0", "40", "9", "45", "3580", "99", "4950"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 136 | codeforces |
|
aa909528de85efa4b55581fd8e03c2e2 | Kuro and Topological Parity | Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.
The paper is divided into $n$ pieces enumerated from $1$ to $n$. Shiro has painted some pieces with some color. Specifically, the $i$-th piece has color $c_{i}$ where $c_{i} = 0$ defines black color, $c_{i} = 1$ defines white color and $c_{i} = -1$ means that the piece hasn't been colored yet.
The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($0$ or $1$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $[1 \to 0 \to 1 \to 0]$, $[0 \to 1 \to 0 \to 1]$, $[1]$, $[0]$ are valid paths and will be counted. You can only travel from piece $x$ to piece $y$ if and only if there is an arrow from $x$ to $y$.
But Kuro is not fun yet. He loves parity. Let's call his favorite parity $p$ where $p = 0$ stands for "even" and $p = 1$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $p$.
It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $10^{9} + 7$.
The first line contains two integers $n$ and $p$ ($1 \leq n \leq 50$, $0 \leq p \leq 1$) — the number of pieces and Kuro's wanted parity.
The second line contains $n$ integers $c_{1}, c_{2}, ..., c_{n}$ ($-1 \leq c_{i} \leq 1$) — the colors of the pieces.
Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $p$.
Sample Input
3 1
-1 0 1
2 1
1 0
1 1
-1
Sample Output
612 | {"inputs": ["3 1\n-1 0 1", "2 1\n1 0", "1 1\n-1", "1 0\n-1", "1 1\n0", "5 1\n-1 -1 -1 -1 -1", "5 0\n-1 -1 -1 -1 -1", "10 1\n1 1 1 1 0 0 0 1 0 0", "50 1\n-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1", "20 1\n0 0 -1 0 1 1 1 1 -1 -1 1 1 1 -1 0 0 1 1 1 0", "30 0\n1 0 1 1 0 -1 0 1 -1 0 1 -1 0 -1 1 1 -1 1 0 1 0 -1 1 1 0 1 -1 0 1 1", "40 1\n-1 1 1 1 0 -1 -1 1 1 -1 1 1 1 0 0 -1 1 0 1 -1 -1 1 0 1 1 0 1 0 0 -1 -1 1 -1 1 1 1 1 0 -1 0", "50 1\n-1 -1 0 -1 1 0 1 0 1 -1 -1 0 0 0 -1 0 0 -1 0 1 -1 0 1 -1 1 -1 1 -1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 0 0 -1 0 1 1 0 0", "50 1\n-1 -1 -1 -1 -1 0 -1 -1 -1 0 1 0 -1 0 1 -1 -1 -1 1 0 1 -1 0 1 0 1 0 0 1 1 -1 1 -1 -1 1 1 -1 -1 0 -1 -1 1 -1 1 -1 1 1 0 0 -1", "3 1\n0 -1 -1", "4 0\n1 -1 1 0", "21 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "29 1\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", "41 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "3 0\n0 0 0", "38 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", "25 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", "30 0\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", "46 0\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", "10 0\n1 0 -1 1 -1 0 0 1 1 0", "6 0\n-1 0 -1 1 1 1", "7 0\n1 0 1 1 -1 1 1", "9 0\n0 -1 -1 -1 -1 -1 1 0 -1", "6 1\n1 -1 -1 -1 0 0", "6 0\n0 -1 -1 0 0 -1", "8 0\n-1 0 1 -1 1 -1 1 1", "6 1\n1 1 0 -1 -1 -1", "22 1\n0 -1 1 0 0 1 1 1 -1 -1 1 1 1 -1 1 1 0 0 -1 0 1 1", "47 1\n0 -1 0 1 0 -1 1 -1 1 -1 1 -1 0 0 -1 0 -1 1 -1 -1 0 1 -1 1 0 0 1 -1 0 1 0 1 0 1 0 1 -1 -1 1 -1 -1 -1 0 1 1 0 1", "2 1\n0 1", "36 1\n-1 0 0 1 1 0 -1 -1 -1 -1 1 1 0 -1 0 1 0 -1 0 -1 0 1 0 -1 -1 0 1 -1 0 -1 0 -1 1 0 1 1", "37 0\n0 -1 0 0 0 -1 0 1 0 0 -1 0 -1 -1 0 1 1 0 -1 -1 -1 -1 1 -1 0 0 0 1 -1 -1 1 -1 1 1 -1 -1 -1", "4 1\n1 -1 -1 1", "35 0\n0 0 -1 -1 1 -1 1 -1 1 0 1 0 -1 0 1 1 -1 1 -1 0 0 -1 0 0 1 -1 -1 0 1 1 -1 1 1 1 -1", "25 1\n1 0 0 -1 -1 0 1 0 -1 1 0 0 0 -1 0 0 1 -1 -1 1 -1 -1 -1 1 1", "36 1\n-1 0 -1 -1 1 0 0 -1 1 0 0 -1 1 -1 1 0 1 0 0 0 1 1 1 0 1 1 0 -1 1 -1 0 0 0 1 1 -1", "9 1\n-1 -1 1 1 1 -1 -1 0 1", "36 0\n-1 0 0 -1 -1 -1 0 -1 0 1 -1 -1 1 1 -1 1 0 0 1 -1 1 1 -1 0 0 1 1 1 -1 1 1 -1 1 1 1 -1", "10 1\n1 1 1 -1 0 -1 -1 1 1 0", "7 0\n1 0 -1 1 -1 1 0", "2 0\n-1 0", "5 1\n-1 1 0 0 -1", "2 0\n-1 -1", "4 1\n0 1 -1 -1", "5 0\n-1 0 0 0 1", "17 0\n0 -1 -1 0 1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0", "10 0\n1 -1 0 1 1 -1 -1 0 1 0", "31 0\n1 -1 -1 0 -1 0 -1 -1 0 -1 -1 -1 1 1 0 1 -1 1 1 0 0 -1 0 1 -1 1 0 -1 1 -1 -1", "41 1\n0 0 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 0 1 1 1 0 0 1 1 -1 0 0 1 0 0 1 1 1 -1 0 -1 1 0 1 1 1 1", "37 1\n1 -1 1 -1 -1 -1 0 1 -1 -1 1 0 0 0 1 1 -1 0 -1 1 -1 0 1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 -1 -1 -1", "31 0\n1 0 1 1 0 0 0 -1 -1 -1 -1 -1 0 1 1 1 0 -1 1 -1 -1 1 -1 1 1 0 0 1 1 -1 0", "4 1\n1 0 1 0", "26 1\n1 -1 1 1 1 1 -1 1 -1 1 -1 -1 0 -1 -1 -1 1 0 -1 -1 0 1 -1 0 1 0", "28 1\n0 0 1 1 -1 1 -1 1 0 -1 -1 -1 0 -1 0 -1 1 0 -1 1 0 -1 -1 0 -1 1 1 -1", "24 1\n0 0 0 1 1 0 -1 0 -1 1 -1 -1 0 0 1 1 0 -1 0 0 0 0 1 1", "17 0\n-1 0 -1 1 0 0 1 1 -1 -1 -1 -1 -1 1 1 -1 -1", "42 1\n0 1 -1 0 -1 0 -1 1 -1 1 0 1 1 -1 0 -1 -1 1 -1 -1 0 -1 1 -1 0 1 0 1 -1 1 -1 1 0 0 -1 0 1 0 1 1 0 0", "3 0\n0 -1 -1", "9 1\n0 1 -1 -1 -1 -1 1 1 1", "9 0\n1 1 0 0 1 -1 -1 0 0", "14 1\n-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0", "20 0\n1 -1 1 -1 -1 -1 0 1 1 0 1 0 -1 1 1 -1 1 0 1 1", "18 0\n1 1 1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 -1 0 -1 1", "16 0\n1 -1 0 0 0 -1 -1 -1 0 -1 -1 1 0 0 -1 1", "27 1\n-1 0 -1 -1 -1 0 1 -1 1 0 0 -1 0 1 0 0 0 -1 -1 1 -1 -1 -1 0 1 0 0", "2 0\n-1 1", "34 1\n1 0 -1 0 0 0 -1 1 0 1 1 1 1 1 1 -1 0 0 1 0 -1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 1 -1", "17 0\n1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 -1 0", "16 0\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1", "17 0\n0 0 0 0 0 1 -1 -1 -1 1 -1 1 0 0 1 -1 -1", "38 0\n-1 -1 1 1 -1 -1 1 -1 0 1 -1 1 1 1 -1 1 0 1 0 -1 1 -1 -1 0 0 1 -1 -1 0 -1 0 -1 -1 0 1 0 -1 0", "33 0\n0 1 -1 -1 -1 1 -1 1 1 -1 -1 -1 -1 0 1 0 -1 0 0 -1 1 -1 -1 0 0 -1 0 0 1 0 1 1 1", "32 1\n0 0 1 0 -1 0 1 -1 -1 -1 0 1 0 0 1 0 -1 -1 1 1 1 0 0 1 -1 -1 1 0 0 -1 0 1", "6 0\n-1 1 1 -1 -1 -1", "27 1\n0 -1 1 0 -1 1 1 -1 0 -1 0 0 0 -1 -1 0 0 -1 -1 0 -1 0 -1 0 0 1 1", "27 1\n0 -1 -1 1 1 1 -1 1 0 0 1 -1 -1 1 -1 1 1 1 1 1 0 0 0 0 -1 -1 0", "17 1\n0 -1 -1 0 0 1 -1 -1 0 0 -1 1 0 -1 1 0 0", "34 0\n1 1 1 0 0 0 0 1 0 0 1 -1 1 1 -1 0 -1 1 1 1 0 1 1 -1 0 0 1 -1 -1 0 0 0 -1 -1", "31 1\n1 0 0 0 0 0 0 0 -1 0 0 0 1 -1 -1 -1 0 0 -1 0 1 -1 1 0 1 1 1 1 -1 -1 1", "48 1\n1 0 0 0 1 -1 1 1 0 -1 0 -1 1 1 0 -1 -1 -1 0 0 0 1 0 1 0 -1 -1 -1 -1 1 0 1 -1 -1 -1 1 -1 0 1 0 0 1 -1 0 -1 0 0 0", "5 0\n0 -1 0 0 0", "43 0\n1 0 0 -1 0 -1 0 -1 1 1 -1 1 -1 0 0 1 -1 -1 -1 0 0 -1 1 -1 -1 1 0 0 1 -1 0 -1 -1 -1 -1 -1 1 1 0 -1 -1 -1 0", "11 1\n1 0 1 0 -1 1 0 -1 -1 0 0", "13 1\n-1 1 0 0 -1 0 -1 1 -1 -1 1 1 0"], "outputs": ["6", "1", "2", "0", "1", "16512", "16256", "185921272", "803313751", "483548109", "40673917", "73320910", "772364444", "279519499", "18", "64", "0", "733922348", "0", "0", "0", "322050759", "549790477", "480432768", "743685088", "61440", "2359296", "560111071", "131072", "135168", "56964601", "133120", "981309322", "716651774", "1", "693536347", "915368288", "120", "45647242", "66699122", "77953873", "608326411", "152782818", "487370169", "4194304", "3", "1920", "6", "136", "1088", "310296666", "487370169", "304540143", "589337580", "916646835", "253181331", "32", "996763118", "618844160", "189147304", "555719737", "386658717", "14", "755810045", "438952513", "829277977", "841268608", "557382306", "807669877", "61073361", "3", "132603129", "585862415", "878929813", "427689083", "502273788", "52976952", "247728070", "267264", "28918236", "69931865", "427689083", "115086916", "186475897", "763606955", "768", "477560567", "67049563", "621572676"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
aa950f6569484d8c8e06d95a3f7aaf3a | Boxes Packing | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Print the minimum possible number of visible boxes.
Sample Input
3
1 2 3
4
4 2 4 3
Sample Output
1
2
| {"inputs": ["3\n1 2 3", "4\n4 2 4 3", "10\n58 58 58 58 58 58 58 58 58 58", "10\n86 89 89 86 86 89 86 86 89 89", "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360", "1\n1", "1\n9", "1\n5", "1\n2", "1\n131", "9\n1 1 1 1 1 1 1 1 1", "11\n1 1 1 1 1 1 1 1 1 1 1", "8\n1 2 3 4 5 6 7 8", "8\n1 1 1 1 1 1 1 1", "5\n1 1 1 1 1"], "outputs": ["1", "2", "10", "5", "14", "1", "1", "1", "1", "1", "9", "11", "1", "8", "5"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 197 | codeforces |
|
aa95201684f692785e83233e7b14292e | Cycle | A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes *u* and *v* (*u*<=≠<=*v*) exists either an edge going from *u* to *v*, or an edge from *v* to *u*.
You are given a tournament consisting of *n* vertexes. Your task is to find there a cycle of length three.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=5000). Next *n* lines contain the adjacency matrix *A* of the graph (without spaces). *A**i*,<=*j*<==<=1 if the graph has an edge going from vertex *i* to vertex *j*, otherwise *A**i*,<=*j*<==<=0. *A**i*,<=*j* stands for the *j*-th character in the *i*-th line.
It is guaranteed that the given graph is a tournament, that is, *A**i*,<=*i*<==<=0,<=*A**i*,<=*j*<=≠<=*A**j*,<=*i* (1<=≤<=*i*,<=*j*<=≤<=*n*,<=*i*<=≠<=*j*).
Print three distinct vertexes of the graph *a*1, *a*2, *a*3 (1<=≤<=*a**i*<=≤<=*n*), such that *A**a*1,<=*a*2<==<=*A**a*2,<=*a*3<==<=*A**a*3,<=*a*1<==<=1, or "-1", if a cycle whose length equals three does not exist.
If there are several solutions, print any of them.
Sample Input
5
00100
10000
01001
11101
11000
5
01111
00000
01000
01100
01110
Sample Output
1 3 2 -1
| {"inputs": ["5\n00100\n10000\n01001\n11101\n11000", "5\n01111\n00000\n01000\n01100\n01110", "5\n01000\n00101\n10010\n11001\n10100", "5\n00110\n10110\n00011\n00000\n11010", "10\n0011000010\n1011001101\n0000101100\n0010101010\n1100000100\n1111101100\n1000100000\n1001001011\n0110111001\n1011111000", "10\n0111001000\n0011111000\n0000110110\n0010101110\n1000011001\n1001000010\n0010010101\n1100110000\n1100101100\n1111010110", "10\n0101111011\n0001111111\n1100011110\n0010011000\n0011000110\n0000101011\n0000100000\n1001011011\n0001001000\n0011101010", "10\n0000010011\n1001001111\n1100001110\n1010010011\n1111011000\n0110000001\n1001010100\n1001110000\n0000111101\n0010101100", "10\n0000000000\n1001100111\n1101101111\n1000000011\n1001000111\n1111101111\n1101100111\n1001000011\n1000000001\n1000000000", "1\n0", "2\n00\n10", "3\n001\n100\n010", "3\n010\n001\n100", "2\n01\n00", "3\n011\n000\n010", "4\n0000\n1010\n1001\n1100", "5\n01111\n00111\n00010\n00001\n00100"], "outputs": ["1 3 2 ", "-1", "1 2 3 ", "1 3 5 ", "1 3 5 ", "1 3 5 ", "1 4 3 ", "1 6 2 ", "-1", "-1", "-1", "1 3 2 ", "1 2 3 ", "-1", "-1", "2 3 4 ", "3 4 5 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
aaa6c5a197701f18e7cecda2a36fc449 | Endless Roses Most Beautiful | Arkady decided to buy roses for his girlfriend.
A flower shop has white, orange and red roses, and the total amount of them is *n*. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and white roses. Also, Arkady won't buy a bouquet where all roses have the same color.
Arkady wants to buy exactly *k* roses. For each rose in the shop he knows its beauty and color: the beauty of the *i*-th rose is *b**i*, and its color is *c**i* ('W' for a white rose, 'O' for an orange rose and 'R' for a red rose).
Compute the maximum possible total beauty of a bouquet of *k* roses satisfying the constraints above or determine that it is not possible to make such a bouquet.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200<=000) — the number of roses in the show and the number of roses Arkady wants to buy.
The second line contains a sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=10<=000), where *b**i* equals the beauty of the *i*-th rose.
The third line contains a string *c* of length *n*, consisting of uppercase English letters 'W', 'O' and 'R', where *c**i* denotes the color of the *i*-th rose: 'W' denotes white, 'O' — orange, 'R' — red.
Print the maximum possible total beauty of a bouquet of *k* roses that satisfies the constraints above. If it is not possible to make a single such bouquet, print -1.
Sample Input
5 3
4 3 4 1 6
RROWW
5 2
10 20 14 20 11
RRRRR
11 5
5 6 3 2 3 4 7 5 4 5 6
RWOORWORROW
Sample Output
11
-1
28
| {"inputs": ["5 3\n4 3 4 1 6\nRROWW", "5 2\n10 20 14 20 11\nRRRRR", "11 5\n5 6 3 2 3 4 7 5 4 5 6\nRWOORWORROW", "15 10\n8560 6244 9607 5137 7187 3217 5527 9919 282 8748 3529 6110 5767 521 3393\nOWRWOORWRORWWRO", "10 4\n1208 5835 2637 5827 3722 6837 3499 6438 43 5333\nWRRWRWRWRW", "13 3\n9675 8988 5499 6356 5083 6067 5580 4580 6735 3617 9536 8218 3265\nRRWRRROWRWWWW", "13 7\n8543 3460 1282 3956 8203 762 6059 9361 4427 8868 5849 3439 8891\nWWOOOOWOWWRWO", "30 15\n7926 577 5009 7237 4395 3239 8994 4429 8126 2925 139 320 4442 3397 1292 2800 9505 6043 5946 8058 4031 6871 4689 1977 73 440 5320 5290 4707 387\nOOWOWWORRWOWORWRRRRWORROOWWROW", "1 1\n100\nO", "1 1\n1059\nO", "2 2\n9907 4483\nOO", "1 1\n6750\nW", "2 2\n144 174\nOW", "3 2\n776 4797 9449\nOWO", "2 2\n3486 8968\nWW", "3 2\n2330 2140 3440\nWOW", "4 2\n1175 8186 4321 1810\nWWOO", "1 1\n6479\nR", "2 2\n8512 9903\nOR", "3 2\n7035 5046 7357\nOOR", "2 2\n6442 4558\nWR", "3 2\n9700 698 2122\nOWR", "4 3\n254 4510 2194 9543\nWOOR", "3 2\n517 6744 2364\nRWW", "4 2\n2884 2918 8629 9905\nRWOW", "5 2\n7882 871 789 4432 7664\nOWORW", "2 2\n2926 8428\nRR", "3 2\n7926 1770 3255\nORR", "4 2\n2578 7910 108 3809\nOROR", "3 2\n5920 9303 7542\nWRR", "4 2\n5909 4286 5444 6473\nOWRR", "5 2\n96 6627 8780 3764 970\nRROWO", "4 2\n6657 1489 9138 4273\nRRWW", "5 2\n1598 6700 334 6455 9292\nWORWR", "6 2\n6231 9178 9845 5932 5477 6659\nORRWOW", "1 1\n780\nO", "1 1\n3214\nW", "2 2\n8455 5432\nOW", "1 1\n6555\nR", "2 2\n1120 5670\nOR", "3 2\n8884 4514 1673\nORW", "1 1\n6908\nO", "1 1\n3934\nW", "2 2\n8856 7299\nWO", "1 1\n2683\nR", "2 2\n9094 5772\nRO", "3 2\n518 9438 7938\nWOR", "10 4\n9513 754 5917 1337 2337 1387 3499 9873 9138 7647\nWROWWOWWRO", "20 5\n3747 219 7826 7713 6886 466 1136 7069 1234 7556 3657 6017 9965 2847 6880 362 3179 4676 5934 4913\nWWWOWOWOWOROWOWWWOWW"], "outputs": ["11", "-1", "28", "64282", "-1", "24243", "54352", "91633", "-1", "-1", "-1", "-1", "318", "14246", "-1", "5580", "12507", "-1", "18415", "14392", "-1", "11822", "16247", "-1", "18534", "15546", "-1", "11181", "10488", "-1", "12382", "15407", "-1", "15992", "16076", "-1", "-1", "13887", "-1", "6790", "13398", "-1", "-1", "16155", "-1", "14866", "17376", "32950", "40129"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
aaab33deadf08632a19f4bb503f27565 | none | Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A', or the letter 'B'. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'A', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she had before. Thus the number of oranges and apples Alice had, did not change. If the card had written letter 'B', then Bob did the same, that is, he gave Alice all the fruit that he had, and took from the bag the same set of fruit. After the last card way removed, all the fruit in the bag were over.
You know how many oranges and apples was in the bag at first. Your task is to find any sequence of cards that Alice and Bob could have played with.
The first line of the input contains two integers, *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=1018,<=*xy*<=><=1) — the number of oranges and apples that were initially in the bag.
Print any sequence of cards that would meet the problem conditions as a compressed string of characters 'A' and 'B. That means that you need to replace the segments of identical consecutive characters by the number of repetitions of the characters and the actual character. For example, string AAABAABBB should be replaced by string 3A1B2A3B, but cannot be replaced by 2A1A1B2A3B or by 3AB2A3B. See the samples for clarifications of the output format. The string that you print should consist of at most 106 characters. It is guaranteed that if the answer exists, its compressed representation exists, consisting of at most 106 characters. If there are several possible answers, you are allowed to print any of them.
If the sequence of cards that meet the problem statement does not not exist, print a single word Impossible.
Sample Input
1 4
2 2
3 2
Sample Output
3B
Impossible
1A1B
| {"inputs": ["1 4", "2 2", "3 2", "2 1", "5 3", "5 2", "8 5", "97 101", "1 3", "1000000000000000000 999999999999999999", "55 89", "610 987", "4181 6765", "46368 75025", "832040 514229", "5702887 9227465", "701408733 433494437", "956722026041 591286729879", "498454011879264 806515533049393", "420196140727489673 679891637638612258", "1000000000000000000 1000000000000000000", "1000000000000000000 1", "2 1000000000000000000", "999999999999999999 999999999999999998", "616274828435574301 10268395600356301", "10808314049304201 270039182096201", "1000100020001 100010001", "152139002499 367296043199", "25220791 839761", "27961 931", "127601 6382601", "1 1000000000000000000", "242 100", "507769900974602687 547261784951014891", "585026192452577797 570146946822492493", "568679881256193737 513570106829158157", "567036128564717939 510505130335113937", "519421744863260201 572972909476222789", "529495319593227313 631186172547690847", "540431588408227541 540431588408227541", "410218934960967047 378596216455001869", "395130552422107969 382562323268297483", "416445288135075809 416445288135075809", "402725448165665593 481342602240996343", "412177780967225699 432177937877609093", "423506197818989927 442863139846534733", "453151988636162147 474019690903735841", "408962762283480959 444443583457646111", "976540997167958951 969335176443917693", "957591654759084713 981022104435698593", "962890278562476113 969978235623119279", "963716517445592213 976351630941239591", "964542760623675601 965233603018687501", "977367244641009653 977367244641009653"], "outputs": ["3B", "Impossible", "1A1B", "1A", "1A1B1A", "2A1B", "1A1B1A1B", "1B24A3B", "2B", "1A999999999999999998B", "1B1A1B1A1B1A1B1A1B", "1B1A1B1A1B1A1B1A1B1A1B1A1B1A", "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A", "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B", "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B", "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B", "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B", "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A", "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B", "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B", "Impossible", "999999999999999999A", "Impossible", "1A999999999999999997B", "60A60B60A60B60A60B60A60B60A60B", "40A40B40A40B40A40B40A40B40A40B", "10000A10000B10000A", "2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A", "30A30B30A30B30A", "30A30B30A", "50B50A50B50A", "999999999999999999B", "Impossible", "Impossible", "1A38B3A7B23A2B1A1B1A8B2A1B5A117B2A1B1A2B12A3B10A5B3A2B3A11B2A1B7A", "1A9B3A7B2A3B1A1B1A2B3A2B1A3B2A82B1A7B2A14B2A1B1A4B5A3B2A1B9A1B2A1B4A1B3A1B3A2B", "1A9B32A1B2A1B368A1B1A1B2A4B1A1B23A14B21A5B1A1B2A4B1A1B3A1B1A1B3A1B5A1B1A9B", "1B9A1B2A3B21A1B1A21B2A1B2A12B1A4B1A1B5A160B4A1B1A138B1A1B9A4B3A2B6A", "1B5A4B1A4B1A76B3A2B11A3B7A5B1A1B2A2B7A2B2A8B5A3B143A1B3A8B1A5B1A", "Impossible", "Impossible", "Impossible", "Impossible", "1B5A8B6A2B2A1B20A3B9A5B2A1B4A5B2A4B1A268B9A4B1A1B4A3B2A2B1A2B1A1B3A", "1B20A1B1A1B1A3B1A58B1A4B1A13B206A2B2A5B5A22B3A45B1A7B5A1B1A6B1A1B", "1B21A1B7A4B76A1B3A2B82A1B18A4B1A13B1A3B6A1B1A2B1A22B1A3B2A1B1A2B27A", "1B21A1B2A1B1A16B1A1B1A4B300A1B4A1B11A47B1A6B8A1B1A1B1A2B2A5B3A2B1A7B1A5B1A", "1B11A1B1A9B253A1B5A22B6A1B11A4B3A2B1A1B4A1B13A2B4A1B50A1B6A1B5A3B", "1A134B1A1B11A3B26A2B3A1B1A2B22A1B3A3B1A1B66A63B36A2B1A13B5A3B", "1B40A1B6A1B1A1B68A1B18A2B3A1B2A2B2A1B1A4B1A3B2A1B12A3B604A5B1A1B39A1B1A", "1B135A1B5A1B1A1B1A2B1A1B3A4B2A1B2A2B1A5B3A1B2A2B2A1B2A1B3A2B67A1B1A6B3A1B14A1B3A19B", "1B76A3B1A1B1A52B1A6B2A7B35A1B1A2B17A5B5A4B5A9B3A2B13A1B2A3B1A7B", "1B1396A5B2A4B2A2B1A18B4A1B1A1B2A3B3A1B10A2B3A1B3A1B5A1B1A1B2A10B3A9B1A1B3A2B", "Impossible"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 16 | codeforces |
|
aaae939c861210fcad59ff469f432ee8 | Bakery | Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only *k* storages, located in different cities numbered *a*1,<=*a*2,<=...,<=*a**k*.
Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another *n*<=-<=*k* cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.
Formally, Masha will pay *x* roubles, if she will open the bakery in some city *b* (*a**i*<=≠<=*b* for every 1<=≤<=*i*<=≤<=*k*) and choose a storage in some city *s* (*s*<==<=*a**j* for some 1<=≤<=*j*<=≤<=*k*) and *b* and *s* are connected by some path of roads of summary length *x* (if there are more than one path, Masha is able to choose which of them should be used).
Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of *k* storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.
The first line of the input contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.
Then *m* lines follow. Each of them contains three integers *u*, *v* and *l* (1<=≤<=*u*,<=*v*<=≤<=*n*, 1<=≤<=*l*<=≤<=109, *u*<=≠<=*v*) meaning that there is a road between cities *u* and *v* of length of *l* kilometers .
If *k*<=><=0, then the last line of the input contains *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*) — the number of cities having flour storage located in. If *k*<==<=0 then this line is not presented in the input.
Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.
If the bakery can not be opened (while satisfying conditions) in any of the *n* cities, print <=-<=1 in the only line.
Sample Input
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
3 1 1
1 2 3
3
Sample Output
3-1 | {"inputs": ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3", "2 3 1\n1 2 3\n1 2 18\n1 2 13\n2", "3 7 0\n1 3 9\n1 2 5\n1 2 21\n1 2 12\n1 2 13\n2 3 19\n2 3 8", "4 13 1\n1 4 10\n1 3 6\n1 4 3\n3 4 1\n1 3 2\n1 2 15\n1 4 21\n1 4 20\n2 4 13\n1 4 7\n2 4 2\n1 2 8\n1 3 17\n1", "5 7 3\n2 3 20\n1 2 10\n1 2 11\n4 5 15\n2 3 3\n1 5 19\n1 2 3\n5 3 2", "6 7 4\n5 6 21\n3 6 18\n1 6 5\n4 6 4\n1 2 13\n3 4 7\n1 2 15\n6 1 3 2", "7 39 2\n2 7 10\n5 6 18\n2 7 13\n4 5 11\n3 6 14\n1 2 16\n3 4 2\n1 3 13\n1 5 1\n1 2 20\n1 5 11\n1 4 14\n3 6 21\n1 2 18\n1 4 13\n2 3 4\n3 6 12\n2 5 18\n4 7 17\n1 2 3\n2 3 6\n1 2 21\n1 7 18\n4 6 13\n1 2 13\n1 7 17\n2 3 16\n5 6 5\n2 4 17\n1 2 9\n1 2 21\n4 5 9\n1 2 18\n2 6 6\n2 3 9\n1 4 7\n2 5 7\n3 7 21\n4 5 2\n6 2", "8 57 3\n1 3 15\n2 3 1\n1 7 21\n1 2 8\n2 5 16\n1 6 4\n1 3 2\n3 7 17\n5 8 3\n1 3 18\n1 4 3\n1 2 1\n2 8 14\n1 4 17\n4 5 21\n2 3 6\n3 5 11\n2 8 11\n3 4 1\n1 3 9\n1 4 3\n2 3 12\n1 5 9\n2 3 15\n1 2 14\n1 2 10\n1 4 19\n5 7 7\n5 8 20\n5 8 1\n1 4 3\n4 5 8\n5 7 2\n1 2 14\n4 5 9\n6 7 2\n2 6 9\n2 6 4\n3 7 4\n3 5 11\n4 8 19\n3 7 15\n1 8 21\n6 7 11\n4 6 2\n2 3 21\n6 7 2\n6 8 4\n1 3 21\n3 4 1\n4 5 15\n4 7 21\n2 6 2\n5 6 16\n5 8 9\n2 5 6\n1 7 17\n1 4 8", "350 10 39\n2 13 693\n6 31 482\n72 312 617\n183 275 782\n81 123 887\n26 120 1205\n135 185 822\n64 219 820\n74 203 874\n19 167 1422\n252 332 204 334 100 350 26 14 134 213 32 84 331 215 181 158 99 190 206 265 343 241 287 74 113 15 12 338 27 110 98 132 35 95 51 315 297 69 163", "7 7 3\n1 2 1\n2 4 1\n3 4 1\n1 3 1\n5 7 2\n6 7 10\n5 6 5\n5 6 7", "7 8 3\n1 2 1\n2 4 1\n3 4 1\n1 3 1\n5 7 2\n6 7 10\n5 6 5\n2 5 31246\n5 6 7", "5 5 5\n1 2 1\n2 3 2\n3 4 3\n4 5 5\n1 5 6\n1 2 3 4 5", "10 10 3\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n7 8 1000000000\n8 9 1000000000\n9 10 1000000000\n10 1 1000000000\n1 2 3", "2 1 1\n1 2 1000000000\n1", "99999 1 0\n1 2 3", "99999 1 2\n1 2 3\n2 4", "2 1 1\n1 2 99999999\n1", "2 1 1\n1 2 999999\n2"], "outputs": ["3", "-1", "3", "-1", "2", "3", "4", "3", "1", "874", "-1", "31246", "-1", "1000000000", "1000000000", "-1", "3", "99999999", "999999"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 23 | codeforces |
|
aaaffe668fb66d099e8688f0232544af | Vessels | There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the *i*-th vessel goes to the (*i*<=+<=1)-th one. The liquid that overflows from the *n*-th vessel spills on the floor.
Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:
1. Add *x**i* liters of water to the *p**i*-th vessel; 1. Print the number of liters of water in the *k**i*-th vessel.
When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels.
The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=2·105). Each of the next *m* lines contains the description of one query. The query of the first type is represented as "1 *p**i* *x**i*", the query of the second type is represented as "2 *k**i*" (1<=≤<=*p**i*<=≤<=*n*, 1<=≤<=*x**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=*n*).
For each query, print on a single line the number of liters of water in the corresponding vessel.
Sample Input
2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2
3
5 10 8
6
1 1 12
2 2
1 1 6
1 3 2
2 2
2 3
Sample Output
4
5
8
7
10
5
| {"inputs": ["2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2", "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3", "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n2 4\n2 7\n1 3 31\n2 4\n1 6 64\n2 2\n2 2\n1 3 54\n2 9\n2 1\n1 6 86", "10\n3 7 10 1 5 4 4 3 3 1\n20\n2 4\n2 4\n1 1 10\n1 1 10\n2 4\n2 3\n1 4 2\n1 4 6\n2 2\n1 8 9\n2 2\n2 5\n2 9\n1 2 1\n1 6 9\n1 1 6\n2 5\n2 2\n2 3\n1 4 10", "50\n57 63 98 44 22 63 5 65 36 69 49 54 61 15 29 79 50 30 43 93 18 94 46 92 72 67 67 51 34 40 50 77 58 53 79 72 72 34 91 75 83 67 71 80 11 51 85 20 6 3\n20\n2 40\n1 14 102\n2 22\n2 15\n2 43\n1 29 532\n2 27\n2 47\n1 24 107\n1 20 720\n1 21 315\n2 20\n1 2 787\n1 27 532\n2 38\n1 32 445\n1 38 17\n1 26 450\n2 40\n1 45 192", "1\n1\n1\n2 1"], "outputs": ["4\n5\n8", "7\n10\n5", "0\n0\n0\n0\n38\n0\n0\n0\n53\n20", "0\n0\n0\n10\n7\n7\n5\n3\n5\n7\n10", "0\n0\n29\n0\n0\n0\n93\n34\n75", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 5 | codeforces |
|
aac6bac239d06f0aeceefefe8a47c5e9 | Let's Watch Football | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is *c* seconds and Valeric and Valerko wait *t* seconds before the watching. Then for any moment of time *t*0, *t*<=≤<=*t*0<=≤<=*c*<=+<=*t*, the following condition must fulfill: the size of data received in *t*0 seconds is not less than the size of data needed to watch *t*0<=-<=*t* seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.
The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (*c*) denotes the video's length in seconds.
Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
Sample Input
4 1 1
10 3 2
13 12 1
Sample Output
3
5
1
| {"inputs": ["4 1 1", "10 3 2", "13 12 1", "2 1 3", "6 2 4", "5 2 1", "2 1 1", "2 1 4", "5 1 5", "2 1 2", "60 16 1", "64 12 8", "66 38 4", "70 32 1", "24 12 12", "24 19 9", "244 87 4", "305 203 421", "888 777 1", "888 777 1000", "888 777 888", "5 4 10", "1000 1 1", "1000 1 1000", "1000 999 1", "1000 999 1000", "945 812 917", "993 992 991", "17 7 10", "17 10 7", "500 300 300", "196 169 144", "7 3 200", "9 3 300", "561 31 917", "100 10 1", "1000 100 10", "18 14 10", "93 74 831", "960 935 994", "894 1 999", "767 2 514", "765 123 45", "1000 1 1000", "765 123 899", "759 10 258", "100 1 10", "99 8 99", "27 26 1"], "outputs": ["3", "5", "1", "3", "8", "2", "1", "4", "20", "2", "3", "35", "3", "2", "12", "3", "8", "212", "1", "143", "127", "3", "999", "999000", "1", "2", "151", "1", "15", "5", "200", "24", "267", "600", "15678", "9", "90", "3", "214", "27", "892107", "196605", "235", "999000", "4693", "19325", "990", "1127", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 196 | codeforces |
|
aaf53c3223958d02a7990a2f62318615 | Remove Extra One | You are given a permutation *p* of length *n*. Remove one element from permutation to make the number of records the maximum possible.
We remind that in a sequence of numbers *a*1,<=*a*2,<=...,<=*a**k* the element *a**i* is a record if for every integer *j* (1<=≤<=*j*<=<<=*i*) the following holds: *a**j*<=<<=*a**i*.
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=105) — the length of the permutation.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation. All the integers are distinct.
Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.
Sample Input
1
1
5
5 1 2 3 4
Sample Output
1
5
| {"inputs": ["1\n1", "5\n5 1 2 3 4", "5\n4 3 5 1 2", "9\n9 5 8 6 3 2 4 1 7", "3\n3 2 1", "7\n1 6 7 4 2 5 3", "48\n38 6 31 19 45 28 27 43 11 35 36 20 9 16 42 48 14 22 39 18 12 10 34 25 13 26 40 29 17 8 33 46 24 30 37 44 1 15 2 21 3 5 4 47 32 23 41 7", "26\n23 14 15 19 9 22 20 12 5 4 21 1 16 8 6 11 3 17 2 10 24 26 13 18 25 7", "46\n32 25 11 1 3 10 8 12 18 42 28 16 35 30 41 38 43 4 13 23 6 17 36 34 39 22 26 14 45 20 33 44 21 7 15 5 40 46 2 29 37 9 31 19 27 24", "24\n20 3 22 10 2 14 7 18 6 23 17 12 5 11 15 13 19 24 16 1 21 4 8 9", "57\n40 11 43 39 13 29 18 57 54 48 17 4 22 5 38 15 36 53 33 3 51 41 30 9 26 10 55 27 35 56 23 20 1 8 12 46 21 28 6 19 34 2 45 31 49 42 50 16 44 7 25 52 14 32 47 37 24", "85\n82 72 24 38 81 18 49 62 37 28 41 57 10 55 83 67 56 2 73 44 26 85 78 14 27 40 51 61 54 29 16 25 5 31 71 42 21 30 3 74 6 63 76 33 39 68 66 23 53 20 22 43 45 52 80 60 1 59 50 58 12 77 65 36 15 19 46 17 79 9 47 8 70 75 34 7 69 32 4 84 64 35 11 13 48", "5\n2 3 4 1 5", "87\n66 53 79 35 24 61 22 70 29 43 6 21 75 4 85 2 37 18 65 49 40 82 58 73 33 87 71 19 34 83 84 25 56 48 9 63 38 20 67 32 74 42 51 39 11 1 78 86 44 64 81 17 62 72 47 54 52 23 7 5 41 46 3 28 77 57 13 15 59 68 14 36 50 27 80 31 26 10 55 60 69 76 16 12 8 45 30", "92\n42 64 33 89 57 9 24 44 87 67 92 84 39 88 26 27 85 62 22 83 23 71 14 13 73 79 15 49 2 12 76 53 81 40 31 3 72 58 1 61 7 82 20 54 46 77 11 16 28 48 6 45 36 43 60 38 18 4 32 74 10 91 19 86 75 51 50 52 78 25 65 8 55 30 90 69 59 63 56 80 29 68 70 17 35 41 37 47 66 34 5 21", "5\n1 2 3 4 5"], "outputs": ["1", "5", "1", "9", "1", "2", "38", "23", "42", "1", "57", "82", "1", "79", "1", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 12 | codeforces |
|
ab1ba7a3a8c64af0d4dacb38a45591ed | Sanatorium | Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
The only line contains three integers *b*, *d* and *s* (0<=≤<=*b*,<=*d*,<=*s*<=≤<=1018,<=<=*b*<=+<=*d*<=+<=*s*<=≥<=1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
Sample Input
3 2 1
1 0 0
1 1 1
1000000000000000000 0 1000000000000000000
Sample Output
1
0
0
999999999999999999
| {"inputs": ["3 2 1", "1 0 0", "1 1 1", "1000000000000000000 0 1000000000000000000", "1000 0 0", "0 1 0", "0 0 1", "1 1 0", "0 1 1", "1000000000000000000 999999999999999999 999999999999999999", "1000000000000000000 1000000000000000000 999999999999999999", "1000000000000000000 1000000000000000000 1000000000000000000", "999999999999999999 999999999999999999 999999999999999999", "999999999999999999 1000000000000000000 999999999999999999", "999999999999999999 1000000000000000000 1000000000000000000", "999999999999999999 999999999999999998 999999999999999999", "999999999999999999 999999999999999999 1000000000000000000", "10 10 10", "9 11 11", "10 8 9", "12 8 8", "13 18 14", "94 87 14", "35 91 108", "1671 24 419", "7759 10296 4966", "8912 10561 8205", "1000000100 1000000083 1000000047", "999996782 1000007108 1000009860", "999342691 1000075839 1000144842", "951468821 1005782339 1063348170", "498556507 1820523034 1566999959", "99999999999999938 99999999999999971 99999999999999944", "99999999999995757 100000000000000116 99999999999999158", "100000000481729714 100000000353636209 99999999472937283", "100000330161030627 99999005090484867 99999729994406004", "100040306518636197 100049788380618015 99377557930019414", "117864695669097197 53280311324979856 171825292362519668", "64058874468711639 248004345115813505 265277488186534632", "0 323940200031019351 1000000000000000000", "0 1000000000000000000 0", "4 3 5", "0 0 1000000000000000000", "1000000000000000000 0 0", "0 1000000000000000000 1000000000000000000", "1000000000000000000 1000000000000000000 0", "6436340231848 215 5328562123", "1 4352626266226 1", "647397084215 513125 15999899", "429 42 132", "1 3 1", "0 6 0", "100 100 99", "3 3 2", "10 10 9", "3 3 1", "100 99 100", "5 5 4", "50 70 80", "4 4 4", "4 4 3", "1 0 1", "0 0 2", "1 1 10", "5 2 3", "5 5 1", "10 200000 10", "3 0 0", "100 100 100", "3 5 5", "3 4 3", "1000000000000000000 1 0", "2 0 0", "5 6 4", "0 2 2", "1000000000000000000 100000000000000000 0", "2 2 1", "1000000000000000000 1 1", "1 2 2", "1 1 5", "10 0 5", "10 10 0", "0 1000 0"], "outputs": ["1", "0", "0", "999999999999999999", "1998", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "1", "6", "7", "85", "88", "2897", "7865", "4003", "68", "15828", "871152", "169445178", "1575489600", "58", "5315", "1136885934", "1925237170381", "681712312580417", "172505577730962281", "218491756788544118", "1676059799968980647", "1999999999999999998", "1", "1999999999999999998", "1999999999999999998", "999999999999999999", "999999999999999999", "12867351901356", "8705252532448", "1294777655404", "682", "2", "10", "0", "0", "0", "1", "0", "0", "38", "0", "0", "0", "2", "16", "3", "3", "399978", "4", "0", "1", "0", "1999999999999999997", "2", "1", "1", "1899999999999999998", "0", "1999999999999999996", "0", "6", "13", "9", "1998"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 16 | codeforces |
|
ab243f42ee37afd8273312305780af22 | Electric Charges | Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.
A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: axis *X* is positive and axis *Y* is negative.
Experienced laboratory worker marked *n* points with integer coordinates (*x**i*,<=*y**i*) on the plane and stopped the time. Sasha should use "atomic tweezers" to place elementary particles in these points. He has an unlimited number of electrons (negatively charged elementary particles) and protons (positively charged elementary particles). He can put either an electron or a proton at each marked point. As soon as all marked points are filled with particles, laboratory worker will turn on the time again and the particles will come in motion and after some time they will stabilize in equilibrium. The objective of the laboratory work is to arrange the particles in such a way, that the diameter of the resulting state (the maximum distance between the pairs of points of the set) is as small as possible.
Since Sasha is a programmer, he naively thinks that all the particles will simply "fall" into their projections on the corresponding axes: electrons will fall on axis *X*, while protons will fall on axis *Y*. As we are programmers too, we will consider the same model as Sasha. That is, a particle gets from point (*x*,<=*y*) to point (*x*,<=0) if it is an electron and to point (0,<=*y*) if it is a proton.
As the laboratory has high background radiation and Sasha takes care of his laptop, he did not take it with him, and now he can't write a program that computes the minimum possible diameter of the resulting set. Therefore, you will have to do it for him.
Print a square of the minimum possible diameter of the set.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of points marked on the plane.
Each of the next *n* lines contains two integers *x**i* and *y**i* (<=-<=108<=≤<=*x**i*,<=*y**i*<=≤<=108) — the coordinates of the *i*-th point. It is guaranteed that no two points coincide.
Print a single integer — the square of the minimum possible diameter of the set.
Sample Input
3
1 10
1 20
1 30
2
1 10
10 1
Sample Output
0
2
| {"inputs": ["3\n1 10\n1 20\n1 30", "2\n1 10\n10 1", "10\n1 6\n2 2\n-1 9\n-8 8\n-4 10\n-10 -6\n5 -1\n-3 -7\n-4 3\n9 4", "18\n-14 -745\n87 -4611\n89 -3748\n-77 273\n-21 -4654\n-86 -5108\n-70 3232\n25 -6313\n-71 -4846\n88 -1894\n-65 9707\n-51 -3290\n-19 -580\n-62 -2408\n1 -6832\n52 -4279\n21 -7322\n55 9392", "12\n996 -72\n-145 68\n-514 79\n743 -96\n765 -52\n720 86\n-615 -57\n690 81\n-885 -5\n265 4\n-533 -23\n-693 -72", "17\n-10 -36\n1 -10\n53 -2\n-23 5\n7 -19\n10 -33\n9 78\n-7 -3\n70 2\n5 -1\n7 -93\n9 -2\n2 -82\n16 2\n8 48\n52 2\n-76 -6", "16\n22 -370\n90 -8\n46 235\n336 51\n-447 5\n-105 -53\n212 87\n245 -90\n7 -63\n-44 -56\n-426 2\n-485 26\n-31 37\n-93 -410\n39 -108\n-202 -85", "20\n857 286\n-653 -1302\n761 1685\n-783 -94\n208 -1381\n-229 -1333\n664 -296\n-1157 -189\n-2124 956\n837 -2086\n-1872 16\n474 797\n-984 -1224\n188 -1104\n2017 850\n-2211 222\n955 -2275\n-100 1708\n152 199\n-1340 -462", "10\n-594331 634748\n-438198 823828\n-1450064 -200132\n-832505 -718261\n-830561 867133\n1104363 -90870\n696748 -925127\n-755002 -110409\n-1721605 -870036\n344418 -761993", "14\n17434000 -29825809\n3349481 -27203247\n79083185 21513757\n-53052180 -83100420\n543299 -43187896\n-30785780 18551223\n9271044 -77707401\n65259560 -30266930\n-65672492 -20223080\n-37161541 -4703585\n99525015 2119039\n-13413357 -52673928\n83407206 -6063556\n3333364 -56550616", "14\n3 44\n-99 -1\n-11 -9\n3 -57\n83 5\n4 -45\n4 -62\n46 -4\n36 6\n3 -22\n-69 -2\n3 75\n-3 -37\n46 -8", "19\n174 17\n-65 458\n460 -6\n141 8\n53 -441\n-71 -1\n415 -3\n46 -337\n-4 319\n307 -17\n-84 208\n-428 5\n-91 336\n-301 -12\n40 -5\n218 -13\n423 8\n-110 -6\n-24 -20", "1\n42 100000000", "2\n-100000000 100000000\n1 -35", "4\n100000000 100000000\n100000000 -100000000\n-100000000 100000000\n-100000000 -100000000", "5\n25367999 -12921025\n88213873 -62251536\n29698878 -60793556\n69696879 -57681615\n4150867 -42378134", "10\n52725948 -50921428\n22965991 -854605\n19081182 -54959209\n46359108 -78898591\n12280123 -98335714\n96326175 -61967241\n36354396 -64148342\n8164394 -70121916\n94434246 -46350207\n6706998 -57888515", "10\n6 -50790171\n-2 218761\n-1 6364807\n-5 -96100004\n6 13672536\n-31685933 2\n-87361182 6\n6 79979970\n-4 20223120\n3 -33646313", "20\n544 -4618768\n8229332 791\n-19838403 912\n714 81730211\n685 86922721\n976 74377764\n691 -75144278\n767 -14551029\n592 52209892\n868 -16289108\n652 44552695\n963 -60723986\n-98704842 668\n900 28147242\n49913319 735\n534 -69309373\n841 -1918555\n571 -70059713\n821 -70358434\n605 81860132", "9\n-99999999 -99999999\n-99999999 -100000000\n99999999 99999999\n100000000 -99999999\n-99999999 100000000\n-100000000 100000000\n-99999999 99999999\n99999999 100000000\n99999999 -99999999", "1\n100000000 100000000", "2\n100000000 100000000\n100000000 -100000000", "2\n-100000000 100000000\n100000000 100000000", "4\n100000000 -100000000\n-100000000 -100000000\n100000000 100000000\n-100000000 100000000", "5\n46954043 53045957\n86519258 13480742\n12941533 87058467\n53212386 46787614\n57186237 42813763", "5\n635720 157\n702516 142\n286757 348\n756308 132\n751562 133", "5\n99857497 5336678\n78010540 62564811\n51604294 85656271\n88779790 46023350\n99288757 11905571", "10\n-88884243 11115757\n-38391053 61608947\n-67774598 32225402\n-62658046 37341954\n-32014021 67985979\n-49601142 50398858\n-13046283 86953717\n-91869075 8130925\n-85955759 14044241\n-81154428 18845572", "10\n484 206445\n417 239562\n135 736435\n100 995898\n669 149428\n148148 675\n162 615397\n400 249827\n102 973876\n173 575939", "10\n22080299 -97531842\n99982368 -1877760\n82007780 -57225204\n95632512 -29230506\n40850397 -91275654\n39838009 -91722041\n2527763 -99968046\n30181880 -95336530\n59384374 -80458039\n32198040 -94674633", "13\n-2 0\n0 2\n2 0\n-1 1\n0 0\n0 -1\n1 -1\n0 -2\n0 1\n1 0\n1 1\n-1 0\n-1 -1", "81\n-2 -1\n-3 1\n2 1\n1 0\n-3 -1\n1 2\n-1 1\n-3 3\n0 -3\n3 1\n-1 -2\n2 3\n2 2\n1 -2\n3 -1\n-1 -4\n1 3\n3 3\n2 -3\n0 -4\n1 -1\n0 3\n-2 0\n-4 1\n0 -5\n-4 3\n2 -4\n4 2\n-3 -4\n-3 4\n-3 0\n-2 4\n1 1\n4 1\n-4 0\n0 -1\n0 4\n4 0\n-4 -1\n3 -4\n-2 1\n3 2\n0 2\n-1 0\n-3 -2\n3 -3\n0 1\n2 0\n2 -1\n-2 3\n1 -3\n-1 -1\n-2 -3\n3 4\n2 -2\n1 -4\n3 -2\n4 -1\n4 -3\n1 4\n3 0\n-3 -3\n-1 2\n-5 0\n-2 -2\n-4 -2\n4 3\n0 -2\n-4 -3\n-4 2\n-2 2\n-1 -3\n5 0\n-1 3\n2 4\n0 5\n-2 -4\n-3 2\n4 -2\n0 0\n-1 4", "21\n5 0\n2 2\n0 1\n0 2\n2 0\n4 0\n1 1\n3 0\n3 2\n1 0\n1 2\n3 1\n1 3\n2 3\n0 3\n0 5\n0 4\n0 0\n2 1\n1 4\n4 1", "66\n3 0\n2 7\n0 5\n5 1\n6 4\n0 2\n3 1\n3 4\n4 1\n7 0\n10 0\n0 6\n7 1\n7 2\n5 0\n1 1\n6 0\n2 3\n3 5\n0 10\n3 6\n4 0\n1 8\n2 2\n1 6\n6 2\n0 3\n0 9\n2 0\n8 1\n4 4\n2 4\n1 3\n1 9\n3 3\n9 0\n7 3\n2 8\n4 5\n0 8\n5 4\n3 7\n8 2\n5 5\n1 4\n1 5\n4 2\n4 3\n3 2\n1 7\n6 1\n1 0\n0 0\n6 3\n2 1\n8 0\n9 1\n0 1\n0 7\n2 6\n1 2\n4 6\n0 4\n5 2\n5 3\n2 5", "1\n-32222 98", "1\n-1 -1", "3\n10 10\n10 20\n20 10", "2\n5 5\n1000 1000", "2\n1 1\n-1 -1", "3\n-1 7\n8 2\n5 -3", "11\n86252958 -8453022\n20979758 -6495116\n-78204472 -7527274\n66289339 9784937\n-15941740 412492\n58997345 9109992\n90222551 -4687529\n12732746 9064427\n-85673028 -8886670\n37578830 -8279001\n59212726 788692", "10\n-8055884 -28179455\n-9336503 98988615\n19433716 53975448\n58614993 -69147933\n-53287109 35247908\n-75259375 94365460\n43802543 96926279\n53740260 -15640682\n-97179864 -25661311\n-17951783 -51266382", "14\n-66 7\n2 71\n3 -36\n5 26\n-21 6\n41 -5\n32 -2\n-26 -5\n2 -60\n86 -6\n34 -8\n-24 9\n-75 -8\n-92 1", "16\n-68 259\n-90 65\n65 454\n242 74\n358 -86\n-441 -80\n44 -422\n67 178\n15 -425\n88 109\n-66 -246\n-24 285\n-131 60\n-152 52\n-18 -129\n204 -11", "10\n622 1946\n422 1399\n165 -203\n-903 -2133\n-1152 964\n-842 -1150\n1849 5\n-11 471\n1966 -379\n67 776", "15\n-128458 573454\n751293 1852055\n1546241 438377\n642614 -1677745\n1768534 -919019\n205820 357582\n-877851 792499\n313687 -491257\n1334705 533906\n-136082 -42692\n-1948794 304398\n-602602 -557714\n-847986 -1248897\n-1915382 76977\n-1118694 -705173", "12\n-3979966 -64785636\n54498897 11255152\n52322390 -67233168\n32879609 -16571480\n50371826 19645523\n-68348841 22478633\n3424248 90696875\n-42961539 -43574884\n36163900 62201849\n-53982801 42129019\n-55804340 70782236\n13142275 39447287", "18\n3 -55\n-54 -2\n2 -42\n-8 68\n82 4\n-2 -73\n1 44\n-29 3\n-48 -3\n91 4\n4 -16\n24 -2\n-5 36\n46 -2\n24 -3\n76 4\n51 1\n-76 -1", "17\n337 -16\n-53 16\n-247 -10\n-88 -224\n62 -426\n67 2\n320 19\n239 3\n82 269\n76 -237\n-8 -1\n195 -18\n82 131\n31 -276\n48 -2\n-66 228\n-463 -18", "18\n745 1353\n248 -68\n-636 -647\n-335 712\n270 5\n-402 128\n29 -1871\n648 -182\n-403 -469\n616 -1341\n898 2358\n361 2296\n1074 9\n-452 1480\n993 -2039\n-491 1690\n-656 1759\n2087 30", "14\n88 242\n-1763 920\n-160 -1921\n2368 562\n123 -2003\n165 656\n-20 2333\n-1786 -771\n-1648 -242\n-1842 150\n-2078 -428\n-1865 860\n-140 -311\n-2453 571", "20\n-691166 1857437\n308748 757809\n-908302 1208183\n213496 81845\n1882976 -9001\n-1459847 -58718\n902599 -1235585\n499018 1161414\n658542 -86418\n-803191 -1737709\n1682313 -49632\n-166179 1387536\n-203007 18260\n1579851 -79901\n128002 906577\n-57584 -70366\n-493935 -15924\n1900231 6581\n894309 851468\n954724 1678804", "16\n840204 -563586\n-1482 -306408\n-45167 -1969028\n73804 525097\n69604 198191\n65491 -1345144\n-1609018 -285663\n404867 -210266\n255601 832851\n4999 1764313\n541223 736278\n-20170 1911573\n-281805 251017\n52312 1029263\n72529 -38660\n32894 1380373", "12\n-44489842 18113240\n-2081704 -1338672\n-3803741 36271320\n40239596 12868007\n-97939521 33357113\n60348507 -45490328\n59546944 -64898105\n1073008 86908503\n5160027 39955776\n1531464 64470852\n51713010 -35029180\n43419463 -8413764", "14\n-4788460 -58174715\n3667616 -42701029\n58801800 -67135593\n-27712521 33013050\n70162832 21395449\n430668 18516811\n27425137 13550355\n73782530 -33761391\n-3092363 29002645\n-79768595 21183779\n-434563 -46164603\n3072648 -44934958\n2954859 6384655\n-9768771 -50164937", "1\n0 0", "2\n0 0\n-1 5"], "outputs": ["0", "2", "100", "30625", "33124", "400", "31329", "3759721", "1545691540850", "3884184249754176", "225", "20736", "0", "10000000000000001", "40000000000000000", "2433499315521121", "5989105851707745", "121", "1784320", "39999999600000001", "0", "0", "0", "40000000000000000", "2981356830435938", "46656", "2328371599759209", "3854694816242280", "903186", "6801227848213492", "4", "36", "8", "41", "0", "0", "100", "990025", "2", "25", "348628907962449", "14175740317838724", "289", "25600", "2325625", "2654110172736", "8458157168697600", "144", "28900", "2719201", "2859481", "3090265147225", "663578047609", "4754639284823818", "4701923207266041", "0", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
ab514d2189903ec3467ac95baa7abde1 | Table Decorations | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner.
The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Print a single integer *t* — the maximum number of tables that can be decorated in the required manner.
Sample Input
5 4 3
1 1 1
2 3 3
Sample Output
4
1
2
| {"inputs": ["5 4 3", "1 1 1", "2 3 3", "0 1 0", "0 3 3", "4 0 4", "1000000000 1000000000 1000000000", "100 99 56", "1000 1000 1002", "0 1 1000000000", "500000000 1000000000 500000000", "1000000000 2000000000 1000000000", "2000000000 2000000000 2000000000", "0 0 0", "1 2000000000 1000000000", "1585222789 1889821127 2000000000", "10000 7500 7500", "150000 75000 75000", "999288131 55884921 109298382", "100500 100500 3", "1463615122 1988383731 837331500", "1938 8999 1882", "45 33 76", "100000 1 2", "198488 50 18", "82728372 939848 100139442", "99 5747 5298", "3 5 2", "7511 7512 7513", "1234567890 123456789 987654321", "500000000 2000000000 500000000", "500000002 2000000000 500000001", "520000000 1000000033 501000000", "10000 1000 100000", "2000000000 500000000 499999999", "1999999999 500000000 500000000", "1 1 9", "3 0 0", "6 1 1", "2000000000 1999999999 1999999999", "3 4 9", "3 3 6"], "outputs": ["4", "1", "2", "0", "2", "2", "1000000000", "85", "1000", "1", "666666666", "1333333333", "2000000000", "0", "1000000000", "1825014638", "8333", "100000", "165183303", "67001", "1429776784", "3820", "51", "3", "68", "61269220", "3714", "3", "7512", "781893000", "1000000000", "1000000001", "673666677", "11000", "999999999", "999999999", "2", "0", "2", "1999999999", "5", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 77 | codeforces |
|
ab6d5d8599c453ad60eda6bce18f0d4c | File List | Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
- name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters; - ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
The input data consists of a single string *s*, its length is from 1 to 4·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
In the first line print "YES" (without the quotes), if it is possible to divide *s* into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in *s*. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Sample Input
read.meexample.txtb.cpp
version.infontldrcontestdata.zip
Sample Output
YES
read.m
eexample.t
xtb.cpp
NO
| {"inputs": ["read.meexample.txtb.cpp", "version.infontldrcontestdata.zip", "thisis.text.txt", "oops.t", "thisislongfilename", "double..dot", "one.one.one.one.one.one.one.one.one.one", ".", "z", "a.", ".a", "za", "..", "xlq", ".r.", "ulmc", "nja.", "t..kz", "twaha", "m..dw.", "utsvfg.", ".we.voae", "kw.gkcxk.", ".c.v.hpehh", "....e.afx.h", "akymwh", "jx.lqv.", "qkwtq.zw", "yxwvlk..b", "ph..qlr.pt", "cab.ab.bac", "badaba.ae", "badabaca.mor", "bae.a", "b.baba.ebpbac.iabaeabac.abab.adabacaba.ahcggibij.adaacab.ebaba.aa.abacaba.dacabada.daqjcpc.jadab.dab", ".ab", "aa.aa.aaaabbbbccc.ddd.ee", "a.aaaa", "aaaaread.meexample.txtb.cpp", "abcdabcd.a", "qwertyuio.qwe", "asd.", "aaaaaaaa.", "a.txtaaaaaaaaa.txt", ".abcde.cpp", ".abc.cpp", "abcdefgh.aaaabcdefgh.bbb", "filename.exe", ".abcd.cpp", "abc.bcdabcdabcd.abc", "abc.abcde", "a.cp", "a.b.c", ".ha", "a.a.a.a", "a.a.a", "qwertyui.cp", "ss.aaaaaaaaaaaa.aa", "name.extnamename.ext", ".aaaa.aaa", "aaaaaaaaaaaaaaaaaaaa.a", ".filena.exe", "a.aaaaaaaaaaa.a", ".aa.w"], "outputs": ["YES\nread.m\neexample.t\nxtb.cpp", "NO", "YES\nthisis.t\next.txt", "YES\noops.t", "NO", "NO", "YES\none.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.o\nne.one", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES\nqkwtq.zw", "NO", "NO", "YES\ncab.a\nb.bac", "YES\nbadaba.ae", "YES\nbadabaca.mor", "YES\nbae.a", "YES\nb.b\naba.e\nbpbac.i\nabaeabac.a\nbab.a\ndabacaba.a\nhcggibij.a\ndaacab.e\nbaba.a\na.a\nbacaba.d\nacabada.d\naqjcpc.j\nadab.dab", "NO", "YES\naa.a\na.aaa\nabbbbccc.d\ndd.ee", "NO", "YES\naaaaread.m\neexample.t\nxtb.cpp", "YES\nabcdabcd.a", "NO", "NO", "NO", "NO", "NO", "NO", "YES\nabcdefgh.aaa\nabcdefgh.bbb", "YES\nfilename.exe", "NO", "YES\nabc.bcd\nabcdabcd.abc", "NO", "YES\na.cp", "NO", "NO", "NO", "NO", "YES\nqwertyui.cp", "NO", "YES\nname.ext\nnamename.ext", "NO", "NO", "NO", "YES\na.aaa\naaaaaaaa.a", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 13 | codeforces |
|
ab84e591c27936e4ef3d86b9651f6fd0 | Optimal Point on a Line | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Sample Input
4
1 2 3 4
Sample Output
2
| {"inputs": ["4\n1 2 3 4", "5\n-1 -10 2 6 7", "10\n-68 10 87 22 30 89 82 -97 -52 25", "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424", "2\n-1 0", "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981", "1\n1", "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000", "4\n-1 -1 0 1", "10\n0 0 0 0 0 0 0 0 0 1000000000", "2\n1 -1", "2\n100 50", "2\n1 2", "1\n10", "3\n606194955 -856471310 117647402", "2\n615002717 -843553590", "2\n-1 2", "1\n0", "1\n2", "5\n-638512131 348325781 -550537933 -618161835 -567935532", "1\n120", "2\n-1000000000 1000000000", "1\n618309368"], "outputs": ["2", "2", "22", "64", "-1", "15", "1", "1", "-1", "0", "-1", "50", "1", "10", "117647402", "-843553590", "-1", "0", "2", "-567935532", "120", "-1000000000", "618309368"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 107 | codeforces |
|
ab9570f400b71baf4b0f8f8379616f4c | Not Afraid | Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick and one Morty. They're gathering in *m* groups. Each person can be in many groups and a group can contain an arbitrary number of members.
Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn't considered this possibility).
Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there's a group such that every member in that group is a traitor (they will plan and destroy the world).
Summer knows that if there's a possibility that world ends (there's a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there's at least one scenario (among all 2*n* possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104) — number of universes and number of groups respectively.
The next *m* lines contain the information about the groups. *i*-th of them first contains an integer *k* (number of times someone joined *i*-th group, *k*<=><=0) followed by *k* integers *v**i*,<=1,<=*v**i*,<=2,<=...,<=*v**i*,<=*k*. If *v**i*,<=*j* is negative, it means that Rick from universe number <=-<=*v**i*,<=*j* has joined this group and otherwise it means that Morty from universe number *v**i*,<=*j* has joined it.
Sum of *k* for all groups does not exceed 104.
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
Sample Input
4 2
1 -3
4 -2 3 2 -3
5 2
5 3 -2 1 -1 5
3 -5 2 5
7 2
3 -1 6 7
7 -5 4 2 4 7 -3 4
Sample Output
YES
NO
YES
| {"inputs": ["4 2\n1 -3\n4 -2 3 2 -3", "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "2 1\n2 -2 2", "7 7\n1 -2\n1 6\n2 7 -6\n2 -6 4\n2 -4 -6\n3 -5 7 -5\n1 -6", "100 50\n2 62 -62\n2 19 -19\n2 38 -38\n2 -84 84\n2 -16 16\n2 67 -67\n2 41 -41\n2 -32 32\n2 32 -32\n2 -62 62\n2 89 -89\n2 -84 84\n2 96 -96\n2 -11 11\n2 59 -59\n2 -13 13\n2 -70 70\n2 -3 3\n2 -41 41\n2 -74 74\n2 47 -47\n2 87 -87\n2 17 -17\n2 20 -20\n2 -14 14\n2 -67 67\n2 -95 95\n2 -15 15\n2 -49 49\n2 75 -75\n2 -11 11\n2 -35 35\n2 -10 10\n2 -70 70\n2 -82 82\n2 33 -33\n2 14 -14\n2 -23 23\n2 83 -83\n2 21 -21\n2 86 -86\n2 -51 51\n2 -21 21\n2 -83 83\n2 94 -94\n2 -8 8\n2 75 -75\n2 69 -69\n2 -18 18\n2 42 -42", "1 1\n1 1", "1 1\n2 1 -1", "1 50\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 1 -1\n2 1 -1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 -1 1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 1 -1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 1 -1\n2 -1 1\n2 -1 1\n2 -1 1", "10000 1\n2 -6748 6748", "10000 1\n1 2550", "10000 1\n10 5365 -2216 -866 -7450 -6342 4329 -777 -4329 5225 -2884", "3 1\n3 1 1 2", "5 1\n2 -1 -1", "4 1\n3 1 1 -1", "4 1\n4 3 3 3 3", "1 1\n2 1 1", "2 1\n2 2 2", "4 2\n2 1 -1\n1 1", "7 2\n3 -1 1 7\n7 -5 4 2 4 7 -3 4", "4 1\n1 -1", "10 1\n2 4 4", "1 2\n2 1 -1\n2 -1 -1", "10000 1\n2 -3 -3", "1 2\n2 1 1\n2 -1 -1", "5 1\n2 1 1", "3 1\n2 3 3", "4 1\n2 1 1", "4 2\n3 -1 1 2\n3 -2 4 3"], "outputs": ["YES", "NO", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 69 | codeforces |
|
ab9bbca22e4ebbfac690204da5b4e636 | pSort | One day *n* cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move *i*-th cell can exchange it's value with the value of some other *j*-th cell, if |*i*<=-<=*j*|<==<=*d**i*, where *d**i* is a favourite number of *i*-th cell. Cells make moves in any order, the number of moves is unlimited.
The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to *n*. You are to determine whether the game could move to this state.
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of cells in the array. The second line contains *n* distinct integers from 1 to *n* — permutation. The last line contains *n* integers from 1 to *n* — favourite numbers of the cells.
If the given state is reachable in the described game, output YES, otherwise NO.
Sample Input
5
5 4 3 2 1
1 1 1 1 1
7
4 3 5 1 2 7 6
4 6 6 1 6 6 1
7
4 2 5 1 3 7 6
4 6 6 1 6 6 1
Sample Output
YES
NO
YES
| {"inputs": ["5\n5 4 3 2 1\n1 1 1 1 1", "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "6\n3 2 1 4 6 5\n3 6 1 6 6 1", "6\n3 5 1 4 6 2\n3 6 1 6 6 1", "4\n1 2 3 4\n1 1 1 1", "71\n1 63 3 4 5 6 7 8 9 44 29 12 13 14 55 34 42 18 52 20 21 33 23 24 25 26 27 28 19 30 47 32 15 71 37 36 69 38 39 40 41 17 43 10 45 58 35 48 49 11 51 50 53 54 22 56 57 46 59 60 61 62 2 64 65 66 67 68 31 70 16\n21 45 8 62 56 53 25 22 65 34 39 43 30 63 18 18 25 10 31 64 70 33 49 70 34 21 69 25 21 4 38 41 4 36 4 28 6 48 6 25 57 11 62 48 62 69 12 14 12 70 41 2 49 30 40 37 67 12 13 22 50 35 61 42 33 30 10 47 10 65 37", "76\n44 47 38 4 31 6 33 8 50 69 35 26 73 14 74 16 41 9 59 75 46 7 23 52 58 10 17 49 29 64 42 19 12 36 65 34 3 37 39 1 30 76 27 2 22 55 61 48 24 5 54 11 51 28 68 18 57 60 56 71 63 25 15 66 62 32 67 53 43 70 45 72 13 40 20 21\n54 63 9 55 65 59 4 1 42 31 63 5 28 26 19 35 50 21 39 23 40 64 45 36 74 74 70 67 53 20 19 27 13 2 71 62 6 51 2 65 61 58 55 55 32 75 54 75 48 45 40 45 7 43 72 75 54 9 32 52 8 36 33 59 57 58 68 32 71 21 63 69 7 40 28 68", "82\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 59 17 18 19 20 21 22 23 24 25 26 27 28 29 61 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 16 60 30 79 63 64 65 66 67 68 69 70 71 72 73 74 75 76 82 78 62 80 81 77\n8 79 66 53 45 15 70 17 53 28 30 70 14 49 51 43 45 14 27 30 37 51 29 55 6 5 24 6 61 31 64 47 71 60 79 64 28 64 17 38 11 13 3 72 24 70 16 14 30 72 52 33 31 71 32 66 29 45 55 32 48 14 63 60 50 50 61 2 47 26 4 26 72 3 56 19 1 47 17 26 66 5", "13\n13 1 12 4 6 10 7 8 9 3 11 5 2\n6 12 12 7 11 7 10 3 1 5 2 2 1", "5\n1 3 2 4 5\n1 4 1 2 4", "10\n6 2 9 4 8 7 5 10 3 1\n2 9 7 9 4 5 1 5 3 2", "68\n1 2 3 46 5 6 7 8 9 63 11 57 13 14 15 16 40 18 19 20 21 22 23 24 25 26 27 28 29 35 31 32 33 34 30 36 37 64 39 17 41 12 43 52 58 4 47 44 49 50 51 48 53 54 55 56 42 59 45 60 61 62 10 38 65 66 67 68\n13 48 67 55 4 39 47 8 4 35 50 28 28 30 63 60 52 29 2 33 48 57 40 43 25 34 62 50 60 5 3 66 32 15 7 51 51 26 47 23 67 30 27 53 40 42 5 4 60 67 11 4 31 10 62 46 45 13 14 13 24 66 53 25 22 60 14 42", "52\n17 35 19 41 21 51 46 45 13 10 15 43 37 30 34 12 39 20 14 48 49 3 23 6 4 26 47 18 16 5 31 36 27 29 24 11 52 38 33 42 1 8 9 32 44 7 28 22 40 50 2 25\n47 6 50 13 49 22 17 18 3 11 2 43 35 8 25 38 19 41 17 5 7 8 10 51 17 30 34 48 41 8 46 10 11 45 15 28 42 32 37 33 43 31 38 13 43 19 32 19 2 47 42 46", "50\n5 2 4 31 1 10 44 24 9 38 20 27 35 14 37 46 8 18 41 34 7 22 25 45 32 43 6 47 39 15 26 48 30 23 16 36 17 21 50 40 3 11 12 19 42 29 28 49 33 13\n27 15 18 20 19 23 49 18 28 32 29 2 16 23 23 2 17 25 27 43 32 31 11 3 49 46 22 44 14 48 35 15 32 35 2 49 10 22 5 36 49 16 43 46 33 11 31 15 45 23", "60\n1 2 17 4 27 6 43 26 32 10 11 12 29 14 15 16 3 44 56 20 21 22 53 24 25 8 5 28 58 7 31 9 33 57 48 36 37 38 39 30 41 50 40 35 45 46 13 18 47 55 51 52 23 54 42 19 34 49 59 60\n59 25 14 52 1 24 36 16 42 8 59 22 41 47 49 33 36 35 37 30 25 6 30 8 50 2 25 3 29 10 52 20 8 45 13 43 53 45 10 33 54 53 47 26 32 4 2 38 33 45 19 4 56 22 13 40 45 45 24 14", "79\n1 2 3 67 5 6 7 60 9 71 63 12 31 57 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 64 32 79 34 35 45 37 38 39 40 41 42 43 44 36 46 47 48 11 50 51 52 74 54 55 56 14 58 59 8 61 62 49 13 65 66 4 68 72 70 10 69 73 53 75 76 77 78 33\n17 46 68 35 48 11 78 40 65 61 52 45 51 66 13 56 53 63 61 43 22 60 13 67 34 16 64 19 11 27 33 8 9 1 68 9 17 62 65 23 50 1 55 20 70 61 65 55 38 47 9 45 55 70 39 31 43 47 40 52 20 5 20 75 25 25 63 2 36 12 60 3 35 21 78 38 39 25 46", "80\n39 2 33 16 36 27 65 62 40 17 44 6 13 10 43 31 66 64 63 20 59 72 9 24 12 29 77 47 71 79 50 32 55 4 35 60 7 69 14 54 3 42 15 11 75 22 28 30 49 18 46 56 51 68 5 38 25 58 73 26 61 21 37 80 19 45 53 1 70 67 23 52 41 74 34 76 57 8 48 78\n6 23 42 42 13 72 14 45 66 76 74 44 49 10 14 64 17 15 4 68 14 34 42 56 50 65 17 52 15 26 1 42 27 22 6 52 25 47 76 45 48 67 18 44 74 48 62 58 59 79 13 5 12 14 5 13 51 21 57 59 49 43 8 34 7 16 34 29 38 74 40 72 18 46 47 43 2 4 17 1", "8\n5 2 3 4 8 6 1 7\n6 7 7 7 7 7 2 7", "17\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17\n13 9 16 5 16 12 11 4 4 7 12 16 2 7 14 6 3", "19\n7 2 17 18 4 16 1 9 12 10 8 11 6 13 14 19 3 5 15\n12 4 9 1 13 18 14 10 18 2 17 16 12 3 16 6 5 7 7", "47\n1 32 29 9 47 6 8 36 37 10 11 16 2 14 38 40 15 44 19 35 18 22 23 12 17 41 5 31 26 25 4 27 33 34 42 7 24 28 45 20 46 13 43 30 21 3 39\n38 28 41 46 28 20 36 9 4 10 44 28 9 39 12 36 32 38 43 3 13 33 34 35 22 23 1 4 39 2 11 34 20 19 25 13 20 26 45 36 36 43 45 13 31 9 5", "1\n1\n1", "2\n1 2\n2 2", "2\n1 2\n1 1", "2\n2 1\n2 2", "2\n2 1\n1 1"], "outputs": ["YES", "NO", "YES", "YES", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "NO", "YES"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 27 | codeforces |
|
aba1ae6e26971be89042dc7797363ba2 | The Road to Berland is Paved With Good Intentions | Berland has *n* cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not.
The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every day Valera chooses exactly one city and orders the crew to asphalt all roads that come from the city. The valiant crew fulfilled the King's order in a day, then workers went home.
Unfortunately, not everything is as great as Valera II would like. The main part of the group were gastarbeiters — illegal immigrants who are enthusiastic but not exactly good at understanding orders in Berlandian. Therefore, having received orders to asphalt the roads coming from some of the city, the group asphalted all non-asphalted roads coming from the city, and vice versa, took the asphalt from the roads that had it.
Upon learning of this progress, Valera II was very upset, but since it was too late to change anything, he asked you to make a program that determines whether you can in some way asphalt Berlandian roads in at most *n* days. Help the king.
The first line contains two space-separated integers *n*,<=*m* — the number of cities and roads in Berland, correspondingly. Next *m* lines contain the descriptions of roads in Berland: the *i*-th line contains three space-separated integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 0<=≤<=*c**i*<=≤<=1). The first two integers (*a**i*,<=*b**i*) are indexes of the cities that are connected by the *i*-th road, the third integer (*c**i*) equals 1, if the road was initially asphalted, and 0 otherwise.
Consider the cities in Berland indexed from 1 to *n*, and the roads indexed from 1 to *m*. It is guaranteed that between two Berlandian cities there is not more than one road.
In the first line print a single integer *x* (0<=≤<=*x*<=≤<=*n*) — the number of days needed to asphalt all roads. In the second line print *x* space-separated integers — the indexes of the cities to send the workers to. Print the cities in the order, in which Valera send the workers to asphalt roads. If there are multiple solutions, print any of them.
If there's no way to asphalt all roads, print "Impossible" (without the quotes).
Sample Input
4 4
1 2 1
2 4 0
4 3 1
3 2 0
3 3
1 2 0
2 3 0
3 1 0
Sample Output
4
3 2 1 3
Impossible
| {"inputs": ["4 4\n1 2 1\n2 4 0\n4 3 1\n3 2 0", "3 3\n1 2 0\n2 3 0\n3 1 0", "4 5\n3 2 0\n1 4 0\n4 3 1\n3 1 0\n1 2 0", "2 1\n2 1 0", "6 13\n4 6 0\n4 2 1\n6 2 0\n5 4 1\n1 3 1\n5 6 1\n1 5 1\n1 4 1\n2 3 1\n1 2 1\n3 6 0\n6 1 1\n2 5 1", "7 13\n5 7 1\n1 2 0\n5 3 0\n6 1 1\n6 3 0\n2 7 0\n7 1 1\n6 4 1\n6 2 1\n4 7 1\n2 5 0\n1 5 0\n7 3 0", "16 20\n8 5 1\n12 11 1\n13 2 1\n3 7 0\n6 8 0\n16 6 0\n7 14 0\n13 12 1\n8 15 1\n14 5 0\n12 10 0\n11 16 1\n11 9 0\n2 15 1\n12 1 0\n9 5 0\n14 15 0\n3 14 1\n2 8 1\n1 14 1", "15 33\n12 4 1\n8 10 1\n6 13 0\n2 6 1\n10 7 0\n1 14 1\n3 9 0\n3 1 0\n7 12 1\n13 5 0\n10 4 0\n1 7 1\n11 15 0\n2 3 0\n9 8 1\n6 9 1\n9 4 1\n4 8 1\n7 8 0\n2 13 1\n15 8 0\n12 15 0\n14 4 0\n1 11 1\n4 2 0\n13 11 0\n13 3 0\n14 7 1\n12 11 1\n13 8 0\n2 8 1\n9 5 1\n12 2 1", "14 10\n12 11 1\n7 6 1\n7 9 1\n6 9 1\n5 4 0\n2 7 1\n1 8 1\n1 4 0\n13 5 0\n8 4 0", "18 32\n10 11 1\n16 7 1\n18 10 0\n15 2 1\n14 2 0\n4 9 1\n10 16 1\n13 17 0\n8 3 1\n14 8 1\n17 11 0\n16 9 1\n12 1 1\n5 11 0\n16 13 0\n18 4 0\n5 7 0\n4 13 1\n17 1 0\n8 12 1\n10 1 0\n8 18 1\n5 9 0\n2 3 0\n3 15 1\n11 4 1\n14 11 1\n7 6 0\n1 2 0\n6 10 0\n3 1 1\n13 2 0", "19 40\n10 13 0\n3 9 0\n5 12 0\n8 16 0\n4 10 1\n2 5 0\n17 6 1\n5 13 0\n5 11 0\n12 11 0\n17 16 0\n2 9 1\n6 9 0\n7 9 0\n10 14 1\n14 2 1\n12 6 1\n6 1 0\n11 17 0\n13 19 0\n16 14 1\n7 11 1\n18 6 0\n18 12 1\n2 15 1\n8 12 0\n9 1 1\n2 19 1\n17 2 0\n5 7 0\n6 2 1\n13 7 0\n9 14 0\n13 8 0\n11 1 1\n9 15 0\n18 4 0\n18 7 0\n1 14 0\n3 12 1", "20 40\n5 16 0\n6 10 0\n16 12 0\n13 15 1\n18 13 1\n15 18 1\n4 13 0\n12 10 1\n13 9 1\n19 5 0\n18 10 0\n8 18 0\n3 15 0\n12 13 0\n3 20 1\n11 15 1\n15 1 1\n3 2 1\n12 9 0\n10 16 0\n5 7 1\n7 6 0\n5 20 1\n20 18 0\n20 10 1\n16 15 1\n7 1 0\n3 8 1\n3 10 1\n9 7 0\n9 20 0\n17 1 1\n2 1 0\n2 19 0\n8 16 0\n11 7 0\n6 20 0\n16 2 0\n10 15 0\n10 19 0", "11 18\n10 2 0\n9 10 0\n3 10 1\n9 4 1\n6 10 0\n5 7 1\n3 1 0\n7 2 1\n8 2 1\n10 7 0\n6 8 1\n5 2 1\n10 11 0\n4 3 0\n7 8 1\n4 5 1\n7 11 1\n9 7 1", "100 49\n9 51 0\n59 35 0\n42 4 1\n18 70 1\n95 44 0\n8 57 0\n38 1 1\n33 56 1\n44 30 1\n62 98 0\n99 7 0\n9 71 1\n63 76 0\n45 22 1\n24 43 0\n97 3 1\n23 71 1\n98 8 1\n67 69 1\n39 15 1\n71 74 1\n9 85 1\n85 91 1\n93 40 0\n76 70 0\n22 5 1\n36 29 1\n10 80 1\n38 12 0\n68 86 0\n53 25 0\n2 39 1\n50 43 1\n60 76 0\n96 36 0\n95 34 0\n31 4 1\n82 76 1\n50 63 0\n4 72 0\n32 63 0\n26 7 0\n76 96 1\n10 97 1\n91 58 0\n4 10 0\n83 12 1\n97 80 1\n48 12 0", "100 41\n3 89 1\n31 33 0\n88 83 0\n45 97 0\n32 86 0\n19 12 1\n75 74 0\n74 10 0\n69 73 1\n69 80 0\n97 61 1\n73 68 0\n70 51 1\n56 92 1\n95 42 0\n69 51 1\n2 51 0\n72 38 1\n86 10 1\n35 50 1\n81 58 0\n34 8 0\n93 82 1\n81 84 1\n68 61 0\n69 20 0\n77 25 1\n81 13 0\n21 20 1\n46 5 1\n71 60 1\n46 65 1\n29 54 1\n11 55 1\n16 81 0\n77 30 1\n68 45 1\n74 84 0\n89 1 1\n70 83 1\n18 4 0", "4 2\n1 2 0\n3 4 0"], "outputs": ["4\n3 2 1 3", "Impossible", "Impossible", "1\n1 ", "Impossible", "Impossible", "6\n1 3 6 9 10 14 ", "Impossible", "3\n1 5 8 ", "Impossible", "Impossible", "10\n1 6 9 11 13 15 16 17 18 19 ", "2\n3 10 ", "25\n1 4 7 18 24 25 29 30 31 34 35 36 38 40 42 44 48 51 57 58 60 62 63 68 70 ", "16\n2 4 8 13 16 20 21 31 32 42 45 58 68 74 80 88 ", "2\n1 3 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
abbad00030e70b95b58997b453592058 | Playing with Dice | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Sample Input
2 5
2 4
Sample Output
3 0 3
2 1 3
| {"inputs": ["2 5", "2 4", "5 3", "1 6", "5 1", "6 3", "2 3", "5 6", "4 4", "1 1", "6 4", "1 4", "5 5", "4 5", "4 3", "1 5", "6 5", "2 2", "1 3", "3 6", "3 1", "3 2", "3 5", "3 3", "6 2", "4 1", "5 2", "4 2", "2 1", "6 1", "4 6", "2 6", "3 4", "1 2", "6 6", "5 4", "3 3", "1 1"], "outputs": ["3 0 3", "2 1 3", "2 1 3", "3 0 3", "3 1 2", "2 0 4", "2 0 4", "5 0 1", "0 6 0", "0 6 0", "1 1 4", "2 0 4", "0 6 0", "4 0 2", "3 0 3", "2 1 3", "1 0 5", "0 6 0", "1 1 4", "4 0 2", "4 1 1", "4 0 2", "3 1 2", "0 6 0", "2 1 3", "4 0 2", "3 0 3", "3 1 2", "5 0 1", "3 0 3", "4 1 1", "3 1 2", "3 0 3", "1 0 5", "0 6 0", "2 0 4", "0 6 0", "0 6 0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 672 | codeforces |
|
abc27619c76daf559804e27c90524aa3 | Black and White Tree | The board has got a painted tree graph, consisting of *n* nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.
Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge contains its value written on it as a non-negative integer.
A bad boy Vasya came up to the board and wrote number *s**v* near each node *v* — the sum of values of all edges that are incident to this node. Then Vasya removed the edges and their values from the board.
Your task is to restore the original tree by the node colors and numbers *s**v*.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of nodes in the tree. Next *n* lines contain pairs of space-separated integers *c**i*, *s**i* (0<=≤<=*c**i*<=≤<=1, 0<=≤<=*s**i*<=≤<=109), where *c**i* stands for the color of the *i*-th vertex (0 is for white, 1 is for black), and *s**i* represents the sum of values of the edges that are incident to the *i*-th vertex of the tree that is painted on the board.
Print the description of *n*<=-<=1 edges of the tree graph. Each description is a group of three integers *v**i*, *u**i*, *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, *v**i*<=≠<=*u**i*, 0<=≤<=*w**i*<=≤<=109), where *v**i* and *u**i* — are the numbers of the nodes that are connected by the *i*-th edge, and *w**i* is its value. Note that the following condition must fulfill *c**v**i*<=≠<=*c**u**i*.
It is guaranteed that for any input data there exists at least one graph that meets these data. If there are multiple solutions, print any of them. You are allowed to print the edges in any order. As you print the numbers, separate them with spaces.
Sample Input
3
1 3
1 2
0 5
6
1 0
0 3
1 8
0 2
0 3
0 0
Sample Output
3 1 3
3 2 2
2 3 3
5 3 3
4 3 2
1 6 0
2 1 0
| {"inputs": ["3\n1 3\n1 2\n0 5", "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0", "2\n0 0\n1 0", "5\n1 11\n0 9\n1 4\n0 4\n0 2", "10\n0 24\n1 164\n0 206\n0 45\n1 110\n0 66\n1 59\n1 92\n0 152\n1 68", "20\n0 569\n1 328\n1 74\n1 88\n1 90\n1 124\n0 78\n0 39\n1 9\n1 59\n1 41\n1 73\n1 45\n0 45\n0 13\n1 39\n0 24\n0 37\n0 95\n0 70", "30\n0 110\n1 263\n0 169\n1 138\n1 153\n0 146\n0 7\n0 68\n0 136\n0 76\n1 156\n0 80\n0 76\n1 43\n1 119\n1 199\n0 54\n0 44\n0 7\n1 43\n0 84\n0 90\n0 29\n0 22\n1 55\n0 23\n0 33\n1 60\n1 66\n0 41", "50\n1 574339\n0 409333\n0 330634\n0 420557\n0 323095\n0 63399\n0 69999\n1 82396\n1 90197\n0 265793\n0 65065\n1 38496\n1 43632\n1 95792\n1 61780\n1 87623\n1 31246\n0 48483\n1 76824\n1 81693\n1 66004\n1 72826\n1 146477\n1 12359\n1 27042\n1 12542\n0 81514\n0 28986\n1 73958\n1 8219\n0 5679\n0 77936\n1 892\n0 69776\n1 71921\n1 86390\n0 47969\n1 51544\n0 22463\n1 69975\n1 80092\n1 90894\n0 56989\n1 79786\n0 24301\n1 72558\n1 73728\n0 24482\n1 8467\n1 66761", "6\n0 0\n1 0\n0 0\n1 0\n0 0\n1 0", "4\n1 0\n1 0\n0 0\n0 0", "9\n0 3\n1 8\n0 2\n0 3\n1 0\n1 0\n1 0\n1 0\n1 0", "6\n0 0\n0 0\n0 0\n1 0\n1 0\n1 0", "5\n0 0\n0 0\n0 0\n0 0\n1 0", "4\n0 0\n1 0\n0 0\n1 0", "5\n1 0\n0 0\n0 0\n0 0\n0 0", "6\n1 1\n1 1\n1 1\n0 1\n0 1\n0 1", "7\n1 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0"], "outputs": ["3 1 3\n3 2 2", "2 3 3\n5 3 3\n4 3 2\n1 6 0\n2 1 0", "1 2 0", "2 1 9\n4 3 4\n5 1 2\n2 3 0", "3 2 164\n9 5 110\n6 8 66\n4 10 45\n3 7 42\n9 8 26\n1 10 23\n9 7 16\n1 7 1", "1 2 328\n1 6 124\n1 5 90\n19 4 88\n7 3 74\n20 12 70\n14 10 45\n8 13 39\n18 11 37\n1 16 27\n17 10 14\n15 16 12\n17 9 9\n19 13 6\n7 11 4\n15 12 1\n17 12 1\n19 12 1\n7 2 0", "3 2 169\n6 16 146\n9 11 136\n1 5 110\n22 4 90\n21 15 84\n12 2 80\n10 29 66\n13 28 60\n8 25 55\n17 16 53\n18 4 44\n30 5 41\n27 14 33\n23 20 29\n26 15 23\n24 11 20\n13 2 14\n8 20 13\n10 15 10\n7 14 7\n19 4 4\n19 14 3\n13 5 2\n24 15 2\n17 20 1\n7 11 0\n9 16 0\n6 2 0", "4 1 420557\n2 1 153782\n3 23 146477\n5 14 95792\n10 42 90894\n2 9 90197\n5 16 87623\n3 36 86390\n10 8 82396\n2 20 81693\n5 41 80092\n3 44 79786\n10 19 76824\n2 29 73958\n27 47 73728\n32 22 72826\n7 46 69999\n34 35 69776\n11 40 65065\n6 50 63399\n5 21 59588\n43 15 56989\n18 38 48483\n37 13 43632\n28 12 28986\n48 17 24482\n45 25 24301\n39 26 12542\n3 24 12359\n10 12 9510\n39 49 8467\n2 30 8219\n27 17 6764\n10 21 6169\n31 40 4910\n3 15 4791\n32 50 3362\n37 38 3061\n32 25 1748\n2 46 1484\n39 35 1454\n37 46 107...", "1 6 0\n2 5 0\n3 6 0\n4 5 0\n5 6 0", "1 4 0\n2 4 0\n3 2 0", "1 2 3\n4 2 3\n3 2 2\n5 4 0\n6 4 0\n7 4 0\n8 4 0\n9 4 0", "1 6 0\n2 6 0\n3 6 0\n4 3 0\n5 3 0", "1 5 0\n2 5 0\n3 5 0\n4 5 0", "1 4 0\n2 3 0\n3 4 0", "1 5 0\n2 1 0\n3 1 0\n4 1 0", "4 1 1\n5 2 1\n6 3 1\n4 3 0\n6 2 0", "1 7 0\n2 7 0\n3 2 0\n4 2 0\n5 2 0\n6 2 0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
abe3564167e92c6206670f366b48b0e5 | none | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
Sample Input
helloworld
ehoolwlroz
hastalavistababy
hastalavistababy
merrychristmas
christmasmerry
Sample Output
3
h e
l o
d z
0
-1
| {"inputs": ["helloworld\nehoolwlroz", "hastalavistababy\nhastalavistababy", "merrychristmas\nchristmasmerry", "kusyvdgccw\nkusyvdgccw", "bbbbbabbab\naaaaabaaba", "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx", "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc", "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd", "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak", "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc", "ab\naa", "a\nz", "zz\nzy", "as\ndf", "abc\nbca", "rtfg\nrftg", "y\ny", "qwertyuiopasdfghjklzx\nzzzzzzzzzzzzzzzzzzzzz", "qazwsxedcrfvtgbyhnujmik\nqwertyuiasdfghjkzxcvbnm", "aaaaaa\nabcdef", "qwerty\nffffff", "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh", "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe", "bacccbbacabbcaacbbba\nbacccbbacabbcaacbbba", "dbadbddddb\nacbacaaaac", "dacbdbbbdd\nadbdadddaa", "bbbbcbcbbc\ndaddbabddb", "dddddbcdbd\nbcbbbdacdb", "cbadcbcdaa\nabbbababbb", "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk", "acbbccabaa\nabbbbbabaa", "ccccaccccc\naaaabaaaac", "acbacacbbb\nacbacacbbb", "abbababbcc\nccccccccbb", "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh", "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage", "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai", "z\nz", "a\nz", "z\na", "aa\nzz", "az\nza", "aa\nza", "za\nzz", "aa\nab", "hehe\nheeh", "bd\ncc", "he\nhh", "hee\nheh", "aa\nac", "ab\naa", "hello\nehlol", "ac\naa", "aaabbb\nbbbaab", "aa\nfa", "hg\nee", "helloworld\nehoolwlrow", "abb\nbab", "aaa\naae", "aba\nbaa", "aa\nba", "da\naa", "aaa\naab", "xy\nzz"], "outputs": ["3\nh e\nl o\nd z", "0", "-1", "0", "1\nb a", "-1", "1\nd b", "0", "5\ng f\nn i\nd h\ne o\nb k", "0", "-1", "1\na z", "-1", "2\na d\ns f", "-1", "1\nt f", "0", "-1", "-1", "-1", "-1", "0", "-1", "0", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "0", "-1", "-1", "-1", "-1", "0", "1\na z", "1\nz a", "1\na z", "1\na z", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 52 | codeforces |
|
abf11aeddeb0af07ea9ac20715e7c810 | Solution for Cube | During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence.
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
Sample Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Sample Output
NOYES | {"inputs": ["2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4", "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3", "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1", "3 4 2 3 5 5 6 6 4 5 4 6 5 1 1 1 6 2 1 3 3 2 4 2", "5 5 2 5 3 3 2 6 6 4 2 4 6 1 4 3 1 6 2 1 3 4 5 1", "6 6 1 2 6 1 1 3 5 4 3 4 3 5 5 2 4 4 6 2 1 5 3 2", "2 2 1 1 5 5 5 5 3 3 4 4 1 4 1 4 2 3 2 3 6 6 6 6", "1 1 1 1 5 5 3 3 4 4 4 4 3 3 2 2 6 6 5 5 2 2 6 6", "1 1 1 1 3 3 3 3 5 5 5 5 2 2 2 2 4 4 4 4 6 6 6 6", "5 4 5 4 4 6 4 6 6 3 6 3 1 1 1 1 2 2 2 2 5 3 5 3", "3 3 5 5 2 2 2 2 6 6 4 4 6 3 6 3 4 5 4 5 1 1 1 1", "6 6 6 6 2 2 5 5 1 1 1 1 4 4 2 2 5 5 3 3 3 3 4 4", "4 6 4 6 6 1 6 1 1 3 1 3 2 2 2 2 5 5 5 5 4 3 4 3", "6 6 2 2 3 3 3 3 4 4 5 5 4 6 4 6 5 2 5 2 1 1 1 1", "3 3 3 3 4 4 5 5 1 1 1 1 2 2 4 4 5 5 6 6 6 6 2 2", "2 5 2 5 4 2 4 2 1 4 1 4 6 6 6 6 3 3 3 3 1 5 1 5", "4 4 3 3 5 5 5 5 1 1 6 6 3 6 3 6 4 1 4 1 2 2 2 2", "5 5 5 5 6 6 2 2 3 3 3 3 2 2 1 1 4 4 6 6 1 1 4 4", "1 4 3 4 2 6 5 2 1 5 1 6 3 4 3 6 5 5 1 3 2 6 4 2", "4 4 2 5 3 2 4 2 5 3 6 4 6 5 1 3 1 5 6 3 1 1 6 2", "4 5 3 4 5 5 6 3 2 5 1 6 2 1 6 3 1 4 2 3 2 6 1 4", "3 3 2 3 6 4 4 4 1 2 1 3 2 5 6 6 1 2 6 5 4 5 1 5", "5 6 1 1 4 5 6 5 4 6 2 1 4 2 6 5 3 2 3 2 3 1 3 4", "4 4 4 5 2 3 4 1 3 3 1 5 6 5 6 6 1 3 6 2 5 2 1 2", "3 2 5 6 1 4 3 4 6 5 4 3 2 3 2 2 1 4 1 1 6 5 6 5", "5 4 6 2 5 6 4 1 6 3 3 1 3 2 4 1 1 6 2 3 5 2 4 5", "6 6 3 1 5 6 5 3 2 5 3 1 2 4 1 6 4 5 2 2 4 1 3 4", "6 5 4 1 6 5 2 3 3 5 3 6 4 2 6 5 4 2 1 1 4 1 3 2", "1 3 5 6 4 4 4 3 5 2 2 2 3 1 5 6 3 4 6 5 1 2 1 6", "3 6 5 4 4 6 1 4 3 2 5 2 1 2 6 2 5 4 1 3 1 6 5 3", "5 2 6 1 5 3 5 3 1 1 3 6 6 2 4 2 5 4 4 2 1 3 4 6", "2 5 6 2 3 6 5 6 2 3 1 3 6 4 5 4 1 1 1 5 3 4 4 2", "4 5 4 4 3 3 1 2 3 1 1 5 2 2 5 6 6 4 3 2 6 5 1 6", "5 2 5 2 3 5 3 5 4 3 4 3 6 6 6 6 1 1 1 1 4 2 4 2", "2 4 2 4 4 5 4 5 5 1 5 1 3 3 3 3 6 6 6 6 2 1 2 1", "3 5 3 5 5 1 5 1 1 4 1 4 6 6 6 6 2 2 2 2 3 4 3 4", "2 1 2 1 4 2 4 2 6 4 6 4 5 5 5 5 3 3 3 3 6 1 6 1", "4 4 2 2 1 1 1 1 5 5 6 6 2 6 2 6 4 5 4 5 3 3 3 3", "1 1 2 2 4 4 4 4 5 5 6 6 5 1 5 1 6 2 6 2 3 3 3 3", "2 2 6 6 4 4 4 4 1 1 5 5 1 2 1 2 5 6 5 6 3 3 3 3", "2 2 3 3 6 6 6 6 4 4 1 1 3 1 3 1 2 4 2 4 5 5 5 5", "6 6 6 6 4 4 3 3 5 5 5 5 3 3 1 1 2 2 4 4 1 1 2 2", "2 2 2 2 4 4 5 5 3 3 3 3 6 6 4 4 5 5 1 1 1 1 6 6", "1 1 1 1 5 5 6 6 3 3 3 3 4 4 5 5 6 6 2 2 2 2 4 4", "4 4 4 4 2 2 3 3 1 1 1 1 3 3 6 6 5 5 2 2 6 6 5 5", "1 1 1 1 2 2 3 3 6 6 6 6 5 5 4 4 3 3 2 2 4 4 5 5", "1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5 6 6 6 6", "5 5 5 5 1 1 2 2 6 6 6 6 4 4 3 3 3 3 4 4 2 2 1 1"], "outputs": ["NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 29 | codeforces |
|
ac0c2716962ff08b4b4c6c7396f716d9 | Tree Requests | Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always less than the index of the vertex (i.e., *p**i*<=<<=*i*).
The depth of the vertex is the number of nodes on the path from the root to *v* along the edges. In particular, the depth of the root is equal to 1.
We say that vertex *u* is in the subtree of vertex *v*, if we can get from *u* to *v*, moving from the vertex to the parent. In particular, vertex *v* is in its subtree.
Roma gives you *m* queries, the *i*-th of which consists of two numbers *v**i*, *h**i*. Let's consider the vertices in the subtree *v**i* located at depth *h**i*. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=500<=000) — the number of nodes in the tree and queries, respectively.
The following line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* — the parents of vertices from the second to the *n*-th (1<=≤<=*p**i*<=<<=*i*).
The next line contains *n* lowercase English letters, the *i*-th of these letters is written on vertex *i*.
Next *m* lines describe the queries, the *i*-th line contains two numbers *v**i*, *h**i* (1<=≤<=*v**i*,<=*h**i*<=≤<=*n*) — the vertex and the depth that appear in the *i*-th query.
Print *m* lines. In the *i*-th line print "Yes" (without the quotes), if in the *i*-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).
Sample Input
6 5
1 1 1 3 3
zacccd
1 1
3 3
4 1
6 1
1 2
Sample Output
Yes
No
Yes
Yes
Yes
| {"inputs": ["6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2", "5 6\n1 1 2 3\ncbcab\n3 1\n5 2\n1 3\n4 1\n4 2\n1 1", "5 6\n1 2 2 1\nbaabb\n1 1\n1 2\n5 1\n4 1\n4 2\n3 2", "5 9\n1 1 1 2\nedbcb\n1 3\n2 1\n1 3\n2 1\n2 2\n2 2\n1 1\n1 3\n2 1", "8 12\n1 1 1 2 1 1 4\ncbecdcce\n1 2\n1 2\n2 1\n1 1\n2 1\n1 3\n1 3\n1 3\n1 2\n2 3\n1 3\n1 1", "1 1\n\np\n1 1", "1 1\n\na\n1 1"], "outputs": ["Yes\nNo\nYes\nYes\nYes", "Yes\nYes\nNo\nYes\nYes\nYes", "Yes\nNo\nYes\nYes\nYes\nYes", "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes", "No\nNo\nYes\nYes\nYes\nNo\nNo\nNo\nNo\nYes\nNo\nYes", "Yes", "Yes"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
ac413e3d23d2317e4f1b0c9a24087720 | Fix a Tree | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with *n* vertices, numbered 1 through *n*. There are many ways to represent such a tree. One way is to create an array with *n* integers *p*1,<=*p*2,<=...,<=*p**n*, where *p**i* denotes a parent of vertex *i* (here, for convenience a root is considered its own parent).
Given a sequence *p*1,<=*p*2,<=...,<=*p**n*, one is able to restore a tree:
1. There must be exactly one index *r* that *p**r*<==<=*r*. A vertex *r* is a root of the tree. 1. For all other *n*<=-<=1 vertices *i*, there is an edge between vertex *i* and vertex *p**i*.
A sequence *p*1,<=*p*2,<=...,<=*p**n* is called valid if the described procedure generates some (any) rooted tree. For example, for *n*<==<=3 sequences (1,2,2), (2,3,1) and (2,1,3) are not valid.
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n*, not necessarily valid. Your task is to change the minimum number of elements, in order to get a valid sequence. Print the minimum number of changes and an example of a valid sequence after that number of changes. If there are many valid sequences achievable in the minimum number of changes, print any of them.
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of vertices in the tree.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*).
In the first line print the minimum number of elements to change, in order to get a valid sequence.
In the second line, print any valid sequence possible to get from (*a*1,<=*a*2,<=...,<=*a**n*) in the minimum number of changes. If there are many such sequences, any of them will be accepted.
Sample Input
4
2 3 3 4
5
3 2 2 5 3
8
2 3 5 4 1 6 6 7
Sample Output
1
2 3 4 4
0
3 2 2 5 3
2
2 3 7 8 1 6 6 7
| {"inputs": ["4\n2 3 3 4", "5\n3 2 2 5 3", "8\n2 3 5 4 1 6 6 7", "2\n1 2", "7\n4 3 2 6 3 5 2", "6\n6 2 6 2 4 2", "7\n1 6 4 4 5 6 7", "7\n7 5 3 1 2 1 5", "7\n1 2 3 4 5 6 7", "18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18", "8\n2 1 2 2 6 5 6 6", "3\n2 1 1"], "outputs": ["1\n2 3 4 4 ", "0\n3 2 2 5 3 ", "2\n2 3 7 8 1 6 6 7", "1\n2 2 ", "1\n4 3 3 6 3 5 2 ", "0\n6 2 6 2 4 2 ", "4\n7 6 4 7 7 7 7 ", "1\n7 5 3 1 3 1 5 ", "6\n7 7 7 7 7 7 7 ", "5\n2 18 4 5 2 7 18 9 10 7 18 18 18 15 13 17 18 18 ", "2\n1 1 2 2 1 5 6 6 ", "1\n1 1 1 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 12 | codeforces |
|
ac689f494ff393c5b62ac0af2dd8b902 | Bar | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Sample Input
5
18
VODKA
COKE
19
17
Sample Output
2
| {"inputs": ["5\n18\nVODKA\nCOKE\n19\n17", "2\n2\nGIN", "3\nWHISKEY\n3\nGIN", "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW", "4\nSAKE\nSAKE\n13\n2", "2\n0\n17", "1\n0"], "outputs": ["2", "2", "3", "1", "4", "2", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 272 | codeforces |
|
ac9108f0e82902b1ab432959abb62764 | Counterexample | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Sample Input
2 4
10 11
900000000000000009 900000000000000029
Sample Output
2 3 4
-1
900000000000000009 900000000000000010 900000000000000021
| {"inputs": ["2 4", "10 11", "900000000000000009 900000000000000029", "640097987171091791 640097987171091835", "19534350415104721 19534350415104725", "933700505788726243 933700505788726280", "1 3", "1 4", "1 1", "266540997167959130 266540997167959164", "267367244641009850 267367244641009899", "268193483524125978 268193483524125993", "269019726702209402 269019726702209432", "269845965585325530 269845965585325576", "270672213058376250 270672213058376260", "271498451941492378 271498451941492378", "272324690824608506 272324690824608523", "273150934002691930 273150934002691962", "996517375802030516 996517375802030524", "997343614685146644 997343614685146694", "998169857863230068 998169857863230083", "998996101041313492 998996101041313522", "999822344219396916 999822344219396961", "648583102513043 648583102513053", "266540997167959130 266540997167959131", "267367244641009850 267367244641009850", "268193483524125978 268193483524125979", "269019726702209402 269019726702209402", "269845965585325530 269845965585325530", "270672213058376250 270672213058376254", "271498451941492378 271498451941492379", "272324690824608506 272324690824608508", "273150934002691930 273150934002691931", "996517375802030516 996517375802030518", "997343614685146644 997343614685146644", "2147483647 2147483649", "3 5", "1 7", "9 12", "4 4", "11 13", "2 2"], "outputs": ["2 3 4", "-1", "900000000000000009 900000000000000010 900000000000000021", "640097987171091792 640097987171091793 640097987171091794", "19534350415104722 19534350415104723 19534350415104724", "933700505788726244 933700505788726245 933700505788726246", "-1", "2 3 4", "-1", "266540997167959130 266540997167959131 266540997167959132", "267367244641009850 267367244641009851 267367244641009852", "268193483524125978 268193483524125979 268193483524125980", "269019726702209402 269019726702209403 269019726702209404", "269845965585325530 269845965585325531 269845965585325532", "270672213058376250 270672213058376251 270672213058376252", "-1", "272324690824608506 272324690824608507 272324690824608508", "273150934002691930 273150934002691931 273150934002691932", "996517375802030516 996517375802030517 996517375802030518", "997343614685146644 997343614685146645 997343614685146646", "998169857863230068 998169857863230069 998169857863230070", "998996101041313492 998996101041313493 998996101041313494", "999822344219396916 999822344219396917 999822344219396918", "648583102513044 648583102513045 648583102513046", "-1", "-1", "-1", "-1", "-1", "270672213058376250 270672213058376251 270672213058376252", "-1", "272324690824608506 272324690824608507 272324690824608508", "-1", "996517375802030516 996517375802030517 996517375802030518", "-1", "-1", "-1", "2 3 4", "9 11 12", "-1", "-1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 367 | codeforces |
|
ac9bff232861d45cba367272ddb2c80e | Eternal Victory | Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these *n* cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities.
All cities are numbered 1 to *n*. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city.
Help Shapur find how much He should travel.
First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities.
Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road.
A single integer number, the minimal length of Shapur's travel.
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).
Sample Input
3
1 2 3
2 3 4
3
1 2 3
1 3 3
Sample Output
7
9
| {"inputs": ["3\n1 2 3\n2 3 4", "3\n1 2 3\n1 3 3", "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14", "3\n2 1 63\n3 1 78", "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6 4 18\n7 1 79\n3 2 58\n9 7 92\n10 6 62\n4 3 5\n12 4 87\n5 3 66", "2\n2 1 89", "12\n3 1 31\n5 2 94\n9 8 37\n10 9 45\n7 5 75\n4 2 77\n6 3 31\n11 6 14\n8 7 19\n2 1 68\n12 1 60", "2\n2 1 5", "12\n3 2 52\n4 1 2\n5 2 68\n6 1 93\n8 5 60\n2 1 88\n9 8 44\n7 5 48\n11 2 31\n10 4 45\n12 7 58", "15\n12 1 52\n3 2 10\n4 1 45\n11 7 20\n10 3 54\n13 9 44\n15 2 8\n14 5 55\n9 3 32\n2 1 32\n8 4 14\n6 5 24\n5 3 74\n7 6 88", "1", "3\n1 2 0\n2 3 0", "6\n1 2 3\n1 3 1\n3 4 1\n4 5 1\n5 6 1"], "outputs": ["7", "9", "371", "204", "1126", "89", "764", "5", "916", "856", "0", "0", "10"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 18 | codeforces |
|
acd4c4fb1076614e330c5341053f7a0a | Rectangle and Square | 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.
Sample Input
0 0
10 11
10 0
0 11
1 1
2 2
2 1
1 2
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
0 0
4 4
4 0
0 4
1 2
2 3
3 2
2 1
Sample Output
YES
5 6 7 8
1 2 3 4
NO
YES
1 2 3 4
5 6 7 8
| {"inputs": ["0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1", "-160 336\n-76 672\n8 168\n-580 588\n-1000 504\n-496 840\n-496 84\n-664 0", "8 -328\n-440 568\n-104 8\n-1000 -664\n8 456\n-328 8\n-552 120\n-664 -1000", "65 852\n-645 284\n-361 710\n-1000 71\n-219 284\n207 426\n-716 0\n-929 355", "980 518\n584 -670\n-208 914\n-736 -340\n-604 -274\n-1000 -736\n-604 -1000\n-340 -604", "48 264\n144 240\n24 0\n168 48\n120 144\n0 72\n144 120\n24 168", "576 -616\n192 -424\n384 152\n768 248\n384 -1000\n0 -808\n480 -232\n864 -136", "547 -167\n-1000 -762\n190 904\n-762 -1000\n-167 71\n904 547\n71 -167\n-167 190", "-1000 -736\n1200 408\n1728 12\n188 -1000\n1332 -516\n-736 -208\n452 -472\n804 -120", "210 140\n140 0\n210 210\n455 140\n70 210\n525 385\n0 70\n280 455", "-1000 -829\n-715 -601\n311 197\n197 -715\n-829 -1000\n-601 311\n-658 -487\n-487 -658", "329 -859\n282 -765\n376 81\n0 -906\n47 -1000\n846 -577\n940 -13\n282 -483", "40 100\n210 20\n100 60\n120 230\n0 40\n60 0\n60 80\n270 170", "-252 -1000\n-1000 -932\n-864 20\n-796 -864\n768 -388\n-932 -796\n-864 -1000\n156 632", "351 234\n234 741\n234 351\n702 819\n117 0\n0 117\n312 273\n780 351", "434 372\n0 62\n496 868\n868 620\n620 248\n248 496\n62 434\n372 0", "-40 -1000\n-440 120\n2200 -200\n1800 920\n-200 -680\n-840 120\n-40 -360\n-1000 -200", "-850 -1000\n-475 -325\n1025 800\n-325 575\n-325 -850\n-1000 -475\n-100 -775\n1250 -550", "70 64\n32 0\n58 48\n48 80\n72 50\n0 48\n56 62\n80 32", "937 937\n-851 43\n-404 1086\n43 -106\n788 -404\n-553 -255\n-1000 -851\n-106 -1000", "-1 -223\n554 110\n-778 -1000\n-667 -445\n-1000 -667\n-445 -778\n443 -334\n110 221", "1610 0\n1700 270\n-1000 -900\n2105 315\n800 0\n-190 -900\n1925 90\n1880 495", "-360 120\n600 440\n-680 -40\n440 600\n-520 -360\n-200 -200\n-840 -1000\n-1000 -840", "-11 220\n-11 22\n176 -66\n-198 -22\n-198 176\n220 -198\n0 88\n44 -44", "378 504\n504 504\n126 0\n504 126\n0 378\n252 546\n294 798\n546 756", "312 468\n312 0\n728 728\n468 676\n520 416\n0 0\n780 468\n0 468", "180 100\n180 220\n80 0\n240 760\n0 80\n100 180\n720 160\n780 700", "-1000 -742\n1064 290\n32 634\n720 -742\n-742 -226\n-312 -398\n-484 -1000\n-226 -484", "-153 -238\n-204 34\n102 119\n34 0\n-663 -306\n0 68\n-612 -578\n136 51", "-620 -1000\n-1000 -620\n976 672\n-240 140\n596 140\n140 -240\n1052 216\n520 596", "203 232\n232 348\n58 0\n0 58\n319 203\n290 232\n348 319\n232 290", "-328 260\n-664 -1000\n-1000 -496\n92 -496\n-1000 -1000\n-664 -496\n-496 -328\n260 92", "-586 414\n-931 0\n-103 276\n-448 897\n-655 414\n35 759\n-586 345\n-1000 69", "-424 920\n-1000 152\n344 -232\n-232 536\n-424 -1000\n-616 -40\n344 -616\n536 728", "427 -451\n549 -573\n122 -1000\n0 -85\n183 -512\n427 98\n610 -329\n0 -878", "89 -307\n-109 -505\n-10 89\n-1000 -604\n-505 -1000\n-406 -10\n-307 -406\n-604 -109", "5 0\n16 -54\n9 5\n0 4\n0 -6\n4 9\n40 -24\n-24 -36", "-845 860\n-535 -225\n-380 85\n395 550\n-225 -535\n-1000 -690\n-690 -1000\n-70 1325", "702 628\n-334 -408\n-482 -852\n850 -704\n-408 -334\n-926 -1000\n-1000 -926\n-630 480", "-465 -37\n-465 -1000\n177 -37\n-144 177\n-1000 -37\n-1000 -1000\n-358 -144\n-37 -358", "-1000 176\n408 88\n-384 528\n-648 704\n-472 792\n-736 0\n-384 0\n320 880", "-1000 786\n-906 1256\n-671 1021\n-812 974\n598 316\n-765 1303\n598 -1000\n-1000 -530", "550 -70\n-8 -597\n-70 -628\n-39 -690\n-1000 -380\n23 -659\n-70 550\n-380 -1000", "184 230\n46 0\n0 184\n23 184\n115 552\n483 460\n391 92\n230 46", "692 -60\n-812 316\n128 880\n-248 -624\n-812 692\n-1000 -1000\n-1000 692\n-812 -1000", "-1000 -852\n-852 -1000\n332 480\n36 1812\n184 2996\n480 332\n-408 776\n-556 -408", "68 0\n374 221\n306 204\n323 136\n272 340\n391 153\n0 272\n340 68", "296 -163\n350 -190\n-190 -1000\n701 -730\n782 -244\n215 -649\n-1000 -460\n-460 350", "280 0\n504 420\n0 0\n0 168\n644 504\n280 168\n532 532\n616 392", "728 656\n584 152\n1160 152\n-1000 -1000\n1016 944\n-568 -424\n1448 440\n1016 728", "0 25\n725 325\n250 225\n575 675\n375 175\n225 525\n25 0\n225 250", "116 488\n-628 -1000\n-70 -70\n116 1604\n-814 860\n488 -628\n860 674\n-1000 116", "-208 -703\n-109 -604\n-406 -10\n287 188\n-208 -406\n-1000 -802\n-901 -1000\n485 -505", "1136 602\n1403 -21\n-21 -911\n-1000 424\n-733 513\n-288 -1000\n780 -288\n513 335", "760 980\n1420 -120\n320 -780\n-1000 -560\n100 -340\n-340 320\n-560 -1000\n-340 100", "2843 260\n3347 890\n2780 827\n1520 134\n-1000 -874\n2276 8\n-244 -1000\n3410 323", "0 336\n112 476\n196 448\n336 0\n560 896\n140 560\n224 532\n896 560", "0 39\n169 117\n182 182\n104 130\n117 195\n65 0\n39 104\n104 65", "-610 40\n-1000 -220\n-870 -1000\n-220 352\n-298 -350\n-220 -90\n92 -38\n-90 -870", "560 140\n0 140\n280 280\n560 700\n420 560\n700 560\n140 0\n700 420", "400 -580\n-580 -895\n-475 -720\n-580 -1000\n-405 -1000\n-20 400\n-300 -825\n-1000 -20", "-736 -560\n56 -560\n-208 320\n-736 -472\n56 760\n-648 320\n-1000 -1000\n144 232", "688 516\n387 258\n0 129\n387 430\n43 0\n430 129\n774 215\n473 129", "-856 -1000\n224 872\n-136 8\n584 656\n8 512\n368 296\n8 -136\n-1000 -856", "-880 0\n400 -240\n-640 480\n-160 240\n-240 480\n-520 360\n320 0\n-1000 120", "58 0\n0 58\n377 145\n261 203\n203 261\n406 29\n290 0\n261 116", "420 280\n308 196\n336 392\n224 308\n0 224\n224 280\n56 0\n280 56", "136 -1000\n544 -864\n408 -456\n816 156\n340 88\n884 -320\n0 -592\n408 -388", "920 -360\n2088 200\n-1000 600\n2024 -56\n1576 -184\n1240 -1000\n-680 -40\n1512 -440", "528 660\n792 660\n660 528\n528 0\n0 132\n330 462\n132 0\n990 198", "248 404\n872 794\n950 846\n560 -1000\n-1000 716\n924 716\n1002 768\n-688 -688", "-656 0\n-140 344\n-140 516\n-484 860\n-1000 344\n-54 946\n204 602\n-398 688", "744 -19\n-1000 -782\n-237 90\n-128 -346\n-346 -891\n-891 -1000\n635 -1000\n-19 -564", "420 -664\n0 -160\n420 260\n-840 -412\n420 -580\n-840 92\n420 -160\n0 -1000", "558 930\n0 837\n930 558\n310 775\n372 0\n0 372\n124 651\n186 961", "-1000 448\n120 448\n876 224\n1212 -84\n36 588\n372 280\n-776 0\n-104 896", "-320 904\n3896 -184\n224 224\n3624 -48\n-1000 360\n-456 -320\n-864 -864\n-592 -1000", "302 488\n-814 860\n-70 984\n-690 116\n-814 -1000\n488 302\n54 240\n-1000 -814", "0 0\n4 -16\n24 36\n-60 60\n-56 44\n36 43\n40 12\n52 19", "-1000 282\n-154 705\n-859 0\n974 846\n833 141\n128 282\n-13 423\n269 987", "20 -40\n-40 60\n-20 -15\n100 -90\n40 45\n0 0\n60 60\n40 10", "-192 -192\n-495 616\n-1000 -596\n414 -91\n313 717\n-394 -192\n-798 -1000\n10 -596", "-1000 -637\n-516 -274\n-274 -153\n-32 -516\n452 210\n210 -516\n-758 -1000\n-274 452", "-799 407\n-665 -531\n-531 -866\n-866 -1000\n-263 -933\n809 407\n1345 -933\n-1000 -665", "-1000 640\n-16 640\n312 -1000\n968 -16\n640 968\n-672 -344\n-672 -1000\n968 -672", "-1000 -676\n-136 -460\n-460 188\n188 80\n-568 -460\n-460 -136\n-676 -1000\n80 -568", "748 68\n663 -34\n0 680\n425 0\n663 -68\n425 680\n0 0\n578 -170", "248 92\n-1000 -792\n-584 -376\n-168 40\n-116 -376\n-792 -1000\n-376 -584\n300 -324", "140 42\n126 84\n-154 238\n-420 406\n14 0\n0 42\n-518 532\n-56 112", "477 0\n636 371\n106 689\n212 265\n0 53\n530 795\n53 530\n530 477", "0 -814\n93 -256\n372 -349\n186 23\n837 -628\n744 -442\n93 -1000\n465 -70", "-832 -286\n-748 -664\n-916 -1000\n302 -160\n-328 344\n-202 -790\n-1000 -748\n-664 -916", "25 10\n0 10\n41 34\n5 0\n39 30\n37 36\n35 32\n20 20", "-522 -1000\n912 1629\n912 434\n-283 1629\n-1000 -283\n195 -522\n-283 195\n-283 2824", "-586 -310\n-310 104\n104 -586\n-172 -1000\n-1000 -310\n-724 -862\n-34 -448\n-586 -1000", "-445 -1\n-556 -1000\n554 443\n-1000 -445\n-445 -334\n443 -445\n-1 -556\n-334 554", "-288 -822\n-733 -110\n-733 -1000\n1047 -555\n-1000 -911\n780 780\n-466 -199\n-555 513", "2024 8\n1352 -1000\n1016 -244\n512 344\n1856 344\n2360 -748\n-1000 -664\n344 -664", "-1000 -400\n1190 450\n1460 420\n800 50\n1250 -550\n1100 360\n1370 330\n-550 -1000", "1175 450\n-130 -1000\n160 160\n-1000 -1000\n-1000 450\n-130 450\n1465 -565\n450 -855", "424 -288\n-1000 -466\n68 246\n246 1492\n-644 -1000\n-644 -110\n-1000 1136\n602 246", "-471 -80\n-1000 35\n-402 127\n150 -885\n-885 -1000\n35 150\n-333 -11\n-540 58", "-400 -1000\n-400 1000\n600 400\n400 1000\n400 1200\n-1000 -400\n-200 200\n1000 400", "292 1414\n802 1312\n-1000 -1000\n462 2400\n-184 -235\n-847 326\n-31 1091\n972 2298", "0 0\n8 12\n14 4\n0 10\n7 5\n5 10\n15 11\n5 0", "60 260\n280 0\n100 240\n80 200\n0 0\n0 400\n280 400\n40 220", "-850 -1000\n-1000 -850\n-800 -250\n250 -700\n-50 50\n-500 -1000\n-650 -800\n-800 -650", "-125 -825\n1100 -475\n400 -300\n-1000 -475\n-475 400\n-650 -1000\n50 225\n750 750", "-725 1596\n155 -1000\n-758 1530\n-571 1376\n-1000 320\n-692 1497\n-659 1563\n584 56", "-638 3887\n-1000 1896\n448 1353\n-95 4430\n-457 -1000\n-276 4611\n-95 4249\n-819 4068", "216 0\n828 504\n648 612\n504 432\n756 792\n288 576\n0 144\n936 684", "72 32\n4 40\n44 32\n32 0\n40 72\n20 16\n28 56\n0 40", "457 -329\n-530 611\n-624 0\n-953 658\n-577 188\n-859 -141\n692 -188\n-1000 235", "-841 -205\n590 -205\n-1000 -1000\n-364 1385\n-682 113\n-841 -1000\n-1000 -205\n908 1067", "-1000 -604\n-604 1112\n-340 -736\n452 1376\n-604 -340\n-736 -1000\n716 320\n-340 56", "-260 332\n-112 776\n776 184\n-1000 -1000\n-112 1368\n-852 36\n628 924\n36 36", "600 0\n460 600\n500 960\n0 200\n660 760\n300 800\n100 500\n700 300", "15 160\n-101 334\n-855 -1000\n-275 -101\n-1000 -855\n160 15\n160 -275\n334 160", "0 108\n216 144\n480 360\n0 0\n60 108\n240 192\n60 0\n-24 -24", "344 -200\n-200 -520\n-680 -1000\n280 -8\n-1000 -680\n536 -136\n-520 -200\n472 56", "270 2024\n-486 -1000\n-162 2672\n162 2888\n540 728\n918 1862\n-864 1160\n486 2510", "0 336\n128 80\n240 272\n0 0\n368 -112\n128 -256\n144 96\n464 64", "-526 -447\n-1000 -526\n-526 -1000\n-131 -131\n-368 106\n185 -526\n-210 -842\n106 -368", "648 440\n720 -1000\n0 -280\n-120 1520\n-840 2240\n720 488\n672 560\n600 512", "-1000 568\n-432 639\n278 710\n-929 0\n-361 355\n-361 71\n-219 852\n136 213", "-520 480\n-40 240\n-1000 240\n240 360\n-400 240\n-160 520\n-880 0\n120 640", "270 225\n297 387\n315 135\n387 315\n45 0\n0 90\n225 297\n315 225", "60 30\n0 18\n24 6\n81 36\n75 57\n18 24\n54 51\n6 0", "134 -496\n-496 -118\n-748 8\n-1000 -748\n8 -244\n-370 134\n-622 260\n-874 -1000", "1538 -718\n-1000 -718\n3277 -13\n3089 645\n3747 833\n-718 -1000\n3935 175\n1820 -1000", "116 232\n87 0\n319 116\n203 174\n58 145\n174 0\n203 261\n0 58", "-912 -296\n672 -560\n-472 -296\n-648 -208\n-648 1288\n-824 -1000\n-1000 -912\n936 1024", "428 -796\n-592 -1000\n666 3318\n-1000 1856\n190 2842\n462 3454\n394 2706\n20 2060", "684 399\n0 228\n570 342\n228 285\n342 0\n228 570\n570 855\n114 741", "-1000 -373\n254 1090\n-791 672\n463 -164\n-373 -373\n-373 -1000\n-164 463\n672 45", "-536 -304\n-536 508\n-768 -188\n-768 -1000\n-1000 -768\n160 276\n-72 -420\n-304 -536", "120 30\n200 160\n130 0\n150 40\n40 200\n0 40\n160 10\n160 0", "595 -159\n421 -565\n-275 -1000\n-275 -420\n189 15\n-1000 -1000\n-1000 -420\n15 -391", "6 40\n0 35\n4 50\n5 0\n35 40\n40 5\n10 46\n0 44", "360 300\n210 240\n240 90\n180 210\n150 390\n300 450\n0 120\n60 0", "434 116\n434 426\n-186 -1000\n-186 -256\n0 116\n434 -628\n62 54\n372 488", "520 -325\n260 0\n650 -455\n0 195\n130 390\n195 455\n455 260\n260 260", "189 135\n261 153\n0 54\n81 0\n234 108\n216 180\n135 81\n54 135", "864 -540\n972 -162\n342 216\n0 -324\n108 54\n468 378\n486 234\n324 360", "265 220\n30 -60\n330 -420\n140 110\n15 0\n140 200\n15 90\n345 -480", "94 112\n-190 360\n-280 0\n0 0\n94 84\n74 76\n114 120\n90 360", "234 104\n0 52\n286 104\n598 624\n208 156\n182 520\n26 0\n702 208", "0 304\n456 532\n532 304\n456 76\n304 380\n152 0\n608 228\n228 152", "517 551\n940 786\n376 -13\n799 -1000\n-94 -154\n329 -906\n329 81\n-94 81", "117 0\n195 312\n312 195\n0 117\n312 663\n195 390\n468 273\n585 546", "646 102\n238 136\n102 510\n136 0\n578 578\n102 238\n0 102\n170 34", "-856 -1000\n440 728\n728 296\n-1000 -856\n296 8\n-424 -280\n-280 -424\n8 440", "160 120\n180 120\n340 140\n20 0\n320 300\n180 40\n160 280\n0 80", "195 260\n533 390\n455 546\n0 65\n260 195\n65 0\n689 468\n611 624", "123 0\n-410 123\n902 -123\n-82 369\n123 492\n0 492\n574 -369\n0 0", "42 -168\n966 252\n462 126\n840 756\n336 630\n0 -588\n-252 -168\n-294 -588", "280 480\n360 -80\n-1000 -640\n-200 -160\n-760 -1000\n-280 -160\n-280 400\n-40 -520", "-622 315\n-1000 126\n-937 0\n-55 315\n-559 189\n-433 441\n-307 819\n71 693", "410 533\n287 41\n615 164\n328 246\n697 451\n246 287\n0 246\n41 0", "-919 0\n53 648\n-514 405\n-433 729\n-1000 162\n-28 162\n-433 243\n-514 243", "-1000 276\n-586 828\n-34 414\n104 414\n-862 690\n-448 276\n-34 966\n-172 0", "-544 -316\n140 368\n-1000 -772\n-316 -544\n-316 596\n-544 140\n-88 -88\n-772 -1000", "980 -520\n860 -430\n620 -250\n500 -160\n20 1220\n-1000 980\n380 -760\n-640 -1000", "432 -1000\n0 -1000\n0 -520\n432 -520\n864 104\n192 8\n960 -568\n288 -664", "872 872\n-766 -1000\n170 -64\n1808 989\n1925 53\n989 -64\n-64 170\n-1000 -766", "-620 -1000\n-430 -240\n45 -240\n-810 -145\n-145 520\n-715 -430\n-905 330\n-1000 -905", "-316 684\n-1000 -228\n444 76\n520 152\n1204 380\n-316 0\n-240 0\n368 760", "364 -688\n-260 248\n-312 40\n0 -532\n0 -792\n104 -792\n260 -428\n-52 -1000", "96 180\n-204 108\n-144 36\n84 102\n-12 0\n0 6\n-72 72\n12 84", "357 -1000\n119 190\n714 -48\n0 -643\n833 -524\n952 547\n476 -167\n357 785", "598 368\n414 92\n0 0\n138 46\n368 322\n644 138\n138 0\n0 46", "-480 -350\n-1000 -870\n-870 -1000\n-155 495\n-740 -285\n40 -870\n625 -90\n-350 -480", "-340 1640\n-1000 650\n320 375\n705 485\n815 100\n430 -10\n-340 -10\n-1000 -1000", "120 120\n105 30\n30 0\n0 75\n75 90\n90 165\n75 105\n45 135", "840 980\n140 532\n980 840\n588 420\n700 868\n252 980\n140 0\n0 140", "-244 -730\n512 998\n-460 -946\n728 1214\n-1000 -568\n728 -892\n80 -1000\n-352 -460", "62 60\n54 50\n6 42\n64 42\n0 6\n36 0\n72 52\n42 36", "-941 -1000\n-764 -410\n-823 -882\n-882 -823\n-1000 -941\n1006 298\n475 -941\n-233 829", "360 648\n504 360\n0 360\n648 288\n288 504\n648 576\n288 0\n432 720", "792 -648\n-352 -142\n704 -1000\n88 -472\n0 -824\n-682 1046\n572 -208\n242 980", "-1000 176\n100 616\n-824 0\n-780 396\n-252 88\n-780 440\n-428 968\n-604 220", "-1000 -580\n-1000 -1000\n330 960\n610 260\n-860 -580\n120 470\n-860 -1000\n820 750", "0 -970\n90 -580\n585 500\n150 -880\n270 -400\n30 -1000\n405 320\n120 -850", "600 500\n700 200\n600 180\n620 100\n700 120\n100 0\n680 200\n0 300", "256 496\n304 512\n576 0\n320 464\n272 448\n0 64\n64 640\n640 576", "128 112\n40 72\n64 96\n72 40\n80 32\n32 0\n0 32\n144 48", "-1000 1052\n140 -392\n292 -1000\n900 -848\n-12 368\n672 -544\n748 -240\n-316 140", "-208 -10\n188 -208\n386 188\n-505 -1000\n-505 -703\n-10 386\n-1000 -1000\n-1000 -703", "153 102\n187 170\n102 153\n153 68\n0 51\n221 102\n51 0\n119 136", "-1000 -60\n-342 -1000\n1444 -248\n1162 -718\n1538 -624\n1914 -530\n786 692\n2290 -436", "3368 858\n-1000 -546\n1886 0\n3914 702\n3602 429\n3056 585\n-298 -780\n2588 -234", "780 68\n424 -466\n68 -110\n246 424\n246 -466\n-110 -110\n-822 -1000\n-1000 -644", "-372 93\n-403 31\n31 -31\n558 186\n248 434\n279 155\n0 -93\n527 465", "-859 329\n-1000 141\n81 705\n-906 0\n-577 987\n-718 329\n-624 188\n-201 47", "-97 -140\n290 -97\n290 935\n935 290\n-1000 -355\n-140 247\n247 290\n-355 -1000", "426 518\n-609 449\n633 -1000\n-586 2220\n-954 2174\n-632 2588\n-1000 2542\n-816 1967", "410 -754\n574 312\n82 66\n820 -180\n410 -1000\n0 -1000\n328 -426\n0 -754", "-700 120\n-370 -90\n-40 510\n-490 150\n-1000 -60\n-670 -270\n-850 600\n-400 960", "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n0 -10", "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n6 2", "100 100\n100 101\n101 100\n101 101\n0 0\n1 5\n11 5\n10 0", "0 0\n1 0\n0 1\n1 1\n100 100\n100 101\n101 100\n101 101", "0 8\n-2 0\n-3 0\n0 -8\n2 0\n3 0\n0 2\n0 -2", "-8 0\n0 -3\n8 0\n10000 10000\n9999 9999\n9999 10000\n0 3\n10000 9999", "-8 0\n0 -3\n8 0\n10000 10000\n9998 9999\n9998 10000\n0 3\n10000 9999", "10 10\n15 11\n15 9\n20 10\n100 100\n100 102\n107 102\n107 100", "0 0\n5 0\n8 4\n3 4\n-2 -2\n-2 -1\n-1 -1\n-1 -2", "0 0\n1 1\n2 2\n3 3\n4 4\n4 5\n5 4\n5 5", "0 0\n0 1\n1 0\n1 1\n10 10\n14 10\n12 16\n12 20", "0 0\n0 1\n1 0\n1 1\n2 0\n2 1\n3 1\n4 0", "1 1\n1 2\n2 1\n2 2\n100 100\n101 100\n101 102\n102 102", "0 0\n2 0\n2 2\n0 2\n1 1\n5 0\n5 2\n9 1", "0 0\n0 1\n1 0\n1 1\n2 2\n3 2\n3 3\n4 3", "4 1\n7 3\n9 4\n4 5\n1 3\n9 6\n12 4\n12 6", "0 0\n3 0\n3 4\n6 4\n100 100\n101 100\n100 101\n101 101", "1 0\n0 4\n2 4\n1 8\n15 15\n15 16\n18 15\n18 16", "0 0\n0 1\n1 1\n1 0\n1000 1000\n1001 1003\n1004 1004\n1003 1001", "1 0\n2 2\n0 2\n1 4\n7 0\n9 0\n7 1\n9 1", "0 0\n1 0\n1 1\n0 1\n5 6\n100 190\n6 7\n10 196", "0 0\n1 0\n2 0\n1 2\n50 50\n50 51\n51 51\n51 50"], "outputs": ["YES\n5 6 7 8\n1 2 3 4", "NO", "YES\n1 2 3 4\n5 6 7 8", "YES\n2 3 4 7\n1 5 6 8", "YES\n2 3 5 7\n1 4 6 8", "YES\n1 3 5 6\n2 4 7 8", "YES\n1 2 3 5\n4 6 7 8", "YES\n1 2 5 8\n3 4 6 7", "YES\n1 2 5 6\n3 4 7 8", "YES\n1 3 6 8\n2 4 5 7", "NO", "YES\n1 2 5 7\n3 4 6 8", "YES\n2 3 4 6\n1 5 7 8", "YES\n3 6 7 8\n1 2 4 5", "YES\n1 3 5 6\n2 4 7 8", "YES\n2 4 6 7\n1 3 5 8", "YES\n2 4 7 8\n1 3 5 6", "YES\n3 4 5 6\n1 2 7 8", "NO", "YES\n1 2 5 6\n3 4 7 8", "YES\n1 3 5 7\n2 4 6 8", "YES\n1 3 5 6\n2 4 7 8", "YES\n3 4 5 6\n1 2 7 8", "NO", "YES\n1 3 5 6\n2 4 7 8", "NO", "YES\n1 3 4 5\n2 6 7 8", "YES\n3 4 5 7\n1 2 6 8", "YES\n2 4 7 8\n1 3 5 6", "YES\n2 3 4 6\n1 5 7 8", "NO", "YES\n3 5 7 8\n1 2 4 6", "YES\n1 2 5 7\n3 4 6 8", "YES\n1 4 7 8\n2 3 5 6", "YES\n1 3 4 6\n2 5 7 8", "YES\n1 3 6 8\n2 4 5 7", "YES\n4 5 6 7\n1 2 3 8", "YES\n1 3 6 7\n2 4 5 8", "NO", "YES\n1 3 4 8\n2 5 6 7", "YES\n1 3 4 8\n2 5 6 7", "YES\n3 4 7 8\n1 2 5 6", "YES\n2 5 7 8\n1 3 4 6", "NO", "YES\n2 3 4 6\n1 5 7 8", "YES\n4 5 6 7\n1 2 3 8", "YES\n1 2 3 4\n5 6 7 8", "NO", "YES\n2 3 4 6\n1 5 7 8", "YES\n1 4 5 6\n2 3 7 8", "YES\n2 5 7 8\n1 3 4 6", "NO", "YES\n2 4 5 6\n1 3 7 8", "YES\n3 4 5 7\n1 2 6 8", "YES\n1 3 4 8\n2 5 6 7", "NO", "YES\n1 2 3 6\n4 5 7 8", "NO", "YES\n2 3 6 7\n1 4 5 8", "YES\n2 3 4 5\n1 6 7 8", "YES\n1 4 5 7\n2 3 6 8", "YES\n1 3 5 8\n2 4 6 7", "YES\n2 3 5 7\n1 4 6 8", "NO", "YES\n1 4 7 8\n2 3 5 6", "YES\n2 4 5 6\n1 3 7 8", "NO", "YES\n3 6 7 8\n1 2 4 5", "YES\n1 2 3 4\n5 6 7 8", "YES\n1 2 3 7\n4 5 6 8", "NO", "YES\n2 4 6 8\n1 3 5 7", "NO", "YES\n2 6 7 8\n1 3 4 5", "YES\n1 3 5 7\n2 4 6 8", "NO", "YES\n2 4 7 8\n1 3 5 6", "NO", "NO", "YES\n2 3 4 7\n1 5 6 8", "NO", "YES\n4 5 6 8\n1 2 3 7", "NO", "YES\n2 4 5 6\n1 3 7 8", "YES\n2 5 6 8\n1 3 4 7", "NO", "YES\n2 3 4 6\n1 5 7 8", "YES\n3 4 5 8\n1 2 6 7", "NO", "YES\n1 4 5 8\n2 3 6 7", "NO", "YES\n2 3 4 6\n1 5 7 8", "YES\n2 3 4 8\n1 5 6 7", "YES\n1 4 5 6\n2 3 7 8", "YES\n3 5 6 7\n1 2 4 8", "NO", "YES\n1 4 6 7\n2 3 5 8", "YES\n1 2 4 7\n3 5 6 8", "YES\n1 4 6 8\n2 3 5 7", "NO", "NO", "YES\n1 3 7 8\n2 4 5 6", "YES\n4 6 7 8\n1 2 3 5", "YES\n2 4 5 6\n1 3 7 8", "YES\n2 3 5 7\n1 4 6 8", "NO", "YES\n2 3 5 7\n1 4 6 8", "YES\n1 3 4 8\n2 5 6 7", "YES\n3 4 5 6\n1 2 7 8", "YES\n1 2 5 8\n3 4 6 7", "NO", "NO", "YES\n2 3 5 8\n1 4 6 7", "YES\n2 3 6 7\n1 4 5 8", "NO", "YES\n2 4 5 8\n1 3 6 7", "YES\n1 3 5 6\n2 4 7 8", "NO", "YES\n2 3 5 6\n1 4 7 8", "YES\n2 4 7 8\n1 3 5 6", "NO", "YES\n1 4 6 8\n2 3 5 7", "NO", "NO", "YES\n1 4 6 7\n2 3 5 8", "NO", "YES\n1 2 4 6\n3 5 7 8", "YES\n2 4 6 8\n1 3 5 7", "YES\n2 4 7 8\n1 3 5 6", "YES\n1 4 5 7\n2 3 6 8", "YES\n2 3 6 7\n1 4 5 8", "NO", "YES\n3 5 6 7\n1 2 4 8", "YES\n1 2 5 8\n3 4 6 7", "NO", "YES\n2 3 5 6\n1 4 7 8", "YES\n2 3 5 8\n1 4 6 7", "YES\n2 3 6 7\n1 4 5 8", "YES\n1 3 4 7\n2 5 6 8", "YES\n1 2 5 8\n3 4 6 7", "YES\n2 4 5 6\n1 3 7 8", "YES\n1 2 5 6\n3 4 7 8", "NO", "NO", "YES\n1 2 5 6\n3 4 7 8", "NO", "NO", "NO", "YES\n3 4 6 8\n1 2 5 7", "YES\n3 4 5 8\n1 2 6 7", "NO", "YES\n5 6 7 8\n1 2 3 4", "YES\n2 4 6 7\n1 3 5 8", "YES\n2 3 5 8\n1 4 6 7", "YES\n2 3 5 7\n1 4 6 8", "YES\n2 3 7 8\n1 4 5 6", "NO", "NO", "YES\n1 2 4 7\n3 5 6 8", "YES\n4 6 7 8\n1 2 3 5", "YES\n1 3 4 5\n2 6 7 8", "YES\n2 4 6 8\n1 3 5 7", "YES\n2 4 6 7\n1 3 5 8", "YES\n2 5 6 7\n1 3 4 8", "NO", "YES\n5 6 7 8\n1 2 3 4", "YES\n1 4 5 6\n2 3 7 8", "YES\n3 5 6 7\n1 2 4 8", "NO", "NO", "NO", "YES\n2 3 6 8\n1 4 5 7", "YES\n1 2 5 6\n3 4 7 8", "YES\n4 5 6 7\n1 2 3 8", "NO", "YES\n2 3 4 7\n1 5 6 8", "YES\n2 4 5 6\n1 3 7 8", "NO", "YES\n1 2 4 7\n3 5 6 8", "YES\n2 6 7 8\n1 3 4 5", "YES\n1 3 4 7\n2 5 6 8", "NO", "YES\n2 5 6 7\n1 3 4 8", "YES\n3 4 6 8\n1 2 5 7", "NO", "YES\n3 4 5 7\n1 2 6 8", "YES\n1 2 4 5\n3 6 7 8", "YES\n1 3 5 8\n2 4 6 7", "NO", "YES\n1 2 3 6\n4 5 7 8", "YES\n2 4 6 8\n1 3 5 7", "NO", "NO", "YES\n1 2 4 6\n3 5 7 8", "NO", "YES\n1 3 5 8\n2 4 6 7", "YES\n1 2 6 7\n3 4 5 8", "NO", "YES\n2 3 4 7\n1 5 6 8", "NO", "NO", "NO", "NO", "YES\n1 2 3 4\n5 6 7 8", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 8 | codeforces |
|
ad14725a5fe6b814b4b6bbb9fe4458f0 | Destroying Roads | In some country there are exactly *n* cities and *m* bidirectional roads connecting the cities. Cities are numbered with integers from 1 to *n*. If cities *a* and *b* are connected by a road, then in an hour you can go along this road either from city *a* to city *b*, or from city *b* to city *a*. The road network is such that from any city you can get to any other one by moving along the roads.
You want to destroy the largest possible number of roads in the country so that the remaining roads would allow you to get from city *s*1 to city *t*1 in at most *l*1 hours and get from city *s*2 to city *t*2 in at most *l*2 hours.
Determine what maximum number of roads you need to destroy in order to meet the condition of your plan. If it is impossible to reach the desired result, print -1.
The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=3000, ) — the number of cities and roads in the country, respectively.
Next *m* lines contain the descriptions of the roads as pairs of integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). It is guaranteed that the roads that are given in the description can transport you from any city to any other one. It is guaranteed that each pair of cities has at most one road between them.
The last two lines contains three integers each, *s*1, *t*1, *l*1 and *s*2, *t*2, *l*2, respectively (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*, 0<=≤<=*l**i*<=≤<=*n*).
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
Sample Input
5 4
1 2
2 3
3 4
4 5
1 3 2
3 5 2
5 4
1 2
2 3
3 4
4 5
1 3 2
2 4 2
5 4
1 2
2 3
3 4
4 5
1 3 2
3 5 1
Sample Output
0
1
-1
| {"inputs": ["5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 3", "9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 4", "10 11\n1 3\n2 3\n3 4\n4 5\n4 6\n3 7\n3 8\n4 9\n4 10\n7 9\n8 10\n1 5 3\n6 2 3", "1 0\n1 1 0\n1 1 0", "2 1\n1 2\n1 1 0\n1 2 1", "2 1\n1 2\n1 1 0\n1 2 0", "6 5\n1 3\n2 3\n3 4\n4 5\n4 6\n1 6 3\n5 2 3", "6 5\n1 2\n2 3\n3 4\n3 5\n2 6\n1 4 3\n5 6 3", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n4 2 2"], "outputs": ["0", "1", "-1", "2", "3", "6", "0", "0", "-1", "0", "0", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
ad19bf2016662dc02a3757bd711fb08f | Sereja and Prefixes | Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.
Sereja takes a blank piece of paper. Then he starts writing out the sequence in *m* stages. Each time he either adds a new number to the end of the sequence or takes *l* first elements of the current sequence and adds them *c* times to the end. More formally, if we represent the current sequence as *a*1,<=*a*2,<=...,<=*a**n*, then after we apply the described operation, the sequence transforms into *a*1,<=*a*2,<=...,<=*a**n*[,<=*a*1,<=*a*2,<=...,<=*a**l*] (the block in the square brackets must be repeated *c* times).
A day has passed and Sereja has completed the sequence. He wonders what are the values of some of its elements. Help Sereja.
The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of stages to build a sequence.
Next *m* lines contain the description of the stages in the order they follow. The first number in the line is a type of stage (1 or 2). Type 1 means adding one number to the end of the sequence, in this case the line contains integer *x**i* (1<=≤<=*x**i*<=≤<=105) — the number to add. Type 2 means copying a prefix of length *l**i* to the end *c**i* times, in this case the line further contains two integers *l**i*,<=*c**i* (1<=≤<=*l**i*<=≤<=105,<=1<=≤<=*c**i*<=≤<=104), *l**i* is the length of the prefix, *c**i* is the number of copyings. It is guaranteed that the length of prefix *l**i* is never larger than the current length of the sequence.
The next line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements Sereja is interested in. The next line contains the numbers of elements of the final sequence Sereja is interested in. The numbers are given in the strictly increasing order. It is guaranteed that all numbers are strictly larger than zero and do not exceed the length of the resulting sequence. Consider the elements of the final sequence numbered starting from 1 from the beginning to the end of the sequence.
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.
Print the elements that Sereja is interested in, in the order in which their numbers occur in the input.
Sample Input
6
1 1
1 2
2 2 1
1 3
2 5 2
1 4
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Sample Output
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
| {"inputs": ["6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16", "2\n1 33085\n1 44638\n2\n1 2", "10\n1 57757\n1 45234\n1 80807\n1 38496\n1 27469\n1 42645\n1 72643\n1 33235\n1 10843\n1 80598\n10\n1 2 3 4 5 6 7 8 9 10", "3\n1 97601\n1 32580\n1 70519\n3\n1 2 3", "7\n1 53989\n1 47249\n1 71935\n2 1 3\n1 84520\n1 84185\n2 6 1\n14\n1 2 3 4 5 6 7 8 9 10 11 12 13 14", "1\n1 1\n1\n1"], "outputs": ["1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4", "33085 44638", "57757 45234 80807 38496 27469 42645 72643 33235 10843 80598", "97601 32580 70519", "53989 47249 71935 53989 53989 53989 84520 84185 53989 47249 71935 53989 53989 53989", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 3 | codeforces |
|
ad1f8a840e84be956b38eac4b391343f | Petr and Permutations | Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation. He generates a random permutation just like Petr but swaps elements $7n+1$ times instead of $3n$ times. Because it is more random, OK?!
You somehow get a test from one of these problems and now you want to know from which one.
In the first line of input there is one integer $n$ ($10^{3} \le n \le 10^{6}$).
In the second line there are $n$ distinct integers between $1$ and $n$ — the permutation of size $n$ from the test.
It is guaranteed that all tests except for sample are generated this way: First we choose $n$ — the size of the permutation. Then we randomly choose a method to generate a permutation — the one of Petr or the one of Alex. Then we generate a permutation using chosen method.
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
Sample Input
5
2 4 5 1 3
Sample Output
Petr
| {"inputs": ["5\n2 4 5 1 3"], "outputs": ["Petr"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 13 | codeforces |
|
ad220da3e1b05b8f889f1484c2d540f7 | Drazil and Park | Drazil is a monkey. He lives in a circular park. There are *n* trees around the park. The distance between the *i*-th tree and (*i*<=+<=1)-st trees is *d**i*, the distance between the *n*-th tree and the first tree is *d**n*. The height of the *i*-th tree is *h**i*.
Drazil starts each day with the morning run. The morning run consists of the following steps:
- Drazil chooses two different trees - He starts with climbing up the first tree - Then he climbs down the first tree, runs around the park (in one of two possible directions) to the second tree, and climbs on it - Then he finally climbs down the second tree.
But there are always children playing around some consecutive trees. Drazil can't stand children, so he can't choose the trees close to children. He even can't stay close to those trees.
If the two trees Drazil chooses are *x*-th and *y*-th, we can estimate the energy the morning run takes to him as 2(*h**x*<=+<=*h**y*)<=+<=*dist*(*x*,<=*y*). Since there are children on exactly one of two arcs connecting *x* and *y*, the distance *dist*(*x*,<=*y*) between trees *x* and *y* is uniquely defined.
Now, you know that on the *i*-th day children play between *a**i*-th tree and *b**i*-th tree. More formally, if *a**i*<=≤<=*b**i*, children play around the trees with indices from range [*a**i*,<=*b**i*], otherwise they play around the trees with indices from .
Please help Drazil to determine which two trees he should choose in order to consume the most energy (since he wants to become fit and cool-looking monkey) and report the resulting amount of energy for each day.
The first line contains two integer *n* and *m* (3<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=105), denoting number of trees and number of days, respectively.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=109), the distances between consecutive trees.
The third line contains *n* integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), the heights of trees.
Each of following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*) describing each new day. There are always at least two different trees Drazil can choose that are not affected by children.
For each day print the answer in a separate line.
Sample Input
5 3
2 2 2 2 2
3 5 2 1 4
1 3
2 2
4 5
3 3
5 1 4
5 1 4
3 3
2 2
1 1
Sample Output
12
16
18
17
22
11
| {"inputs": ["5 3\n2 2 2 2 2\n3 5 2 1 4\n1 3\n2 2\n4 5", "3 3\n5 1 4\n5 1 4\n3 3\n2 2\n1 1", "10 10\n8477 33103 38654 6582 27496 1106 15985 3644 29818 8849\n88745 72099 87767 85285 73517 94562 87214 63194 83791 77619\n2 8\n1 5\n9 5\n7 8\n6 9\n8 1\n6 1\n4 9\n8 10\n5 10", "9 9\n1 1 1 1 1 1 1 1 1\n1 1 1 1 1000000000 1 1 1 1\n9 1\n9 9\n1 1\n8 9\n7 9\n9 2\n8 2\n1 1\n1 2", "10 10\n91616899 35356500 87449167 31557462 21778951 474730484 302870359 398428048 174667839 183336304\n955685310 810816265 348361987 966143351 883722429 699134978 928163574 775129554 873615248 931808862\n4 4\n7 1\n2 7\n8 9\n6 2\n8 4\n9 10\n8 8\n3 10\n3 6"], "outputs": ["12\n16\n18", "17\n22\n11", "383739\n394915\n364658\n509685\n428294\n439157\n386525\n394604\n480926\n428294", "2000000005\n2000000006\n2000000006\n2000000006\n2000000006\n2000000005\n2000000004\n2000000006\n2000000006", "5234627463\n3731289022\n4218061919\n4645770639\n3731289022\n4120281441\n4510187231\n4704051250\n3624620049\n4827000318"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
ad656fd9fb168c5779c1eec25fd50ee2 | Sagheer and Crossroads | 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.
Sample Input
1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1
0 1 1 0
1 0 1 0
1 1 0 0
0 0 0 1
1 0 0 0
0 0 0 1
0 0 0 0
1 0 1 0
Sample Output
YES
NO
NO
| {"inputs": ["1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0", "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "1 1 1 0\n0 1 0 1\n1 1 1 0\n1 1 1 1", "0 1 1 0\n0 1 0 0\n1 0 0 1\n1 0 0 0", "1 0 0 0\n0 1 0 0\n1 1 0 0\n0 1 1 0", "0 0 0 0\n0 1 0 1\n1 0 1 1\n1 1 1 0", "1 1 0 0\n0 1 0 1\n1 1 1 0\n0 0 1 1", "0 1 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1", "0 0 1 0\n0 0 0 0\n1 1 0 0\n0 0 0 1", "0 0 1 0\n0 1 0 1\n1 0 1 0\n0 0 1 0", "1 1 1 0\n0 1 0 1\n1 1 1 1\n0 0 0 1", "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 1", "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "0 0 0 0\n0 1 0 1\n1 0 1 1\n0 0 0 1", "1 1 0 0\n0 1 0 0\n1 1 1 0\n1 0 1 0", "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 1", "1 0 1 0\n1 1 0 0\n1 1 0 0\n0 0 0 0", "0 0 1 0\n1 1 0 0\n1 0 1 0\n1 0 0 0", "0 0 1 0\n1 0 0 0\n0 0 0 1\n0 0 0 1", "0 1 1 0\n1 1 0 1\n1 0 0 1\n1 1 1 0", "1 0 0 0\n1 1 0 0\n1 1 0 1\n0 0 1 0", "0 0 0 0\n1 1 0 0\n0 0 0 1\n0 0 1 0", "0 1 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 1", "0 1 0 0\n1 1 0 1\n1 0 0 1\n1 1 0 1", "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0", "0 0 0 1\n0 1 0 0\n0 0 0 0\n0 0 0 0", "0 0 0 1\n0 0 1 0\n0 0 0 0\n0 0 0 0", "0 0 0 1\n0 0 0 0\n1 0 0 0\n0 0 0 0", "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0", "0 0 0 1\n0 0 0 0\n0 0 1 0\n0 0 0 0", "0 0 0 1\n0 0 0 0\n0 0 0 0\n1 0 0 0", "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 1 0 0", "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 1 0", "1 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0", "0 1 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0", "0 0 1 0\n0 0 0 1\n0 0 0 0\n0 0 0 0", "0 0 0 0\n1 0 0 1\n0 0 0 0\n0 0 0 0", "0 0 0 0\n0 1 0 1\n0 0 0 0\n0 0 0 0", "0 0 0 0\n0 0 1 1\n0 0 0 0\n0 0 0 0", "0 0 0 0\n0 0 0 1\n1 0 0 0\n0 0 0 0", "0 0 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 0", "0 0 0 0\n0 0 0 1\n0 0 1 0\n0 0 0 0", "0 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 0 0", "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 1 0 0", "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 1 0", "1 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0", "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0", "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 0", "0 0 0 0\n1 0 0 0\n0 0 0 1\n0 0 0 0", "0 0 0 0\n0 1 0 0\n0 0 0 1\n0 0 0 0", "0 0 0 0\n0 0 1 0\n0 0 0 1\n0 0 0 0", "0 0 0 0\n0 0 0 0\n1 0 0 1\n0 0 0 0", "0 0 0 0\n0 0 0 0\n0 1 0 1\n0 0 0 0", "0 0 0 0\n0 0 0 0\n0 0 1 1\n0 0 0 0", "0 0 0 0\n0 0 0 0\n0 0 0 1\n1 0 0 0", "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0", "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 1 0", "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1", "0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1", "0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1", "0 0 0 0\n1 0 0 0\n0 0 0 0\n0 0 0 1", "0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 1", "0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 1", "0 0 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1", "0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 1", "0 0 0 0\n0 0 0 0\n0 0 1 0\n0 0 0 1", "0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 1", "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 1", "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 1 1", "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0", "1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1", "1 0 0 0\n0 1 0 0\n0 0 1 0\n0 0 0 1", "1 1 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0", "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0", "0 1 1 0\n1 0 1 0\n1 1 1 0\n0 0 0 1", "1 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "1 1 1 0\n1 1 1 0\n1 1 1 0\n0 0 0 1", "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1", "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0", "0 0 0 1\n0 0 1 1\n0 0 0 0\n0 0 0 0", "0 0 0 1\n0 1 1 1\n0 0 0 0\n0 0 0 0", "0 0 0 1\n0 1 0 1\n0 0 0 0\n0 0 0 0", "0 0 0 1\n0 0 0 1\n0 0 0 0\n0 1 0 0", "0 0 0 1\n0 0 0 1\n1 0 0 0\n0 0 0 0"], "outputs": ["YES", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 74 | codeforces |
|
ad7defe219bd7fa8acbe1890ffa08b24 | none | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109).
Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments.
Sample Input
5 2
1 2 3 4 5
5 1
-4 -5 -3 -2 -1
Sample Output
5
-5
| {"inputs": ["5 2\n1 2 3 4 5", "5 1\n-4 -5 -3 -2 -1", "10 2\n10 9 1 -9 -7 -9 3 8 -10 5", "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9", "1 1\n504262064", "3 3\n-54481850 -878017339 -486296116", "2 2\n-333653905 224013643", "14 2\n-14 84 44 46 -75 -75 77 -49 44 -82 -74 -51 -9 -50", "88 71\n-497 -488 182 104 40 183 201 282 -384 44 -29 494 224 -80 -491 -197 157 130 -52 233 -426 252 -61 -51 203 -50 195 -442 -38 385 232 -243 -49 163 340 -200 406 -254 -29 227 -194 193 487 -325 230 146 421 158 20 447 -97 479 493 -130 164 -471 -198 -330 -152 359 -554 319 544 -444 235 281 -467 337 -385 227 -366 -210 266 69 -261 525 526 -234 -355 177 109 275 -301 7 -41 553 -284 540", "39 1\n676941771 -923780377 -163050076 -230110947 -208029500 329620771 13954060 158950156 -252501602 926390671 -678745080 -921892226 -100127643 610420285 602175224 -839193819 471391946 910035173 777969600 -736144413 -489685522 60986249 830784148 278642552 -375298304 197973611 -354482364 187294011 636628282 25350767 636184407 -550869740 53830680 -42049274 -451383278 900048257 93225803 877923341 -279506435", "3 2\n1 5 3", "5 2\n1 2 5 4 3", "3 2\n1 3 2", "3 2\n1 3 1", "5 3\n-2 -2 -2 -2 -2", "5 2\n1 2 3 5 4", "5 2\n1 1 11 1 1", "3 3\n3 8 4", "6 3\n4 3 1 5 6 2", "2 1\n1 2", "5 2\n2 5 4 3 1", "5 2\n-1 1 5 4 3", "5 2\n5 2 1 9 3", "2 1\n1000000000 1000000000", "1 1\n1000000000", "5 2\n1 5 3 4 1", "3 2\n-1000000000 -1000000000 -1000000000", "2 2\n5 2", "7 3\n1 1 1 10 1 1 1", "9 3\n1 2 1 1 5 1 1 1 2", "9 3\n2 2 2 2 9 2 2 2 2", "3 3\n-1000000000 -1000000000 -1000000000"], "outputs": ["5", "-5", "10", "9", "504262064", "-54481850", "224013643", "-14", "553", "-923780377", "3", "3", "2", "1", "-2", "4", "1", "8", "6", "1", "2", "3", "5", "1000000000", "1000000000", "1", "-1000000000", "5", "10", "5", "9", "-1000000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 140 | codeforces |
|
adb059482de1a081f75f56e8d0085745 | Position in Fraction | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9).
Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Sample Input
1 2 0
2 3 7
Sample Output
2-1 | {"inputs": ["1 2 0", "2 3 7", "1 100000 1", "1 7 7", "99999 100000 8", "44102 73848 2", "7 31 3", "8880 81608 9", "4942 62768 5", "69168 84860 4", "971 1883 3", "1636 3269 6", "6873 7769 3", "13805 15538 3", "10958 21926 3", "8 51 0", "1 10 1", "1 9 0", "53 101 6", "1 10001 9", "25102 31579 2", "38790 39359 0", "47117 78718 0", "1 57 0", "1 3 0", "1 100 0", "2 3 0", "99971 99989 0", "567 1580 0", "45 97 0", "35 111 4", "1 2 5", "1 7 0"], "outputs": ["2", "-1", "5", "6", "-1", "132", "15", "161", "122", "107", "130", "150", "163", "164", "117", "10", "1", "-1", "-1", "5", "174", "212", "213", "1", "-1", "1", "-1", "9", "6", "39", "-1", "1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 86 | codeforces |
|
adbf79a9d4af5e615e98841bd63ff9b3 | Meeting of Old Friends | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Sample Input
1 10 9 20 1
1 100 50 200 75
Sample Output
2
50
| {"inputs": ["1 10 9 20 1", "1 100 50 200 75", "6 6 5 8 9", "1 1000000000 1 1000000000 1", "5 100 8 8 8", "1 1000000000000000000 2 99999999999999999 1000000000", "1 1 1 1 1", "1 2 3 4 5", "1 1000000000 2 999999999 3141592", "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "11814 27385 22309 28354 23595", "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "1 3 3 5 3", "1 5 8 10 9", "1 2 4 5 10", "1 2 2 3 5", "2 4 3 7 3", "1 2 9 10 1", "5 15 1 10 5", "1 4 9 20 25", "2 4 1 2 5", "10 1000 1 100 2", "1 3 3 8 10", "4 6 6 8 9", "2 3 1 4 3", "1 2 2 3 100", "1 2 100 120 2", "1 3 5 7 4", "1 3 5 7 5", "1 4 8 10 6", "1 2 5 6 100", "1 2 5 10 20", "1 2 5 6 7", "2 5 7 12 6", "10 20 50 100 80", "1 2 5 10 2", "1 2 5 6 4", "5 9 1 2 3", "50 100 1 20 3", "10 20 3 7 30", "1 5 10 10 100", "100 101 1 2 3", "1 5 10 20 6", "1 10 15 25 5", "1 2 5 10 3", "2 3 5 6 100", "1 2 4 5 6", "6 10 1 2 40", "20 30 1 5 1", "20 40 50 100 50", "1 1 4 9 2", "1 2 5 6 1", "1 100 400 500 450", "5 6 1 2 5", "1 10 21 30 50", "100 200 300 400 101", "2 8 12 16 9", "1 5 7 9 6", "300 400 100 200 101", "1 2 2 3 10", "1 10 100 200 5", "1 3 3 4 4", "10 20 30 40 25", "1 2 5 10 1", "2 4 8 10 1", "2 5 10 15 7", "100 200 5 10 1", "1 2 100 200 300", "30 100 10 20 25", "10 20 1 5 6", "4 5 1 2 4", "11 100 1 9 1000", "1 1 10 10 228", "5 7 10 20 15", "1 3 8 9 7", "1 10 2 8 8", "1 5 9 15 1", "1 3 5 6 12", "1 100 500 1000 3", "1 1 1 1 2", "1 1000 100 1000 200", "4 5 1 4 1", "1 5 5 7 3", "1 4 4 10 11", "1 1 3 4 100", "1 4 3 5 6", "10 100 20 30 40", "5 9 1 11 7"], "outputs": ["2", "50", "1", "999999999", "0", "99999999999999997", "0", "0", "999999997", "0", "27788438422925", "5076", "29117730788587", "81604391064", "47247500916780901", "0", "48172141432145241", "99277597320376979", "256787461333454149", "37925278862451249", "0", "0", "0", "1", "1", "0", "5", "0", "1", "91", "1", "1", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "6", "0", "0", "0", "1", "900", "1", "1", "1", "0", "2", "11", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 142 | codeforces |
|
adc74535feb0901a59a1c5135823da3b | Word Correction | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
Sample Input
5
weird
4
word
5
aaeaa
Sample Output
werd
word
a
| {"inputs": ["5\nweird", "4\nword", "5\naaeaa", "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "12\nmmmmmmmmmmmm", "18\nyaywptqwuyiqypwoyw", "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "13\nmmmmmmmmmmmmm", "10\nmmmmmmmmmm", "11\nmmmmmmmmmmm", "15\nmmmmmmmmmmmmmmm", "1\na", "14\nmmmmmmmmmmmmmm", "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "2\naa", "18\niuiuqpyyaoaetiwliu", "5\nxxxxx", "6\nxxxahg", "3\nzcv", "4\naepo", "5\nqqqqq", "6\naaaaaa", "4\naeta", "20\nttyttlwaoieulyiluuri", "1\nb", "3\nanc", "1\ne", "3\naie", "3\nvio", "2\nea", "3\nuas", "2\nba", "2\naq", "2\nya", "2\nou", "2\nbb", "7\nayylmao", "2\nab", "19\nyuouiyaoiiweqrryqqp", "25\niqypwqpriiioetiuqqqttouei", "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz", "17\naccccccccccccccca", "5\nababa", "10\naaaaaaaaaa", "22\naaaaabbbbboyoyoyoyoyac", "7\nmahmoud"], "outputs": ["werd", "word", "a", "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "mmmmmmmmmmmm", "ywptqwuqypwow", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "mmmmmmmmmmmmm", "mmmmmmmmmm", "mmmmmmmmmmm", "mmmmmmmmmmmmmmm", "a", "mmmmmmmmmmmmmm", "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "a", "iqpytiwli", "xxxxx", "xxxahg", "zcv", "apo", "qqqqq", "a", "ata", "ttyttlwalyluri", "b", "anc", "e", "a", "vi", "e", "us", "ba", "aq", "y", "o", "bb", "alma", "ab", "yweqrryqqp", "iqypwqpritiqqqtto", "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz", "accccccccccccccca", "ababa", "a", "abbbbboc", "mahmod"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 307 | codeforces |
|
adcd6dbdc21f29d273d9dcf1d6cb45ab | Tavas and Karafs | Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s**i*<==<=*A*<=+<=(*i*<=-<=1)<=×<=*B*.
For a given *m*, let's define an *m*-bite operation as decreasing the height of at most *m* distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you *n* queries. In each query he gives you numbers *l*, *t* and *m* and you should find the largest number *r* such that *l*<=≤<=*r* and sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* can be eaten by performing *m*-bite no more than *t* times or print -1 if there is no such number *r*.
The first line of input contains three integers *A*, *B* and *n* (1<=≤<=*A*,<=*B*<=≤<=106, 1<=≤<=*n*<=≤<=105).
Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=≤<=*l*,<=*t*,<=*m*<=≤<=106) for *i*-th query.
For each query, print its answer in a single line.
Sample Input
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
1 5 2
1 5 10
2 7 4
Sample Output
4
-1
8
-1
1
2
| {"inputs": ["2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8", "1 5 2\n1 5 10\n2 7 4", "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1", "1000000 1000000 1\n1000000 1000000 1000000", "999999 1000000 1\n1 1000000 1000000", "1 1000000 1\n1 1000000 1000000", "1 5000 1\n1 1000000 1000000", "1 1 1\n1 1000000 1000000", "447 74474 4\n47 777474 747\n74 744744 74477\n477 477447 777\n7 477777 444444"], "outputs": ["4\n-1\n8\n-1", "1\n2", "1000000\n1\n1413\n1", "-1", "1", "1", "200", "1000000", "-1\n-1\n-1\n7"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 10 | codeforces |
|
ade770083603ea41310a40d70e1f2c83 | Recover the String | For each string *s* consisting of characters '0' and '1' one can define four integers *a*00, *a*01, *a*10 and *a*11, where *a**xy* is the number of subsequences of length 2 of the string *s* equal to the sequence {*x*,<=*y*}.
In these problem you are given four integers *a*00, *a*01, *a*10, *a*11 and have to find any non-empty string *s* that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than 1<=000<=000.
The only line of the input contains four non-negative integers *a*00, *a*01, *a*10 and *a*11. Each of them doesn't exceed 109.
If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed 1<=000<=000.
Sample Input
1 2 3 4
1 2 2 1
Sample Output
Impossible
0110
| {"inputs": ["1 2 3 4", "1 2 2 1", "10 7 28 21", "0 0 0 0", "499928010 820999488 178951395 499991253", "49995000 11667 4308334 93096", "499928010 601314341 398636540 499991253", "0 2548 1752 650", "4950 53524 2876 158766", "20946628 20410736 263003096 958497436", "49995000 1061 8939 0", "0 0 0 45", "49995000 302076 4017924 93096", "105 2 598 780", "1 0 0 0", "0 0 0 1", "0 0 1 0", "0 1 0 0", "487577 9219238 1758432 61721604", "0 0 0 49995000", "49995000 0 0 0", "0 29083 917 449985000", "449985000 27522 2478 0", "49995000 49710535 50289465 49995000", "1000000000 0 0 0", "0 1000000000 0 0", "0 0 1000000000 0", "0 0 0 1000000000", "0 1 1 1", "1 1 1 0", "0 10000 10000 199990000", "1 20000 20001 200010000", "800020000 0 0 0", "0 0 0 800020000", "1 1 1 3", "199990000 202805432 197214568 200010000", "449985000 449414656 450735344 450135010", "450015000 147860287 152299718 50045010", "76935810 186858014 185577301 450675253", "499959631 500684485 499266399 499959631", "999961560 0 0 0", "1000000000 1000000000 1000000000 1000000000", "321451234 456748672 987936461 785645414", "123456789 987654321 123456789 1", "0 0 0 999961560", "999961560 31417 13304 0", "0 22769 21952 999961560", "4950 512066 487934 49995000", "49995000 479093 520907 4950", "999961560 999983920 999983921 999961560", "999916840 999939200 999939200 999916840", "999872121 999894480 999894481 999872121", "999827403 999849762 999849762 999827403", "4950 51367 5033 158766", "20946628 10679306 272734526 958497438", "49995000 584 9417 0", "105 14 588 780", "4950 15963710 22674282 11352058", "12497500 129337096 141847619 166302785", "511984000 6502095 8718005 17279400", "0 36 7 2", "496 41513 39598 43143", "127765 3290 752 1579", "93096 1351848 3613069 9687152", "89253 254334 736333 2741312", "499928010 25040 6580 2", "999961560 0 0 999961560", "999961560 0 0 0", "499959631 14240 17384 2", "450014999 312276555 663878 54397664", "999961560 69018 20424 1", "0 43292 1429 999961560", "999961560 7712000 4675717 38226", "38226 6041195 6346522 999961560", "124750 22337010 22490 999872121", "499928010 251220459 748730424 499991253", "499959631 82474061 917476823 499959631", "45 0 100 45", "449985000 0 900000000 449985000", "449985000 900000000 0 449985000", "799980000 0 400000000 49995000", "49995000 400000000 0 799980000", "49995000 0 400000000 799980000", "799980000 400000000 0 49995000", "799980000 0 400000 45", "45 400000 0 799980000", "45 0 400000 799980000", "799980000 400000 0 45", "199990000 300000000 300000000 449985000", "449985000 300000000 300000000 199990000", "312487500 250000000 375000000 312487500", "312487500 375000000 250000000 312487500", "647982000 324000000 648000000 364486500", "364486500 648000000 324000000 647982000", "499264200 0 998560000 499264200", "499295800 0 998623201 499295800", "499327401 0 998686404 499327401", "499359003 0 998749609 499359003", "499390606 0 998812816 499390606", "499422210 0 998876025 499422210", "499453815 0 998939236 499453815", "499485421 0 999002449 499485421", "499517028 0 999065664 499517028", "499264200 0 998876000 499580245", "499295800 0 998939211 499611855", "499327401 0 999002424 499643466", "499359003 0 999065639 499675078", "499390606 0 999128856 499706691", "499422210 0 999192075 499738305", "499453815 0 999255296 499769920", "499485421 0 999318519 499801536", "499517028 0 999381744 499833153", "499580245 998876000 0 499264200", "499611855 998939211 0 499295800", "499643466 999002424 0 499327401", "499675078 999065639 0 499359003", "499706691 999128856 0 499390606", "499738305 999192075 0 499422210", "499769920 999255296 0 499453815", "499801536 999318519 0 499485421", "499833153 999381744 0 499517028", "499264200 998560000 0 499264200", "499295800 998623201 0 499295800", "499327401 998686404 0 499327401", "499359003 998749609 0 499359003", "499390606 998812816 0 499390606", "499422210 998876025 0 499422210", "499453815 998939236 0 499453815", "499485421 999002449 0 499485421", "499517028 999065664 0 499517028", "737260800 998400000 215193600 499390606", "750761875 999750000 224866250 499359003", "762822270 999936000 234477180 499359003", "780697855 999729500 249063045 499359003", "799980000 1000000000 264000000 499264200", "750761875 999750000 224788750 499295800", "762822270 999936000 234438120 499327401", "780697855 999729500 249142075 499422210", "799980000 1000000000 264160000 499390606", "799980000 1000000000 240000000 480484500", "799980000 264000000 1000000000 499264200", "499295800 264040000 1000000000 799980000", "865592028 998592000 316220800 499264200", "499264200 373308800 998384000 942105528", "499264200 396072000 994580800 968330028", "968022000 924021000 704016000 684481500", "968066001 704032000 686431200 499264200", "968814171 730759419 660329019 499327401", "0 0 0 2", "544483500 0 0 0", "10 0 0 10", "6 4 0 0", "3 0 0 0", "3 10 10 0", "0 0 0 4", "6 0 0 0", "1 4 4 1", "10 0 0 6", "0 0 4 6", "3 0 0 3", "0 0 0 6", "0 1 1 0", "1 0 2 0", "0 0 2 1"], "outputs": ["Impossible", "0110", "011111110000", "0", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "Impossible", "Impossible", "Impossible", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111101100000000000000", "00", "11", "10", "01", "Impossible", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "Impossible", "Impossible", "Impossible", "Impossible", "101", "010", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "Impossible", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "Impossible", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "Impossible", "Impossible", "Impossible", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "Impossible", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "Impossible", "Impossible", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "11111111110000000000", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "Impossible", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "Impossible", "00001", "000", "Impossible", "Impossible", "0000", "Impossible", "Impossible", "11110", "Impossible", "1111", "Impossible", "100", "110"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 6 | codeforces |
|
ae083f1956b67b67e4911b0d0a0c0ecf | Preparing for Merge Sort | Ivan has an array consisting of *n* different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.
Ivan represent his array with increasing sequences with help of the following algorithm.
While there is at least one unused number in array Ivan repeats the following procedure:
- iterate through array from the left to the right; - Ivan only looks at unused numbers on current iteration; - if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down.
For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one — [2, 4].
Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of elements in Ivan's array.
The second line contains a sequence consisting of distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — Ivan's array.
Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.
Sample Input
5
1 3 2 5 4
4
4 3 2 1
4
10 30 50 101
Sample Output
1 3 5
2 4
4
3
2
1
10 30 50 101
| {"inputs": ["5\n1 3 2 5 4", "4\n4 3 2 1", "4\n10 30 50 101", "1\n1", "1\n200000", "2\n1 2", "2\n2 1", "2\n1 200000", "2\n200000 1", "10\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967", "3\n1 100 1000000000", "3\n1000000000 100 1"], "outputs": ["1 3 5 \n2 4 ", "4 \n3 \n2 \n1 ", "10 30 50 101 ", "1 ", "200000 ", "1 2 ", "2 \n1 ", "1 200000 ", "200000 \n1 ", "71550121 446173607 640274071 802030518 983359971 \n402690754 598196518 796619138 799843967 \n96204862 ", "1 100 1000000000 ", "1000000000 \n100 \n1 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 32 | codeforces |
|
ae0fdc5010d3494e36f04cc00ad43570 | Cutting | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins.
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
Sample Input
6 4
1 2 5 10 15 20
4 10
1 3 2 4
6 100
1 2 3 4 5 6
Sample Output
1
0
2
| {"inputs": ["6 4\n1 2 5 10 15 20", "4 10\n1 3 2 4", "6 100\n1 2 3 4 5 6", "2 100\n13 78", "10 1\n56 56 98 2 11 64 97 41 95 53", "10 100\n94 65 24 47 29 98 20 65 6 17", "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100 36 27 3 34 55 8 90 61 34 20 15 39 43 46 60 60 14 23 4 22 75 51 98 23 69 22 99 57 63 30 79 7 16 8 34 84 13 47 93 40 48 25 93 1 80 6 82 93 6 21", "100 10\n3 20 3 29 90 69 2 30 70 28 71 99 22 99 34 70 87 48 3 92 71 61 26 90 14 38 51 81 16 33 49 71 14 52 50 95 65 16 80 57 87 47 29 14 40 31 74 15 87 76 71 61 30 91 44 10 87 48 84 12 77 51 25 68 49 38 79 8 7 9 39 19 48 40 15 53 29 4 60 86 76 84 6 37 45 71 46 38 80 68 94 71 64 72 41 51 71 60 79 7", "100 100\n60 83 82 16 17 7 89 6 83 100 85 41 72 44 23 28 64 84 3 23 33 52 93 30 81 38 67 25 26 97 94 78 41 74 74 17 53 51 54 17 20 81 95 76 42 16 16 56 74 69 30 9 82 91 32 13 47 45 97 40 56 57 27 28 84 98 91 5 61 20 3 43 42 26 83 40 34 100 5 63 62 61 72 5 32 58 93 79 7 18 50 43 17 24 77 73 87 74 98 2", "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55", "100 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "10 10\n94 32 87 13 4 22 85 81 18 95", "10 50\n40 40 9 3 64 96 67 19 21 30", "100 50\n13 31 29 86 46 10 2 87 94 2 28 31 29 15 64 3 94 71 37 76 9 91 89 38 12 46 53 33 58 11 98 4 37 72 30 52 6 86 40 98 28 6 34 80 61 47 45 69 100 47 91 64 87 41 67 58 88 75 13 81 36 58 66 29 10 27 54 83 44 15 11 33 49 36 61 18 89 26 87 1 99 19 57 21 55 84 20 74 14 43 15 51 2 76 22 92 43 14 72 77", "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30", "100 10\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", "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34", "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "100 10\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "100 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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", "100 30\n2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1 2 1 1 2", "100 80\n1 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 2", "100 30\n100 99 100 99 99 100 100 99 100 99 99 100 100 100 99 99 99 100 99 99 99 99 100 99 99 100 100 99 100 99 99 99 100 99 100 100 99 100 100 100 100 100 99 99 100 99 99 100 99 100 99 99 100 100 99 100 99 99 100 99 100 100 100 100 99 99 99 100 99 100 99 100 100 100 99 100 100 100 99 100 99 99 100 100 100 100 99 99 99 100 99 100 100 99 99 99 100 100 99 99", "100 80\n99 100 100 100 99 99 99 99 100 99 99 99 99 99 99 99 99 100 100 99 99 99 99 99 100 99 100 99 100 100 100 100 100 99 100 100 99 99 100 100 100 100 100 99 100 99 100 99 99 99 100 99 99 99 99 99 99 99 99 100 99 100 100 99 99 99 99 100 100 100 99 100 100 100 100 100 99 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 100 100 100 100 99 100 99 100", "100 30\n100 100 39 39 39 100 100 39 39 100 39 39 100 39 100 39 100 100 100 100 100 39 100 100 100 39 39 39 100 39 100 100 39 39 100 39 39 39 100 100 39 100 39 100 39 39 100 100 39 100 39 100 39 39 39 100 39 100 39 39 39 100 39 39 100 100 39 39 39 100 100 39 39 39 100 100 100 100 39 100 100 100 39 39 100 39 100 100 39 100 39 100 39 39 100 39 39 100 100 100", "100 80\n39 100 39 100 100 100 100 39 39 100 100 39 39 100 39 39 39 39 100 39 39 39 39 100 100 100 100 39 100 39 39 100 100 39 39 100 39 100 39 100 100 39 39 100 39 39 39 100 39 100 39 100 100 100 100 100 100 100 39 100 39 100 100 100 39 39 39 39 39 100 100 100 39 100 100 100 100 39 100 100 39 39 100 39 39 39 100 39 100 39 39 100 100 39 100 39 39 39 100 39", "4 1\n1 2 3 4", "4 1\n1 2 1 2", "4 4\n1 2 6 7", "4 8\n1 2 10 11", "6 2\n1 2 3 4 5 6", "6 1\n1 2 1 2 1 2", "6 4\n1 2 4 5 7 8", "6 3\n1 2 5 10 15 20"], "outputs": ["1", "0", "2", "0", "0", "2", "0", "2", "11", "3", "49", "1", "1", "3", "0", "0", "1", "1", "10", "49", "11", "12", "14", "4", "5", "6", "1", "1", "1", "1", "2", "1", "2", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 234 | codeforces |
|
ae1ae244542fda4e96c524e9b099768c | President and Roads | Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town *t*, for which his motorcade passes along some path from *s* to *t* (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from *s* to *t*, along which he will travel the fastest.
The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer.
The first lines contain four integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (*s*<=≠<=*t*).
Next *m* lines contain the roads. Each road is given as a group of three integers *a**i*,<=*b**i*,<=*l**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*l**i*<=≤<=106) — the cities that are connected by the *i*-th road and the time needed to ride along it. The road is directed from city *a**i* to city *b**i*.
The cities are numbered from 1 to *n*. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from *s* to *t* along the roads.
Print *m* lines. The *i*-th line should contain information about the *i*-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the *i*-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.
If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes).
Sample Input
6 7 1 6
1 2 2
1 3 10
2 3 7
2 4 8
3 5 3
4 5 2
5 6 1
3 3 1 3
1 2 10
2 3 10
1 3 100
2 2 1 2
1 2 1
1 2 2
Sample Output
YES
CAN 2
CAN 1
CAN 1
CAN 1
CAN 1
YES
YES
YES
CAN 81
YES
NO
| {"inputs": ["6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 100", "2 2 1 2\n1 2 1\n1 2 2", "2 1 1 2\n1 2 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 19", "4 3 1 4\n1 2 1\n2 3 1\n3 4 1", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 2", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "6 6 1 6\n1 2 2\n2 3 4\n2 4 3\n3 5 2\n4 5 3\n5 6 10", "6 6 1 6\n1 2 2\n2 3 3\n2 4 3\n3 5 2\n4 5 3\n5 6 10", "2 1 1 2\n1 2 1", "2 2 1 2\n1 2 6\n1 2 6", "2 3 1 2\n1 2 7\n1 2 7\n1 2 7", "2 10 1 2\n1 2 5\n1 2 5\n1 2 7\n1 2 5\n1 2 6\n1 2 5\n1 2 5\n1 2 6\n1 2 5\n1 2 6", "3 2 1 2\n3 2 3\n1 3 6", "3 3 1 3\n2 3 7\n2 3 7\n1 2 6", "3 4 3 1\n2 1 4\n2 1 2\n3 2 1\n2 1 2", "3 5 1 2\n1 3 3\n1 2 9\n3 2 6\n1 2 10\n1 3 3", "3 7 1 3\n1 3 11\n1 3 12\n1 2 2\n1 3 11\n1 2 2\n2 3 9\n2 3 9", "5 7 3 2\n5 4 8\n3 1 2\n1 2 20\n1 5 8\n4 2 4\n1 5 8\n5 4 9", "7 8 5 3\n4 3 5\n7 1 8\n2 1 16\n2 7 7\n2 6 21\n5 2 10\n6 4 4\n1 6 5", "6 8 1 6\n1 2 13\n3 2 3\n4 5 6\n1 6 28\n1 3 10\n1 4 18\n2 4 4\n5 6 4", "7 10 4 7\n6 3 9\n2 1 4\n3 7 3\n5 2 6\n1 3 12\n5 2 6\n4 5 4\n4 5 3\n1 6 3\n4 6 16", "10 13 2 10\n7 3 5\n6 1 10\n9 6 4\n4 10 48\n9 5 2\n1 10 3\n5 6 2\n7 6 19\n4 8 8\n2 4 8\n8 7 7\n7 6 20\n3 9 10", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 4 3", "5 6 1 5\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6 1 5\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "2 1 1 2\n1 2 1", "3 3 1 3\n1 2 1\n1 3 2\n2 3 1", "10 10 1 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157", "10 10 1 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242", "3 3 1 3\n1 2 1\n2 3 1\n1 3 2", "6 7 1 6\n1 2 1000000\n2 3 1000000\n2 5 1000000\n1 3 1000000\n3 5 1000000\n2 4 1000000\n5 6 1000000", "2 1 1 2\n1 2 1000000", "2 2 1 2\n1 2 1000000\n1 2 1000000", "2 2 1 2\n1 2 1000000\n1 2 1000000", "2 9 1 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000", "2 9 1 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000", "3 2 1 3\n1 3 1\n1 2 1", "4 5 1 4\n1 2 1\n1 2 1\n2 3 1\n3 4 1\n3 4 1", "3 3 1 3\n1 2 666\n2 3 555\n3 1 1"], "outputs": ["YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES", "YES\nYES\nCAN 81", "YES\nNO", "YES", "CAN 2\nCAN 2\nYES", "YES\nYES\nYES", "NO\nNO\nYES\nCAN 1", "NO\nNO\nYES\nYES", "YES\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES", "YES\nYES\nCAN 2\nYES\nCAN 2\nYES", "YES", "CAN 1\nCAN 1", "CAN 1\nCAN 1\nCAN 1", "CAN 1\nCAN 1\nCAN 3\nCAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 2\nCAN 1\nCAN 2", "YES\nYES", "CAN 1\nCAN 1\nYES", "CAN 3\nCAN 1\nYES\nCAN 1", "CAN 1\nCAN 1\nCAN 1\nCAN 2\nCAN 1", "CAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nCAN 1", "CAN 1\nYES\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nCAN 2", "YES\nYES\nCAN 2\nYES\nCAN 2\nYES\nYES\nYES", "CAN 1\nCAN 1\nYES\nCAN 2\nCAN 1\nCAN 2\nYES\nYES", "CAN 1\nCAN 1\nYES\nCAN 1\nCAN 1\nCAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 1", "CAN 1\nYES\nCAN 1\nCAN 2\nCAN 1\nYES\nCAN 1\nCAN 1\nYES\nYES\nYES\nCAN 2\nCAN 1", "NO\nNO\nNO\nCAN 1", "NO\nCAN 3\nCAN 3\nYES\nYES\nYES", "NO\nCAN 3\nCAN 3\nYES\nYES\nYES", "YES", "NO\nCAN 1\nNO", "NO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES", "YES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES", "NO\nNO\nCAN 1", "CAN 1\nNO\nCAN 1\nCAN 1\nCAN 1\nNO\nYES", "YES", "CAN 1\nCAN 1", "CAN 1\nCAN 1", "NO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO", "CAN 999999\nCAN 999999\nCAN 999999\nCAN 999999\nYES\nCAN 999999\nCAN 999999\nCAN 999999\nCAN 999999", "YES\nNO", "NO\nNO\nYES\nNO\nNO", "YES\nYES\nNO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.