contestId
int64
0
1.01k
name
stringlengths
2
58
tags
sequencelengths
0
11
title
stringclasses
523 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
test_cases
listlengths
0
402
timeConsumedMillis
int64
0
8k
memoryConsumedBytes
int64
0
537M
score
float64
-1
3.99
__index_level_0__
int64
0
621k
301
Yaroslav and Time
[ "binary search", "graphs", "shortest paths" ]
null
null
Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has *n* clock stations, station number *i* is at point (*x**i*,<=*y**i*) of the plane. As the player visits station number *i*, he increases the current time on his timer by *a**i*. The stations are for one-time use only, so if the player visits some station another time, the time on his timer won't grow. A player spends *d*Β·*dist* time units to move between stations, where *dist* is the distance the player has covered and *d* is some constant. The distance between stations *i* and *j* is determined as |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Initially, the player is at station number 1, and the player has strictly more than zero and strictly less than one units of time. At station number 1 one unit of money can increase the time on the timer by one time unit (you can buy only integer number of time units). Now Yaroslav is wondering, how much money he needs to get to station *n*. Help Yaroslav. Consider the time to buy and to increase the timer value negligibly small.
The first line contains integers *n* and *d* (3<=≀<=*n*<=≀<=100,<=103<=≀<=*d*<=≀<=105) β€” the number of stations and the constant from the statement. The second line contains *n*<=-<=2 integers: *a*2,<=*a*3,<=...,<=*a**n*<=-<=1 (1<=≀<=*a**i*<=≀<=103). The next *n* lines contain the coordinates of the stations. The *i*-th of them contains two integers *x**i*, *y**i* (-100<=≀<=*x**i*,<=*y**i*<=≀<=100). It is guaranteed that no two stations are located at the same point.
In a single line print an integer β€” the answer to the problem.
[ "3 1000\n1000\n0 0\n0 1\n0 3\n", "3 1000\n1000\n1 0\n1 1\n1 2\n" ]
[ "2000\n", "1000\n" ]
none
[ { "input": "3 1000\n1000\n0 0\n0 1\n0 3", "output": "2000" }, { "input": "3 1000\n1000\n1 0\n1 1\n1 2", "output": "1000" }, { "input": "5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67", "output": "169099" }, { "input": "6 1000\n142 712 254 869\n7 0\n95 38\n96 -20\n-7 93\n75 -45\n-80 -20", "output": "107000" }, { "input": "7 1288\n943 265 649 447 806\n-4 -51\n-26 32\n47 -28\n31 32\n61 65\n-45 -37\n82 42", "output": "229903" }, { "input": "8 1931\n440 627 324 538 539 119\n-85 -41\n-91 61\n-84 11\n92 -19\n8 -5\n16 -25\n97 -98\n91 78", "output": "569018" }, { "input": "9 1829\n98 513 987 291 162 637 356\n38 -3\n-89 93\n-86 45\n-43 -84\n-3 -87\n53 -59\n18 -19\n81 -74\n-85 32", "output": "288982" }, { "input": "10 1000\n759 222 589 423 947 507 31 414\n-4 -71\n-31 -53\n24 28\n-13 -65\n-59 -49\n-42 -79\n85 -71\n-60 -17\n28 66\n74 2", "output": "151000" }, { "input": "11 1199\n282 735 54 1000 419 939 901 789 128\n10 -81\n26 72\n19 -91\n-61 85\n0 -33\n-62 79\n-59 65\n-2 -77\n-63 100\n-15 53\n94 54", "output": "262581" }, { "input": "12 1609\n196 486 94 344 524 588 315 504 449 201\n86 -22\n-2 25\n-95 -8\n-5 -30\n-78 71\n5 -54\n-69 -92\n-41 0\n10 19\n61 17\n75 -39\n-46 22", "output": "282231" }, { "input": "3 97325\n40\n43 43\n45 -95\n-93 63", "output": "15182700" }, { "input": "11 1615\n137 681 199 33 388 585 241 518 7\n-60 89\n24 6\n-100 -55\n-26 -90\n-40 -33\n-100 28\n12 34\n-60 -13\n38 -89\n62 81\n-35 54", "output": "96900" }, { "input": "22 1000\n94 609 173 244 930 515 169 56 192 974 923 749 652 987 145 447 578 518 630 917\n13 93\n99 6\n41 -54\n67 -85\n24 38\n23 -65\n9 -60\n-29 -78\n-29 -32\n53 -70\n-83 -50\n31 1\n-85 16\n74 95\n-30 89\n89 -67\n70 -74\n-78 -73\n19 17\n97 4\n97 -27\n-4 -48", "output": "158000" }, { "input": "4 62071\n706 480\n6 96\n51 -12\n99 66\n-69 -61", "output": "14400472" }, { "input": "12 1542\n389 356 290 648 182 94 585 988 762 494\n-46 96\n1 88\n0 95\n-91 -100\n-42 -29\n45 -27\n-52 -34\n-62 27\n-19 46\n-100 95\n5 -55\n-36 -65", "output": "263034" }, { "input": "3 100000\n1\n-100 -100\n-100 -99\n100 100", "output": "39999999" }, { "input": "12 1211\n1 5 7 1000 1000 1000 1000 1000 1000 1000\n1 1\n5 5\n3 4\n4 3\n0 1\n0 2\n0 5\n0 7\n1 0\n3 0\n8 0\n10 10", "output": "20220" }, { "input": "6 1000\n1000 1000 1000 1000\n0 0\n0 -1\n1 -1\n2 -1\n2 0\n2 1", "output": "1000" } ]
248
307,200
3
32,456
960
Pathwalks
[ "data structures", "dp", "graphs" ]
null
null
You are given a directed graph with *n* nodes and *m* edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value. Please note that the edges picked don't have to be consecutive in the input.
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=100000,1<=≀<=*m*<=≀<=100000)Β β€” the number of vertices and edges in the graph, respectively. *m* lines follows. The *i*-th of these lines contains three space separated integers *a**i*, *b**i* and *w**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*, 0<=≀<=*w**i*<=≀<=100000), denoting an edge from vertex *a**i* to vertex *b**i* having weight *w**i*
Print one integer in a single line β€” the maximum number of edges in the path.
[ "3 3\n3 1 3\n1 2 1\n2 3 2\n", "5 5\n1 3 2\n3 2 3\n3 4 5\n5 4 0\n4 5 8\n" ]
[ "2", "3" ]
The answer for the first sample input is 2: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/609340f155794c4e9eebcd9cdfa23c73cf982f28.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that you cannot traverse <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9b1d1f66686c43090329870c208942499764a73b.png" style="max-width: 100.0%;max-height: 100.0%;"/> because edge <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/030fc9181b578c2d906254d38dc56da5554323eb.png" style="max-width: 100.0%;max-height: 100.0%;"/> appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges. In the second sample, it's optimal to pick 1-st, 3-rd and 5-th edges to get the optimal answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bd608e0d11c1e7d39405f62afde4e5a2d18cecf6.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "3 3\n3 1 3\n1 2 1\n2 3 2", "output": "2" }, { "input": "5 5\n1 3 2\n3 2 3\n3 4 5\n5 4 0\n4 5 8", "output": "3" }, { "input": "5 10\n3 4 8366\n5 1 6059\n2 1 72369\n2 2 35472\n5 3 50268\n2 4 98054\n5 1 26220\n2 3 24841\n1 3 42450\n3 1 59590", "output": "3" }, { "input": "1000 10\n11 368 48256\n192 176 81266\n236 360 25346\n377 962 3089\n486 176 49857\n693 810 36660\n692 698 35141\n879 822 10964\n974 439 31998\n364 142 62668", "output": "1" }, { "input": "1 1\n1 1 1000", "output": "1" }, { "input": "6 5\n1 2 1\n2 3 2\n3 4 3\n5 4 10\n4 6 11", "output": "4" } ]
1,000
10,956,800
0
32,501
0
none
[ "none" ]
null
null
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors *x* and *y* of size *n* is the sum of the products of the corresponding components of the vectors. The unusual square of an *n*<=Γ—<=*n* square matrix *A* is defined as the sum of *n* dot products. The *i*-th of them is the dot product of the *i*-th row vector and the *i*-th column vector in the matrix *A*. Fortunately for Chris, he has to work only in *GF*(2)! This means that all operations (addition, multiplication) are calculated modulo 2. In fact, the matrix *A* is binary: each element of *A* is either 0 or 1. For example, consider the following matrix *A*: The unusual square of *A* is equal to (1Β·1<=+<=1Β·0<=+<=1Β·1)<=+<=(0Β·1<=+<=1Β·1<=+<=1Β·0)<=+<=(1Β·1<=+<=0Β·1<=+<=0Β·0)<==<=0<=+<=1<=+<=1<==<=0. However, there is much more to the homework. Chris has to process *q* queries; each query can be one of the following: 1. given a row index *i*, flip all the values in the *i*-th row in *A*; 1. given a column index *i*, flip all the values in the *i*-th column in *A*; 1. find the unusual square of *A*. To flip a bit value *w* means to change it to 1<=-<=*w*, i.e., 1 changes to 0 and 0 changes to 1. Given the initial matrix *A*, output the answers for each query of the third type! Can you solve Chris's homework?
The first line of input contains an integer *n* (1<=≀<=*n*<=≀<=1000), the number of rows and the number of columns in the matrix *A*. The next *n* lines describe the matrix: the *i*-th line contains *n* space-separated bits and describes the *i*-th row of *A*. The *j*-th number of the *i*-th line *a**ij* (0<=≀<=*a**ij*<=≀<=1) is the element on the intersection of the *i*-th row and the *j*-th column of *A*. The next line of input contains an integer *q* (1<=≀<=*q*<=≀<=106), the number of queries. Each of the next *q* lines describes a single query, which can be one of the following: - 1 *i* β€” flip the values of the *i*-th row; - 2 *i* β€” flip the values of the *i*-th column; - 3 β€” output the unusual square of *A*. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
Let the number of the 3rd type queries in the input be *m*. Output a single string *s* of length *m*, where the *i*-th symbol of *s* is the value of the unusual square of *A* for the *i*-th query of the 3rd type as it appears in the input.
[ "3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3\n" ]
[ "01001\n" ]
none
[ { "input": "3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3", "output": "01001" }, { "input": "1\n1\n9\n1 1\n3\n1 1\n1 1\n3\n1 1\n3\n1 1\n3", "output": "0010" }, { "input": "3\n1 0 1\n0 1 1\n1 0 1\n4\n3\n3\n3\n3", "output": "1111" }, { "input": "1\n0\n5\n1 1\n3\n1 1\n1 1\n3", "output": "11" }, { "input": "2\n0 0\n0 0\n9\n3\n1 2\n2 2\n1 1\n2 1\n3\n1 2\n1 1\n3", "output": "000" }, { "input": "2\n0 1\n1 0\n7\n3\n3\n2 2\n3\n2 2\n2 1\n3", "output": "0011" }, { "input": "5\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n7\n3\n2 4\n1 3\n3\n2 5\n1 5\n3", "output": "111" }, { "input": "2\n1 0\n1 0\n4\n1 2\n3\n1 2\n3", "output": "01" }, { "input": "4\n1 1 0 0\n1 1 0 0\n0 0 0 0\n0 0 0 0\n2\n1 1\n3", "output": "1" }, { "input": "2\n1 1\n1 0\n5\n3\n1 1\n3\n2 1\n3", "output": "101" }, { "input": "2\n1 0\n1 1\n6\n1 2\n3\n2 1\n3\n1 1\n3", "output": "101" }, { "input": "2\n0 0\n0 0\n2\n1 1\n3", "output": "1" }, { "input": "2\n1 0\n0 1\n1\n3", "output": "0" } ]
951
73,318,400
3
32,577
144
Meeting
[ "implementation" ]
null
null
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits. Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the number *r**i* β€” the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal to *r**i*, than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points (*x*1,<=*y*1) and (*x*2,<=*y*2) is Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place. The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under the table) or on the perimeter (directly under some general). Even in this case their radius does not change.
The first input line contains coordinates of two opposite table corners *x**a*, *y**a*, *x**b*, *y**b* (*x**a*<=β‰ <=*x**b*,<=*y**a*<=β‰ <=*y**b*). The second line contains integer *n* β€” the number of radiators (1<=≀<=*n*<=≀<=103). Then *n* lines contain the heaters' coordinates as "*x**i* *y**i* *r**i*", the numbers are separated by spaces. All input data numbers are integers. The absolute value of all coordinates does not exceed 1000, 1<=≀<=*r**i*<=≀<=1000. Several radiators can be located at the same point.
Print the only number β€” the number of blankets you should bring.
[ "2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2\n", "5 2 6 3\n2\n6 2 2\n6 5 3\n" ]
[ "4\n", "0\n" ]
In the first sample the generals are sitting at points: (2, 2), (2, 3), (2, 4), (2, 5), (3, 2), (3, 5), (4, 2), (4, 3), (4, 4), (4, 5). Among them, 4 generals are located outside the heating range. They are the generals at points: (2, 5), (3, 5), (4, 4), (4, 5). In the second sample the generals are sitting at points: (5, 2), (5, 3), (6, 2), (6, 3). All of them are located inside the heating range.
[ { "input": "2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2", "output": "4" }, { "input": "5 2 6 3\n2\n6 2 2\n6 5 3", "output": "0" }, { "input": "-705 595 -702 600\n1\n-589 365 261", "output": "4" }, { "input": "-555 674 -553 774\n5\n-656 128 631\n597 -220 999\n-399 793 155\n-293 -363 1000\n-557 -914 1000", "output": "49" }, { "input": "-210 783 -260 833\n10\n406 551 1000\n372 -373 999\n-12 -532 999\n371 -30 999\n258 480 558\n648 -957 1000\n-716 654 473\n156 813 366\n-870 425 707\n-288 -426 1000", "output": "0" }, { "input": "671 244 771 1000\n20\n701 904 662\n170 -806 1000\n-330 586 1000\n466 467 205\n-736 266 999\n629 734 42\n-616 630 999\n-94 416 765\n-98 280 770\n288 597 384\n-473 266 999\n-330 969 999\n492 -445 713\n352 -967 1000\n401 -340 645\n400 -80 425\n-177 560 848\n361 -7 400\n-564 -807 1000\n621 333 51", "output": "20" }, { "input": "-343 -444 -419 -421\n30\n363 -249 790\n704 57 999\n-316 -305 119\n-778 -543 373\n-589 466 904\n516 -174 893\n-742 -662 390\n-382 825 1000\n520 -732 909\n-220 -985 555\n-39 -697 396\n-701 -882 520\n-105 227 691\n-113 -470 231\n-503 98 525\n236 69 759\n150 393 951\n414 381 1000\n849 530 999\n-357 485 905\n432 -616 794\n123 -465 467\n768 -875 1000\n61 -932 634\n375 -410 718\n-860 -624 477\n49 264 789\n-409 -874 429\n876 -169 999\n-458 345 767", "output": "42" }, { "input": "0 0 1 1\n1\n-1 -1000 1000", "output": "4" }, { "input": "1 1 1000 1000\n1\n50 50 1", "output": "3996" } ]
2,000
614,400
0
32,602
425
Sereja and Squares
[ "binary search", "data structures", "hashing" ]
null
null
Sereja has painted *n* distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.
The first line contains integer *n* (1<=≀<=*n*<=≀<=105). Each of the next *n* lines contains two integers *x**i*,<=*y**i* (0<=≀<=*x**i*,<=*y**i*<=≀<=105), the integers represent the coordinates of the *i*-th point. It is guaranteed that all the given points are distinct.
In a single line print the required number of squares.
[ "5\n0 0\n0 2\n2 0\n2 2\n1 1\n", "9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1\n" ]
[ "1\n", "5\n" ]
none
[ { "input": "5\n0 0\n0 2\n2 0\n2 2\n1 1", "output": "1" }, { "input": "9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1", "output": "5" }, { "input": "54\n0 8\n3 2\n9 3\n7 2\n8 2\n2 8\n10 10\n7 6\n1 1\n9 7\n4 0\n6 10\n10 1\n10 8\n5 1\n0 4\n7 10\n3 6\n0 5\n4 3\n3 0\n5 10\n6 9\n5 4\n6 6\n8 5\n0 7\n5 8\n1 2\n2 2\n9 4\n2 4\n0 10\n5 9\n10 9\n7 9\n9 9\n2 5\n4 10\n8 9\n7 7\n5 2\n6 5\n4 1\n10 6\n6 3\n9 6\n0 9\n7 3\n7 5\n8 4\n1 3\n0 3\n2 10", "output": "14" }, { "input": "87\n5 10\n5 0\n9 2\n2 4\n6 6\n4 4\n3 4\n0 3\n10 6\n1 0\n7 1\n2 5\n6 10\n5 3\n1 6\n8 7\n5 6\n5 9\n9 8\n2 6\n6 9\n6 4\n3 2\n10 10\n0 4\n8 9\n8 8\n4 8\n10 2\n10 0\n3 8\n8 2\n3 1\n9 5\n9 1\n5 4\n4 6\n10 7\n2 0\n10 9\n9 0\n9 9\n6 2\n3 9\n10 8\n7 0\n7 3\n6 0\n5 2\n6 5\n4 7\n1 3\n9 7\n1 5\n4 1\n7 10\n0 2\n0 8\n9 10\n0 5\n4 10\n7 4\n1 8\n2 7\n10 3\n9 3\n10 5\n6 1\n8 3\n10 1\n8 0\n5 1\n3 10\n10 4\n2 10\n4 5\n5 7\n7 9\n1 7\n8 6\n1 1\n7 2\n7 5\n5 5\n1 4\n6 8\n6 3", "output": "101" }, { "input": "3\n1 6\n10 8\n4 3", "output": "0" }, { "input": "72\n8 2\n2 4\n3 5\n9 10\n7 6\n1 5\n0 0\n3 3\n1 6\n7 10\n8 8\n7 9\n6 0\n3 6\n9 3\n8 1\n3 4\n3 7\n0 7\n10 8\n2 6\n6 8\n0 6\n5 6\n6 6\n6 5\n6 4\n0 2\n9 9\n4 8\n7 2\n8 0\n9 4\n0 10\n4 5\n9 8\n10 3\n8 7\n8 5\n7 7\n6 7\n5 7\n5 4\n8 4\n3 2\n7 3\n9 0\n0 8\n0 5\n3 9\n2 10\n7 1\n4 3\n1 10\n3 0\n5 9\n10 1\n6 1\n4 10\n1 0\n2 1\n2 0\n3 8\n10 7\n7 4\n0 9\n1 1\n1 8\n8 3\n5 2\n6 3\n4 2", "output": "51" }, { "input": "71\n5 3\n1 10\n10 3\n5 2\n3 5\n10 9\n10 2\n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n1 8", "output": "11" }, { "input": "1\n0 0", "output": "0" }, { "input": "1\n100000 100000", "output": "0" } ]
2,000
3,481,600
0
32,604
0
none
[ "none" ]
null
null
Π ΠΎΠ΄ΠΈΡ‚Π΅Π»ΠΈ Васи хотят, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ ΠΊΠ°ΠΊ ΠΌΠΎΠΆΠ½ΠΎ Π»ΡƒΡ‡ΡˆΠ΅ учился. ΠŸΠΎΡΡ‚ΠΎΠΌΡƒ Ссли ΠΎΠ½ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ подряд Ρ‚Ρ€ΠΈ ΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΎΡ†Π΅Π½ΠΊΠΈ (Β«Ρ‡Π΅Ρ‚Π²Ρ‘Ρ€ΠΊΠΈΒ» ΠΈΠ»ΠΈ «пятёрки»), ΠΎΠ½ΠΈ дарят Π΅ΠΌΡƒ ΠΏΠΎΠ΄Π°Ρ€ΠΎΠΊ. БоотвСтствСнно, ΠΎΡ†Π΅Π½ΠΊΠΈ Β«Π΅Π΄ΠΈΠ½ΠΈΡ†Π°Β», Β«Π΄Π²ΠΎΠΉΠΊΠ°Β» ΠΈ Β«Ρ‚Ρ€ΠΎΠΉΠΊΠ°Β» Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΠΈ Васи ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ ΠΏΠ»ΠΎΡ…ΠΈΠΌΠΈ. Когда Вася ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ подряд Ρ‚Ρ€ΠΈ Ρ…ΠΎΡ€ΠΎΡˆΠΈΠ΅ ΠΎΡ†Π΅Π½ΠΊΠΈ, Π΅ΠΌΡƒ сразу Π²Ρ€ΡƒΡ‡Π°ΡŽΡ‚ ΠΏΠΎΠ΄Π°Ρ€ΠΎΠΊ, Π½ΠΎ для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ Π΅Ρ‰Ρ‘ ΠΎΠ΄ΠΈΠ½ ΠΏΠΎΠ΄Π°Ρ€ΠΎΠΊ, Π΅ΠΌΡƒ вновь Π½Π°Π΄ΠΎ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ подряд Π΅Ρ‰Ρ‘ Ρ‚Ρ€ΠΈ Ρ…ΠΎΡ€ΠΎΡˆΠΈΠ΅ ΠΎΡ†Π΅Π½ΠΊΠΈ. НапримСр, Ссли Вася ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ подряд ΠΏΡΡ‚ΡŒ Β«Ρ‡Π΅Ρ‚Π²Ρ‘Ρ€ΠΎΠΊΒ» ΠΎΡ†Π΅Π½ΠΎΠΊ, Π° ΠΏΠΎΡ‚ΠΎΠΌ Β«Π΄Π²ΠΎΠΉΠΊΡƒΒ», Ρ‚ΠΎ Π΅ΠΌΡƒ Π΄Π°Π΄ΡƒΡ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄ΠΈΠ½ ΠΏΠΎΠ΄Π°Ρ€ΠΎΠΊ, Π° Π²ΠΎΡ‚ Ссли Π±Ρ‹ Β«Ρ‡Π΅Ρ‚Π²Ρ‘Ρ€ΠΎΠΊΒ» Π±Ρ‹Π»ΠΎ ΡƒΠΆΠ΅ ΡˆΠ΅ΡΡ‚ΡŒ, Ρ‚ΠΎ ΠΏΠΎΠ΄Π°Ρ€ΠΊΠΎΠ² Π±Ρ‹Π»ΠΎ Π±Ρ‹ Π΄Π²Π°. Π—Π° мСсяц Вася ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠ» *n* ΠΎΡ†Π΅Π½ΠΎΠΊ. Π’Π°ΠΌ прСдстоит ΠΏΠΎΡΡ‡ΠΈΡ‚Π°Ρ‚ΡŒ количСство ΠΏΠΎΠ΄Π°Ρ€ΠΊΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠ» Вася. ΠžΡ†Π΅Π½ΠΊΠΈ Π±ΡƒΠ΄ΡƒΡ‚ Π΄Π°Π½Ρ‹ ΠΈΠΌΠ΅Π½Π½ΠΎ Π² Ρ‚ΠΎΠΌ порядкС, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ Вася ΠΈΡ… ΠΏΠΎΠ»ΡƒΡ‡Π°Π».
Π’ ΠΏΠ΅Ρ€Π²ΠΎΠΉ строкС Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… слСдуСт Ρ†Π΅Π»ΠΎΠ΅ ΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ число *n* (3<=≀<=*n*<=≀<=1000)Β β€” количСство ΠΎΡ†Π΅Π½ΠΎΠΊ, ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹Ρ… ВасСй. Π’ΠΎ Π²Ρ‚ΠΎΡ€ΠΎΠΉ строкС Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… слСдуСт ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΈΠ· *n* чисСл *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=5)Β β€” ΠΎΡ†Π΅Π½ΠΊΠΈ, ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹Π΅ ВасСй. ΠžΡ†Π΅Π½ΠΊΠΈ Π·Π°Π΄Π°Π½Ρ‹ Π² Ρ‚ΠΎΠΌ порядкС, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ Вася ΠΈΡ… ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠ».
Π’Ρ‹Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΎΠ΄Π½ΠΎ Ρ†Π΅Π»ΠΎΠ΅ число — количСство ΠΏΠΎΠ΄Π°Ρ€ΠΊΠΎΠ², ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹Ρ… ВасСй.
[ "6\n4 5 4 5 4 4\n", "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5\n" ]
[ "2\n", "3\n" ]
Π’ ΠΏΠ΅Ρ€Π²ΠΎΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ Вася ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ Π΄Π²Π° ΠΏΠΎΠ΄Π°Ρ€ΠΊΠ°Β β€” Π·Π° ΠΏΠ΅Ρ€Π²Ρ‹Π΅ Ρ‚Ρ€ΠΈ ΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΎΡ†Π΅Π½ΠΊΠΈ ΠΈ Π·Π° ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ Ρ‚Ρ€ΠΎΠΉΠΊΡƒ ΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… ΠΎΡ†Π΅Π½ΠΎΠΊ соотвСтствСнно.
[ { "input": "6\n4 5 4 5 4 4", "output": "2" }, { "input": "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5", "output": "3" }, { "input": "3\n4 5 4", "output": "1" }, { "input": "3\n4 5 1", "output": "0" }, { "input": "4\n5 4 3 5", "output": "0" }, { "input": "10\n4 4 5 4 4 5 5 5 4 4", "output": "3" }, { "input": "20\n5 5 5 4 5 4 5 5 5 5 5 4 4 5 3 4 4 4 5 4", "output": "5" }, { "input": "30\n4 4 5 5 5 4 5 5 4 5 4 4 5 4 4 4 5 4 4 4 5 5 5 5 4 5 5 5 4 4", "output": "10" }, { "input": "40\n5 4 4 5 5 5 1 5 4 4 4 4 4 2 4 4 4 4 4 4 5 4 4 4 5 5 3 4 4 5 5 5 4 4 4 4 4 1 3 4", "output": "11" }, { "input": "50\n4 5 4 4 5 2 4 4 1 3 5 4 4 4 4 5 5 5 5 3 5 4 4 5 5 4 4 4 5 4 4 4 4 4 2 4 5 4 4 4 1 5 4 5 4 5 4 1 4 4", "output": "11" }, { "input": "60\n4 4 5 5 5 4 4 5 4 4 4 4 5 5 4 5 4 2 4 5 5 4 5 4 5 5 5 4 4 5 5 4 4 5 4 5 4 5 4 5 5 5 4 5 5 5 5 4 4 4 5 4 5 5 4 4 4 5 5 5", "output": "19" }, { "input": "70\n5 4 4 4 4 4 5 4 4 5 4 5 4 3 5 5 5 4 4 5 5 4 4 4 4 5 4 4 5 5 4 4 5 4 5 4 5 4 4 4 5 5 4 4 4 4 5 4 4 4 5 5 5 5 4 4 4 1 5 5 4 1 5 5 4 4 5 4 4 5", "output": "21" }, { "input": "80\n5 5 4 4 5 5 4 4 5 4 4 4 5 5 4 4 5 4 5 5 4 4 5 4 4 4 5 5 5 5 5 4 5 5 4 4 4 4 4 5 5 5 1 4 4 5 4 4 5 4 5 5 3 5 5 5 2 4 4 5 5 5 5 5 2 4 5 5 5 4 5 4 4 4 3 4 4 2 5 4", "output": "23" }, { "input": "90\n4 4 4 4 4 5 4 4 5 4 5 5 4 5 5 5 5 5 5 5 5 4 5 5 4 4 4 5 4 5 5 5 5 5 4 5 5 4 5 5 4 4 5 5 4 5 5 4 5 5 5 5 4 5 4 4 5 5 4 3 5 5 5 5 5 5 5 1 5 5 4 4 5 5 4 5 4 5 5 4 4 4 4 4 4 4 5 5 4 5", "output": "28" }, { "input": "100\n4 4 5 5 4 4 5 4 4 4 5 5 4 4 4 4 4 4 4 4 5 4 5 5 5 5 5 5 4 5 5 5 5 4 5 5 4 4 5 4 5 5 3 4 4 4 4 4 5 5 4 5 4 5 4 4 4 4 5 4 4 5 5 5 4 4 5 5 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5 5 5 5 4 4 5 5 4 5 4 5 3 4 5 5 4 4 4 5 4 5 5 4 4 4 5 5 4 4 4 4 4 5", "output": "76" }, { "input": "250\n4 4 2 5 1 5 5 4 5 4 4 4 4 4 4 5 5 4 4 5 4 5 1 5 5 4 1 5 5 4 5 5 4 4 4 4 5 4 4 5 5 5 5 5 4 5 4 5 5 4 5 4 4 4 4 4 4 5 5 4 5 5 1 4 4 4 5 1 5 3 4 5 4 4 4 4 4 5 5 4 4 4 4 4 5 4 5 5 5 4 4 5 4 4 4 5 5 5 5 4 5 4 5 4 5 5 5 5 4 4 4 4 5 5 5 5 5 5 4 4 3 4 4 5 5 3 5 4 4 4 4 4 4 5 5 5 4 5 4 4 4 2 4 5 5 5 5 5 5 5 4 5 5 4 5 3 5 4 4 5 5 5 5 4 3 5 5 1 5 5 5 5 4 4 5 4 4 4 4 5 4 5 4 4 4 5 5 3 4 5 5 4 4 4 5 4 4 4 4 4 4 4 5 5 4 4 5 4 5 4 4 5 4 4 5 5 5 4 5 4 1 4 4 5 4 4 4 4 5 2 4 4 5 5 5 4 5 4 5 5 5 4 4 4 4 4 4 1 5 5", "output": "69" }, { "input": "7\n4 5 3 4 5 4 1", "output": "1" }, { "input": "9\n4 5 4 3 3 3 4 4 4", "output": "2" }, { "input": "10\n4 5 4 5 4 5 4 5 3 4", "output": "2" }, { "input": "10\n4 3 4 5 4 5 4 5 4 3", "output": "2" }, { "input": "6\n4 5 3 4 5 4", "output": "1" }, { "input": "6\n3 3 3 4 5 5", "output": "1" }, { "input": "11\n5 5 5 5 5 5 5 5 5 5 5", "output": "3" }, { "input": "18\n4 5 4 3 3 3 2 2 2 4 4 4 1 1 1 4 5 4", "output": "3" }, { "input": "8\n4 4 4 4 5 5 5 5", "output": "2" }, { "input": "9\n5 5 5 4 4 4 3 4 4", "output": "2" } ]
77
4,608,000
3
32,703
753
Interactive Bulls and Cows (Easy)
[ "brute force", "constructive algorithms", "implementation" ]
null
null
This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java β€” call System.out.flush(), and in Pascal β€” flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers β€” the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is *s* and the second player are trying to guess it with a string *x*. The number of "bulls" is a number of such positions *i* (1<=≀<=*i*<=≀<=4) where *s*[*i*]<==<=*x*[*i*]. The number of "cows" is a number of such digits *c* that *s* contains *c* in the position *i* (i.e. *s*[*i*]<==<=*c*), *x* contains *c*, but *x*[*i*]<=β‰ <=*c*. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string *s* that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons β€” the program either guessed the number *x* or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits β€” the secret string.
To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string *s* and the string *x**i* printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the *i*-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value *x**i* in a single line and executes operation flush.
The program must use the standard output to print queries. Your program must output requests β€” 4-digit strings *x*1,<=*x*2,<=..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries.
[ "0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n" ]
[ "8000\n0179\n3159\n3210\n0112\n0123" ]
The secret string *s* in the example is "0123".
[ { "input": "0123", "output": "20" }, { "input": "1234", "output": "20" }, { "input": "9876", "output": "20" }, { "input": "7158", "output": "20" }, { "input": "7590", "output": "20" }, { "input": "7325", "output": "20" }, { "input": "7524", "output": "20" }, { "input": "7269", "output": "20" }, { "input": "7802", "output": "20" }, { "input": "7436", "output": "20" }, { "input": "7190", "output": "20" }, { "input": "7390", "output": "20" }, { "input": "2548", "output": "20" }, { "input": "2193", "output": "20" }, { "input": "2491", "output": "20" }, { "input": "2469", "output": "20" }, { "input": "2659", "output": "20" }, { "input": "2405", "output": "20" }, { "input": "2058", "output": "20" }, { "input": "2580", "output": "20" }, { "input": "2316", "output": "20" }, { "input": "2516", "output": "20" }, { "input": "8796", "output": "20" }, { "input": "8534", "output": "20" }, { "input": "9067", "output": "20" }, { "input": "8712", "output": "20" }, { "input": "9023", "output": "20" }, { "input": "8645", "output": "20" }, { "input": "8623", "output": "20" }, { "input": "8923", "output": "20" }, { "input": "8567", "output": "20" }, { "input": "8756", "output": "20" }, { "input": "0351", "output": "20" }, { "input": "9863", "output": "20" }, { "input": "0518", "output": "20" }, { "input": "0263", "output": "20" }, { "input": "0462", "output": "20" }, { "input": "0429", "output": "20" }, { "input": "0629", "output": "20" }, { "input": "0374", "output": "20" }, { "input": "3209", "output": "20" } ]
46
4,608,000
-1
32,707
744
Hongcow Draws a Circle
[ "geometry" ]
null
null
Hongcow really likes the color red. Hongcow doesn't like the color blue. Hongcow is standing in an infinite field where there are *n* red points and *m* blue points. Hongcow wants to draw a circle in the field such that this circle contains at least one red point, and no blue points. Points that line exactly on the boundary of the circle can be counted as either inside or outside. Compute the radius of the largest circle that satisfies this condition. If this circle can have arbitrarily large size, print <=-<=1. Otherwise, your answer will be accepted if it has relative or absolute error at most 10<=-<=4.
The first line of the input will contain two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=1,<=000). The next *n* lines will contain two integers *x**i*,<=*y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=104). This denotes the coordinates of a red point. The next *m* lines will contain two integers *x**i*,<=*y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=104). This denotes the coordinates of a blue point. No two points will have the same coordinates.
Print <=-<=1 if the circle can have arbitrary size. Otherwise, print a floating point number representing the largest radius circle that satisfies the conditions. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4. Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "2 5\n2 3\n3 4\n1 1\n1 4\n4 2\n4 7\n2 5\n", "1 6\n3 3\n1 5\n5 4\n2 1\n3 4\n4 2\n1 3\n", "2 2\n2 2\n3 3\n1 1\n4 4\n" ]
[ "3.5355338827\n", "1.5811388195\n", "-1\n" ]
This is a picture of the first sample This is a picture of the second sample
[]
30
0
0
32,808
451
Devu and Flowers
[ "bitmasks", "combinatorics", "number theory" ]
null
null
Devu wants to decorate his garden with flowers. He has purchased *n* boxes, where the *i*-th box contains *f**i* flowers. All flowers in a single box are of the same color (hence they are indistinguishable). Also, no two boxes have flowers of the same color. Now Devu wants to select exactly *s* flowers from the boxes to decorate his garden. Devu would like to know, in how many different ways can he select the flowers from each box? Since this number may be very large, he asks you to find the number modulo (109<=+<=7). Devu considers two ways different if there is at least one box from which different number of flowers are selected in these two ways.
The first line of input contains two space-separated integers *n* and *s* (1<=≀<=*n*<=≀<=20, 0<=≀<=*s*<=≀<=1014). The second line contains *n* space-separated integers *f*1,<=*f*2,<=... *f**n* (0<=≀<=*f**i*<=≀<=1012).
Output a single integer β€” the number of ways in which Devu can select the flowers modulo (109<=+<=7).
[ "2 3\n1 3\n", "2 4\n2 2\n", "3 5\n1 3 2\n" ]
[ "2\n", "1\n", "3\n" ]
Sample 1. There are two ways of selecting 3 flowers: {1, 2} and {0, 3}. Sample 2. There is only one way of selecting 4 flowers: {2, 2}. Sample 3. There are three ways of selecting 5 flowers: {1, 2, 2}, {0, 3, 2}, and {1, 3, 1}.
[ { "input": "2 3\n1 3", "output": "2" }, { "input": "2 4\n2 2", "output": "1" }, { "input": "3 5\n1 3 2", "output": "3" }, { "input": "2 270030023747\n891135146290 437305641972", "output": "30021858" }, { "input": "20 4385085334307\n273634411136 208521328637 450482376435 844118010709 197241285878 472126475472 2414038897 672334205413 809269727018 409013884362 739986692075 953956651947 462216461906 388007176838 245504550965 527140291750 632844435887 550532123833 757200390348 944901802640", "output": "316418090" }, { "input": "20 3752307092657\n283053521097 653583221811 681984546714 933027822250 487241474739 534269715560 834243597472 848019110117 485265346854 396702345118 408945102153 816559907551 401511139988 367150665755 712567362471 717769226958 548952754032 434801840119 879399744983 324531633609", "output": "381258106" }, { "input": "20 16619020188439\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "801984344" }, { "input": "20 262144\n0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287", "output": "725216474" }, { "input": "20 5230175580\n2 8 26 80 242 728 2186 6560 19682 59048 177146 531440 1594322 4782968 14348906 43046720 129140162 387420488 1162261466 3486784400", "output": "538211934" }, { "input": "20 5230176570\n2 8 26 80 242 728 2186 6560 19682 59048 177146 531440 1594322 4782968 14348906 43046720 129140162 387420488 1162261466 3486784400", "output": "19372190" }, { "input": "20 818000201\n0 2 8 26 80 242 728 2186 6560 19682 59048 177146 531440 1594322 4782968 14348906 43046720 129140162 387420488 1162261466", "output": "505949526" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 3\n1 3", "output": "2" }, { "input": "5 4\n3 3 4 4 4", "output": "68" }, { "input": "3 850878851187\n599705086316 802990808570 221067397125", "output": "334902111" }, { "input": "4 731767033652\n306127542694 172970942464 358017806176 394151815116", "output": "418840506" }, { "input": "5 1199105497223\n12549999072 542951076358 494968215227 507969287352 287108873850", "output": "997302283" }, { "input": "6 2407012786524\n721119939098 908636242955 629771140630 619639275940 522572133850 990422786968", "output": "338886284" }, { "input": "7 1658412315976\n390687619668 278616376849 766721549681 733456748176 716885650745 179493438565 887893058525", "output": "227709251" }, { "input": "8 3813157100184\n94962592398 646449027095 903671958732 847274220411 915494134937 336004281651 958773586686 419294404968", "output": "789858236" }, { "input": "9 3583740972033\n805680016072 12134193693 38474884135 958944208999 114102619129 486072673792 990651855390 976802100017 464520935171", "output": "411195526" }, { "input": "10 1303630103199\n335013516244 958354148440 976543431084 565663694920 818191244892 247036352979 903603155051 844331675449 5958875397 633112048156", "output": "130003736" }, { "input": "11 3413722756227\n41435972622 328334282334 113493840135 681628650803 53654504892 397104745120 937628907403 397544403202 978080140924 138793325393 275583919363", "output": "481042457" }, { "input": "12 3950166899748\n752153396296 698314416228 246149281890 795446123039 250115505435 549320620909 4214468268 918197322444 952348890098 685624345734 963610131910 998304966486", "output": "704755232" }, { "input": "13 3231756157805\n456428369026 63999582826 385247174589 909263595275 444429022331 701536496698 38240220621 473557533845 887615379817 195600590268 694933571209 105486312375 699514624098", "output": "21927593" }, { "input": "14 5118792034176\n162850825404 433979716719 522197583640 20933583863 643037506523 851604888839 104825781485 989915485791 859736645343 740284126961 419814559564 214815141912 468744648539 228783909097", "output": "80223119" }, { "input": "15 1558494741523\n871420765430 803959850613 654853025395 134751056099 837351023419 8115731924 136704050190 545275697192 831857910870 250260371494 109988255759 324143971449 270534481491 203417577675 71520651905", "output": "674766437" }, { "input": "16 788453604753\n577843221808 167497533563 791803434447 283275820494 72814283419 158184124065 203289611054 98488424946 799684209100 792796424539 834869244114 427030350042 39764505931 217053505710 484435378338 862395026264", "output": "652797798" }, { "input": "17 9007952448244\n282118194538 537477667457 930901327146 397093292730 264980316667 347254775663 237315363407 616993860539 771805474627 339627444880 525042940309 536359179580 804699563076 230689433744 897350104771 814486287026 524910356697", "output": "31329302" }, { "input": "18 7999930929823\n992835618212 907457801350 63556768901 515205732262 463588800858 499470651452 303900924272 170206588293 707071964345 849603689414 249923928664 643540525469 608636879676 207470585970 342824639716 768725031437 470251089472 346311861570", "output": "648904203" }, { "input": "19 9705775952949\n662403298782 277437935244 200507177952 626875720850 657902317754 649539043593 337926676624 688712023886 679193229872 394287226107 940097624859 752869355006 377866904116 218959030357 755739366148 759818551656 454594081704 739525703426 242214895448", "output": "810780885" }, { "input": "2 412849959951\n186777869134 354554126688", "output": "482034976" }, { "input": "3 994437863260\n596847635049 634289413919 671297779787", "output": "912049453" }, { "input": "4 484402508263\n19064884611 335165127717 322359010582 281374567239", "output": "289015253" }, { "input": "5 791953923546\n435577101470 614900414949 563017233052 356648566543 441001524035", "output": "173305014" }, { "input": "6 2640586287988\n845646867385 315776128746 214078463847 838768025119 708835459344 934321520813", "output": "795903668" }, { "input": "7 2053179920110\n674709576219 593363932330 454736686317 330887483693 391367370275 279198145307 147889917494", "output": "893383692" }, { "input": "8 439869733705\n96926825781 294239646128 105797917112 808711974973 661348789232 209376794178 892923476071 68560519128", "output": "158940804" }, { "input": "9 1291213158274\n506996591696 573974933359 753301598853 302978917195 348175667460 544253418672 652252001943 837793929669 992753968527", "output": "115213603" }, { "input": "10 957014537036\n817957214028 21216064562 782979338116 99716780532 466634308294 252843354854 653225805495 197215781879 450502843918 936581467941", "output": "339756041" }, { "input": "11 2523835918230\n238026979942 300951351794 27195109640 583983722756 153461186521 589867462996 410406847719 383294651690 434136016355 239499156985 605005205631", "output": "410668022" }, { "input": "12 237485322803\n654539196801 989679581945 674698791381 76103181330 828140581102 517898628219 165440406295 160380578581 10923729522 532416846030 869246361010 697649464752", "output": "882287279" }, { "input": "13 3269153679576\n76756446363 279414869175 913209530202 553927672610 103827032762 854922736361 505775989249 925319021826 982409418312 237885027049 548185492012 981990500354 816927519686", "output": "771986243" }, { "input": "14 3533400720920\n486826212278 970290582974 566418244646 46047131184 780653910990 782953901584 265104515121 121397891635 966042590749 530802716094 816721614687 274184052307 410140678523 769875336369", "output": "641684934" }, { "input": "15 2774417264718\n899043461842 260025870205 221774442737 121321130489 60635329946 132125493373 24433040993 886336334879 945380795890 823720405139 90962770066 149532144989 995501321008 824453862177 210161921008", "output": "36123304" }, { "input": "16 6819891369867\n321260711404 950901584003 458137697911 603440589064 737462208174 469149601515 771614083218 82415204689 522168509057 535631037101 355203925446 429578213295 590861963493 295877847255 313625384311 583033522628", "output": "348393153" }, { "input": "17 2309534620849\n148175936589 240636871234 113493896003 95560047639 15296143483 397180766738 530942609090 847353647933 503654197846 828548726146 36290540095 711771765248 184075122329 350456373063 419236331263 152256813920 755146994664", "output": "379054730" }, { "input": "18 1950920788528\n560393186152 931512585032 349857151176 577679506214 687828054415 734204874881 285976167666 626587058472 487287370283 127171447894 300531695475 996112800850 765140797519 400739931575 522699794566 124030597188 562898195459 475763385703", "output": "698191096" }, { "input": "19 4682267377407\n970462952067 221247872263 995213349269 65503997493 957809473372 662236040104 43157209890 812665928283 64075083449 420089136939 564772850855 288306352803 360501440003 860016433006 626163257870 93656896807 955951420632 637845969941 165819589855", "output": "523191343" }, { "input": "20 14017821532816\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "347848142" }, { "input": "20 16335271760241\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "395113180" }, { "input": "20 18060579396941\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "668178260" }, { "input": "20 10137806992108\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "357383650" }, { "input": "20 17054536210144\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "517516660" }, { "input": "20 14387278835382\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "467238355" }, { "input": "20 10472667171608\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "868395358" }, { "input": "20 9876740295167\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "125737184" }, { "input": "20 9502335428550\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "209415674" }, { "input": "20 16899776686559\n1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000", "output": "212580649" }, { "input": "1 1\n0", "output": "0" }, { "input": "20 10043\n2 8 26 80 242 728 2186 6560 19682 59048 177146 531440 1594322 4782968 14348906 43046720 129140162 387420488 1162261466 3486784400", "output": "52142433" }, { "input": "1 0\n1", "output": "1" }, { "input": "17 953674316167\n4 24 124 624 3124 15624 78124 390624 1953124 9765624 48828124 244140624 1220703124 6103515624 30517578124 152587890624 762939453124", "output": "197405646" }, { "input": "17 953674314899\n4 24 124 624 3124 15624 78124 390624 1953124 9765624 48828124 244140624 1220703124 6103515624 30517578124 152587890624 762939453124", "output": "307042369" }, { "input": "17 953674312906\n4 24 124 624 3124 15624 78124 390624 1953124 9765624 48828124 244140624 1220703124 6103515624 30517578124 152587890624 762939453124", "output": "81725967" }, { "input": "20 33554432\n0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287", "output": "0" }, { "input": "20 1048554\n0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287", "output": "19" }, { "input": "20 1048455\n0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287", "output": "461657829" }, { "input": "20 1038555\n0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287", "output": "216743080" }, { "input": "20 64741\n0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287", "output": "181890008" }, { "input": "20 125618\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288", "output": "435524008" }, { "input": "1 1\n1", "output": "1" } ]
46
0
0
32,823
78
Evacuation
[ "flows", "graphs", "shortest paths" ]
E. Evacuation
1
256
They've screwed something up yet again... In one nuclear reactor of a research station an uncontrolled reaction is in progress and explosion which will destroy the whole station will happen soon. The station is represented by a square *n*<=Γ—<=*n* divided into 1<=Γ—<=1 blocks. Each block is either a reactor or a laboratory. There can be several reactors and exactly one of them will explode soon. The reactors can be considered impassable blocks, but one can move through laboratories. Between any two laboratories, which are in adjacent blocks, there is a corridor. Blocks are considered adjacent if they have a common edge. In each laboratory there is some number of scientists and some number of rescue capsules. Once the scientist climbs into a capsule, he is considered to be saved. Each capsule has room for not more than one scientist. The reactor, which is about to explode, is damaged and a toxic coolant trickles from it into the neighboring blocks. The block, which contains the reactor, is considered infected. Every minute the coolant spreads over the laboratories through corridors. If at some moment one of the blocks is infected, then the next minute all the neighboring laboratories also become infected. Once a lab is infected, all the scientists there that are not in rescue capsules die. The coolant does not spread through reactor blocks. There are exactly *t* minutes to the explosion. Any scientist in a minute can move down the corridor to the next lab, if it is not infected. On any corridor an unlimited number of scientists can simultaneously move in both directions. It is believed that the scientists inside a lab moves without consuming time. Moreover, any scientist could get into the rescue capsule instantly. It is also believed that any scientist at any given moment always has the time to perform their actions (move from the given laboratory into the next one, or climb into the rescue capsule) before the laboratory will be infected. Find the maximum number of scientists who will be able to escape.
The first line contains two integers *n* and *t* (2<=≀<=*n*<=≀<=10, 1<=≀<=*t*<=≀<=60). Each of the next *n* lines contains *n* characters. These lines describe the scientists' locations. Then exactly one empty line follows. Each of the next *n* more lines contains *n* characters. These lines describe the rescue capsules' locations. In the description of the scientists' and the rescue capsules' locations the character "Y" stands for a properly functioning reactor, "Z" stands for the malfunctioning reactor. The reactors' positions in both descriptions coincide. There is exactly one malfunctioning reactor on the station. The digits "0" - "9" stand for the laboratories. In the description of the scientists' locations those numbers stand for the number of scientists in the corresponding laboratories. In the rescue capsules' descriptions they stand for the number of such capsules in each laboratory.
Print a single number β€” the maximum number of scientists who will manage to save themselves.
[ "3 3\n1YZ\n1YY\n100\n\n0YZ\n0YY\n003\n", "4 4\nY110\n1Y1Z\n1Y0Y\n0100\n\nY001\n0Y0Z\n0Y0Y\n0005\n" ]
[ "2", "3" ]
In the second sample the events could take place as follows:
[]
46
0
0
33,062
77
Martian Food
[ "geometry" ]
E. Martian Food
1
256
Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of *R*, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of *r* and is located as close to the edge of the plate as possible staying entirely within the plate. I. e. Golden Honduras touches the edge of the plate from the inside. It is believed that the proximity of the portion of the Golden Honduras to the edge of a plate demonstrates the neatness and exactness of the Martians. Then a perfectly round portion of Pink Guadeloupe is put on the plate. The Guadeloupe should not overlap with Honduras, should not go beyond the border of the plate, but should have the maximum radius. I. e. Pink Guadeloupe should touch the edge of the plate from the inside, and touch Golden Honduras from the outside. For it is the size of the Rose Guadeloupe that shows the generosity and the hospitality of the Martians. Further, the first portion (of the same perfectly round shape) of Green Bull Terrier is put on the plate. It should come in contact with Honduras and Guadeloupe, should not go beyond the border of the plate and should have maximum radius. Each of the following portions of the Green Bull Terrier must necessarily touch the Golden Honduras, the previous portion of the Green Bull Terrier and touch the edge of a plate, but should not go beyond the border. To determine whether a stranger is worthy to touch the food, the Martians ask him to find the radius of the *k*-th portion of the Green Bull Terrier knowing the radii of a plate and a portion of the Golden Honduras. And are you worthy?
The first line contains integer *t* (1<=≀<=*t*<=≀<=104) β€” amount of testcases. Each of the following *t* lines contain three positive integers: the radii of the plate and a portion of the Golden Honduras *R* and *r* (1<=≀<=*r*<=&lt;<=*R*<=≀<=104) and the number *k* (1<=≀<=*k*<=≀<=104). In the pretests 1<=≀<=*k*<=≀<=2.
Print *t* lines β€” the radius of the *k*-th portion of the Green Bull Terrier for each test. The absolute or relative error of the answer should not exceed 10<=-<=6.
[ "2\n4 3 1\n4 2 2\n" ]
[ "0.9230769231\n0.6666666667\n" ]
Dish from the first sample looks like this: <img class="tex-graphics" src="https://espresso.codeforces.com/e15f6caf257ceae8305cd82507b96dfac1b579ee.png" style="max-width: 100.0%;max-height: 100.0%;"/> Dish from the second sample looks like this: <img class="tex-graphics" src="https://espresso.codeforces.com/625a74ccb42332c9df05a22f8e17f81f086476d5.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "2\n4 3 1\n4 2 2", "output": "0.9230769231\n0.6666666667" }, { "input": "1\n4 2 2", "output": "0.6666666667" }, { "input": "1\n7 2 1", "output": "1.7948717949" }, { "input": "1\n8 7 2", "output": "0.9333333333" }, { "input": "1\n2 1 1", "output": "0.6666666667" }, { "input": "1\n1000 999 2", "output": "0.9999959960" }, { "input": "1\n1000 1 2", "output": "0.2501875781" }, { "input": "1\n1000 998 1000", "output": "0.3993597439" }, { "input": "1\n1000 1 1000", "output": "0.0000010010" }, { "input": "1\n1000 500 123", "output": "0.0660894852" }, { "input": "1\n1000 999 1", "output": "0.9999989990" }, { "input": "1\n1000 1 1", "output": "0.9999989990" } ]
249
7,782,400
3.861004
33,214
34
Road Map
[ "dfs and similar", "graphs" ]
D. Road Map
2
256
There are *n* cities in Berland. Each city has its index β€” an integer number from 1 to *n*. The capital has index *r*1. All the roads in Berland are two-way. The road system is such that there is exactly one path from the capital to each city, i.e. the road map looks like a tree. In Berland's chronicles the road map is kept in the following way: for each city *i*, different from the capital, there is kept number *p**i* β€” index of the last city on the way from the capital to *i*. Once the king of Berland Berl XXXIV decided to move the capital from city *r*1 to city *r*2. Naturally, after this the old representation of the road map in Berland's chronicles became incorrect. Please, help the king find out a new representation of the road map in the way described above.
The first line contains three space-separated integers *n*, *r*1, *r*2 (2<=≀<=*n*<=≀<=5Β·104,<=1<=≀<=*r*1<=β‰ <=*r*2<=≀<=*n*) β€” amount of cities in Berland, index of the old capital and index of the new one, correspondingly. The following line contains *n*<=-<=1 space-separated integers β€” the old representation of the road map. For each city, apart from *r*1, there is given integer *p**i* β€” index of the last city on the way from the capital to city *i*. All the cities are described in order of increasing indexes.
Output *n*<=-<=1 numbers β€” new representation of the road map in the same format.
[ "3 2 3\n2 2\n", "6 2 4\n6 1 2 4 2\n" ]
[ "2 3 ", "6 4 1 4 2 " ]
none
[ { "input": "3 2 3\n2 2", "output": "2 3 " }, { "input": "6 2 4\n6 1 2 4 2", "output": "6 4 1 4 2 " }, { "input": "7 7 6\n7 7 5 5 7 7", "output": "7 7 5 5 7 6 " }, { "input": "4 2 3\n2 1 3", "output": "3 1 3 " }, { "input": "5 5 4\n5 4 1 5", "output": "5 4 1 4 " }, { "input": "6 2 1\n4 1 2 2 2", "output": "4 1 1 2 2 " }, { "input": "2 1 2\n1", "output": "2 " }, { "input": "2 2 1\n2", "output": "1 " }, { "input": "3 1 3\n1 2", "output": "2 3 " }, { "input": "10 4 3\n5 6 9 10 1 9 6 8 4", "output": "6 6 10 1 8 9 9 3 5 " }, { "input": "100 62 42\n45 66 13 18 93 47 83 19 41 66 5 70 16 29 54 28 65 91 92 24 90 54 7 40 77 53 68 58 70 65 68 30 94 80 16 18 69 21 94 1 99 61 97 2 69 15 79 38 61 46 88 32 57 84 35 18 17 77 38 91 84 2 53 54 68 19 13 78 62 16 63 17 76 49 28 45 94 13 35 69 37 56 12 41 95 70 57 24 45 84 87 65 14 76 95 94 31 67 5", "output": "45 66 13 18 93 47 83 19 41 66 5 84 16 29 54 28 65 91 92 24 90 54 7 40 77 53 68 58 70 65 68 30 94 80 16 18 69 21 94 1 99 97 2 69 15 79 38 61 46 88 32 57 84 35 18 17 77 38 91 42 70 2 53 54 68 19 13 78 12 16 63 17 76 49 28 45 94 13 35 69 37 56 61 41 95 70 57 24 45 84 87 65 14 76 95 94 31 67 5 " } ]
155
102,400
0
33,229
855
Nagini
[ "binary search", "data structures" ]
null
null
Nagini, being a horcrux You-know-who created with the murder of Bertha Jorkins, has accumulated its army of snakes and is launching an attack on Hogwarts school. Hogwarts' entrance can be imagined as a straight line (x-axis) from 1 to 105. Nagini is launching various snakes at the Hogwarts entrance. Each snake lands parallel to the entrance, covering a segment at a distance *k* from *x*<==<=*l* to *x*<==<=*r*. Formally, each snake can be imagined as being a line segment between points (*l*,<=*k*) and (*r*,<=*k*). Note that *k* can be both positive and negative, but not 0. Let, at some *x*-coordinate *x*<==<=*i*, there be snakes at point (*i*,<=*y*1) and point (*i*,<=*y*2), such that *y*1<=&gt;<=0 and *y*2<=&lt;<=0. Then, if for any point (*i*,<=*y*3) containing a snake such that *y*3<=&gt;<=0, *y*1<=≀<=*y*3 holds and for any point (*i*,<=*y*4) containing a snake such that *y*4<=&lt;<=0, |*y*2|<=≀<=|*y*4| holds, then the danger value at coordinate *x*<==<=*i* is *y*1<=+<=|*y*2|. If no such *y*1 and *y*2 exist, danger value is 0. Harry wants to calculate the danger value of various segments of the Hogwarts entrance. Danger value for a segment [*l*,<=*r*) of the entrance can be calculated by taking the sum of danger values for each integer *x*-coordinate present in the segment. Formally, you have to implement two types of queries: - 1 l r k: a snake is added parallel to entrance from *x*<==<=*l* to *x*<==<=*r* at y-coordinate *y*<==<=*k* (*l* inclusive, *r* exclusive). - 2 l r: you have to calculate the danger value of segment *l* to *r* (*l* inclusive, *r* exclusive).
First line of input contains a single integer *q* (1<=≀<=*q*<=≀<=5Β·104) denoting the number of queries. Next *q* lines each describe a query. Each query description first contains the query type *type**i* (1<=≀<=*type**i*<=≀<=2). This is followed by further description of the query. In case of the type being 1, it is followed by integers *l**i*,<=*r**i* and *k**i* (, <=-<=109<=≀<=*k**i*<=≀<=109, *k*<=β‰ <=0). Otherwise, it just contains two integers, *l**i* and *r**i* (1<=≀<=*l**i*<=&lt;<=*r**i*<=≀<=105).
Output the answer for each query of type 2 in a separate line.
[ "3\n1 1 10 10\n1 2 4 -7\n2 1 10\n", "7\n1 2 3 5\n1 1 10 10\n1 4 5 -5\n2 4 8\n1 1 10 -10\n2 4 8\n2 1 10\n" ]
[ "34\n", "15\n75\n170\n" ]
In the first sample case, the danger value for *x*-coordinates 1 is 0 as there is no *y*<sub class="lower-index">2</sub> satisfying the above condition for *x* = 1. Danger values for *x*-coordinates 2 and 3 is 10 + | - 7| = 17. Danger values for *x*-coordinates 4 to 9 is again 0 as there is no *y*<sub class="lower-index">2</sub> satisfying the above condition for these coordinates. Thus, total danger value is 17 + 17 = 34.
[]
30
0
0
33,263
360
Levko and Array
[ "binary search", "dp" ]
null
null
Levko has an array that consists of integers: *a*1,<=*a*2,<=... ,<=*a**n*. But he doesn’t like this array at all. Levko thinks that the beauty of the array *a* directly depends on value *c*(*a*), which can be calculated by the formula: It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most *k* array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible. Help Levko and calculate what minimum number *c*(*a*) he can reach.
The first line contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=2000). The second line contains space-separated integers *a*1,<=*a*2,<=... ,<=*a**n* (<=-<=109<=≀<=*a**i*<=≀<=109).
A single number β€” the minimum value of *c*(*a*) Levko can get.
[ "5 2\n4 7 4 7 4\n", "3 1\n-100 0 100\n", "6 3\n1 2 3 7 8 9\n" ]
[ "0\n", "100\n", "1\n" ]
In the first sample Levko can change the second and fourth elements and get array: 4, 4, 4, 4, 4. In the third sample he can get array: 1, 2, 3, 4, 5, 6.
[ { "input": "5 2\n4 7 4 7 4", "output": "0" }, { "input": "3 1\n-100 0 100", "output": "100" }, { "input": "6 3\n1 2 3 7 8 9", "output": "1" }, { "input": "4 1\n-1000000000 -1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "10 1\n-6 5 -7 -7 -7 -7 5 -9 4 7", "output": "12" }, { "input": "20 17\n-5 -9 11 -7 -17 -8 0 -14 -20 -15 7 -13 0 -3 -14 0 9 -10 6 -19", "output": "0" }, { "input": "5 1\n-1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "2000000000" }, { "input": "16 13\n441427217 689669074 -194425155 750543104 6572770 -417122148 483768301 -687067832 703108904 -4865435 -626501708 -222868350 692734658 667640778 259672206 418102760", "output": "2593562" }, { "input": "1 1\n3243243", "output": "0" }, { "input": "1 1\n-1000000000", "output": "0" }, { "input": "2 1\n1234234 -3434", "output": "0" }, { "input": "2 2\n1 5", "output": "0" }, { "input": "4 1\n100 0 7 0", "output": "7" } ]
62
1,638,400
0
33,344
630
Hexagons!
[ "math" ]
null
null
After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might &amp; Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than *n* cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when *n* increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given *n*, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than *n* cells away from a given cell.
The only line of the input contains one integer *n* (0<=≀<=*n*<=≀<=109).
Output one integer β€” the number of hexagons situated not farther than *n* cells away from a given cell.
[ "2\n" ]
[ "19" ]
none
[ { "input": "2", "output": "19" }, { "input": "0", "output": "1" }, { "input": "1", "output": "7" }, { "input": "3", "output": "37" }, { "input": "749431", "output": "1684942719577" }, { "input": "748629743", "output": "1681339478558627377" }, { "input": "945234000", "output": "2680401947103702001" }, { "input": "900000000", "output": "2430000002700000001" }, { "input": "999999999", "output": "2999999997000000001" }, { "input": "1000000000", "output": "3000000003000000001" } ]
31
0
3
33,591
13
Triangles
[ "dp", "geometry" ]
D. Triangles
2
64
Little Petya likes to draw. He drew *N* red and *M* blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.
The first line contains two non-negative integer numbers *N* and *M* (0<=≀<=*N*<=≀<=500, 0<=≀<=*M*<=≀<=500) β€” the number of red and blue points respectively. The following *N* lines contain two integer numbers each β€” coordinates of red points. The following *M* lines contain two integer numbers each β€” coordinates of blue points. All coordinates do not exceed 109 by absolute value.
Output one integer β€” the number of distinct triangles with vertices in red points which do not contain any blue point inside.
[ "4 1\n0 0\n10 0\n10 10\n5 4\n2 1\n", "5 5\n5 10\n6 1\n8 6\n-6 -7\n7 -1\n5 -1\n10 -4\n-10 -8\n-10 5\n-2 -8\n" ]
[ "2\n", "7\n" ]
none
[]
30
0
0
33,637
529
Group Photo 2 (online mirror version)
[ "brute force", "greedy", "sortings" ]
null
null
Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo. Simply speaking, the process of photographing can be described as follows. Each friend occupies a rectangle of pixels on the photo: the *i*-th of them in a standing state occupies a *w**i* pixels wide and a *h**i* pixels high rectangle. But also, each person can lie down for the photo, and then he will occupy a *h**i* pixels wide and a *w**i* pixels high rectangle. The total photo will have size *W*<=Γ—<=*H*, where *W* is the total width of all the people rectangles, and *H* is the maximum of the heights. The friends want to determine what minimum area the group photo can they obtain if no more than *n*<=/<=2 of them can lie on the ground (it would be strange if more than *n*<=/<=2 gentlemen lie on the ground together, isn't it?..) Help them to achieve this goal.
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of friends. The next *n* lines have two integers *w**i*,<=*h**i* (1<=≀<=*w**i*,<=*h**i*<=≀<=1000) each, representing the size of the rectangle, corresponding to the *i*-th friend.
Print a single integer equal to the minimum possible area of the photo containing all friends if no more than *n*<=/<=2 of them can lie on the ground.
[ "3\n10 1\n20 2\n30 3\n", "3\n3 1\n2 2\n4 3\n", "1\n5 10\n" ]
[ "180\n", "21\n", "50\n" ]
none
[ { "input": "3\n10 1\n20 2\n30 3", "output": "180" }, { "input": "3\n3 1\n2 2\n4 3", "output": "21" }, { "input": "1\n5 10", "output": "50" }, { "input": "1\n1 1", "output": "1" }, { "input": "1\n1000 1000", "output": "1000000" }, { "input": "1\n1 1000", "output": "1000" }, { "input": "2\n1 1000\n1000 1", "output": "2000" }, { "input": "2\n1 1\n1000 1000", "output": "1001000" }, { "input": "1\n1000 1", "output": "1000" }, { "input": "5\n407 830\n12 199\n768 215\n668 28\n628 310", "output": "1070700" }, { "input": "3\n379 820\n923 407\n916 853", "output": "1570946" }, { "input": "3\n99 768\n477 885\n169 118", "output": "614190" }, { "input": "3\n227 612\n223 259\n423 895", "output": "781335" }, { "input": "3\n651 161\n480 32\n485 672", "output": "756672" }, { "input": "3\n779 301\n34 214\n442 937", "output": "728049" }, { "input": "3\n203 145\n780 692\n992 713", "output": "1366821" }, { "input": "3\n627 286\n37 65\n53 490", "output": "235752" }, { "input": "3\n755 938\n487 543\n307 459", "output": "1307660" }, { "input": "3\n475 487\n41 20\n368 236", "output": "366224" }, { "input": "3\n922 71\n719 26\n462 700", "output": "1013790" }, { "input": "2\n881 4\n788 2", "output": "6676" }, { "input": "2\n1 304\n8 892", "output": "8028" }, { "input": "3\n227 2\n223 9\n423 5", "output": "7857" }, { "input": "3\n7 612\n3 259\n3 895", "output": "11635" }, { "input": "4\n573 7\n169 9\n447 7\n947 3", "output": "19224" }, { "input": "10\n864 874\n534 702\n73 363\n856 895\n827 72\n435 468\n888 921\n814 703\n648 715\n384 781", "output": "4909752" }, { "input": "10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160", "output": "3231747" }, { "input": "1\n1 1", "output": "1" }, { "input": "1\n1000 1000", "output": "1000000" }, { "input": "1\n1 1000", "output": "1000" }, { "input": "2\n1 1000\n1000 1", "output": "2000" }, { "input": "2\n1 1\n1000 1000", "output": "1001000" }, { "input": "1\n1000 1", "output": "1000" }, { "input": "2\n1 1\n1 1", "output": "2" }, { "input": "4\n3 817\n9 729\n7 407\n7 433", "output": "21242" }, { "input": "3\n500 500\n2 1\n10 5", "output": "253500" } ]
61
5,632,000
0
33,639
369
Valera and Queries
[ "binary search", "data structures" ]
null
null
Valera loves segments. He has recently come up with one interesting problem. The *Ox* axis of coordinates has *n* segments, the *i*-th segment starts in position *l**i* and ends in position *r**i* (we will mark it as [*l**i*,<=*r**i*]). Your task is to process *m* queries, each consists of number *cnt**i* and a set of *cnt**i* coordinates of points located on the *Ox* axis. The answer to the query is the number of segments, such that each of them contains at least one point from the query. Segment [*l*,<=*r*] contains point *q*, if *l*<=≀<=*q*<=≀<=*r*. Valera found the solution of this problem too difficult. So he asked you to help him. Help Valera.
The first line contains two integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=3Β·105) β€” the number of segments on the axis of coordinates and the number of queries. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two positive integers *l**i*, *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=106) β€” the borders of the *i*-th segment. Next *m* lines contain the description of the queries, one per line. Each line starts from integer *cnt**i* (1<=≀<=*cnt**i*<=≀<=3Β·105) β€” the number of points in the *i*-th query. Then the line contains *cnt**i* distinct positive integers *p*1,<=*p*2,<=...,<=*p**cnt**i* (1<=≀<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**cnt**i*<=≀<=106) β€” the coordinates of points in the *i*-th query. It is guaranteed that the total number of points in all queries doesn't exceed 3Β·105.
Print *m* non-negative integers, where the *i*-th number is the response to the *i*-th query.
[ "3 3\n1 3\n4 5\n6 7\n3 1 4 7\n2 4 5\n1 8\n" ]
[ "3\n1\n0\n" ]
none
[ { "input": "3 3\n1 3\n4 5\n6 7\n3 1 4 7\n2 4 5\n1 8", "output": "3\n1\n0" }, { "input": "1 1\n172921 894619\n1 14141", "output": "0" }, { "input": "3 1\n439010 864662\n377278 743032\n771051 955458\n1 568232", "output": "2" }, { "input": "3 3\n328789 478281\n248154 348247\n820715 860013\n1 344703\n1 592310\n1 104937", "output": "2\n0\n0" }, { "input": "5 3\n529971 921435\n466874 801474\n178558 921765\n193565 251465\n346414 727740\n5 328292 498601 509140 588519 820032\n5 221904 249439 491524 570871 945281\n5 357080 543431 566949 932654 947658", "output": "4\n5\n4" }, { "input": "5 1\n678201 810289\n778357 940848\n778406 946358\n151271 684580\n203524 382911\n5 358312 424531 460539 542697 775332", "output": "3" }, { "input": "5 1\n862248 965768\n78738 994773\n236426 318177\n186078 241439\n76304 568725\n1 509307", "output": "2" }, { "input": "5 3\n547230 805495\n810625 899397\n203912 240535\n432981 477594\n229222 465101\n1 908682\n1 942879\n1 808024", "output": "0\n0\n0" }, { "input": "5 5\n643450 686584\n30981 862245\n68908 575075\n558374 713102\n480946 865118\n1 680156\n1 557501\n1 95807\n1 972121\n1 262787", "output": "4\n3\n2\n0\n2" }, { "input": "10 3\n172267 379903\n546621 772370\n581059 880021\n321531 376831\n229673 432639\n106645 948268\n855783 967973\n541573 920416\n7682 695665\n492612 836502\n1 873101\n1 818922\n1 198181", "output": "4\n4\n3" }, { "input": "10 3\n356907 564385\n519660 960519\n84077 747040\n374095 956206\n476778 728678\n278858 977832\n158558 723270\n130593 261834\n125493 250966\n307770 792762\n3 56100 382258 579673\n3 40029 266600 440635\n3 36944 414002 843837", "output": "8\n6\n7" }, { "input": "10 10\n366228 895993\n228160 722127\n400056 671311\n683144 765009\n196492 360241\n304744 916576\n450846 764055\n211322 967136\n696553 766931\n282539 425248\n1 130996\n1 682994\n1 183255\n1 165896\n1 396547\n1 558594\n1 894712\n1 945830\n1 842172\n1 704247", "output": "0\n5\n0\n0\n5\n6\n3\n1\n3\n7" }, { "input": "3 4\n1000000 1000000\n5000 5000\n1 1\n1 1\n1 1000000\n1 999999\n1 2", "output": "1\n1\n0\n0" }, { "input": "3 4\n1 1000000\n5000 5000\n1 1\n1 1\n1 1000000\n1 999999\n1 2", "output": "2\n1\n1\n1" }, { "input": "1 1\n1000000 1000000\n1 1000000", "output": "1" }, { "input": "1 1\n1 1\n1 1", "output": "1" } ]
46
0
0
33,762
444
DZY Loves Physics
[ "greedy", "math" ]
null
null
DZY loves Physics, and he enjoys calculating density. Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: Once DZY got a graph *G*, now he wants to find a connected induced subgraph *G*' of the graph, such that the density of *G*' is as large as possible. An induced subgraph *G*'(*V*',<=*E*') of a graph *G*(*V*,<=*E*) is a graph that satisfies: - ; - edge if and only if , and edge ; - the value of an edge in *G*' is the same as the value of the corresponding edge in *G*, so as the value of a node. Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected.
The first line contains two space-separated integers *n*Β (1<=≀<=*n*<=≀<=500), . Integer *n* represents the number of nodes of the graph *G*, *m* represents the number of edges. The second line contains *n* space-separated integers *x**i*Β (1<=≀<=*x**i*<=≀<=106), where *x**i* represents the value of the *i*-th node. Consider the graph nodes are numbered from 1 to *n*. Each of the next *m* lines contains three space-separated integers *a**i*,<=*b**i*,<=*c**i*Β (1<=≀<=*a**i*<=&lt;<=*b**i*<=≀<=*n*;Β 1<=≀<=*c**i*<=≀<=103), denoting an edge between node *a**i* and *b**i* with value *c**i*. The graph won't contain multiple edges.
Output a real number denoting the answer, with an absolute or relative error of at most 10<=-<=9.
[ "1 0\n1\n", "2 1\n1 2\n1 2 1\n", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63\n" ]
[ "0.000000000000000\n", "3.000000000000000\n", "2.965517241379311\n" ]
In the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1. In the second sample, choosing the whole graph is optimal.
[ { "input": "1 0\n1", "output": "0.000000000000000" }, { "input": "2 1\n1 2\n1 2 1", "output": "3.000000000000000" }, { "input": "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63", "output": "2.965517241379311" }, { "input": "1 0\n734135", "output": "0.000000000000000" }, { "input": "10 10\n132402 148489 472187 403302 657890 205188 750668 276911 372190 828796\n8 10 162\n1 8 489\n6 7 279\n1 10 740\n5 6 721\n3 6 862\n2 3 194\n7 10 601\n2 10 658\n1 5 930", "output": "6825.351851851852200" }, { "input": "20 20\n265918 744212 196368 74731 293587 679367 460805 632939 453630 565881 835276 606327 181087 721045 219431 849838 370939 582350 335676 32244\n2 16 989\n14 19 628\n1 6 483\n5 8 733\n13 19 556\n10 17 911\n2 7 599\n13 17 390\n10 20 965\n9 11 449\n3 15 310\n3 6 557\n14 18 225\n1 18 703\n10 18 234\n6 14 114\n8 18 23\n1 7 13\n5 6 108\n4 12 80", "output": "55901.769230769234000" }, { "input": "30 7\n757449 649347 745109 33126 786508 643820 514399 195852 220502 122381 298189 760229 330623 782818 92550 737997 981538 185996 139833 694984 605470 928975 574293 485050 265558 56466 247185 372975 847922 530210\n21 22 604\n3 12 859\n24 30 56\n15 24 627\n3 23 494\n2 27 409\n13 25 806", "output": "18129.642857142859000" }, { "input": "40 0\n333755 354468 763743 983044 791235 558007 639137 977841 767439 595261 276101 212062 189789 573751 751706 311404 689132 603080 300272 15008 274365 411257 191645 451302 387673 289269 427129 352075 335498 665358 917537 392450 219168 587894 920119 930721 72109 817927 33248 189473", "output": "0.000000000000000" }, { "input": "5 7\n348 348 348 348 348\n1 2 9\n2 4 9\n2 3 9\n1 4 9\n3 5 9\n1 3 9\n3 4 9", "output": "77.333333333333329" }, { "input": "10 23\n483 482 483 483 483 482 483 482 483 482\n4 6 360\n1 4 360\n3 4 360\n1 2 360\n1 9 359\n3 5 360\n7 9 359\n6 7 360\n1 6 360\n5 10 359\n3 7 360\n2 9 360\n3 10 359\n1 10 360\n4 5 359\n1 7 360\n7 8 359\n3 8 359\n4 7 359\n2 7 359\n2 10 360\n1 8 359\n2 5 360", "output": "2.690807799442897" }, { "input": "3 3\n100 100 1\n1 2 50\n1 3 49\n2 3 49", "output": "4.000000000000000" } ]
0
0
-1
33,820
42
Game of chess unfinished
[ "implementation" ]
B. Game of chess unfinished
2
256
Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", β€” Volodya said and was right for sure. And your task is to say whether whites had won or not. Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king β€” to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3).
The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8<=Γ—<=8 chessboard is denoted by two symbols β€” ('a' - 'h') and ('1' - '8') β€” which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other.
Output should contain one word: "CHECKMATE" if whites mate blacks, and "OTHER" otherwise.
[ "a6 b4 c8 a8\n", "a6 c4 b6 b8\n", "a2 b1 a3 a1\n" ]
[ "CHECKMATE\n", "OTHER\n", "OTHER\n" ]
none
[ { "input": "a6 b4 c8 a8", "output": "CHECKMATE" }, { "input": "a6 c4 b6 b8", "output": "OTHER" }, { "input": "a2 b1 a3 a1", "output": "OTHER" }, { "input": "a5 c5 c2 a1", "output": "CHECKMATE" }, { "input": "a5 c5 c3 a1", "output": "OTHER" }, { "input": "c1 c2 d1 f1", "output": "OTHER" }, { "input": "a1 a2 c4 c2", "output": "CHECKMATE" }, { "input": "a1 a2 d4 c2", "output": "OTHER" }, { "input": "a1 a2 b4 c2", "output": "OTHER" }, { "input": "b2 c2 b3 c1", "output": "OTHER" }, { "input": "b2 c2 b3 b1", "output": "OTHER" }, { "input": "b3 a8 c2 a3", "output": "CHECKMATE" }, { "input": "b3 a8 c4 a3", "output": "CHECKMATE" }, { "input": "b3 a8 d3 a3", "output": "OTHER" }, { "input": "d4 e5 a7 a5", "output": "CHECKMATE" }, { "input": "d4 e5 b7 a5", "output": "CHECKMATE" }, { "input": "d4 e5 c7 a5", "output": "OTHER" }, { "input": "h7 h8 d8 a8", "output": "OTHER" }, { "input": "h7 h8 c7 a8", "output": "OTHER" }, { "input": "a6 a8 c2 a1", "output": "CHECKMATE" }, { "input": "a7 b7 d8 a6", "output": "CHECKMATE" }, { "input": "a5 b5 g2 a8", "output": "CHECKMATE" }, { "input": "a2 f1 g3 d1", "output": "CHECKMATE" }, { "input": "b3 a5 g6 a8", "output": "CHECKMATE" }, { "input": "c6 b2 g6 b4", "output": "OTHER" }, { "input": "c6 b4 h4 d1", "output": "OTHER" }, { "input": "d8 b4 f2 c5", "output": "OTHER" }, { "input": "e1 c8 g5 b3", "output": "OTHER" }, { "input": "e6 e7 d4 h2", "output": "OTHER" }, { "input": "f1 a2 c7 d1", "output": "CHECKMATE" }, { "input": "f6 d5 h5 b6", "output": "OTHER" }, { "input": "f7 h7 f4 h4", "output": "CHECKMATE" }, { "input": "f1 h2 h5 c8", "output": "OTHER" }, { "input": "g5 c1 a3 c2", "output": "OTHER" }, { "input": "g5 c4 a7 g3", "output": "OTHER" }, { "input": "g4 e5 h2 e1", "output": "OTHER" }, { "input": "g8 h5 a6 h3", "output": "CHECKMATE" }, { "input": "h7 c8 c2 e8", "output": "CHECKMATE" }, { "input": "h1 g8 b8 h6", "output": "CHECKMATE" }, { "input": "h2 h4 h8 f5", "output": "OTHER" }, { "input": "h7 g7 h6 h8", "output": "CHECKMATE" }, { "input": "h7 g7 g6 g8", "output": "OTHER" }, { "input": "h7 g7 h6 f7", "output": "OTHER" }, { "input": "h7 g8 f8 h8", "output": "OTHER" }, { "input": "h7 g8 h6 h8", "output": "OTHER" }, { "input": "e8 e7 d8 g8", "output": "CHECKMATE" }, { "input": "e8 e7 h8 f8", "output": "CHECKMATE" }, { "input": "d8 d7 h8 f8", "output": "CHECKMATE" }, { "input": "e8 e7 f8 h8", "output": "OTHER" }, { "input": "a6 a8 c2 a1", "output": "CHECKMATE" }, { "input": "a7 b7 d8 a6", "output": "CHECKMATE" }, { "input": "a5 b5 g2 a8", "output": "CHECKMATE" }, { "input": "a2 f1 g3 d1", "output": "CHECKMATE" }, { "input": "b3 a5 g6 a8", "output": "CHECKMATE" }, { "input": "c6 b2 g6 b4", "output": "OTHER" }, { "input": "c6 b4 h4 d1", "output": "OTHER" }, { "input": "d8 b4 f2 c5", "output": "OTHER" }, { "input": "e1 c8 g5 b3", "output": "OTHER" }, { "input": "e6 e7 d4 h2", "output": "OTHER" }, { "input": "f1 a2 c7 d1", "output": "CHECKMATE" }, { "input": "f6 d5 h5 b6", "output": "OTHER" }, { "input": "f7 h5 f8 h8", "output": "CHECKMATE" }, { "input": "f7 h7 f4 h4", "output": "CHECKMATE" }, { "input": "f1 h2 h5 c8", "output": "OTHER" }, { "input": "g5 c1 a3 c2", "output": "OTHER" }, { "input": "g5 c4 a7 g3", "output": "OTHER" }, { "input": "g4 e5 h2 e1", "output": "OTHER" }, { "input": "g8 h5 a6 h3", "output": "CHECKMATE" }, { "input": "h7 c8 c2 e8", "output": "CHECKMATE" }, { "input": "h1 g8 b8 h6", "output": "CHECKMATE" }, { "input": "a1 a2 h1 e1", "output": "CHECKMATE" } ]
312
6,553,600
0
33,855
713
Searching Rectangles
[ "binary search", "constructive algorithms", "interactive" ]
null
null
Filya just learned new geometry objectΒ β€” rectangle. He is given a field consisting of *n*<=Γ—<=*n* unit cells. Rows are numbered from bottom to top with integer from 1 to *n*. Columns are numbered from left to right with integers from 1 to *n*. Cell, located at the intersection of the row *r* and column *c* is denoted as (*r*,<=*c*). Filya has painted two rectangles, such that their sides are parallel to coordinate axes and each cell lies fully inside or fully outside each of them. Moreover, no cell lies in both rectangles. Later, hedgehog Filya became interested in the location of his rectangles but was unable to find the sheet of paper they were painted on. They were taken by Sonya and now she wants to play a little game with Filya. He tells her a query rectangle and she replies with the number of initial rectangles that lie fully inside the given query rectangle. The query rectangle should match the same conditions as initial rectangles. Rectangle lies fully inside the query if each o its cells lies inside the query. Filya knows Sonya really well, so is sure that if he asks more than 200 questions she will stop to reply.
The first line of the input contains an integer *n* (2<=≀<=*n*<=≀<=216)Β β€” size of the field. For each query an integer between 0 and 2 is returnedΒ β€” the number of initial rectangles that lie fully inside the query rectangle.
To make a query you have to print "? *x*1 *y*1 *x*2 *y*2" (without quotes) (1<=≀<=*x*1<=≀<=*x*2<=≀<=*n*, 1<=≀<=*y*1<=≀<=*y*2<=≀<=*n*), where (*x*1,<=*y*1) stands for the position of the bottom left cell of the query and (*x*2,<=*y*2) stands for the up right cell of the query. You are allowed to ask no more than 200 queries. After each query you should perform "flush" operation and read the answer. In case you suppose you've already determined the location of two rectangles (or run out of queries) you should print "! *x*11 *y*11 *x*12 *y*12 *x*21 *y*21 *x*22 *y*22" (without quotes), where first four integers describe the bottom left and up right cells of the first rectangle, and following four describe the corresponding cells of the second rectangle. You can print the rectangles in an arbitrary order. After you have printed the answer, print the end of the line and perform "flush". Your program should terminate immediately after it print the answer.
[ "5\n2\n1\n0\n1\n1\n1\n0\n1\n" ]
[ "? 1 1 5 5\n? 1 1 3 3\n? 1 1 3 1\n? 2 2 2 2\n? 3 3 5 5\n? 3 3 3 5\n? 3 3 3 4\n? 3 4 3 5\n! 2 2 2 2 3 4 3 5\n" ]
none
[ { "input": "5\n2 2 2 2\n3 4 3 5", "output": "17\n2 2 2 2 3 4 3 5" }, { "input": "10\n1 2 4 2\n1 6 4 9", "output": "21\n1 2 4 2 1 6 4 9" }, { "input": "10\n2 2 4 4\n7 10 9 10", "output": "23\n2 2 4 4 7 10 9 10" }, { "input": "10\n1 1 10 1\n5 5 5 10", "output": "23\n5 5 5 10 1 1 10 1" }, { "input": "10\n3 4 10 4\n1 1 10 1", "output": "21\n1 1 10 1 3 4 10 4" }, { "input": "100\n8 7 90 37\n4 64 4 100", "output": "48\n4 64 4 100 8 7 90 37" }, { "input": "10\n1 3 1 3\n5 6 5 6", "output": "22\n1 3 1 3 5 6 5 6" }, { "input": "8\n5 5 5 5\n7 7 7 7", "output": "24\n5 5 5 5 7 7 7 7" }, { "input": "65536\n56677 37631 57096 58131\n37503 6356 53664 37172", "output": "126\n37503 6356 53664 37172 56677 37631 57096 58131" }, { "input": "32768\n17828 4528 27798 14063\n19889 15555 23469 23334", "output": "118\n19889 15555 23469 23334 17828 4528 27798 14063" }, { "input": "65536\n1 1 1 1\n65536 65536 65536 65536", "output": "96\n1 1 1 1 65536 65536 65536 65536" }, { "input": "65536\n10000 10000 65536 20000\n1 1 9999 9999", "output": "121\n1 1 9999 9999 10000 10000 65536 20000" }, { "input": "65536\n1 1 1 1\n2 1 2 1", "output": "65\n1 1 1 1 2 1 2 1" }, { "input": "65536\n1 1 1 1\n65536 65533 65536 65534", "output": "96\n1 1 1 1 65536 65533 65536 65534" }, { "input": "65536\n1 1 35536 35536\n35537 35537 65536 65536", "output": "126\n1 1 35536 35536 35537 35537 65536 65536" }, { "input": "65536\n65536 65535 65536 65535\n65535 65536 65535 65536", "output": "128\n65535 65536 65535 65536 65536 65535 65536 65535" }, { "input": "65536\n2 2 65536 65536\n1 1 1 1", "output": "96\n1 1 1 1 2 2 65536 65536" }, { "input": "65536\n65536 65536 65536 65536\n1 1 1 1", "output": "96\n1 1 1 1 65536 65536 65536 65536" }, { "input": "65536\n1 65536 1 65536\n65536 1 65536 1", "output": "96\n1 65536 1 65536 65536 1 65536 1" }, { "input": "100\n45 67 89 90\n3 4 6 75", "output": "49\n3 4 6 75 45 67 89 90" }, { "input": "65536\n65536 65536 65536 65536\n65535 65535 65535 65535", "output": "128\n65535 65535 65535 65535 65536 65536 65536 65536" }, { "input": "65536\n1 2 1 2\n2 1 2 1", "output": "66\n1 2 1 2 2 1 2 1" }, { "input": "65536\n406 5764 16570 33442\n6167 61342 10305 65256", "output": "123\n6167 61342 10305 65256 406 5764 16570 33442" }, { "input": "65536\n39235 60239 60844 61310\n734 4630 35003 28918", "output": "126\n734 4630 35003 28918 39235 60239 60844 61310" }, { "input": "65536\n25633 6000 45095 36812\n7134 43330 26516 61810", "output": "125\n7134 43330 26516 61810 25633 6000 45095 36812" }, { "input": "65536\n57837 9982 62234 60010\n14205 9254 19852 49347", "output": "126\n14205 9254 19852 49347 57837 9982 62234 60010" }, { "input": "65535\n27509 43826 63611 52595\n8620 8098 59547 19624", "output": "125\n8620 8098 59547 19624 27509 43826 63611 52595" }, { "input": "65535\n8954 26504 22410 59426\n31023 21131 45504 44500", "output": "125\n8954 26504 22410 59426 31023 21131 45504 44500" }, { "input": "10000\n4937 5137 9011 6326\n2224 5663 2565 9554", "output": "104\n2224 5663 2565 9554 4937 5137 9011 6326" }, { "input": "65536\n1 1 32768 32768\n32769 32769 65536 65536", "output": "126\n1 1 32768 32768 32769 32769 65536 65536" }, { "input": "65536\n1 1 32768 32768\n32768 32769 65536 65536", "output": "126\n1 1 32768 32768 32768 32769 65536 65536" }, { "input": "65536\n1 32769 32768 65536\n32769 1 65536 32768", "output": "126\n1 32769 32768 65536 32769 1 65536 32768" }, { "input": "65536\n20903 30909 20903 30909\n20904 30910 20904 30910", "output": "124\n20903 30909 20903 30909 20904 30910 20904 30910" }, { "input": "65536\n21755 18195 21758 18198\n21753 18198 21754 18199", "output": "123\n21753 18198 21754 18199 21755 18195 21758 18198" }, { "input": "65536\n21814 15058 21817 15061\n21817 15056 21818 15057", "output": "122\n21814 15058 21817 15061 21817 15056 21818 15057" }, { "input": "65536\n1 1 1 65536\n2 1 2 65536", "output": "97\n1 1 1 65536 2 1 2 65536" }, { "input": "65536\n65536 1 65536 65536\n65535 1 65535 65536", "output": "128\n65535 1 65535 65536 65536 1 65536 65536" }, { "input": "65536\n1 65536 65536 65536\n1 65535 65536 65535", "output": "128\n1 65535 65536 65535 1 65536 65536 65536" }, { "input": "65536\n1 2 65536 2\n1 1 65536 1", "output": "97\n1 1 65536 1 1 2 65536 2" }, { "input": "65536\n1 32768 65536 32768\n1 32769 65536 32769", "output": "127\n1 32768 65536 32768 1 32769 65536 32769" }, { "input": "65536\n32768 1 32768 65536\n32769 1 32769 65536", "output": "127\n32768 1 32768 65536 32769 1 32769 65536" }, { "input": "65536\n41 1 41 65536\n42 1 42 65536", "output": "108\n41 1 41 65536 42 1 42 65536" }, { "input": "65536\n1 245 65536 245\n1 246 65536 246", "output": "112\n1 245 65536 245 1 246 65536 246" }, { "input": "65536\n617 24698 617 24698\n618 24698 618 24698", "output": "114\n617 24698 617 24698 618 24698 618 24698" }, { "input": "65536\n774 16333 774 16333\n774 16334 774 16334", "output": "112\n774 16333 774 16333 774 16334 774 16334" }, { "input": "65536\n32768 32768 32768 32768\n32768 32769 32768 32769", "output": "125\n32768 32768 32768 32768 32768 32769 32768 32769" }, { "input": "65536\n32768 32768 32768 32768\n32769 32768 32769 32768", "output": "125\n32768 32768 32768 32768 32769 32768 32769 32768" }, { "input": "65536\n32771 32771 32771 32771\n32772 32771 32772 32771", "output": "128\n32771 32771 32771 32771 32772 32771 32772 32771" }, { "input": "65536\n32771 32771 32771 32771\n32771 32772 32771 32772", "output": "128\n32771 32771 32771 32771 32771 32772 32771 32772" }, { "input": "65536\n1 1 1 1\n2 2 65536 65536", "output": "96\n1 1 1 1 2 2 65536 65536" }, { "input": "65536\n65536 1 65536 1\n1 2 65535 65536", "output": "111\n1 2 65535 65536 65536 1 65536 1" }, { "input": "65536\n1 1 1 1\n2 1 65536 65536", "output": "96\n1 1 1 1 2 1 65536 65536" }, { "input": "65536\n1 1 1 1\n1 2 65536 65536", "output": "96\n1 1 1 1 1 2 65536 65536" }, { "input": "65536\n65536 65536 65536 65536\n1 1 65535 65536", "output": "127\n1 1 65535 65536 65536 65536 65536 65536" }, { "input": "65536\n65536 65536 65536 65536\n1 1 65536 65535", "output": "127\n1 1 65536 65535 65536 65536 65536 65536" }, { "input": "10\n4 2 9 6\n8 7 10 9", "output": "25\n4 2 9 6 8 7 10 9" } ]
218
22,323,200
0
33,916
0
none
[ "none" ]
null
null
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure. At each step he selects one of his guests *A*, who pairwise introduces all of his friends to each other. After this action any two friends of *A* become friends. This process is run until all pairs of guests are friends. Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=22; )Β β€” the number of guests at the party (including Arseny) and the number of pairs of people which are friends. Each of the next *m* lines contains two integers *u* and *v* (1<=≀<=*u*,<=*v*<=≀<=*n*; *u*<=β‰ <=*v*), which means that people with numbers *u* and *v* are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
In the first line print the minimum number of steps required to make all pairs of guests friends. In the second line print the ids of guests, who are selected at each step. If there are multiple solutions, you can output any of them.
[ "5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n", "4 4\n1 2\n1 3\n1 4\n3 4\n" ]
[ "2\n2 3 ", "1\n1 " ]
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them. In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.
[]
46
5,529,600
0
33,920
85
Guard Towers
[ "binary search", "dsu", "geometry", "graphs", "sortings" ]
E. Guard Towers
1
256
In a far away kingdom lives a very greedy king. To defend his land, he built *n* guard towers. Apart from the towers the kingdom has two armies, each headed by a tyrannical and narcissistic general. The generals can't stand each other, specifically, they will never let soldiers of two armies be present in one tower. During defence operations to manage a guard tower a general has to send part of his army to that tower. Each general asks some fee from the king for managing towers. As they live in a really far away kingdom, each general evaluates his fee in the following weird manner: he finds two remotest (the most distant) towers, where the soldiers of his army are situated and asks for the fee equal to the distance. Each tower is represented by a point on the plane with coordinates (*x*,<=*y*), and the distance between two points with coordinates (*x*1,<=*y*1) and (*x*2,<=*y*2) is determined in this kingdom as |*x*1<=-<=*x*2|<=+<=|*y*1<=-<=*y*2|. The greedy king was not exactly satisfied with such a requirement from the generals, that's why he only agreed to pay one fee for two generals, equal to the maximum of two demanded fees. However, the king is still green with greed, and among all the ways to arrange towers between armies, he wants to find the cheapest one. Each tower should be occupied by soldiers of exactly one army. He hired you for that. You should find the minimum amount of money that will be enough to pay the fees. And as the king is also very scrupulous, you should also count the number of arrangements that will cost the same amount of money. As their number can be quite large, it is enough for the king to know it as a remainder from dividing by 109<=+<=7. Two arrangements are distinct if the sets of towers occupied by soldiers of the first general are distinct.
The first line contains an integer *n* (2<=≀<=*n*<=≀<=5000), *n* is the number of guard towers. Then follow *n* lines, each of which contains two integers *x*,<=*y* β€” the coordinates of the *i*-th tower (0<=≀<=*x*,<=*y*<=≀<=5000). No two towers are present at one point. Pretest 6 is one of the maximal tests for this problem.
Print on the first line the smallest possible amount of money that will be enough to pay fees to the generals. Print on the second line the number of arrangements that can be carried out using the smallest possible fee. This number should be calculated modulo 1000000007 (109<=+<=7).
[ "2\n0 0\n1 1\n", "4\n0 0\n0 1\n1 0\n1 1\n", "3\n0 0\n1000 1000\n5000 5000\n" ]
[ "0\n2\n", "1\n4\n", "2000\n2\n" ]
In the first example there are only two towers, the distance between which is equal to 2. If we give both towers to one general, then we well have to pay 2 units of money. If each general receives a tower to manage, to fee will be equal to 0. That is the smallest possible fee. As you can easily see, we can obtain it in two ways.
[]
46
0
0
34,008
965
Single-use Stones
[ "binary search", "flows", "greedy", "two pointers" ]
null
null
A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l &lt; w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them. The stones are located at integer distances from the banks. There are $a_i$ stones at the distance of $i$ units from the bank the frogs are currently at. Each stone can only be used once by one frog, after that it drowns in the water. What is the maximum number of frogs that can cross the river, given that then can only jump on the stones?
The first line contains two integers $w$ and $l$ ($1 \le l &lt; w \le 10^5$)Β β€” the width of the river and the maximum length of a frog's jump. The second line contains $w - 1$ integers $a_1, a_2, \ldots, a_{w-1}$ ($0 \le a_i \le 10^4$), where $a_i$ is the number of stones at the distance $i$ from the bank the frogs are currently at.
Print a single integerΒ β€” the maximum number of frogs that can cross the river.
[ "10 5\n0 0 1 0 2 0 0 1 0\n", "10 3\n1 1 1 1 2 1 1 1 1\n" ]
[ "3\n", "3\n" ]
In the first sample two frogs can use the different stones at the distance $5$, and one frog can use the stones at the distances $3$ and then $8$. In the second sample although there are two stones at the distance $5$, that does not help. The three paths are: $0 \to 3 \to 6 \to 9 \to 10$, $0 \to 2 \to 5 \to 8 \to 10$, $0 \to 1 \to 4 \to 7 \to 10$.
[ { "input": "10 5\n0 0 1 0 2 0 0 1 0", "output": "3" }, { "input": "10 3\n1 1 1 1 2 1 1 1 1", "output": "3" }, { "input": "2 1\n0", "output": "0" }, { "input": "2 1\n5", "output": "5" }, { "input": "10 4\n0 0 6 2 7 1 6 4 0", "output": "8" }, { "input": "100 15\n0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0", "output": "5" }, { "input": "10 4\n10 10 10 10 10 10 10 10 10", "output": "40" }, { "input": "100 34\n16 0 10 11 12 13 0 5 4 14 6 15 4 9 1 20 19 14 1 7 14 11 10 20 6 9 12 8 3 19 20 4 17 17 8 11 14 18 5 20 17 0 3 18 14 12 11 12 5 5 11 7 9 17 4 8 4 10 0 0 12 9 15 3 15 14 19 12 6 8 17 19 4 18 19 3 8 3 9 1 6 15 4 16 1 18 13 16 3 5 20 11 10 9 9 17 20 15 12", "output": "312" } ]
31
0
0
34,014
63
Bulls and Cows
[ "brute force", "implementation" ]
C. Bulls and Cows
2
256
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "*x* bulls *y* cows". *x* represents the number of digits in the experimental number that occupy the same positions as in the sought number. *y* represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present. For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one). When the guesser is answered "4 bulls 0 cows", the game is over. Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.
The first input line contains an integer *n* (1<=≀<=*n*<=≀<=10) which represents the number of already made guesses. Then follow *n* lines in the form of "*a**i* *b**i* *c**i*", where *a**i* is the *i*-th experimental number, *b**i* is the number of bulls, *c**i* is the number of cows (1<=≀<=*i*<=≀<=*n*, 0<=≀<=*b**i*,<=*c**i*,<=*b**i*<=+<=*c**i*<=≀<=4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.
If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.
[ "2\n1263 1 2\n8103 2 1\n", "2\n1234 2 2\n1256 0 2\n", "2\n0123 1 1\n4567 1 2\n" ]
[ "Need more data", "2134", "Incorrect data" ]
none
[ { "input": "2\n1263 1 2\n8103 2 1", "output": "Need more data" }, { "input": "2\n1234 2 2\n1256 0 2", "output": "2134" }, { "input": "2\n0123 1 1\n4567 1 2", "output": "Incorrect data" }, { "input": "1\n1234 0 0", "output": "Need more data" }, { "input": "4\n4789 1 0\n7189 1 0\n7829 1 0\n7893 1 0", "output": "4123" }, { "input": "4\n1789 1 0\n7198 1 0\n9817 1 0\n8971 1 0", "output": "Incorrect data" }, { "input": "6\n1234 3 0\n1235 3 0\n1236 3 0\n1237 3 0\n1238 3 0\n1239 3 0", "output": "1230" }, { "input": "3\n0123 0 4\n1230 0 4\n3012 0 4", "output": "2301" }, { "input": "1\n0714 1 1", "output": "Need more data" }, { "input": "2\n0159 1 0\n0153 1 0", "output": "Need more data" }, { "input": "3\n9703 3 0\n0925 0 2\n3059 0 3", "output": "Need more data" }, { "input": "4\n1689 0 1\n0159 0 2\n4326 0 1\n9048 0 2", "output": "Need more data" }, { "input": "5\n9084 1 0\n4615 0 1\n0826 0 2\n1275 0 3\n5631 0 1", "output": "Need more data" }, { "input": "6\n1586 0 2\n6105 1 1\n5382 0 1\n8164 0 2\n0647 0 1\n6059 1 1", "output": "Need more data" }, { "input": "7\n7401 0 2\n1524 0 0\n1495 0 0\n9230 0 2\n9874 1 0\n9574 1 0\n4693 1 1", "output": "6073" }, { "input": "8\n7954 0 1\n5638 0 1\n8204 0 2\n8293 1 1\n3598 0 1\n0894 0 1\n6324 1 2\n0572 0 1", "output": "Need more data" }, { "input": "9\n8742 0 1\n5183 1 1\n6149 1 0\n3568 0 2\n9258 1 2\n5193 1 2\n7403 0 1\n9124 0 2\n3058 0 2", "output": "5239" }, { "input": "10\n7098 2 1\n7693 1 1\n6428 0 2\n5209 0 2\n1683 0 2\n0432 0 1\n5697 1 1\n2437 0 0\n4593 1 0\n1784 0 1", "output": "8096" }, { "input": "10\n8795 0 3\n4971 1 1\n5032 0 1\n5479 0 3\n2501 0 1\n9052 1 0\n3649 0 1\n1927 1 0\n9173 0 1\n8014 0 2", "output": "4857" }, { "input": "10\n0459 2 0\n2371 0 1\n5209 2 1\n1306 0 0\n0213 1 0\n4173 0 0\n5076 0 1\n9674 0 1\n2894 0 3\n3527 0 2", "output": "8259" }, { "input": "10\n0132 0 1\n6801 0 1\n8749 1 1\n8036 0 0\n7384 0 2\n8594 1 1\n9307 1 0\n7390 0 1\n6127 1 1\n0381 0 1", "output": "1547" }, { "input": "10\n9360 0 1\n5208 0 2\n7861 1 0\n8916 0 1\n5937 1 1\n7082 0 1\n3402 0 2\n7230 1 0\n1794 0 1\n8293 0 2", "output": "4835" }, { "input": "2\n3794 2 2\n8647 0 4", "output": "Incorrect data" }, { "input": "2\n9726 3 1\n6583 1 1", "output": "Incorrect data" }, { "input": "3\n6093 3 0\n7902 2 0\n2305 2 1", "output": "Incorrect data" }, { "input": "3\n6108 0 3\n4975 1 1\n0981 1 2", "output": "Incorrect data" }, { "input": "4\n7153 2 1\n5810 1 0\n8439 0 2\n2794 1 3", "output": "Incorrect data" }, { "input": "4\n4259 1 3\n1985 0 3\n5263 2 2\n5703 3 1", "output": "Incorrect data" }, { "input": "5\n9784 3 0\n2657 0 3\n7536 1 0\n0762 1 3\n2014 1 1", "output": "Incorrect data" }, { "input": "5\n2746 0 3\n1509 3 0\n4135 2 0\n7536 0 4\n1825 3 0", "output": "Incorrect data" }, { "input": "6\n5132 1 0\n3085 3 0\n0523 1 3\n6912 3 0\n7406 2 1\n3179 2 1", "output": "Incorrect data" }, { "input": "6\n1034 3 0\n0514 2 2\n1092 2 2\n0814 0 4\n9182 2 0\n9534 0 0", "output": "Incorrect data" }, { "input": "7\n9230 3 1\n7401 3 1\n6073 0 0\n1495 0 0\n9574 2 0\n4693 2 2\n1524 1 2", "output": "Incorrect data" }, { "input": "4\n0789 1 0\n7189 1 0\n7829 1 0\n7893 1 0", "output": "0123" }, { "input": "1\n1234 3 1", "output": "Incorrect data" }, { "input": "2\n1234 0 0\n5678 0 0", "output": "Incorrect data" }, { "input": "2\n1340 0 0\n2435 0 0", "output": "Need more data" }, { "input": "3\n1024 0 1\n5678 3 0\n1542 0 0", "output": "0678" }, { "input": "3\n1234 0 4\n2413 0 4\n4123 0 4", "output": "Incorrect data" }, { "input": "5\n0123 0 1\n4567 0 1\n8901 0 1\n6789 0 1\n2345 0 1", "output": "Incorrect data" }, { "input": "1\n1234 2 2", "output": "Need more data" }, { "input": "2\n1234 2 2\n2134 2 2", "output": "Incorrect data" }, { "input": "3\n6789 0 2\n1234 0 2\n3467 0 0", "output": "Need more data" }, { "input": "3\n6789 0 2\n1234 2 0\n3467 0 0", "output": "1298" }, { "input": "4\n0123 1 0\n0342 1 0\n5678 2 0\n2981 0 1", "output": "0679" }, { "input": "3\n1234 3 0\n5678 0 0\n1239 3 0", "output": "1230" }, { "input": "6\n3102 3 0\n4102 3 0\n5102 3 0\n6102 3 0\n7102 3 0\n8102 3 0", "output": "9102" }, { "input": "4\n0123 1 3\n3012 1 3\n2301 2 2\n1230 0 4", "output": "Incorrect data" }, { "input": "10\n0231 2 2\n3021 2 2\n2301 2 2\n0451 2 2\n5041 2 2\n4501 2 2\n0671 2 2\n7061 2 2\n8901 2 2\n0891 2 2", "output": "Incorrect data" }, { "input": "8\n1023 2 2\n1032 2 2\n1045 2 2\n1054 2 2\n1067 2 2\n1076 2 2\n1089 2 2\n1098 2 2", "output": "Incorrect data" }, { "input": "2\n5678 1 3\n5432 1 3", "output": "Incorrect data" }, { "input": "2\n2034 2 2\n2056 0 2", "output": "0234" }, { "input": "6\n0132 2 2\n0321 2 2\n3120 2 2\n0213 2 2\n2103 2 2\n1023 2 2", "output": "0123" }, { "input": "3\n0235 3 0\n0236 3 0\n7894 1 0", "output": "0234" }, { "input": "2\n1234 0 0\n5678 0 0", "output": "Incorrect data" }, { "input": "2\n1234 3 1\n1253 3 1", "output": "Incorrect data" }, { "input": "5\n3210 0 4\n0789 1 0\n7189 1 0\n7829 1 0\n7893 1 0", "output": "0123" }, { "input": "2\n1234 3 1\n1253 3 1", "output": "Incorrect data" }, { "input": "2\n1234 0 0\n5678 0 0", "output": "Incorrect data" } ]
248
512,000
3.937046
34,103
698
Fix a Tree
[ "constructive algorithms", "dfs and similar", "dsu", "graphs", "trees" ]
null
null
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.
[ "4\n2 3 3 4\n", "5\n3 2 2 5 3\n", "8\n2 3 5 4 1 6 6 7\n" ]
[ "1\n2 3 4 4 \n", "0\n3 2 2 5 3 \n", "2\n2 3 7 8 1 6 6 7\n" ]
In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because *p*<sub class="lower-index">4</sub> = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On both drawings, roots are painted red. In the second sample, the given sequence is already valid.
[ { "input": "4\n2 3 3 4", "output": "1\n2 3 4 4 " }, { "input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3 " }, { "input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7" }, { "input": "2\n1 2", "output": "1\n2 2 " }, { "input": "7\n4 3 2 6 3 5 2", "output": "1\n4 3 3 6 3 5 2 " }, { "input": "6\n6 2 6 2 4 2", "output": "0\n6 2 6 2 4 2 " }, { "input": "7\n1 6 4 4 5 6 7", "output": "4\n7 6 4 7 7 7 7 " }, { "input": "7\n7 5 3 1 2 1 5", "output": "1\n7 5 3 1 3 1 5 " }, { "input": "7\n1 2 3 4 5 6 7", "output": "6\n7 7 7 7 7 7 7 " }, { "input": "18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18", "output": "5\n2 18 4 5 2 7 18 9 10 7 18 18 18 15 13 17 18 18 " }, { "input": "8\n2 1 2 2 6 5 6 6", "output": "2\n1 1 2 2 1 5 6 6 " }, { "input": "3\n2 1 1", "output": "1\n1 1 1 " } ]
467
42,188,800
0
34,150
690
Brain Network (hard)
[ "trees" ]
null
null
Breaking news from zombie neurology! It turns out that – contrary to previous beliefs – every zombie is born with a single brain, and only later it evolves into a complicated brain structure. In fact, whenever a zombie consumes a brain, a new brain appears in its nervous system and gets immediately connected to one of the already existing brains using a single brain connector. Researchers are now interested in monitoring the brain latency of a zombie. Your task is to write a program which, given a history of evolution of a zombie's nervous system, computes its brain latency at every stage.
The first line of the input contains one number *n* – the number of brains in the final nervous system (2<=≀<=*n*<=≀<=200000). In the second line a history of zombie's nervous system evolution is given. For convenience, we number all the brains by 1,<=2,<=...,<=*n* in the same order as they appear in the nervous system (the zombie is born with a single brain, number 1, and subsequently brains 2,<=3,<=...,<=*n* are added). The second line contains *n*<=-<=1 space-separated numbers *p*2,<=*p*3,<=...,<=*p**n*, meaning that after a new brain *k* is added to the system, it gets connected to a parent-brain .
Output *n*<=-<=1 space-separated numbers – the brain latencies after the brain number *k* is added, for *k*<==<=2,<=3,<=...,<=*n*.
[ "6\n1\n2\n2\n1\n5\n" ]
[ "1 2 2 3 4 " ]
none
[ { "input": "2\n1", "output": "1 " }, { "input": "3\n1\n2", "output": "1 2 " }, { "input": "10\n1\n1\n1\n1\n3\n3\n7\n5\n5", "output": "1 2 2 2 3 3 4 5 5 " }, { "input": "120\n1\n1\n2\n2\n3\n3\n4\n4\n5\n5\n6\n6\n7\n7\n8\n8\n9\n9\n10\n10\n11\n11\n12\n12\n13\n13\n14\n14\n15\n15\n16\n16\n17\n17\n18\n18\n19\n19\n20\n20\n21\n21\n22\n22\n23\n23\n24\n24\n25\n25\n26\n26\n27\n27\n28\n28\n29\n29\n30\n30\n31\n31\n32\n32\n33\n33\n34\n34\n35\n35\n36\n36\n37\n37\n38\n38\n39\n39\n40\n40\n41\n41\n42\n42\n43\n43\n44\n44\n45\n45\n46\n46\n47\n47\n48\n48\n49\n49\n50\n50\n51\n51\n52\n52\n53\n53\n54\n54\n55\n55\n56\n56\n57\n57\n58\n58\n59\n59\n60", "output": "1 2 3 3 4 4 5 5 5 5 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 " }, { "input": "6\n1\n2\n2\n1\n5", "output": "1 2 2 3 4 " } ]
2,000
62,976,000
0
34,181
49
Disposition
[ "constructive algorithms", "math" ]
C. Disposition
2
256
Vasya bought the collected works of a well-known Berland poet Petya in *n* volumes. The volumes are numbered from 1 to *n*. He thinks that it does not do to arrange the book simply according to their order. Vasya wants to minimize the number of the disposition’s divisors β€” the positive integers *i* such that for at least one *j* (1<=≀<=*j*<=≀<=*n*) is true both: *j* *mod* *i*<==<=0 and at the same time *p*(*j*) *mod* *i*<==<=0, where *p*(*j*) is the number of the tome that stands on the *j*-th place and *mod* is the operation of taking the division remainder. Naturally, one volume can occupy exactly one place and in one place can stand exactly one volume. Help Vasya β€” find the volume disposition with the minimum number of divisors.
The first line contains number *n* (1<=≀<=*n*<=≀<=100000) which represents the number of volumes and free places.
Print *n* numbers β€” the sought disposition with the minimum divisor number. The *j*-th number (1<=≀<=*j*<=≀<=*n*) should be equal to *p*(*j*) β€” the number of tome that stands on the *j*-th place. If there are several solutions, print any of them.
[ "2\n", "3\n" ]
[ "2 1 \n", "1 3 2 \n" ]
none
[ { "input": "2", "output": "2 1 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "5", "output": "1 3 2 5 4 " }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "1", "output": "1 " }, { "input": "7", "output": "1 3 2 5 4 7 6 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "1 3 2 5 4 7 6 9 8 " }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "97", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "99", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "9996", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "9997", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "9998", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "9999", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "10000", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "99996", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "99997", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "99998", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "99999", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "100000", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "9149", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "72877", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "52956", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "33035", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "13114", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "93193", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "73273", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "37000", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "17079", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "84653", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "27251", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "53496", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "96093", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." }, { "input": "22338", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..." }, { "input": "64935", "output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..." } ]
310
7,987,200
3.907623
34,273
883
Packmen Strike Back
[ "binary search", "dp", "math" ]
null
null
Game field is represented by a line of *n* square cells. In some cells there are packmen, in some cells there are asterisks and the rest of the cells are empty. Packmen eat asterisks. Before the game starts you can choose a movement direction, left or right, for each packman. Once the game begins all the packmen simultaneously start moving according their directions. A packman can't change the given direction. Once a packman enters a cell containing an asterisk, packman immediately eats the asterisk. Once the packman leaves the cell it becomes empty. Each packman moves at speed 1 cell per second. If a packman enters a border cell, the packman stops. Packmen do not interfere with the movement of other packmen; in one cell there can be any number of packmen moving in any directions. Your task is to assign a direction to each packman so that they eat the maximal number of asterisks. If there are multiple ways to assign directions to eat the maximal number of asterisks, you should choose the way which minimizes the time to do that.
The first line contains integer number *n* (2<=≀<=*n*<=≀<=1<=000<=000) β€” the number of cells in the game field. The second line contains *n* characters. If the *i*-th character is '.', the *i*-th cell is empty. If the *i*-th character is '*', the *i*-th cell contains an asterisk. If the *i*-th character is 'P', the *i*-th cell contains a packman. The field contains at least one asterisk and at least one packman.
Print two integer numbers β€” the maximal number of asterisks packmen can eat and the minimal time to do it.
[ "6\n*.P*P*\n", "8\n*...P..*\n" ]
[ "3 4\n", "1 3\n" ]
In the first example the leftmost packman should move to the right, the rightmost packman should move to the left. All the asterisks will be eaten, the last asterisk will be eaten after 4 seconds.
[]
2,245
268,390,400
0
34,330
13
Holes
[ "data structures", "dsu" ]
E. Holes
1
64
Little Petya likes to play a lot. Most of all he likes to play a game Β«HolesΒ». This is a game for one person with following rules: There are *N* holes located in a single row and numbered from left to right with numbers from 1 to *N*. Each hole has it's own power (hole number *i* has the power *a**i*). If you throw a ball into hole *i* it will immediately jump to hole *i*<=+<=*a**i*, then it will jump out of it and so on. If there is no hole with such number, the ball will just jump out of the row. On each of the *M* moves the player can perform one of two actions: - Set the power of the hole *a* to value *b*. - Throw a ball into the hole *a* and count the number of jumps of a ball before it jump out of the row and also write down the number of the hole from which it jumped out just before leaving the row. Petya is not good at math, so, as you have already guessed, you are to perform all computations.
The first line contains two integers *N* and *M* (1<=≀<=*N*<=≀<=105, 1<=≀<=*M*<=≀<=105) β€” the number of holes in a row and the number of moves. The second line contains *N* positive integers not exceeding *N* β€” initial values of holes power. The following *M* lines describe moves made by Petya. Each of these line can be one of the two types: - 0 *a* *b* - 1 *a*
For each move of the type 1 output two space-separated numbers on a separate line β€” the number of the last hole the ball visited before leaving the row and the number of jumps it made.
[ "8 5\n1 1 1 1 1 2 8 2\n1 1\n0 1 3\n1 1\n0 3 4\n1 2\n" ]
[ "8 7\n8 5\n7 3\n" ]
none
[ { "input": "8 5\n1 1 1 1 1 2 8 2\n1 1\n0 1 3\n1 1\n0 3 4\n1 2", "output": "8 7\n8 5\n7 3" }, { "input": "10 10\n5 1 2 4 1 7 3 8 10 8\n0 5 6\n1 8\n1 1\n0 10 3\n1 5\n1 3\n1 2\n0 6 1\n1 9\n1 1", "output": "8 1\n6 2\n5 1\n5 2\n5 3\n9 1\n10 4" } ]
1,000
102,400
0
34,335
128
Birthday
[ "geometry", "math" ]
null
null
Anna's got a birthday today. She invited many guests and cooked a huge (nearly infinite) birthday cake decorated by *n* banana circles of different sizes. Maria's birthday is about to start in 7 minutes too, and while Anna is older, she decided to play the boss a little. She told Maria to cut the cake by *k* straight-line cuts (the cutting lines can intersect) to divide banana circles into banana pieces. Anna has many guests and she wants everyone to get at least one banana piece. That's why she told Maria to make the total number of banana pieces maximum. It's not a problem if some banana pieces end up on the same cake piece β€” the key is to make the maximum number of banana pieces. Determine what result Maria will achieve.
The first line contains two integers *n* and *k* β€” the number of banana circles and the number of cuts Maria should perform (1<=≀<=*n*<=≀<=1000, 1<=≀<=*k*<=≀<=105). Next *n* lines contain the positions and sizes of the banana circles (all banana circles are round). On the cake the Cartesian coordinate system is defined. Each line contains three integers *x*, *y* and *r* β€” the coordinates of the center of the corresponding banana piece and its radius (<=-<=1000<=≀<=*x*,<=*y*<=≀<=1000, 1<=≀<=*r*<=≀<=1000). It is guaranteed that the banana circles do not intersect, do not touch each other and do not overlap with each other. Pretest 10 is big test with *n*<==<=*k*<==<=1000.
Print the only integer β€” the largest number of banana pieces that Maria can get after she performs the *k* straight-line cuts. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "1 1\n0 0 1\n", "3 1\n0 0 1\n3 0 1\n6 0 1\n", "1 3\n0 0 1\n" ]
[ "2\n", "6\n", "7\n" ]
none
[]
92
0
0
34,368
0
none
[ "none" ]
null
null
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are *n* flights that must depart today, the *i*-th of them is planned to depart at the *i*-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first *k* minutes of the day, so now the new departure schedule must be created. All *n* scheduled flights must now depart at different minutes between (*k*<=+<=1)-th and (*k*<=+<=*n*)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do soΒ β€” their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule. Helen knows that each minute of delay of the *i*-th flight costs airport *c**i* burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.
The first line contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=300<=000), here *n* is the number of flights, and *k* is the number of minutes in the beginning of the day that the flights did not depart. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≀<=*c**i*<=≀<=107), here *c**i* is the cost of delaying the *i*-th flight for one minute.
The first line must contain the minimum possible total cost of delaying the flights. The second line must contain *n* different integers *t*1,<=*t*2,<=...,<=*t**n* (*k*<=+<=1<=≀<=*t**i*<=≀<=*k*<=+<=*n*), here *t**i* is the minute when the *i*-th flight must depart. If there are several optimal schedules, print any of them.
[ "5 2\n4 2 1 10 2\n" ]
[ "20\n3 6 7 4 5 \n" ]
Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)Β·4 + (4 - 2)Β·2 + (5 - 3)Β·1 + (6 - 4)Β·10 + (7 - 5)Β·2 = 38 burles. However, the better schedule is shown in the sample answer, its cost is (3 - 1)Β·4 + (6 - 2)Β·2 + (7 - 3)Β·1 + (4 - 4)Β·10 + (5 - 5)Β·2 = 20 burles.
[ { "input": "5 2\n4 2 1 10 2", "output": "20\n3 6 7 4 5 " }, { "input": "3 2\n3 1 2", "output": "11\n3 5 4 " }, { "input": "5 5\n5 5 9 100 3", "output": "321\n9 8 7 6 10 " }, { "input": "1 1\n1", "output": "1\n2 " }, { "input": "1 1\n10000000", "output": "10000000\n2 " }, { "input": "6 4\n85666 52319 21890 51912 90704 10358", "output": "1070345\n6 7 9 8 5 10 " }, { "input": "10 5\n66220 81797 38439 54881 86879 94346 8802 59094 57095 41949", "output": "2484818\n9 8 14 12 7 6 15 10 11 13 " }, { "input": "8 1\n3669 11274 87693 33658 58862 78334 42958 30572", "output": "29352\n9 2 3 4 5 6 7 8 " }, { "input": "2 2\n16927 73456", "output": "124237\n4 3 " }, { "input": "6 6\n21673 27126 94712 82700 59725 46310", "output": "1616325\n12 11 7 8 9 10 " }, { "input": "10 6\n2226 89307 11261 28772 23196 30298 10832 43119 74662 24028", "output": "1246672\n16 7 14 11 13 10 15 8 9 12 " }, { "input": "9 7\n6972 18785 36323 7549 27884 14286 20795 80005 67805", "output": "1034082\n16 13 10 15 11 14 12 8 9 " }, { "input": "3 1\n20230 80967 85577", "output": "60690\n4 2 3 " }, { "input": "7 1\n783 77740 34830 89295 96042 14966 21810", "output": "5481\n8 2 3 4 5 6 7 " }, { "input": "7 3\n94944 94750 49432 83079 89532 78359 91885", "output": "1572031\n4 5 10 8 6 9 7 " } ]
1,000
58,060,800
0
34,407
898
Alarm Clock
[ "greedy" ]
null
null
Every evening Vitalya sets *n* alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer *a**i*Β β€” number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will definitely wake up if during some *m* consecutive minutes at least *k* alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time. Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
First line contains three integers *n*, *m* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=2Β·105, 1<=≀<=*m*<=≀<=106)Β β€” number of alarm clocks, and conditions of Vitalya's waking up. Second line contains sequence of distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=106) in which *a**i* equals minute on which *i*-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
[ "3 3 2\n3 5 1\n", "5 10 3\n12 8 18 25 1\n", "7 7 2\n7 3 4 1 6 5 2\n", "2 2 2\n1 3\n" ]
[ "1\n", "0\n", "6\n", "0\n" ]
In first example Vitalya should turn off first alarm clock which rings at minute 3. In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring. In third example Vitalya should turn off any 6 alarm clocks.
[ { "input": "3 3 2\n3 5 1", "output": "1" }, { "input": "5 10 3\n12 8 18 25 1", "output": "0" }, { "input": "7 7 2\n7 3 4 1 6 5 2", "output": "6" }, { "input": "2 2 2\n1 3", "output": "0" }, { "input": "1 4 1\n1", "output": "1" }, { "input": "2 3 1\n1 2", "output": "2" }, { "input": "5 4 2\n7 2 4 5 6", "output": "3" }, { "input": "7 5 3\n11 3 13 19 5 18 17", "output": "1" }, { "input": "10 7 2\n30 9 1 40 34 4 35 27 11 3", "output": "6" }, { "input": "13 10 4\n5 28 67 70 68 3 84 4 30 82 96 37 49", "output": "0" }, { "input": "14 5 5\n10 20 22 38 16 35 29 15 25 40 32 6 7 19", "output": "0" }, { "input": "15 20 15\n8 18 12 15 1 9 4 21 23 3 24 5 2 25 14", "output": "0" }, { "input": "16 40 1\n223061 155789 448455 956209 90420 110807 833270 240866 996739 14579 366906 594384 72757 50161 278465 135449", "output": "16" }, { "input": "20 30 10\n37 220 115 125 266 821 642 424 376 542 91 997 813 858 770 447 760 362 392 132", "output": "0" }, { "input": "100 40 20\n148 120 37 65 188 182 199 131 97 174 157 113 62 63 193 8 72 152 138 5 90 48 133 83 197 118 123 2 181 151 53 115 78 177 144 33 196 19 85 104 77 34 173 198 136 44 3 22 86 200 23 129 68 176 29 58 121 56 79 15 159 183 171 60 141 54 158 106 30 17 116 105 190 59 36 46 169 142 165 112 155 126 101 125 38 81 47 127 88 31 55 66 139 184 70 137 21 153 185 76", "output": "11" }, { "input": "4 1 1\n454 234 123 65756", "output": "4" }, { "input": "2 1000000 2\n1 1000000", "output": "1" }, { "input": "20 5 2\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21", "output": "16" }, { "input": "1 1 1\n1000000", "output": "1" } ]
623
14,950,400
3
34,464
350
Looking for Owls
[ "binary search", "data structures", "geometry", "hashing", "sortings" ]
null
null
Emperor Palpatine loves owls very much. The emperor has some blueprints with the new Death Star, the blueprints contain *n* distinct segments and *m* distinct circles. We will consider the segments indexed from 1 to *n* in some way and the circles β€” indexed from 1 to *m* in some way. Palpatine defines an owl as a set of a pair of distinct circles (*i*,<=*j*) (*i*<=&lt;<=*j*) and one segment *k*, such that: 1. circles *i* and *j* are symmetrical relatively to the straight line containing segment *k*; 1. circles *i* and *j* don't have any common points; 1. circles *i* and *j* have the same radius; 1. segment *k* intersects the segment that connects the centers of circles *i* and *j*. Help Palpatine, count the number of distinct owls on the picture.
The first line contains two integers β€” *n* and *m* (1<=≀<=*n*<=≀<=3Β·105, 2<=≀<=*m*<=≀<=1500). The next *n* lines contain four integers each, *x*1, *y*1, *x*2, *y*2 β€” the coordinates of the two endpoints of the segment. It's guaranteed that each segment has positive length. The next *m* lines contain three integers each, *x**i*, *y**i*, *r**i* β€” the coordinates of the center and the radius of the *i*-th circle. All coordinates are integers of at most 104 in their absolute value. The radius is a positive integer of at most 104. It is guaranteed that all segments and all circles are dictinct.
Print a single number β€” the answer to the problem. Please, do not use the %lld specifier to output 64-bit integers is Π‘++. It is preferred to use the cout stream or the %I64d specifier.
[ "1 2\n3 2 3 -2\n0 0 2\n6 0 2\n", "3 2\n0 0 0 1\n0 -1 0 1\n0 -1 0 0\n2 0 1\n-2 0 1\n", "1 2\n-1 0 1 0\n-100 0 1\n100 0 1\n" ]
[ "1\n", "3\n", "0\n" ]
Here's an owl from the first sample. The owl is sitting and waiting for you to count it.
[]
92
0
0
34,470
0
none
[ "none" ]
null
null
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer *m*, bit depth of the game, which means that all numbers in the game will consist of *m* bits. Then he asks Peter to choose some *m*-bit number. After that, Bob computes the values of *n* variables. Each variable is assigned either a constant *m*-bit number or result of bitwise operation. Operands of the operation may be either variables defined before, or the number, chosen by Peter. After that, Peter's score equals to the sum of all variable values. Bob wants to know, what number Peter needs to choose to get the minimum possible score, and what number he needs to choose to get the maximum possible score. In both cases, if there are several ways to get the same score, find the minimum number, which he can choose.
The first line contains two integers *n* and *m*, the number of variables and bit depth, respectively (1<=≀<=*n*<=≀<=5000; 1<=≀<=*m*<=≀<=1000). The following *n* lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of: 1. Binary number of exactly *m* bits. 1. The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter. Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different.
In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as *m*-bit binary numbers.
[ "3 3\na := 101\nb := 011\nc := ? XOR b\n", "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n" ]
[ "011\n100\n", "0\n0\n" ]
In the first sample if Peter chooses a number 011<sub class="lower-index">2</sub>, then *a* = 101<sub class="lower-index">2</sub>, *b* = 011<sub class="lower-index">2</sub>, *c* = 000<sub class="lower-index">2</sub>, the sum of their values is 8. If he chooses the number 100<sub class="lower-index">2</sub>, then *a* = 101<sub class="lower-index">2</sub>, *b* = 011<sub class="lower-index">2</sub>, *c* = 111<sub class="lower-index">2</sub>, the sum of their values is 15. For the second test, the minimum and maximum sum of variables *a*, *bb*, *cx*, *d* and *e* is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 0.
[ { "input": "3 3\na := 101\nb := 011\nc := ? XOR b", "output": "011\n100" }, { "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb", "output": "0\n0" }, { "input": "2 10\nb := 0100101101\na := ? XOR b", "output": "0100101101\n1011010010" }, { "input": "1 10\na := 0110110011", "output": "0000000000\n0000000000" }, { "input": "1 6\na := ? OR ?", "output": "000000\n111111" }, { "input": "13 6\na := 111010\nb := 100100\nc := 001110\nd := b AND b\ne := c AND ?\nf := e OR c\ng := 011110\nh := d XOR ?\ni := 010111\nj := 000011\nk := d OR ?\nl := 011101\nm := b OR j", "output": "100000\n011011" }, { "input": "16 3\na := 011\nb := 110\nc := a XOR b\nd := 110\ne := a XOR b\nf := b XOR a\ng := b XOR e\nh := 111\ni := a XOR h\nj := f XOR ?\nk := 100\nl := 000\nm := 100\nn := 110\no := 110\np := 110", "output": "101\n010" }, { "input": "29 2\naa := 10\nba := 11\nca := 01\nda := aa AND ?\nea := ba OR ?\nfa := da XOR ?\nga := 11\nha := fa XOR ea\nia := 01\nja := ca OR ha\nka := ha XOR ia\nla := ha OR ?\nma := ba AND ba\nna := ma OR ?\noa := 11\npa := oa OR ba\nqa := 00\nra := qa AND ia\nsa := fa OR ?\nta := ha OR ga\nua := 00\nva := 00\nwa := 11\nxa := 10\nya := ja XOR ?\nza := 00\nab := 00\nbb := pa OR qa\ncb := bb AND ?", "output": "00\n11" }, { "input": "10 3\na := 011\nb := ? OR a\nc := 000\nd := ? AND c\ne := 101\nf := ? AND e\ng := 001\nh := ? XOR g\ni := 001\nj := ? XOR i", "output": "001\n110" }, { "input": "12 3\na := 101\nb := a XOR ?\nc := b XOR b\nd := b XOR a\ne := c XOR ?\nf := e XOR ?\ng := c XOR f\nh := 100\ni := c XOR h\nj := c XOR i\nk := b XOR ?\nl := 111", "output": "000\n111" }, { "input": "12 14\na := 01100010000111\nb := ? XOR a\nc := 01101111001010\nd := ? XOR c\ne := 10000011101111\nf := ? XOR e\ng := 10100011001010\nh := ? XOR g\ni := 10010110111111\nj := ? XOR i\nk := 10000111110001\nl := ? XOR k", "output": "10000011001011\n01011000010000" }, { "input": "14 8\na := 01010000\nb := 10101111\nc := 01100100\nd := 10011011\ne := 01001100\nf := 10110011\ng := ? XOR a\nh := b XOR ?\ni := ? XOR c\nj := d XOR ?\nk := ? XOR e\nl := f XOR ?\nm := 00101111\nn := ? XOR m", "output": "00101111\n11010000" }, { "input": "14 14\na := 10000100110000\nb := 01111011001111\nc := 11110001111101\nd := 00001110000010\ne := 00111100000010\nf := 11000011111101\ng := ? XOR a\nh := b XOR ?\ni := ? XOR c\nj := d XOR ?\nk := ? XOR e\nl := f XOR ?\nm := 11110011011001\nn := ? XOR m", "output": "11110011011001\n00001100100110" }, { "input": "17 15\na := 010000111111110\nb := 101100110000100\nc := 100101100100111\nd := 010110101110110\ne := 111111000010110\nf := 011001110111110\ng := 110011010100101\nh := 000001010010001\ni := 110000111001011\nj := 000010000010111\nk := 110110111110110\nl := 010000110000100\nm := 000111101101000\nn := 011111011000111\no := 010110110010100\np := 111001110011001\nq := 000100110001000", "output": "000000000000000\n000000000000000" }, { "input": "22 9\na := 100101111\nb := 010001100\nc := b AND b\nd := 111000010\ne := c AND a\nf := a OR e\ng := e AND ?\nh := 000010001\ni := b OR ?\nj := d AND ?\nk := g AND h\nl := 010100000\nm := a AND a\nn := j AND ?\no := m OR n\np := o AND ?\nq := f OR ?\nr := 000011011\ns := 001110011\nt := 100111100\nu := l AND p\nv := g OR h", "output": "000000000\n111111111" }, { "input": "2 109\na := 1010101010100000000000011111111111111111111111111111111111111111111000000000000000000000000000111111111111111\nb := ? XOR a", "output": "1010101010100000000000011111111111111111111111111111111111111111111000000000000000000000000000111111111111111\n0101010101011111111111100000000000000000000000000000000000000000000111111111111111111111111111000000000000000" } ]
3,000
6,758,400
0
34,487
631
Product Sum
[ "data structures", "dp", "geometry" ]
null
null
Blake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special. You are given an array *a* of length *n*. The characteristic of this array is the value Β β€” the sum of the products of the values *a**i* by *i*. One may perform the following operation exactly once: pick some element of the array and move to any position. In particular, it's allowed to move the element to the beginning or to the end of the array. Also, it's allowed to put it back to the initial position. The goal is to get the array with the maximum possible value of characteristic.
The first line of the input contains a single integer *n* (2<=≀<=*n*<=≀<=200<=000)Β β€” the size of the array *a*. The second line contains *n* integers *a**i* (1<=≀<=*i*<=≀<=*n*, |*a**i*|<=≀<=1<=000<=000)Β β€” the elements of the array *a*.
Print a single integer β€” the maximum possible value of characteristic of *a* that can be obtained by performing no more than one move.
[ "4\n4 3 2 5\n", "5\n1 1 2 7 1\n", "3\n1 1 2\n" ]
[ "39", "49", "9" ]
In the first sample, one may pick the first element and place it before the third (before 5). Thus, the answer will be 3Β·1 + 2Β·2 + 4Β·3 + 5Β·4 = 39. In the second sample, one may pick the fifth element of the array and place it before the third. The answer will be 1Β·1 + 1Β·2 + 1Β·3 + 2Β·4 + 7Β·5 = 49.
[ { "input": "4\n4 3 2 5", "output": "39" }, { "input": "5\n1 1 2 7 1", "output": "49" }, { "input": "3\n1 1 2", "output": "9" }, { "input": "5\n1 2 3 4 5", "output": "55" }, { "input": "5\n-1 -2 -3 -4 -5", "output": "-45" }, { "input": "4\n0 0 0 0", "output": "0" }, { "input": "7\n0 0 0 -1 0 0 0", "output": "-1" }, { "input": "2\n1000000 -1000000", "output": "1000000" }, { "input": "2\n1 1", "output": "3" }, { "input": "2\n-1 -1", "output": "-3" }, { "input": "2\n-1000000 1000000", "output": "1000000" }, { "input": "2\n0 0", "output": "0" }, { "input": "4\n2 1 3 4", "output": "30" }, { "input": "5\n1 2 5 4 5", "output": "62" }, { "input": "4\n2 3 4 1", "output": "30" }, { "input": "4\n4 1 2 3", "output": "30" }, { "input": "6\n5 7 11 83 14 999", "output": "6517" }, { "input": "4\n87 213 141 1", "output": "1378" } ]
577
46,080,000
0
34,520
76
Gift
[ "dsu", "graphs", "sortings", "trees" ]
A. Gift
2
256
The kingdom of Olympia consists of *N* cities and *M* bidirectional roads. Each road connects exactly two cities and two cities can be connected with more than one road. Also it possible that some roads connect city with itself making a loop. All roads are constantly plundered with bandits. After a while bandits became bored of wasting time in road robberies, so they suggested the king of Olympia to pay off. According to the offer, bandits want to get a gift consisted of gold and silver coins. Offer also contains a list of restrictions: for each road it is known *g**i* β€” the smallest amount of gold and *s**i* β€” the smallest amount of silver coins that should be in the gift to stop robberies on the road. That is, if the gift contains *a* gold and *b* silver coins, then bandits will stop robberies on all the roads that *g**i*<=≀<=*a* and *s**i*<=≀<=*b*. Unfortunately kingdom treasury doesn't contain neither gold nor silver coins, but there are Olympian tugriks in it. The cost of one gold coin in tugriks is *G*, and the cost of one silver coin in tugriks is *S*. King really wants to send bandits such gift that for any two cities there will exist a safe path between them. Your task is to find the minimal cost in Olympian tugriks of the required gift.
The first line of the input contains two integers *N* and *M* (2<=≀<=*N*<=≀<=200, 1<=≀<=*M*<=≀<=50<=000) β€” the number of cities and the number of roads, respectively. The second line contains two integers *G* and *S* (1<=≀<=*G*,<=*S*<=≀<=109) β€” the prices of gold and silver coins in tugriks. The following *M* lines contain information about the offer. Each of the records in list is given as four integers *x**i*,<=*y**i*,<=*g**i*,<=*s**i*, where *x**i* and *y**i* are the numbers of cities that the road connects and *g**i*, *s**i* are minimal gold and silver coins requirements for the *i*-th road (1<=≀<=*x**i*,<=*y**i*<=≀<=*N*, 1<=≀<=*g**i*,<=*s**i*<=≀<=109). Cities are numbered from 1 to *N*. It is possible that there are more than one road between a pair of cities. It is possible that a road connects the city with itself.
The output should contain the minimal cost of the gift in Olympian tugriks. If there is no gift that satisfies the given requirements output .
[ "3 3\n2 1\n1 2 10 15\n1 2 4 20\n1 3 5 1\n" ]
[ "30\n" ]
none
[ { "input": "3 3\n2 1\n1 2 10 15\n1 2 4 20\n1 3 5 1", "output": "30" } ]
0
0
-1
34,523
213
Stars
[ "constructive algorithms", "geometry" ]
null
null
Furik loves painting stars. A star is a shape that results if we take a regular pentagon and paint all diagonals in it. Recently he decided to teach Rubik to paint stars. After many years of training Rubik could paint stars easily. But now Furik decided to test Rubik and complicated the task. Rubik must paint *n* stars, observing the following rules: - all stars must be painted in a single move (i.e. it is forbidden to take the pen away from the paper); - it is forbidden to paint the same segment of non-zero length more than once; - the stars can intersect only in their vertexes; - the length of a side of the regular pentagon, in which Rubik paints each star, must equal 10. Help Rubik to cope with this hard task.
A single line contains an integer (1<=≀<=*n*<=≀<=100) β€” the number of stars to paint.
On the first line print an integer *m* (1<=≀<=*m*<=≀<=5Β·*n*). On the next *m* lines print coordinates of *m* distinct points with accuracy of at least 9 and at most 100 digits after decimal point. All coordinates should not exceed 5000 in their absolute value. On each of the next *n* lines print 5 integers β€” the indexes of the points that form the given star in the clockwise or counterclockwise order. On the next line print 5Β·*n*<=+<=1 integers β€” the numbers of points in the order, in which Rubik paints stars. That is, if number with index *i* is *a**i*, and number with index *i*<=+<=1 is *a**i*<=+<=1, then points with indexes *a**i* and *a**i*<=+<=1 will have a segment painted between them. You can consider all *m* printed points indexed from 1 to *m* in the order, in which they occur in the output. Separate the numbers on the lines with whitespaces. Note that the answer has an imprecise validation. Try to obtain as accurate a solution as possible. The validator performs all calculations considering that the absolute error of a participant's answer is not more than 10<=-<=8.
[ "1\n" ]
[ "5\n3.830127018922193 3.366025403784439\n-3.601321235851749 10.057331467373021\n0.466045194906253 19.192786043799030\n10.411264148588986 18.147501411122495\n12.490381056766580 8.366025403784439\n1 2 3 4 5\n1 3 5 2 4 1\n" ]
The initial position of points in the sample is: The order in which Rubik can paint segments is:
[]
92
0
0
34,610
0
none
[ "none" ]
null
null
Appleman has a tree with *n* vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of *k* (0<=≀<=*k*<=&lt;<=*n*) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (*k*<=+<=1) parts. Note, that each part will be a tree with colored vertices. Now Appleman wonders, what is the number of sets splitting the tree in such a way that each resulting part will have exactly one black vertex? Find this number modulo 1000000007 (109<=+<=7).
The first line contains an integer *n* (2<=<=≀<=*n*<=≀<=105) β€” the number of tree vertices. The second line contains the description of the tree: *n*<=-<=1 integers *p*0,<=*p*1,<=...,<=*p**n*<=-<=2 (0<=≀<=*p**i*<=≀<=*i*). Where *p**i* means that there is an edge connecting vertex (*i*<=+<=1) of the tree and vertex *p**i*. Consider tree vertices are numbered from 0 to *n*<=-<=1. The third line contains the description of the colors of the vertices: *n* integers *x*0,<=*x*1,<=...,<=*x**n*<=-<=1 (*x**i* is either 0 or 1). If *x**i* is equal to 1, vertex *i* is colored black. Otherwise, vertex *i* is colored white.
Output a single integer β€” the number of ways to split the tree modulo 1000000007 (109<=+<=7).
[ "3\n0 0\n0 1 1\n", "6\n0 1 1 0 4\n1 1 0 0 1 0\n", "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1\n" ]
[ "2\n", "1\n", "27\n" ]
none
[ { "input": "3\n0 0\n0 1 1", "output": "2" }, { "input": "6\n0 1 1 0 4\n1 1 0 0 1 0", "output": "1" }, { "input": "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "output": "27" }, { "input": "5\n0 1 1 3\n0 0 0 1 1", "output": "1" }, { "input": "10\n0 1 1 2 4 3 3 3 2\n1 0 1 1 1 0 0 1 1 0", "output": "3" }, { "input": "100\n0 0 2 2 0 3 5 0 6 2 0 4 0 2 3 7 8 3 15 19 13 8 18 19 3 14 23 9 6 3 6 17 26 24 20 6 4 27 8 5 14 5 35 31 27 3 41 25 20 14 25 31 49 40 0 1 10 5 50 13 29 58 1 6 8 1 40 52 30 15 50 8 66 52 29 71 25 68 36 7 80 60 6 2 11 43 62 27 84 86 71 38 14 50 88 4 8 95 53\n1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1", "output": "9523200" }, { "input": "2\n0\n1 0", "output": "1" }, { "input": "115\n0 0 1 2 0 4 1 3 4 1 4 5 4 5 0 0 3 1 2 3 3 0 5 1 3 4 1 5 2 0 1 3 3 1 3 5 0 4 5 1 3 0 0 1 3 1 1 3 3 3 2 3 1 3 0 2 5 5 1 1 2 2 1 1 3 2 1 2 3 1 5 4 2 1 2 1 1 2 3 4 3 1 5 0 2 4 4 5 2 5 0 2 4 5 5 5 5 0 3 1 1 4 2 2 4 3 3 0 3 3 0 2 0 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" } ]
46
0
0
34,623
913
Party Lemonade
[ "bitmasks", "dp", "greedy" ]
null
null
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of *n* different volumes at different costs. A single bottle of type *i* has volume 2*i*<=-<=1 liters and costs *c**i* roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least *L* liters of lemonade. How many roubles do you have to spend?
The first line contains two integers *n* and *L* (1<=≀<=*n*<=≀<=30; 1<=≀<=*L*<=≀<=109)Β β€” the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≀<=*c**i*<=≀<=109)Β β€” the costs of bottles of different types.
Output a single integerΒ β€” the smallest number of roubles you have to pay in order to buy at least *L* liters of lemonade.
[ "4 12\n20 30 70 90\n", "4 3\n10000 1000 100 10\n", "4 3\n10 100 1000 10000\n", "5 787787787\n123456789 234567890 345678901 456789012 987654321\n" ]
[ "150\n", "10\n", "30\n", "44981600785557577\n" ]
In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
[ { "input": "4 12\n20 30 70 90", "output": "150" }, { "input": "4 3\n10000 1000 100 10", "output": "10" }, { "input": "4 3\n10 100 1000 10000", "output": "30" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 987654321", "output": "44981600785557577" }, { "input": "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552", "output": "371343078" }, { "input": "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362", "output": "87393281" }, { "input": "30 604179824\n501412684 299363783 300175300 375965822 55881706 96888084 842141259 269152598 954400269 589424644 244226611 443088309 914941214 856763895 380059734 9424058 97467018 912446445 609122261 773853033 728987202 239388430 617092754 182847275 385882428 86295843 416876980 952408652 399750639 326299418", "output": "564859510" }, { "input": "1 1000000000\n1000000000", "output": "1000000000000000000" }, { "input": "1 1\n1", "output": "1" }, { "input": "30 1000000000\n1000000000 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", "output": "2000000000" }, { "input": "5 25\n52 91 84 66 93", "output": "186" }, { "input": "10 660\n2316 3782 9667 4268 4985 2256 6854 9312 4388 9913", "output": "13164" }, { "input": "20 807689532\n499795319 630489472 638483114 54844847 209402053 71113129 931903630 213385792 726471950 950559532 396028074 711222849 458354548 937511907 247071934 160971961 333550064 4453536 857363099 464797922", "output": "27447142368" }, { "input": "30 842765745\n2 2 2 4 6 8 12 12 18 28 52 67 92 114 191 212 244 459 738 1078 1338 1716 1860 1863 2990 4502 8575 11353 12563 23326", "output": "42251" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "1 1000000000\n1", "output": "1000000000" }, { "input": "30 1\n1000000000 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", "output": "1000000000" }, { "input": "30 1000000000\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", "output": "2" }, { "input": "30 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", "output": "1" }, { "input": "1 570846883\n300888960", "output": "171761524945111680" }, { "input": "2 245107323\n357416000 761122471", "output": "87605278957368000" }, { "input": "3 624400466\n824008448 698922561 760128125", "output": "118656089186285061" }, { "input": "5 972921345\n496871039 134331253 959524096 747165691 981088452", "output": "59657618590751221" }, { "input": "8 700735368\n931293374 652764228 183746499 853268148 653623691 684604018 902322304 186452621", "output": "1020734127854016" }, { "input": "13 695896744\n495801986 946818643 421711713 151976207 616318787 713653645 893406153 42255449 871957806 865208878 547381951 478062469 516417162", "output": "87737726572314" }, { "input": "21 186982676\n261355063 273322266 663309548 981847874 432074163 204617748 86151188 381783810 725544703 947880176 870951660 226330358 680228931 959825764 972157951 874066182 208942221 587976360 749662969 377541340 841644620", "output": "134782258380" }, { "input": "29 140874704\n948286516 335531500 165926134 633474522 606947099 21370216 16126534 254131475 624116869 824903957 541685498 351709345 925541565 253434732 759289345 168754543 993046389 636985579 332772332 103110829 311797311 739860627 233674609 950017614 387656468 939870312 161573356 176555912 592529105", "output": "338129268" }, { "input": "6 566613866\n1 3 3 16 11 13", "output": "230186887" }, { "input": "11 435675771\n2 2 2 4 4 5 5 8 10 18 21", "output": "8934765" }, { "input": "13 688240686\n2 4 1 15 7 1 34 129 295 905 1442 1198 3771", "output": "21507522" }, { "input": "15 645491742\n2 2 2 2 3 3 4 8 10 14 19 37 42 74 84", "output": "3309432" }, { "input": "29 592983020\n2 3 7 8 30 45 125 132 124 61 1231 1626 7470 14538 18828 35057 34820 219967 359159 362273 1577550 2434174 1736292 15104217 17689384 39467552 50809520 13580992 414752454", "output": "61009202" }, { "input": "29 42473833\n13 18 21 32 45 72 134 203 320 342 400 565 1039 1093 2142 3383 5360 7894 13056 17053 26524 38453 63285 102775 156618 252874 304854 600862 857837", "output": "304854" }, { "input": "28 48504243\n1 1 6 1 32 37 125 212 187 676 1679 771 485 9030 1895 26084 109430 96769 257473 383668 645160 1550917 6195680 6309095 16595706 13231037 99591007 255861473", "output": "5610124" }, { "input": "28 17734553\n13 22 33 59 93 164 166 308 454 532 771 898 1312 2256 3965 5207 6791 13472 13793 26354 47030 68133 118082 199855 221897 257395 417525 536230", "output": "257395" }, { "input": "27 358801274\n2 3 6 10 2 30 124 35 249 268 79 4013 1693 3522 17730 17110 52968 235714 155787 405063 1809923 667660 2266461 14291190 15502027 54103386 14154765", "output": "27680968" }, { "input": "27 437705674\n13 13 21 21 25 31 49 83 148 243 246 263 268 282 475 867 1709 3333 4587 5947 11467 22629 25843 31715 34392 45690 47657", "output": "333599" }, { "input": "26 519355202\n2 2 6 3 4 23 124 115 312 883 526 3158 2901 14398 797 8137 127577 112515 54101 426458 877533 3978708 6725849 5496068 14408348 27866871", "output": "25264103" }, { "input": "26 707933691\n13 17 31 44 69 70 89 158 246 320 605 934 1635 2364 4351 8660 10262 11664 14090 18908 35845 51033 59963 78775 117479 179510", "output": "3829673" }, { "input": "25 269843721\n1 4 5 12 6 16 123 195 374 475 974 2303 4109 8890 16632 64699 71115 251461 476703 447854 2042296 3095451 2796629 13478163 13314670", "output": "101191398" }, { "input": "25 978161707\n13 22 24 34 66 73 145 287 289 521 693 996 1230 1486 1517 2663 3770 3776 5286 7953 15775 30877 42848 84850 114828", "output": "6718647" }, { "input": "5 304398130\n328619601 758941829 198270024 713154224 371680309", "output": "7071174590398871" }, { "input": "10 354651161\n676522959 11809337 625434179 312329830 399019943 545095979 566206452 292370104 819250687 361397475", "output": "250332233709431" }, { "input": "10 907948615\n369010656 907829481 622481545 200317148 960270397 26028213 655060035 796833494 123373353 324969455", "output": "437565141462561" }, { "input": "10 590326547\n540224591 578261545 271951966 787805881 165741203 795359732 547118852 746648763 284153835 602102300", "output": "655248513971940" }, { "input": "20 264504887\n256244331 292829612 807171068 120710 900798902 214013876 575261859 40214283 293542999 366877272 353675296 705322168 205009788 86530854 620744650 766826836 240331588 700218303 406369581 649737981", "output": "327898333295" }, { "input": "20 749478720\n148277091 195065491 92471169 473441125 104827125 387256363 959435633 241640 395794406 734016994 107553118 129783960 812331272 999596018 837854100 215240378 598412225 653614923 933185587 845929351", "output": "1209345077739" }, { "input": "20 628134337\n706690396 73852246 47785764 655257266 217430459 211108098 623632685 631391825 628008556 962083938 616573502 326152383 7023992 288143889 264733804 886206130 342256543 779010688 657787839 476634612", "output": "571078505096" }, { "input": "20 708413057\n985177466 224645388 772550594 994150052 856456221 65855795 599129505 903908498 200612104 575185982 507918207 574454347 607410366 738301336 274020952 556522307 665003603 363184479 760246523 952436964", "output": "1287105522843" }, { "input": "20 228553575\n966247381 207786628 69006100 269956897 359963312 510868514 95130877 473280024 180071136 34097367 898985854 981155909 369570614 803892852 773207504 603654899 500850166 632114017 442730466 348136258", "output": "151787408488" }, { "input": "25 975185569\n680624205 925575600 711019438 10306 879760994 355425133 204004301 536007340 585477874 216944098 296555029 104013726 892946593 309410720 689188172 687796636 375461496 689356349 680367324 137692780 879054435 925597905 677631315 592123801 742526898", "output": "43630079726" }, { "input": "30 16804972\n38413642 603358594 93465125 772633637 516421484 75369617 249460374 6747 89975200 3230679 944379663 407211965 820471861 763861258 4711346 787274019 447412797 861015104 104795044 430023687 445411345 316560503 908322702 232775431 33149898 101978638 453254685 587956325 920401353 237657930", "output": "34613997" }, { "input": "30 939625169\n799744449 316941501 911543330 868167665 272876554 951480855 826347879 102948940 684991931 833689399 277289558 186462 220073415 602419892 22234767 320279157 908288280 357866038 758158565 784960311 772460297 956631291 623631325 328145434 76400621 637950037 63094834 358429163 210185094 824743978", "output": "766068050" }, { "input": "30 649693919\n523756282 905125099 661420695 854128708 504404014 33547776 632846834 593955985 19432317 644543651 552904895 988070696 321825330 923971248 718082642 900061181 310986828 14810582 525301 623288859 578749693 424452633 901712228 411022879 757920556 825042513 796572495 544557755 747250675 987028137", "output": "1213432868" }, { "input": "30 941342434\n719914212 905507045 191898825 570606628 687781371 937025497 673960221 557202851 29071681 518803370 894863536 212709126 614432746 924724833 699415275 748075226 796159664 198063404 56538360 649136911 46540367 337023198 45896775 548611961 777908744 873523820 99863819 335685200 503317538 894159729", "output": "1443990241" }, { "input": "30 810430346\n807519316 377786333 874568334 100500951 872031247 252690899 923103133 769288634 300502982 184749135 481527896 932556233 978317077 980235169 677287 308980653 527243473 763242606 219639015 712288933 901059456 30978091 127839849 9946626 456644060 226102694 611552752 816642473 434613587 723611518", "output": "964822722" }, { "input": "30 187125289\n660214771 614231774 943973836 50780694 214277957 695192266 425421684 100830325 236002350 233594142 318777769 611117973 758216803 141783036 487402819 42225289 132824573 354540681 64152506 838447015 853800951 605421421 151364012 455396619 928950961 236389207 47829341 743089941 577129072 792900471", "output": "143488023" }, { "input": "30 129428748\n954910836 756938357 407311375 992660029 134837594 230127140 815239978 545145316 559077075 373018190 923169774 981420723 349998683 971610245 428903049 879106876 229199860 842029694 817413103 141736569 236414627 263122579 394309719 946134085 550877425 544748100 732982715 933907937 67960170 145090225", "output": "67960170" }, { "input": "30 12544876\n528459681 350718911 432940853 266976578 679316371 959899124 158423966 471112176 136348553 752311334 979696813 624253517 374825117 338804760 506350966 717644199 528671610 10427712 256677344 288800318 711338213 778230088 616184102 968447942 275963441 257842321 753599064 812398057 815035849 207576747", "output": "207576747" }, { "input": "30 7\n476599619 58464676 796410905 224866489 780155470 404375041 576176595 767831428 598766545 225605178 819316136 781962412 217423411 484904923 194288977 597593185 181464481 65918422 225080972 53705844 584415879 463767806 845989273 434760924 477902363 145682570 721445310 803966515 927906514 191883417", "output": "53705844" }, { "input": "30 9324\n205304890 806562207 36203756 437374231 230840114 828741258 227108614 937997270 74150322 673068857 353683258 757136864 274921753 418595773 638411312 307919005 304470011 439118457 402187013 371389195 981316766 26764964 293610954 177952828 49223547 718589642 982551043 395151318 564895171 138874187", "output": "26764964" }, { "input": "30 512443535\n2 10 30 20 26 9 2 4 24 25 4 27 27 9 13 30 30 5 3 24 10 4 14 14 8 3 2 22 25 25", "output": "16" }, { "input": "30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "553648259" }, { "input": "30 536870912\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "536870913" }, { "input": "30 504365056\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "504365061" }, { "input": "30 536870913\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "536870915" }, { "input": "30 536870911\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "536870913" }, { "input": "30 571580555\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "571580565" }, { "input": "1 1000000000\n1", "output": "1000000000" }, { "input": "4 8\n8 4 4 1", "output": "1" }, { "input": "2 3\n10 1", "output": "2" }, { "input": "30 915378355\n459233266 779915330 685344552 78480977 949046834 774589421 94223415 727865843 464996500 268056254 591348850 753027575 142328565 174597246 47001711 810641112 130836837 251339580 624876035 850690451 290550467 119641933 998066976 791349365 549089363 492937533 140746908 265213422 27963549 109184295", "output": "111854196" }, { "input": "3 7\n20 20 30", "output": "60" }, { "input": "1 1000000000\n1000000000", "output": "1000000000000000000" }, { "input": "5 787787787\n1 2 3 4 5", "output": "246183685" }, { "input": "2 3\n10 5", "output": "10" }, { "input": "28 146201893\n79880639 962577454 837935105 770531287 992949199 401766756 805281924 931353274 246173135 378375823 456356972 120503545 811958850 126793843 720341477 413885800 272086545 758855930 979214555 491838924 465216943 706180852 786946242 646685999 436847726 625436 360241773 620056496", "output": "3127180" }, { "input": "5 9\n2 100 100 10 13", "output": "12" }, { "input": "1 134217728\n1000000000", "output": "134217728000000000" }, { "input": "1 536870912\n1000000000", "output": "536870912000000000" }, { "input": "5 5\n34 22 21 20 30", "output": "20" }, { "input": "1 787787787\n1", "output": "787787787" }, { "input": "7 7\n34 22 21 20 30 20 20", "output": "20" }, { "input": "5 5\n34 22 21 25 30", "output": "25" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 1", "output": "49236737" }, { "input": "6 6\n34 22 21 25 30 35", "output": "25" } ]
124
307,200
3
34,666
74
Shift It!
[ "constructive algorithms" ]
E. Shift It!
2
256
There is a square box 6<=Γ—<=6 in size. It contains 36 chips 1<=Γ—<=1 in size. Those chips contain 36 different characters β€” "0"-"9" and "A"-"Z". There is exactly one chip with each character. You are allowed to make the following operations: you may choose one of 6 rows or one of 6 columns and cyclically shift the chips there to one position to the left or to the right (for the row) or upwards or downwards (for the column). Those operations are allowed to perform several times. To solve the puzzle is to shift the chips using the above described operations so that they were written in the increasing order (exactly equal to the right picture). An example of solving the puzzle is shown on a picture below. Write a program that finds the sequence of operations that solves the puzzle. That sequence should not necessarily be shortest, but you should not exceed the limit of 10000 operations. It is guaranteed that the solution always exists.
The input data are represented by 6 lines containing 6 characters each. They are the puzzle's initial position. Those lines contain each character from the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" exactly once.
On the first line print number *n*, which is the number of operations. On the next *n* lines print the sequence of operations one per line. An operation is described by a word consisting of two characters. The first character shows the direction where the row or the column will be shifted. The possible directions are "L", "R" (to the left, to the right correspondingly, we shift a row), "U", "D" (upwards, downwards correspondingly, we shift a column). The second character is the number of the row (or the column), it is an integer from "1" to "6". The rows are numbered from the top to the bottom, the columns are numbered from the left to the right. The number of operations should not exceed 104. If there are several solutions, print any of them.
[ "01W345\n729AB6\nCD8FGH\nIJELMN\nOPKRST\nUVQXYZ\n" ]
[ "2\nR2\nU3\n" ]
none
[ { "input": "01W345\n729AB6\nCD8FGH\nIJELMN\nOPKRST\nUVQXYZ", "output": "260\nD2\nL2\nD2\nR2\nD2\nL2\nD2\nR2\nD2\nL2\nD2\nR2\nD2\nR1\nU3\nR1\nD3\nR1\nU3\nR1\nD3\nR1\nU3\nR1\nD3\nR1\nD5\nL2\nD5\nR2\nD5\nL2\nD5\nR2\nD5\nL2\nD5\nR2\nD5\nD4\nL2\nD4\nR2\nD4\nL2\nD4\nR2\nD4\nL2\nD4\nR2\nD4\nD3\nL2\nD3\nR2\nD3\nL2\nD3\nR2\nD3\nL2\nD3\nR2\nD3\nD2\nL2\nD2\nR2\nD2\nL2\nD2\nR2\nD2\nL2\nD2\nR2\nD2\nD1\nL2\nD1\nR2\nD1\nL2\nD1\nR2\nD1\nL2\nD1\nR2\nD1\nR2\nU3\nR2\nD3\nR2\nU3\nR2\nD3\nR2\nU3\nR2\nD3\nR2\nD3\nL3\nD3\nR3\nD3\nL3\nD3\nR3\nD3\nL3\nD3\nR3\nD3\nR2\nU4\nR2\nD4\nR2\nU4\nR2\nD4\nR2\nU4..." }, { "input": "012345\n6789AB\nCDEFGH\nIJKLMN\nOPQRST\nUVWXYZ", "output": "0" }, { "input": "102345\n6789AB\nCDEFGH\nIJKLMN\nOPQRST\nUVWXYZ", "output": "13\nD1\nL1\nD1\nR1\nD1\nL1\nD1\nR1\nD1\nL1\nD1\nR1\nD1" }, { "input": "234501\n789AB6\nGHCDEF\nIJKLMN\nRSTOPQ\nZUVWXY", "output": "455\nD4\nL1\nD4\nR1\nD4\nL1\nD4\nR1\nD4\nL1\nD4\nR1\nD4\nD3\nL1\nD3\nR1\nD3\nL1\nD3\nR1\nD3\nL1\nD3\nR1\nD3\nD2\nL1\nD2\nR1\nD2\nL1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U3\nR3\nD3\nR3\nU3\nR3\nD3\nR3\nU..." } ]
404
3,891,200
3.891752
34,689
37
Computer Game
[ "greedy", "implementation" ]
B. Computer Game
1
256
Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level: 1) The boss has two parameters: *max* β€” the initial amount of health and *reg* β€” regeneration rate per second. 2) Every scroll also has two parameters: *pow**i* β€” spell power measured in percents β€” the maximal amount of health counted off the initial one, which allows to use the scroll (i.e. if the boss has more than *pow**i* percent of health the scroll cannot be used); and *dmg**i* the damage per second inflicted upon the boss if the scroll is used. As soon as a scroll is used it disappears and another spell is cast upon the boss that inflicts *dmg**i* of damage per second upon him until the end of the game. During the battle the actions per second are performed in the following order: first the boss gets the damage from all the spells cast upon him, then he regenerates *reg* of health (at the same time he can’t have more than *max* of health), then the player may use another scroll (no more than one per second). The boss is considered to be defeated if at the end of a second he has nonpositive (<=≀<=0) amount of health. Help Petya to determine whether he can win with the set of scrolls available to him and if he can, determine the minimal number of seconds he needs to do it.
The first line contains three integers *N*, *max* and *reg* (1<=≀<=*N*,<=*max*,<=*reg*<=≀<=1000) –– the amount of scrolls and the parameters of the boss. The next *N* lines contain two integers *pow**i* and *dmg**i* each β€” the parameters of the *i*-th scroll (0<=≀<=*pow**i*<=≀<=100, 1<=≀<=*dmg**i*<=≀<=2000).
In case Petya can’t complete this level, output in the single line NO. Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the start of the battle to the moment the scroll was used and the number of the scroll. Scrolls are numbered starting from 1 in the input order. The first scroll is considered to be available to be used after 0 seconds. Output scrolls in the order they were used. It is not allowed to use scrolls after the boss is defeated.
[ "2 10 3\n100 3\n99 1\n", "2 100 10\n100 11\n90 9\n" ]
[ "NO\n", "YES\n19 2\n0 1\n10 2\n" ]
none
[ { "input": "2 10 3\n100 3\n99 1", "output": "NO" }, { "input": "2 100 10\n100 11\n90 9", "output": "YES\n19 2\n0 1\n10 2" }, { "input": "10 100 5\n61 3\n55 2\n12 6\n39 5\n21 10\n39 7\n16 1\n10 1\n70 5\n100 7", "output": "YES\n21 6\n0 10\n15 9\n17 1\n18 2\n19 6\n20 5" }, { "input": "20 1000 35\n10 6\n66 38\n81 11\n18 46\n80 54\n76 55\n100 7\n96 23\n24 37\n4 24\n4 50\n71 4\n83 15\n7 23\n100 44\n99 34\n100 17\n100 66\n23 15\n90 35", "output": "YES\n7 7\n0 18\n1 15\n2 20\n3 5\n4 6\n5 2\n6 4" }, { "input": "20 1000 100\n49 26\n46 36\n1 114\n80 4\n80 125\n100 17\n6 184\n100 20\n59 60\n47 92\n52 20\n44 50\n3 15\n10 192\n6 13\n60 3\n63 102\n78 17\n0 124\n31 100", "output": "NO" }, { "input": "35 999 199\n95 80\n79 279\n14 291\n100 88\n64 55\n100 209\n85 4\n14 237\n75 126\n41 260\n81 67\n99 311\n71 220\n98 312\n53 213\n55 377\n78 374\n79 308\n34 40\n92 281\n53 119\n96 170\n90 7\n87 176\n27 50\n78 95\n31 327\n56 138\n91 221\n7 144\n100 335\n29 139\n61 247\n38 203\n100 242", "output": "YES\n3 3\n0 31\n1 14\n2 16" }, { "input": "50 1000 17\n26 1\n96 22\n100 27\n99 30\n97 5\n39 14\n100 17\n100 8\n98 21\n100 17\n100 34\n75 11\n68 31\n100 13\n3 5\n74 4\n100 12\n100 25\n100 32\n3 14\n100 10\n100 2\n75 28\n24 16\n27 20\n34 13\n64 29\n50 19\n90 22\n42 7\n48 12\n97 34\n22 1\n57 33\n100 13\n100 31\n61 12\n100 18\n64 19\n29 24\n100 33\n87 10\n35 33\n77 28\n100 15\n87 34\n68 2\n44 29\n55 3\n41 5", "output": "YES\n8 8\n0 11\n1 41\n2 32\n3 46\n4 19\n5 13\n6 34\n7 43" }, { "input": "70 1000 1\n91 2\n43 1\n100 1\n79 2\n26 1\n68 2\n4 2\n64 1\n100 1\n80 2\n20 2\n70 1\n25 1\n99 1\n64 1\n35 2\n60 1\n63 2\n93 1\n40 2\n100 1\n54 1\n100 1\n15 2\n72 1\n28 1\n5 1\n93 1\n100 2\n39 2\n54 2\n100 1\n55 1\n43 1\n20 1\n28 2\n21 1\n100 2\n98 1\n35 1\n12 2\n50 2\n7 2\n7 2\n12 2\n100 2\n44 1\n40 2\n56 2\n5 1\n100 1\n94 2\n100 2\n74 1\n83 2\n100 2\n81 2\n37 2\n29 1\n100 2\n99 1\n39 2\n83 2\n96 2\n30 2\n39 1\n38 1\n51 1\n11 1\n100 2", "output": "YES\n34 34\n0 29\n1 38\n2 46\n3 53\n4 56\n5 60\n6 70\n7 64\n8 52\n9 3\n10 1\n11 9\n12 14\n13 19\n14 55\n15 4\n16 10\n17 57\n18 63\n19 6\n20 8\n21 18\n22 12\n23 31\n24 42\n25 49\n26 20\n27 16\n28 30\n29 36\n30 11\n31 24\n32 41\n33 7" }, { "input": "4 660 722\n67 360\n96 778\n6 1041\n62 395", "output": "NO" }, { "input": "5 328 249\n62 265\n32 271\n72 237\n28 99\n22 364", "output": "NO" }, { "input": "5 351 183\n16 337\n19 221\n81 359\n87 253\n5 240", "output": "NO" }, { "input": "2 439 283\n25 510\n31 547", "output": "NO" }, { "input": "4 337 873\n62 81\n87 481\n39 1189\n45 450", "output": "NO" }, { "input": "5 940 591\n92 762\n59 255\n15 1061\n53 1016\n10 527", "output": "NO" }, { "input": "5 851 931\n88 401\n48 1196\n86 1817\n20 1575\n30 1474", "output": "NO" }, { "input": "29 634 982\n60 1351\n54 640\n1 253\n72 24\n40 529\n52 339\n73 21\n34 1284\n32 1264\n76 1346\n92 320\n11 1441\n67 1215\n69 1524\n77 1672\n83 412\n48 241\n25 894\n91 1474\n18 1743\n98 1944\n48 788\n77 860\n31 629\n91 1042\n36 1116\n41 1162\n63 129\n15 1125", "output": "NO" }, { "input": "10 1000 8\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1", "output": "YES\n509 10\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10" }, { "input": "11 2 10\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1", "output": "YES\n12 11\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11" }, { "input": "3 200 10\n100 3\n100 8\n50 1000", "output": "YES\n102 3\n0 2\n1 1\n101 3" }, { "input": "2 100 2\n100 2\n100 2", "output": "YES\n51 2\n0 1\n1 2" }, { "input": "2 1000 1\n100 1\n100 1", "output": "YES\n1001 2\n0 1\n1 2" }, { "input": "6 1000 53\n100 10\n100 10\n100 10\n100 10\n100 10\n100 10", "output": "YES\n148 6\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6" }, { "input": "3 100 2\n100 1\n100 1\n100 1", "output": "YES\n102 3\n0 1\n1 2\n2 3" }, { "input": "3 100 3\n100 1\n100 1\n100 1", "output": "NO" }, { "input": "3 100 4\n100 1\n100 1\n100 1", "output": "NO" }, { "input": "3 100 5\n100 1\n100 1\n100 1", "output": "NO" } ]
46
0
0
34,733
581
Luxurious Houses
[ "implementation", "math" ]
null
null
The capital of Berland has *n* multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same. The new architect is interested in *n* questions, *i*-th of them is about the following: "how many floors should be added to the *i*-th house to make it luxurious?" (for all *i* from 1 to *n*, inclusive). You need to help him cope with this task. Note that all these questions are independent from each other β€” the answer to the question for house *i* does not affect other answers (i.e., the floors to the houses are not actually added).
The first line of the input contains a single number *n* (1<=≀<=*n*<=≀<=105) β€” the number of houses in the capital of Berland. The second line contains *n* space-separated positive integers *h**i* (1<=≀<=*h**i*<=≀<=109), where *h**i* equals the number of floors in the *i*-th house.
Print *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where number *a**i* is the number of floors that need to be added to the house number *i* to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then *a**i* should be equal to zero. All houses are numbered from left to right, starting from one.
[ "5\n1 2 3 1 2\n", "4\n3 2 1 4\n" ]
[ "3 2 0 2 0 ", "2 3 4 0 " ]
none
[ { "input": "5\n1 2 3 1 2", "output": "3 2 0 2 0 " }, { "input": "4\n3 2 1 4", "output": "2 3 4 0 " }, { "input": "1\n2", "output": "0 " }, { "input": "2\n5 4", "output": "0 0 " }, { "input": "5\n10 18 36 33 20", "output": "27 19 0 0 0 " }, { "input": "5\n91 96 94 95 91", "output": "6 0 2 0 0 " }, { "input": "10\n9 6 8 5 5 2 8 9 2 2", "output": "1 4 2 5 5 8 2 0 1 0 " }, { "input": "10\n55 50 51 53 53 52 50 54 54 53", "output": "0 5 4 2 2 3 5 1 0 0 " }, { "input": "20\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 " }, { "input": "20\n82 78 86 80 80 76 88 74 70 88 71 75 73 72 79 85 79 90 79 77", "output": "9 13 5 11 11 15 3 17 21 3 20 16 18 19 12 6 12 0 0 0 " }, { "input": "40\n66 68 59 100 55 53 63 95 70 55 51 54 97 80 88 83 90 81 84 53 84 91 85 75 82 56 88 86 79 97 56 63 57 55 93 93 81 99 58 54", "output": "35 33 42 0 45 47 37 5 30 45 49 46 3 20 12 17 10 19 16 47 16 9 15 25 18 44 12 14 21 3 44 37 43 45 7 7 19 0 0 0 " }, { "input": "40\n99 8 32 95 40 43 69 26 4 81 67 78 17 58 88 55 73 80 16 50 20 14 94 75 66 14 23 68 95 63 1 56 81 68 48 77 2 51 29 27", "output": "0 88 64 1 56 53 27 70 92 15 29 18 79 38 8 41 23 16 80 46 76 82 2 21 30 82 73 28 0 19 81 26 0 10 30 0 50 0 0 0 " }, { "input": "50\n50 53 54 54 52 51 53 51 50 52 53 52 55 52 51 55 52 53 53 52 53 53 52 52 51 52 53 54 50 50 55 50 55 50 55 54 53 50 52 52 51 54 52 54 53 51 54 50 55 54", "output": "6 3 2 2 4 5 3 5 6 4 3 4 1 4 5 1 4 3 3 4 3 3 4 4 5 4 3 2 6 6 1 6 1 6 1 2 3 6 4 4 5 2 4 2 3 5 2 6 0 0 " }, { "input": "50\n94 96 98 96 91 90 96 92 95 96 96 99 99 90 93 90 99 95 91 92 99 91 93 92 100 94 93 90 93 93 98 91 95 96 93 90 90 92 94 91 90 90 97 91 100 96 100 96 91 90", "output": "7 5 3 5 10 11 5 9 6 5 5 2 2 11 8 11 2 6 10 9 2 10 8 9 1 7 8 11 8 8 3 10 6 5 8 11 11 9 7 10 11 11 4 10 1 5 0 0 0 0 " }, { "input": "70\n50 5 6 69 36 65 94 57 33 62 72 89 22 83 37 94 72 46 99 43 64 1 69 85 88 63 70 47 64 20 18 66 73 28 39 67 45 41 66 9 77 77 32 11 14 5 17 44 34 76 8 73 20 85 1 89 22 76 93 70 86 65 82 17 69 86 45 11 11 88", "output": "50 95 94 31 64 35 6 43 67 38 28 11 78 17 63 6 28 54 0 51 30 93 25 9 6 31 24 47 30 74 76 28 21 66 55 27 49 53 28 85 17 17 62 83 80 89 77 50 60 18 86 21 74 9 93 5 72 18 0 19 3 24 7 72 20 3 44 78 78 0 " }, { "input": "70\n40 43 42 40 42 43 41 43 40 40 41 42 40 40 42 42 42 40 43 40 42 43 41 42 43 42 41 41 41 43 42 42 40 41 41 42 43 41 43 40 42 41 43 43 41 40 41 41 43 43 40 41 43 43 41 42 42 40 42 42 43 43 40 40 41 41 41 42 41 43", "output": "4 1 2 4 2 1 3 1 4 4 3 2 4 4 2 2 2 4 1 4 2 1 3 2 1 2 3 3 3 1 2 2 4 3 3 2 1 3 1 4 2 3 1 1 3 4 3 3 1 1 4 3 1 1 3 2 2 4 2 2 1 1 4 4 3 3 3 2 3 0 " }, { "input": "90\n74 78 57 97 75 85 87 89 71 76 50 71 94 82 87 51 84 87 63 51 88 53 82 88 94 90 58 65 91 69 99 56 58 78 74 74 52 80 100 85 72 50 92 97 77 97 91 85 86 64 75 99 51 79 76 64 66 85 64 63 99 84 74 99 83 70 84 54 91 94 51 68 86 61 81 60 100 52 92 52 59 90 57 57 85 83 59 56 67 63", "output": "27 23 44 4 26 16 14 12 30 25 51 30 7 19 14 50 17 14 38 50 13 48 19 13 7 11 43 36 10 32 2 45 43 23 27 27 49 21 1 16 29 51 9 4 24 4 10 16 15 37 26 2 50 22 25 37 35 16 37 38 2 17 27 2 18 31 17 47 10 7 50 33 15 40 20 41 0 41 0 39 32 0 29 29 0 0 9 12 0 0 " }, { "input": "90\n8 11 37 11 34 18 34 5 35 11 16 20 17 14 9 22 39 13 23 36 26 9 20 18 13 10 11 26 22 2 36 17 23 26 12 1 30 5 19 30 21 8 36 25 2 17 16 32 40 4 11 12 21 39 30 1 18 23 19 1 38 25 12 10 35 27 29 35 15 15 37 35 5 23 33 34 2 35 17 38 40 5 25 8 14 38 34 28 13 22", "output": "33 30 4 30 7 23 7 36 6 30 25 21 24 27 32 19 2 28 18 5 15 32 21 23 28 31 30 15 19 39 5 24 18 15 29 40 11 36 22 11 20 33 5 16 39 24 25 9 1 37 30 29 20 2 11 40 23 18 22 40 3 16 29 31 6 14 12 6 26 26 4 6 36 18 8 7 39 6 24 3 0 34 14 31 25 0 0 0 10 0 " }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14", "output": "90 90 27 44 85 91 44 41 64 32 96 81 26 7 58 50 84 39 81 33 90 73 2 52 56 11 28 2 80 65 51 3 20 46 91 75 30 50 87 76 22 87 78 11 33 90 70 86 38 30 45 22 58 86 95 31 62 25 92 93 70 23 44 27 10 95 21 72 70 17 81 16 87 95 67 30 10 14 33 86 7 45 61 94 73 43 82 44 70 95 82 60 70 5 96 32 14 0 0 0 " }, { "input": "100\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9", "output": "10 3 8 3 1 3 6 8 1 8 6 3 7 6 6 6 1 8 5 5 5 5 5 4 9 4 9 7 4 3 8 3 4 9 6 5 10 6 6 4 2 4 5 2 10 3 10 8 5 6 10 8 5 2 6 5 3 7 3 5 1 2 9 2 8 3 4 6 9 1 9 1 8 5 6 6 8 6 1 9 8 4 1 3 3 7 8 7 2 5 0 3 4 4 4 6 1 1 2 0 " }, { "input": "10\n4 5 2 3 4 9 1 2 3 10", "output": "7 6 9 8 7 2 10 9 8 0 " }, { "input": "1\n100", "output": "0 " }, { "input": "2\n1 100", "output": "100 0 " }, { "input": "4\n4 98 99 100", "output": "97 3 2 0 " }, { "input": "5\n5 5 5 5 5", "output": "1 1 1 1 0 " }, { "input": "10\n4 1 4 1 4 1 4 1 4 1", "output": "1 4 1 4 1 4 1 4 0 0 " }, { "input": "5\n1 3 5 7 9", "output": "9 7 5 3 0 " }, { "input": "2\n1 1", "output": "1 0 " }, { "input": "3\n4 4 4", "output": "1 1 0 " }, { "input": "2\n2 2", "output": "1 0 " }, { "input": "4\n1 1 1 1", "output": "1 1 1 0 " }, { "input": "3\n3 3 3", "output": "1 1 0 " }, { "input": "6\n3 3 4 2 3 3", "output": "2 2 0 2 1 0 " } ]
1,000
12,902,400
0
34,739
95
Volleyball
[ "shortest paths" ]
C. Volleyball
2
256
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has *n* junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can have different lengths. Initially each junction has exactly one taxi standing there. The taxi driver from the *i*-th junction agrees to drive Petya (perhaps through several intermediate junctions) to some other junction if the travel distance is not more than *t**i* meters. Also, the cost of the ride doesn't depend on the distance and is equal to *c**i* bourles. Taxis can't stop in the middle of a road. Each taxi can be used no more than once. Petya can catch taxi only in the junction, where it stands initially. At the moment Petya is located on the junction *x* and the volleyball stadium is on the junction *y*. Determine the minimum amount of money Petya will need to drive to the stadium.
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=1000,<=0<=≀<=*m*<=≀<=1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to *n*, inclusive. The next line contains two integers *x* and *y* (1<=≀<=*x*,<=*y*<=≀<=*n*). They are the numbers of the initial and final junctions correspondingly. Next *m* lines contain the roads' description. Each road is described by a group of three integers *u**i*, *v**i*, *w**i* (1<=≀<=*u**i*,<=*v**i*<=≀<=*n*,<=1<=≀<=*w**i*<=≀<=109) β€” they are the numbers of the junctions connected by the road and the length of the road, correspondingly. The next *n* lines contain *n* pairs of integers *t**i* and *c**i* (1<=≀<=*t**i*,<=*c**i*<=≀<=109), which describe the taxi driver that waits at the *i*-th junction β€” the maximum distance he can drive and the drive's cost. The road can't connect the junction with itself, but between a pair of junctions there can be more than one road. All consecutive numbers in each line are separated by exactly one space character.
If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specificator.
[ "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7\n" ]
[ "9\n" ]
An optimal way β€” ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles.
[ { "input": "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "output": "9" }, { "input": "3 3\n1 3\n1 2 2\n1 3 3\n3 2 1\n2 7\n2 7\n3 6", "output": "14" }, { "input": "3 1\n1 3\n1 2 2\n2 7\n2 7\n3 6", "output": "-1" }, { "input": "3 2\n3 3\n1 2 2\n1 3 3\n2 7\n2 7\n3 7", "output": "0" }, { "input": "2 2\n1 2\n1 2 3\n1 2 2\n2 7\n3 2", "output": "7" }, { "input": "1 0\n1 1\n74 47", "output": "0" }, { "input": "5 5\n1 3\n1 3 3\n5 1 6\n4 3 8\n1 3 3\n5 2 4\n1 2\n4 1\n2 5\n5 2\n1 2", "output": "-1" }, { "input": "7 4\n3 4\n6 2 7\n6 1 4\n4 3 5\n3 6 4\n1 6\n7 3\n3 6\n6 5\n3 7\n4 4\n1 4", "output": "-1" }, { "input": "5 5\n4 5\n1 4 8\n4 2 4\n4 1 3\n3 1 9\n4 5 4\n2 7\n2 7\n5 1\n6 3\n3 2", "output": "3" }, { "input": "5 5\n5 4\n2 4 10\n2 4 7\n3 1 7\n2 4 2\n5 3 9\n6 17\n2 4\n3 12\n7 18\n2 5", "output": "-1" }, { "input": "4 7\n3 4\n2 3 5\n3 2 9\n4 1 9\n3 2 1\n3 1 2\n2 3 6\n1 2 8\n2 2\n5 3\n2 1\n1 5", "output": "-1" }, { "input": "7 14\n7 5\n1 3 15\n2 1 10\n1 3 5\n2 4 9\n5 4 19\n1 3 11\n5 1 1\n2 4 5\n2 3 11\n3 2 10\n3 4 18\n5 1 18\n6 2 5\n5 6 2\n3 6\n6 7\n9 1\n3 6\n1 1\n9 4\n9 8", "output": "-1" }, { "input": "7 15\n5 5\n3 4 6\n7 4 3\n7 2 8\n2 5 2\n7 2 8\n5 2 9\n3 1 7\n1 2 4\n7 1 8\n7 5 7\n2 4 2\n4 3 9\n7 4 2\n5 4 8\n7 2 8\n15 4\n18 18\n6 8\n16 5\n11 1\n5 3\n18 4", "output": "0" }, { "input": "8 20\n8 4\n6 3 1\n3 4 4\n5 2 2\n3 6 3\n5 8 7\n6 2 7\n8 6 4\n6 4 5\n4 2 5\n5 3 3\n5 7 3\n8 1 6\n2 4 3\n6 8 5\n1 8 6\n8 2 7\n8 2 3\n1 6 7\n8 7 3\n6 3 6\n2 2\n5 9\n1 9\n4 7\n1 8\n4 8\n9 7\n9 3", "output": "3" }, { "input": "8 20\n8 2\n1 7 5\n3 2 3\n2 7 6\n6 5 6\n4 8 5\n7 8 4\n1 6 2\n7 4 3\n4 3 1\n6 7 5\n4 2 4\n2 8 7\n6 2 2\n2 3 4\n3 7 3\n7 8 4\n5 4 2\n7 1 1\n5 7 3\n4 3 7\n4 4\n2 7\n3 5\n3 1\n3 5\n1 5\n11 4\n10 5", "output": "5" }, { "input": "9 20\n5 1\n8 9 3\n1 8 6\n5 6 3\n2 1 4\n7 1 6\n1 4 4\n3 2 4\n5 6 4\n3 9 6\n6 2 3\n9 1 7\n1 7 1\n1 3 3\n8 4 7\n7 1 7\n6 9 3\n5 8 3\n9 4 5\n6 9 1\n6 2 6\n1 7\n1 3\n6 1\n1 2\n6 1\n2 2\n4 7\n4 5\n4 1", "output": "-1" }, { "input": "10 21\n9 5\n5 2 6\n1 9 7\n6 2 7\n8 10 2\n7 2 1\n6 9 6\n10 9 4\n2 10 2\n10 8 4\n10 1 7\n9 1 7\n1 8 5\n10 9 7\n7 5 3\n2 10 6\n4 7 3\n10 5 6\n5 10 4\n6 9 2\n2 3 6\n1 9 3\n10 6\n7 12\n13 3\n17 4\n18 17\n1 9\n16 16\n12 13\n1 10\n6 15", "output": "-1" }, { "input": "14 20\n7 2\n12 2 17\n13 3 8\n6 8 3\n14 4 16\n13 5 17\n7 14 7\n11 10 6\n12 4 16\n6 11 7\n2 13 12\n13 2 18\n2 10 12\n13 12 1\n12 5 4\n9 4 16\n7 6 7\n2 3 15\n4 14 1\n13 5 3\n10 9 3\n4 6\n4 5\n5 3\n2 6\n2 4\n1 2\n4 7\n2 2\n6 1\n1 1\n6 5\n7 7\n3 4\n2 6", "output": "-1" }, { "input": "15 29\n6 6\n7 12 7\n11 3 7\n4 5 18\n13 9 18\n3 8 12\n6 1 7\n4 1 4\n12 5 18\n10 8 15\n2 10 1\n9 7 11\n2 4 10\n2 14 3\n15 12 14\n1 13 8\n11 4 1\n15 11 2\n1 5 9\n5 2 5\n9 10 5\n15 2 17\n11 5 1\n14 15 14\n10 1 16\n15 9 2\n13 15 6\n13 5 1\n7 12 6\n12 5 13\n8 26\n35 17\n16 14\n12 13\n21 1\n31 9\n7 24\n11 31\n29 5\n16 22\n29 7\n30 20\n36 3\n26 22\n37 6", "output": "0" }, { "input": "5 0\n2 4\n1 2\n6 9\n4 585\n6 9\n7 4", "output": "-1" }, { "input": "5 8\n1 3\n1 2 1\n1 3 3\n1 5 1\n1 4 2\n5 4 3\n3 5 2\n2 3 8\n1 3 2\n2 7\n10 3\n4 7\n2 1\n1 1", "output": "7" }, { "input": "5 7\n1 3\n1 2 1\n1 3 3\n1 5 1\n1 4 2\n5 4 3\n3 5 2\n2 3 8\n2 7\n10 3\n4 7\n2 1\n1 1", "output": "10" }, { "input": "7 5\n6 7\n1 3 1000000000\n2 7 999999999\n5 7 123456789\n1 5 148879589\n5 4 1000000000\n1000000000 1000000000\n1000000000 1000000000\n999999999 145785965\n1000000000 1000000000\n1000000000 1\n123456789 123568591\n1000000000 1000000000", "output": "-1" }, { "input": "7 8\n6 7\n1 3 1000000000\n1 6 1000000000\n1 2 1000000000\n6 2 1000000000\n2 5 1000000000\n5 7 1000000000\n4 7 1\n3 4 1000000000\n1000000000 100000000\n999999999 1\n1000000000 10000000\n1000000000 10000000\n1000000000 128\n1000000000 10000000\n1000000000 1000000000", "output": "130000000" }, { "input": "7 8\n6 7\n1 3 1000000000\n1 6 1000000000\n1 2 1000000000\n6 2 1000000000\n2 5 1000000000\n5 7 1000000000\n4 7 1\n3 4 999999999\n1000000000 100000000\n999999999 1\n999999999 10000000\n1000000000 10000000\n1000000000 128\n1000000000 10000000\n1000000000 1000000000", "output": "130000000" }, { "input": "7 8\n1 7\n1 3 1000000000\n1 6 1000000000\n1 2 1000000000\n6 2 1000000000\n2 5 1000000000\n5 7 1000000000\n4 7 1\n3 4 999999999\n1000000000 100000000\n999999999 1\n999999999 10000000\n1000000000 10000000\n1000000000 128\n1000000000 10000000\n1000000000 1000000000", "output": "120000000" }, { "input": "2 1\n1 2\n1 2 1\n1 999999998\n1 999999998", "output": "999999998" }, { "input": "3 3\n1 3\n2 1 1\n1 2 1000000000\n1 2 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000", "output": "-1" }, { "input": "3 3\n1 2\n2 1 1\n1 2 1000000000\n1 2 1000000000\n10000000 1000000000\n10000000 1000000000\n10000000 1000000000", "output": "1000000000" }, { "input": "3 3\n1 2\n2 1 1000000000\n1 2 1000000000\n1 2 1000000000\n10000000 1000000000\n10000000 1000000000\n10000000 1000000000", "output": "-1" } ]
966
28,057,600
3.706239
34,742
301
Yaroslav and Algorithm
[ "constructive algorithms" ]
null
null
Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as *a*. 1. The algorithm consists of some number of command. Π‘ommand number *i* looks either as *s**i* &gt;&gt; *w**i*, or as *s**i* &lt;&gt; *w**i*, where *s**i* and *w**i* are some possibly empty strings of length at most 7, consisting of digits and characters "?". 1. At each iteration, the algorithm looks for a command with the minimum index *i*, such that *s**i* occurs in *a* as a substring. If this command is not found the algorithm terminates. 1. Let's denote the number of the found command as *k*. In string *a* the first occurrence of the string *s**k* is replaced by string *w**k*. If the found command at that had form *s**k* &gt;&gt; *w**k*, then the algorithm continues its execution and proceeds to the next iteration. Otherwise, the algorithm terminates. 1. The value of string *a* after algorithm termination is considered to be the output of the algorithm. Yaroslav has a set of *n* positive integers, he needs to come up with his favorite algorithm that will increase each of the given numbers by one. More formally, if we consider each number as a string representing the decimal representation of the number, then being run on each of these strings separately, the algorithm should receive the output string that is a recording of the corresponding number increased by one. Help Yaroslav.
The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of elements in the set. The next *n* lines contains one positive integer each. All the given numbers are less than 1025.
Print the algorithm which can individually increase each number of the set. In the *i*-th line print the command number *i* without spaces. Your algorithm will be launched for each of these numbers. The answer will be considered correct if: Β  - Each line will a correct algorithm command (see the description in the problem statement). - The number of commands should not exceed 50. - The algorithm will increase each of the given numbers by one. - To get a respond, the algorithm will perform no more than 200 iterations for each number.
[ "2\n10\n79\n" ]
[ "10&lt;&gt;11\n79&lt;&gt;80\n" ]
none
[ { "input": "2\n10\n79", "output": "10<>11\n79<>80" }, { "input": "5\n9\n99\n999\n9999\n99999", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "5\n99999\n9999\n999\n99\n9", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n392\n605\n903\n154\n293\n383\n422\n717\n719\n896", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n448\n727\n772\n539\n870\n913\n668\n300\n36\n895", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n704\n812\n323\n334\n674\n665\n142\n712\n254\n869", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n548\n645\n663\n758\n38\n860\n724\n742\n530\n779", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n317\n36\n191\n843\n289\n107\n41\n943\n265\n649", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n447\n806\n891\n730\n371\n351\n7\n102\n394\n549", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n630\n624\n85\n955\n757\n841\n967\n377\n932\n309", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" }, { "input": "1\n9999999999999999999999999", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?" } ]
154
20,172,800
0
34,864
986
AND Graph
[ "bitmasks", "dfs and similar", "dsu", "graphs" ]
null
null
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \&amp; y = 0$. Here $\&amp;$ is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). Count the number of connected components in that graph.
In the first line of input there are two integers $n$ and $m$ ($0 \le n \le 22$, $1 \le m \le 2^{n}$). In the second line there are $m$ integers $a_1, a_2, \ldots, a_m$ ($0 \le a_{i} &lt; 2^{n}$)Β β€” the elements of the set. All $a_{i}$ are distinct.
Print the number of connected components.
[ "2 3\n1 2 3\n", "5 5\n5 19 10 20 12\n" ]
[ "2\n", "2\n" ]
Graph from first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/2ae9959ec95b178e60e27e28f5d62c1099bb9ef1.png" style="max-width: 100.0%;max-height: 100.0%;"/> Graph from second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/9f9eee8f2409bbd78cce726875915c405af8a07e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "2 3\n1 2 3", "output": "2" }, { "input": "5 5\n5 19 10 20 12", "output": "2" }, { "input": "3 5\n3 5 0 6 7", "output": "1" }, { "input": "0 1\n0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "1" }, { "input": "6 30\n3 8 13 16 18 19 21 22 24 25 26 28 29 31 33 42 44 46 49 50 51 53 54 57 58 59 60 61 62 63", "output": "10" }, { "input": "6 35\n5 7 10 11 13 14 17 18 25 27 28 29 30 31 33 35 36 37 39 40 41 43 46 47 50 52 55 56 57 58 59 60 61 62 63", "output": "13" }, { "input": "6 22\n21 23 26 28 31 35 38 39 41 42 44 45 47 50 51 52 54 55 56 59 62 63", "output": "20" }, { "input": "6 19\n15 23 27 29 30 31 43 46 47 51 53 55 57 58 59 60 61 62 63", "output": "19" } ]
2,277
268,390,400
0
34,885
549
Degenerate Matrix
[ "binary search", "math" ]
null
null
The determinant of a matrix 2<=Γ—<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is minimum possible. Determine ||*A*<=-<=*B*||.
The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≀<=109), the elements of the first row of matrix *A*. The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≀<=109) the elements of the second row of matrix *A*.
Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9.
[ "1 2\n3 4\n", "1 0\n0 1\n" ]
[ "0.2000000000\n", "0.5000000000\n" ]
In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a07c34fbc6e9328bcb519d3f780eea6e02e5dc87.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "1 2\n3 4", "output": "0.2000000000" }, { "input": "1 0\n0 1", "output": "0.5000000000" }, { "input": "1000000000 0\n0 1000000000", "output": "500000000.0000000000" }, { "input": "8205 9482\n11 -63", "output": "35.0198432832" }, { "input": "0 0\n0 0", "output": "0.0000000000" }, { "input": "1000000000 -1000000000\n1000000000 1000000000", "output": "1000000000.0000000000" }, { "input": "1000000000 1000000000\n1000000000 -1000000000", "output": "1000000000.0000000000" }, { "input": "-1 -1\n1 0", "output": "0.3333333333" }, { "input": "5 2\n-15 -6", "output": "0.0000000000" }, { "input": "2 -5\n-3 2", "output": "0.9166666667" }, { "input": "-5 -2\n-1 -3", "output": "1.1818181818" }, { "input": "-5 8\n1 6", "output": "2.1111111111" }, { "input": "1 3\n3 2", "output": "0.7777777778" }, { "input": "-42 63\n77 -32", "output": "16.3878504673" }, { "input": "91 -7\n-21 91", "output": "38.7333333333" }, { "input": "-67 -77\n-56 -75", "output": "2.5927272727" }, { "input": "-26 53\n-48 -89", "output": "29.6219512195" }, { "input": "97 -934\n-707 184", "output": "334.2819979188" }, { "input": "689 412\n-794 -421", "output": "16.0012953368" }, { "input": "-718 -387\n972 972", "output": "105.5204985241" }, { "input": "-126 -376\n75 367", "output": "19.1122881356" }, { "input": "-7 -3674\n845 5737", "output": "298.5843320666" }, { "input": "-9912 755\n-8220 6419", "output": "2268.9886983324" }, { "input": "-3928 5185\n4331 6665", "output": "3969.3426099731" }, { "input": "2056 9614\n-5171 8965", "output": "3141.2387756983" }, { "input": "41642 63236\n-59604 20357", "output": "32033.4760659150" }, { "input": "-38387 -93294\n-52918 -51288", "output": "12582.8868737997" }, { "input": "92812 73253\n-46231 11374", "output": "22109.0927374802" }, { "input": "12784 -94506\n26149 85264", "output": "18439.1869417765" }, { "input": "955162 -709099\n-743655 578837", "output": "8557.1487662354" }, { "input": "160382 -103968\n301943 -156088", "output": "8802.4244934460" }, { "input": "-634398 -468280\n447621 78431", "output": "98147.3248125840" }, { "input": "-398622 -832591\n-506781 -656493", "output": "66924.0413186624" }, { "input": "-2665612 -7693032\n-2861368 -6201836", "output": "282203.1726406262" }, { "input": "1762462 700391\n-7134185 5042962", "output": "1048758.9114990780" }, { "input": "6190536 5693104\n-8006293 -3712238", "output": "957535.4624752104" }, { "input": "553632 5653328\n-7246622 9164341", "output": "2140390.1895580233" }, { "input": "43469186 94408326\n78066381 -19616812", "output": "41883387.4306073852" }, { "input": "25683826 49101909\n88380777 46573745", "output": "14987456.1603828062" }, { "input": "-87068851 98762810\n3727856 -87235696", "output": "26110777.7289122988" }, { "input": "95145788 53456393\n42406028 83987544", "output": "20815549.6776987243" }, { "input": "876432079 -414820618\n-816514132 -914565422", "output": "520028295.4718751899" }, { "input": "-240038673 376842703\n-241080203 410087456", "output": "5983627.7655281517" }, { "input": "938457872 -536526676\n867891897 -855194260", "output": "105349963.0995401485" }, { "input": "116954418 255136645\n-851641472 174491320", "output": "204147910.8375163887" }, { "input": "1 1\n1 5", "output": "0.5000000000" }, { "input": "1 5\n1 1", "output": "0.5000000000" }, { "input": "5 1\n1 1", "output": "0.5000000000" }, { "input": "1 1\n5 1", "output": "0.5000000000" }, { "input": "-1000000000 -1000000000\n1000000000 1000000000", "output": "0.0000000000" }, { "input": "-1000000000 -1000000000\n999999999 999999999", "output": "0.0000000000" }, { "input": "536870912 88\n536870912 22528", "output": "11219.7636804586" }, { "input": "268435456 268435456\n22512 22528", "output": "7.9993289080" }, { "input": "-1 1\n1 1", "output": "1.0000000000" }, { "input": "-1000 -999\n-1 0", "output": "0.4995000000" }, { "input": "-801658422 -738703776\n910442649 -920729415", "output": "744753719.5468964978" }, { "input": "-203893419 -777818\n295920256 -474540430", "output": "99618123.5339717944" }, { "input": "448944609 529185527\n946362390 958011342", "output": "24529803.2444389601" }, { "input": "348741875 -606207234\n-279810821 -14278204", "output": "143060520.9047362779" }, { "input": "-202195424 182466434\n-722509868 -838173079", "output": "190651913.7089770083" }, { "input": "-48 9\n17 -67", "output": "21.7234042553" }, { "input": "12 180\n79 47", "output": "42.9433962264" }, { "input": "-131 -87\n-66 -109", "output": "21.7226463104" }, { "input": "171 17\n9 93", "output": "54.3103448276" }, { "input": "221 20\n-22 -200", "output": "94.5140388769" }, { "input": "372 -352\n-160 -423", "output": "216.4903748734" }, { "input": "480 37\n-3 -459", "output": "224.9325842697" }, { "input": "-535 -395\n-264 513", "output": "321.2340966921" }, { "input": "-498 -685\n-532 526", "output": "503.1068273092" }, { "input": "-16 450\n-848 27", "output": "284.2416107383" }, { "input": "-621967643 610314360\n-660274542 -772630232", "output": "611623765.8647500770" }, { "input": "222416863 97256131\n897661932 -426944193", "output": "125718637.9005708302" }, { "input": "67861199 302935298\n883117733 559626116", "output": "126575973.2879779836" }, { "input": "1000000000 1\n1000000000 2", "output": "0.4999999993" }, { "input": "-2 1\n1 -2", "output": "0.5000000000" }, { "input": "1000000000 999999995\n99999999 -199992543", "output": "142854098.7306812546" } ]
46
0
-1
34,937
884
Binary Matrix
[ "dsu" ]
null
null
You are given a matrix of size *n*<=Γ—<=*m*. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's. Note that the memory limit is unusual!
The first line contains two numbers *n* and *m* (1<=≀<=*n*<=≀<=212, 4<=≀<=*m*<=≀<=214) β€” the number of rows and columns, respectively. It is guaranteed that *m* is divisible by 4. Then the representation of matrix follows. Each of *n* next lines contains one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from *A* to *F*). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number *B* is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101. Elements are not separated by whitespaces.
Print the number of connected components consisting of 1's.
[ "3 4\n1\nA\n8\n", "2 8\n5F\nE3\n", "1 4\n0\n" ]
[ "3\n", "2\n", "0\n" ]
In the first example the matrix is: It is clear that it has three components. The second example: It is clear that the number of components is 2. There are no 1's in the third example, so the answer is 0.
[ { "input": "3 4\n1\nA\n8", "output": "3" }, { "input": "2 8\n5F\nE3", "output": "2" }, { "input": "1 4\n0", "output": "0" }, { "input": "1 4\nD", "output": "2" }, { "input": "10 120\n4100B3BC23752433106B89343D9BA9\nD0412141283A93738E2805121044D9\nB111606365A975606A60A641110C15\n1134D161132633643B33139A153114\nBA3F155302119840B0C06860401767\n3545720632A7CCB123127825403069\nB6404119C41BA1386A826135516134\n501CE41C0920635BA221421DAA0825\n2C4632C5217332A43372B0009530BA\nB0108731422A737A5D856202C5D328", "output": "161" } ]
108
716,800
0
35,009
323
Black-and-White Cube
[ "combinatorics", "constructive algorithms" ]
null
null
You are given a cube of size *k*<=Γ—<=*k*<=Γ—<=*k*, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face. Your task is to paint each of *k*3 unit cubes one of two colours (black or white), so that the following conditions must be satisfied: - each white cube has exactly 2 neighbouring cubes of white color; - each black cube has exactly 2 neighbouring cubes of black color.
The first line contains integer *k* (1<=≀<=*k*<=≀<=100), which is size of the cube.
Print -1 if there is no solution. Otherwise, print the required painting of the cube consequently by layers. Print a *k*<=Γ—<=*k* matrix in the first *k* lines, showing how the first layer of the cube should be painted. In the following *k* lines print a *k*<=Γ—<=*k* matrix β€” the way the second layer should be painted. And so on to the last *k*-th layer. Note that orientation of the cube in the space does not matter. Mark a white unit cube with symbol "w" and a black one with "b". Use the format of output data, given in the test samples. You may print extra empty lines, they will be ignored.
[ "1\n", "2\n" ]
[ "-1\n", "bb\nww\n\nbb\nww\n" ]
none
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "bb\nww\n\nbb\nww" }, { "input": "3", "output": "-1" }, { "input": "4", "output": "bbbb\nbwwb\nbwwb\nbbbb\n\nwwww\nwbbw\nwbbw\nwwww\n\nbbbb\nbwwb\nbwwb\nbbbb\n\nwwww\nwbbw\nwbbw\nwwww" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "bbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww\n\nbbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww\n\nbbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww" }, { "input": "7", "output": "-1" }, { "input": "8", "output": "bbbbbbbb\nbwwwwwwb\nbwbbbbwb\nbwbwwbwb\nbwbwwbwb\nbwbbbbwb\nbwwwwwwb\nbbbbbbbb\n\nwwwwwwww\nwbbbbbbw\nwbwwwwbw\nwbwbbwbw\nwbwbbwbw\nwbwwwwbw\nwbbbbbbw\nwwwwwwww\n\nbbbbbbbb\nbwwwwwwb\nbwbbbbwb\nbwbwwbwb\nbwbwwbwb\nbwbbbbwb\nbwwwwwwb\nbbbbbbbb\n\nwwwwwwww\nwbbbbbbw\nwbwwwwbw\nwbwbbwbw\nwbwbbwbw\nwbwwwwbw\nwbbbbbbw\nwwwwwwww\n\nbbbbbbbb\nbwwwwwwb\nbwbbbbwb\nbwbwwbwb\nbwbwwbwb\nbwbbbbwb\nbwwwww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‡Π½Ρ‹Π΅ Π²Ρ€Π°Ρ‚Π°
[]
null
null
Π“Π΅Ρ€ΠΎΠΉ Аркадий находится Π½Π° ΡƒΠ·ΠΊΠΎΠΉ полоскС Π·Π΅ΠΌΠ»ΠΈ, Ρ€Π°Π·Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ Π½Π° *n* Π·ΠΎΠ½, ΠΏΡ€ΠΎΠ½ΡƒΠΌΠ΅Ρ€ΠΎΠ²Π°Π½Π½Ρ‹Ρ… ΠΎΡ‚ 1 Π΄ΠΎ *n*. Из *i*-ΠΉ Π·ΠΎΠ½Ρ‹ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΡ€ΠΎΠΉΡ‚ΠΈ лишь Π² (*i*<=-<=1)-ю Π·ΠΎΠ½Ρƒ ΠΈ Π² (*i*<=+<=1)-ю Π·ΠΎΠ½Ρƒ, Ссли ΠΎΠ½ΠΈ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‚. ΠŸΡ€ΠΈ этом ΠΌΠ΅ΠΆΠ΄Ρƒ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΏΠ°Ρ€ΠΎΠΉ сосСдних Π·ΠΎΠ½ находятся ΠΏΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π½Ρ‹Π΅ Π²Ρ€Π°Ρ‚Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π½Ρ‹Ρ… Ρ†Π²Π΅Ρ‚ΠΎΠ², Ρ†Π²Π΅Ρ‚ Π²Ρ€Π°Ρ‚ ΠΌΠ΅ΠΆΠ΄Ρƒ *i*-ΠΉ ΠΈ (*i*<=+<=1)-ΠΉ Π·ΠΎΠ½ΠΎΠΉ Ρ€Π°Π²Π΅Π½ *g**i*. Аркадий ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΡ€ΠΎΠΉΡ‚ΠΈ ΠΏΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π½Ρ‹Π΅ Π²Ρ€Π°Ρ‚Π° Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ Ρ†Π²Π΅Ρ‚Π°, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли ΠΎΠ½ ΠΏΠ΅Ρ€Π΅Π΄ этим ΠΏΠΎΠ±Ρ‹Π²Π°Π» Π² ΠΎΠ΄Π½ΠΎΠΌ ΠΈΠ· ΡˆΠ°Ρ‚Ρ€ΠΎΠ² Ρ…Ρ€Π°Π½ΠΈΡ‚Π΅Π»Π΅ΠΉ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ этого Ρ†Π²Π΅Ρ‚Π° ΠΈ взял ΠΊΠ»ΡŽΡ‡. Π’ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π·ΠΎΠ½Π΅ находится Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄ΠΈΠ½ ΡˆΠ°Ρ‚Π΅Ρ€ хранитСля ΠΊΠ»ΡŽΡ‡Π΅ΠΉ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ Ρ†Π²Π΅Ρ‚Π°, Ρ†Π²Π΅Ρ‚ ΡˆΠ°Ρ‚Ρ€Π° Π² *i*-ΠΉ Π·ΠΎΠ½Π΅ Ρ€Π°Π²Π΅Π½ *k**i*. ПослС посСщСния ΡˆΠ°Ρ‚Ρ€Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠ³ΠΎ Ρ†Π²Π΅Ρ‚Π° Аркадий ΠΌΠΎΠΆΠ΅Ρ‚ Π½Π΅ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½Π½ΠΎΠ΅ число Ρ€Π°Π· ΠΏΡ€ΠΎΡ…ΠΎΠ΄ΠΈΡ‚ΡŒ Ρ‡Π΅Ρ€Π΅Π· Π»ΡŽΠ±Ρ‹Π΅ Π²Ρ€Π°Ρ‚Π° этого Ρ†Π²Π΅Ρ‚Π°. На ΠΏΡ€ΠΎΡ…ΠΎΠ΄ Ρ‡Π΅Ρ€Π΅Π· ΠΎΠ΄Π½ΠΈ Π²Ρ€Π°Ρ‚Π° Аркадий Ρ‚Ρ€Π°Ρ‚ΠΈΡ‚ ΠΎΠ΄ΠΈΠ½ Ρ…ΠΎΠ΄, Π½Π° посСщСниС ΡˆΠ°Ρ‚Ρ€Π° ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠ΅ пСрСмСщСния Ρ…ΠΎΠ΄Ρ‹ Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ΡΡ. Π—Π° ΠΊΠ°ΠΊΠΎΠ΅ минимальноС число Ρ…ΠΎΠ΄ΠΎΠ² Аркадий ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΠΎΠΏΠ°ΡΡ‚ΡŒ ΠΈΠ· Π·ΠΎΠ½Ρ‹ *a* Π² Π·ΠΎΠ½Ρƒ *b*, Ссли ΠΈΠ·Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎ Ρƒ Π½Π΅Π³ΠΎ Π½Π΅Ρ‚ Π½ΠΈΠΊΠ°ΠΊΠΈΡ… ΠΊΠ»ΡŽΡ‡Π΅ΠΉ?
ΠŸΠ΅Ρ€Π²Π°Ρ строка содСрТит Ρ‚Ρ€ΠΈ Ρ†Π΅Π»Ρ‹Ρ… числа *n*, *a*, *b* (2<=≀<=*n*<=≀<=100<=000, 1<=≀<=*a*,<=*b*<=≀<=*n*, *a*<=β‰ <=*b*)Β β€” число Π·ΠΎΠ½, Π½ΠΎΠΌΠ΅Ρ€ Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠΉ Π·ΠΎΠ½Ρ‹ ΠΈ Π½ΠΎΠΌΠ΅Ρ€ ΠΊΠΎΠ½Π΅Ρ‡Π½ΠΎΠΉ Π·ΠΎΠ½Ρ‹, соотвСтствСнно. Вторая строка содСрТит *n*<=-<=1 Ρ†Π΅Π»ΠΎΠ΅ число *g*1,<=*g*2,<=...,<=*g**n*<=-<=1 (1<=≀<=*g**i*<=≀<=100<=000), Π³Π΄Π΅ *g**i* ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Ρ†Π²Π΅Ρ‚ ΠΏΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π½Ρ‹Ρ… Π²Ρ€Π°Ρ‚ ΠΌΠ΅ΠΆΠ΄Ρƒ Π·ΠΎΠ½Π°ΠΌΠΈ *i* ΠΈ *i*<=+<=1. Π’Ρ€Π΅Ρ‚ΡŒΡ строка содСрТит *n* Ρ†Π΅Π»Ρ‹Ρ… чисСл *k*1,<=*k*2,<=...,<=*k**n* (1<=≀<=*k**i*<=≀<=100<=000), Π³Π΄Π΅ *k**i* ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Ρ†Π²Π΅Ρ‚ ΡˆΠ°Ρ‚Ρ€Π° хранитСля ΠΊΠ»ΡŽΡ‡Π΅ΠΉ Π² *i*-ΠΉ Π·ΠΎΠ½Π΅.
Если Аркадий Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΠΎΠΏΠ°ΡΡ‚ΡŒ ΠΈΠ· Π·ΠΎΠ½Ρ‹ *a* Π² Π·ΠΎΠ½Ρƒ *b*, Π½Π΅ имСя ΠΈΠ·Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ, Π²Ρ‹Π²Π΅Π΄ΠΈΡ‚Π΅ -1. Π˜Π½Π°Ρ‡Π΅ Π²Ρ‹Π²Π΅Π΄ΠΈΡ‚Π΅ минимальноС количСство Ρ…ΠΎΠ΄ΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ потрСбуСтся ΠΡ€ΠΊΠ°Π΄ΠΈΡŽ.
[ "5 4 1\n3 1 1 2\n7 1 2 1 3\n", "5 1 5\n4 3 2 1\n4 3 2 5 5\n" ]
[ "7\n", "-1\n" ]
Π’ ΠΏΠ΅Ρ€Π²ΠΎΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠΏΠ°ΡΡ‚ΡŒ ΠΈΠ· Π·ΠΎΠ½Ρ‹ 4 Π² Π·ΠΎΠ½Ρƒ 1, ΠΡ€ΠΊΠ°Π΄ΠΈΡŽ Π½ΡƒΠΆΠ½ΠΎ сначала Π²Π·ΡΡ‚ΡŒ ΠΊΠ»ΡŽΡ‡ Ρ†Π²Π΅Ρ‚Π° 1, ΠΏΡ€ΠΎΠΉΡ‚ΠΈ Π² Π·ΠΎΠ½Ρƒ 3, Ρ‚Π°ΠΌ Π²Π·ΡΡ‚ΡŒ ΠΊΠ»ΡŽΡ‡ Ρ†Π²Π΅Ρ‚Π° 2 ΠΈ ΠΏΡ€ΠΎΠΉΡ‚ΠΈ ΠΎΠ±Ρ€Π°Ρ‚Π½ΠΎ Π² Π·ΠΎΠ½Ρƒ 4 ΠΈ Π·Π°Ρ‚Π΅ΠΌ Π² Π·ΠΎΠ½Ρƒ 5, Π²Π·ΡΡ‚ΡŒ Ρ‚Π°ΠΌ ΠΊΠ»ΡŽΡ‡ Ρ†Π²Π΅Ρ‚Π° 3 ΠΈ Π΄ΠΎΠΉΡ‚ΠΈ Π΄ΠΎ Π·ΠΎΠ½Ρ‹ 1 Π·Π° Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅ Ρ…ΠΎΠ΄Π°. Π’ΠΎ Π²Ρ‚ΠΎΡ€ΠΎΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ Аркадий ΠΌΠΎΠΆΠ΅Ρ‚ Π΄ΠΎΠΉΡ‚ΠΈ лишь Π΄ΠΎ Ρ‡Π΅Ρ‚Π²Π΅Ρ€Ρ‚ΠΎΠΉ Π·ΠΎΠ½Ρ‹, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ ΡˆΠ°Ρ‚Ρ€ΠΎΠ² Ρ…Ρ€Π°Π½ΠΈΡ‚Π΅Π»Π΅ΠΉ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ Ρ†Π²Π΅Ρ‚Π° 1 Π½Π΅Ρ‚ совсСм.
[]
46
5,632,000
0
35,062
344
Simple Molecules
[ "brute force", "graphs", "math" ]
null
null
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number β€” the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.
The single line of the input contains three space-separated integers *a*, *b* and *c* (1<=≀<=*a*,<=*b*,<=*c*<=≀<=106) β€” the valence numbers of the given atoms.
If such a molecule can be built, print three space-separated integers β€” the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
[ "1 1 2\n", "3 4 5\n", "4 1 1\n" ]
[ "0 1 1\n", "1 3 2\n", "Impossible\n" ]
The first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case. The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms. The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself. The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.
[ { "input": "1 1 2", "output": "0 1 1" }, { "input": "3 4 5", "output": "1 3 2" }, { "input": "4 1 1", "output": "Impossible" }, { "input": "1 1 1", "output": "Impossible" }, { "input": "1000000 1000000 1000000", "output": "500000 500000 500000" }, { "input": "3 11 8", "output": "3 8 0" }, { "input": "8 5 12", "output": "Impossible" }, { "input": "1000000 500000 1", "output": "Impossible" }, { "input": "1000000 500000 2", "output": "Impossible" }, { "input": "2 2 2", "output": "1 1 1" }, { "input": "3 3 3", "output": "Impossible" }, { "input": "4 4 4", "output": "2 2 2" }, { "input": "2 4 2", "output": "2 2 0" }, { "input": "10 5 14", "output": "Impossible" }, { "input": "10 5 15", "output": "0 5 10" }, { "input": "10 4 16", "output": "Impossible" }, { "input": "3 3 6", "output": "0 3 3" }, { "input": "9 95 90", "output": "7 88 2" }, { "input": "3 5 8", "output": "0 5 3" }, { "input": "5 8 13", "output": "0 8 5" }, { "input": "6 1 5", "output": "1 0 5" }, { "input": "59 54 56", "output": "Impossible" }, { "input": "246 137 940", "output": "Impossible" }, { "input": "7357 3578 9123", "output": "906 2672 6451" }, { "input": "93952 49553 83405", "output": "30050 19503 63902" }, { "input": "688348 726472 442198", "output": "486311 240161 202037" }, { "input": "602752 645534 784262", "output": "232012 413522 370740" }, { "input": "741349 48244 642678", "output": "Impossible" }, { "input": "655754 418251 468390", "output": "Impossible" }, { "input": "310703 820961 326806", "output": "Impossible" }, { "input": "1 1 3", "output": "Impossible" }, { "input": "5 1 4", "output": "1 0 4" } ]
186
0
3
35,067
0
none
[ "none" ]
null
null
Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street. The street, where the Lou Who family lives can be represented as *n* consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets). After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food. The Lou Whos want to spend no more than *t* time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional *k* kilos of sweets. Cindy Lou wants to know the minimum number of *k* kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street. Your task is to write a program that will determine the minimum possible value of *k*.
The first line of the input contains two space-separated integers *n* and *t* (2<=≀<=*n*<=≀<=5Β·105,<=1<=≀<=*t*<=≀<=109). The second line of the input contains *n* characters, the *i*-th of them equals "H" (if the *i*-th segment contains a house), "S" (if the *i*-th segment contains a shop) or "." (if the *i*-th segment doesn't contain a house or a shop). It is guaranteed that there is at least one segment with a house.
If there isn't a single value of *k* that makes it possible to give sweets to everybody in at most *t* units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of *k*.
[ "6 6\nHSHSHS\n", "14 100\n...HHHSSS...SH\n", "23 50\nHHSS.......SSHHHHHHHHHH\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back. In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction. In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home.
[]
124
0
0
35,163
368
Sereja and Coat Rack
[ "implementation" ]
null
null
Sereja owns a restaurant for *n* people. The restaurant hall has a coat rack with *n* hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the *i*-th hook costs *a**i* rubles. Only one person can hang clothes on one hook. Tonight Sereja expects *m* guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a *d* ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the *m* guests is visiting Sereja's restaurant tonight.
The first line contains two integers *n* and *d* (1<=≀<=*n*,<=*d*<=≀<=100). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=100). The third line contains integer *m* (1<=≀<=*m*<=≀<=100).
In a single line print a single integer β€” the answer to the problem.
[ "2 1\n2 1\n2\n", "2 1\n2 1\n10\n" ]
[ "3\n", "-5\n" ]
In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 =  - 5.
[ { "input": "2 1\n2 1\n2", "output": "3" }, { "input": "2 1\n2 1\n10", "output": "-5" }, { "input": "1 1\n1\n2", "output": "0" }, { "input": "3 96\n83 22 17\n19", "output": "-1414" }, { "input": "8 4\n27 72 39 70 13 68 100 36\n95", "output": "77" }, { "input": "2 65\n23 34\n74", "output": "-4623" }, { "input": "2 48\n12 54\n69", "output": "-3150" }, { "input": "5 30\n63 58 38 60 24\n42", "output": "-867" }, { "input": "9 47\n17 36 91 43 89 7 41 43 65\n49", "output": "-1448" }, { "input": "6 49\n91 30 71 51 7 2\n94", "output": "-4060" }, { "input": "57 27\n73 51 24 86 57 17 27 58 27 58 38 72 70 62 97 23 18 13 18 97 86 42 24 30 30 66 60 33 97 56 54 63 85 35 55 73 58 70 33 64 8 84 12 36 68 49 76 39 24 43 55 12 42 76 60 26 22\n71", "output": "2454" }, { "input": "35 19\n6 84 51 99 80 2 94 35 38 35 57 94 77 6 63 49 82 1 14 42 56 56 43 63 12 78 25 79 53 44 97 74 41 14 76\n73", "output": "1098" }, { "input": "11 91\n18 33 13 96 70 32 41 89 86 91 98\n90", "output": "-6522" }, { "input": "46 48\n54 15 52 41 45 59 36 60 93 6 65 82 4 30 76 9 93 98 50 57 62 28 68 42 30 41 14 75 2 78 16 84 14 93 25 2 93 60 71 29 28 85 76 87 99 71\n88", "output": "382" }, { "input": "5 72\n4 22 64 7 64\n11", "output": "-271" }, { "input": "90 24\n41 65 43 20 14 92 5 19 33 51 6 76 40 4 23 99 48 85 49 72 65 14 76 46 13 47 79 70 63 20 86 90 45 66 41 46 9 19 71 2 24 33 73 53 88 71 64 2 4 24 28 1 70 16 66 29 44 48 89 44 38 10 64 50 82 89 43 9 61 22 59 55 89 47 91 50 44 31 21 49 68 37 84 36 27 86 39 54 30 25\n49", "output": "1306" }, { "input": "60 63\n58 67 45 56 19 27 12 26 56 2 50 97 85 16 65 43 76 14 43 97 49 73 27 7 74 30 5 6 27 13 76 94 66 37 37 42 15 95 57 53 37 39 83 56 16 32 31 42 26 12 38 87 91 51 63 35 94 54 17 53\n9", "output": "86" }, { "input": "34 79\n55 4 35 4 57 49 25 18 14 10 29 1 81 19 59 51 56 62 65 4 77 44 10 3 62 90 49 83 54 75 21 3 24 32\n70", "output": "-1519" }, { "input": "60 91\n9 20 72 4 46 82 5 93 86 14 99 90 23 39 38 11 62 35 9 62 60 94 16 70 38 70 59 1 72 65 18 16 56 16 31 40 13 89 83 55 86 11 85 75 81 16 52 42 16 80 11 99 74 89 78 33 57 90 14 9\n42", "output": "1406" }, { "input": "24 68\n64 29 85 79 1 72 86 75 72 34 68 54 96 69 26 77 30 51 99 10 94 87 81 17\n50", "output": "-312" }, { "input": "29 19\n80 65 22 6 27 17 17 27 67 88 82 65 41 87 22 63 22 65 10 16 3 74 25 42 46 63 24 32 7\n69", "output": "445" }, { "input": "3 37\n8 8 82\n13", "output": "-272" }, { "input": "31 63\n15 10 85 57 91 94 97 53 55 46 9 49 92 13 32 15 40 59 23 5 96 53 70 80 39 24 19 67 60 99 87\n97", "output": "-2524" }, { "input": "34 30\n59 23 47 93 38 26 48 59 3 8 99 31 93 1 79 100 53 49 83 41 16 76 63 68 37 98 19 98 29 52 17 31 50 26\n59", "output": "963" }, { "input": "21 29\n41 61 48 63 56 76 93 62 55 99 47 15 47 89 70 39 64 76 16 22 76\n16", "output": "782" }, { "input": "35 86\n71 6 65 58 63 62 25 50 70 31 24 51 34 26 11 38 37 38 79 94 37 15 65 92 50 36 6 38 5 38 24 65 71 9 69\n82", "output": "-2489" }, { "input": "53 75\n74 53 95 77 27 97 73 50 41 75 20 44 12 42 90 20 66 6 86 17 51 16 10 65 67 94 75 10 1 96 74 90 62 73 69 59 32 69 27 11 23 75 80 11 53 83 92 96 65 75 65 3 56\n61", "output": "2293" }, { "input": "73 13\n22 23 48 78 90 6 96 95 51 44 55 82 13 73 40 29 13 63 68 9 16 9 24 60 35 5 87 20 59 46 7 67 1 68 93 88 33 57 75 48 22 84 23 32 77 84 49 24 83 19 77 21 12 83 57 91 26 25 87 78 70 44 35 78 69 69 92 97 84 29 28 27 72\n98", "output": "3419" }, { "input": "4 39\n28 9 46 9\n86", "output": "-3106" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n100", "output": "10000" }, { "input": "1 100\n100\n100", "output": "-9800" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "5 1\n1 5 2 7 8\n3", "output": "8" }, { "input": "4 44\n3 3 3 3\n1", "output": "3" }, { "input": "3 1\n1 2 3\n1", "output": "1" } ]
46
0
0
35,187
912
Fishes
[ "data structures", "graphs", "greedy", "probabilities", "shortest paths" ]
null
null
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size *n*<=Γ—<=*m*, divided into cells of size 1<=Γ—<=1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gift bundle also includes a square scoop of size *r*<=Γ—<=*r*, designed for fishing. If the lower-left corner of the scoop-net is located at cell (*x*,<=*y*), all fishes inside the square (*x*,<=*y*)...(*x*<=+<=*r*<=-<=1,<=*y*<=+<=*r*<=-<=1) get caught. Note that the scoop-net should lie completely inside the pond when used. Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release *k* fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put *k* fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (*n*<=-<=*r*<=+<=1)Β·(*m*<=-<=*r*<=+<=1) possible positions, the average number of caught fishes is as high as possible.
The only line contains four integers *n*,<=*m*,<=*r*,<=*k* (1<=≀<=*n*,<=*m*<=≀<=105, 1<=≀<=*r*<=≀<=*min*(*n*,<=*m*), 1<=≀<=*k*<=≀<=*min*(*n*Β·*m*,<=105)).
Print a single numberΒ β€” the maximum possible expected number of caught fishes. You answer is considered correct, is its absolute or relative error does not exceed 10<=-<=9. Namely, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct, if .
[ "3 3 2 3\n", "12 17 9 40\n" ]
[ "2.0000000000\n", "32.8333333333\n" ]
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
[ { "input": "3 3 2 3", "output": "2.0000000000" }, { "input": "12 17 9 40", "output": "32.8333333333" }, { "input": "1 1 1 1", "output": "1.0000000000" }, { "input": "10 10 5 100", "output": "25.0000000000" }, { "input": "7 1 1 4", "output": "0.5714285714" }, { "input": "1000 1000 59 100000", "output": "392.2854657164" }, { "input": "100000 100000 1000 100000", "output": "10.2028343872" }, { "input": "100000 100000 100000 100000", "output": "100000.0000000000" }, { "input": "3 100000 2 88700", "output": "1.7740177402" }, { "input": "200 100000 55 100000", "output": "20.7303724833" }, { "input": "74 2 1 36", "output": "0.2432432432" }, { "input": "2 59 1 112", "output": "0.9491525424" }, { "input": "96 33 24 928", "output": "299.8356164384" }, { "input": "20 78 8 997", "output": "55.2026002167" }, { "input": "44 22 13 515", "output": "139.7312500000" }, { "input": "68 66 33 2353", "output": "930.8962418301" }, { "input": "96 7 4 534", "output": "14.6129032258" }, { "input": "20 59 2 88", "output": "0.3194192377" }, { "input": "45 3 1 35", "output": "0.2592592593" }, { "input": "69 48 18 167", "output": "33.5657568238" }, { "input": "34994 5189 2572 83748", "output": "6526.6982502848" }, { "input": "51122 86737 45712 45929", "output": "45929.0000000000" }, { "input": "1308 96219 150 13599", "output": "2.7480097244" }, { "input": "84732 45064 24231 99973", "output": "40039.1022280255" }, { "input": "860 93908 193 29450", "output": "17.5230504355" }, { "input": "51580 42753 1589 91632", "output": "112.4258885780" }, { "input": "67708 58893 32854 21110", "output": "19898.0903744083" }, { "input": "51133 7737 2779 83291", "output": "2682.4996497742" }, { "input": "67261 65094 36712 36961", "output": "36961.0000000000" }, { "input": "17981 81234 438 66438", "output": "8.9916815389" }, { "input": "86852 96025 86852 82059", "output": "82059.0000000000" }, { "input": "96877 86600 86600 94110", "output": "94110.0000000000" }, { "input": "93240 88881 88881 94245", "output": "94245.0000000000" }, { "input": "90706 97197 90706 96593", "output": "96593.0000000000" }, { "input": "93289 95214 93289 96084", "output": "96084.0000000000" }, { "input": "90755 85790 85790 98432", "output": "98432.0000000000" }, { "input": "80779 83807 80779 97924", "output": "97924.0000000000" }, { "input": "98246 89266 89266 80270", "output": "80270.0000000000" }, { "input": "80828 99843 80828 99763", "output": "99763.0000000000" }, { "input": "98295 88157 88157 82110", "output": "82110.0000000000" }, { "input": "52329 55202 45142 8532", "output": "8532.0000000000" }, { "input": "68457 4046 983 38009", "output": "177.6486146644" }, { "input": "18644 46233 17019 62575", "output": "36452.6416224542" }, { "input": "2068 62373 1084 92053", "output": "1628.0869962473" }, { "input": "18196 43921 15918 54235", "output": "30828.1934723611" }, { "input": "68916 60062 7636 83712", "output": "1519.2830994297" }, { "input": "85044 8906 4115 45894", "output": "2003.8686025940" }, { "input": "68468 33559 15324 99563", "output": "24124.0525512989" }, { "input": "84596 49699 46033 61745", "output": "61745.0000000000" }, { "input": "35316 31247 27829 91223", "output": "91223.0000000000" }, { "input": "51444 47388 21532 20700", "output": "12407.9770445558" }, { "input": "67572 96232 61366 50178", "output": "50178.0000000000" }, { "input": "17759 38418 4313 7448", "output": "302.0942031080" }, { "input": "1183 87263 148 4221", "output": "1.0244272005" }, { "input": "84607 36107 29486 33699", "output": "18026.3545226951" }, { "input": "68031 52248 51042 20073", "output": "20073.0000000000" }, { "input": "84159 1092 683 49550", "output": "405.4128682152" }, { "input": "67583 49936 46141 11732", "output": "11732.0000000000" }, { "input": "51007 74589 14733 41209", "output": "4119.5718891113" }, { "input": "34431 23433 19371 27583", "output": "27583.0000000000" }, { "input": "52 45 38 49", "output": "49.0000000000" }, { "input": "80 89 32 26", "output": "9.3680506685" }, { "input": "74 63 30 92", "output": "53.8823529412" }, { "input": "2 20 1 14", "output": "0.3500000000" }, { "input": "22 60 13 48", "output": "13.0000000000" }, { "input": "50 5 4 29", "output": "2.4680851064" }, { "input": "74 49 48 99", "output": "99.0000000000" }, { "input": "2 89 2 80", "output": "1.8181818182" }, { "input": "22 38 9 58", "output": "11.1857142857" }, { "input": "50 86 11 36", "output": "1.4328947368" }, { "input": "98155 95063 95062 98875", "output": "98875.0000000000" }, { "input": "95606 98563 95342 99783", "output": "99783.0000000000" }, { "input": "95468 97642 95176 95192", "output": "95192.0000000000" }, { "input": "96394 96141 96028 96100", "output": "96100.0000000000" }, { "input": "100000 1 1 99999", "output": "0.9999900000" }, { "input": "100000 100000 1 100000", "output": "0.0000100000" }, { "input": "100000 100000 100000 1", "output": "1.0000000000" }, { "input": "88888 99999 77777 1", "output": "1.0000000000" }, { "input": "77777 99999 77777 7", "output": "7.0000000000" }, { "input": "100000 100000 1 1", "output": "0.0000000001" }, { "input": "3689 2691 1885 47808", "output": "47808.0000000000" }, { "input": "3907 4563 2248 99346", "output": "95853.0468547766" }, { "input": "1785 3525 1785 82536", "output": "82534.7300402068" }, { "input": "4761 2433 2433 46586", "output": "46586.0000000000" }, { "input": "3106 2359 1558 16919", "output": "16897.4346155270" }, { "input": "3291 1679 1679 70630", "output": "70630.0000000000" }, { "input": "6439 5463 3240 91287", "output": "91097.0460375450" }, { "input": "10000 10000 3000 100000", "output": "18362.1002496817" }, { "input": "7159 6332 3563 82463", "output": "81427.6340771341" }, { "input": "8402 6135 4222 85384", "output": "85384.0000000000" }, { "input": "8946 8108 4509 80203", "output": "80188.7715868009" }, { "input": "9199 8137 4561 82660", "output": "81268.3728190748" }, { "input": "8208 8895 4508 97736", "output": "97736.0000000000" }, { "input": "9513 11191 5633 90250", "output": "90250.0000000000" }, { "input": "11562 20387 10218 95794", "output": "95794.0000000000" }, { "input": "80000 80000 40000 100000", "output": "99625.0947119987" }, { "input": "7 100 4 12", "output": "0.4948453608" } ]
1,000
30,515,200
0
35,221
303
Rectangle Puzzle II
[ "implementation", "math" ]
null
null
You are given a rectangle grid. That grid's size is *n*<=Γ—<=*m*. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates β€” a pair of integers (*x*,<=*y*) (0<=≀<=*x*<=≀<=*n*,<=0<=≀<=*y*<=≀<=*m*). Your task is to find a maximum sub-rectangle on the grid (*x*1,<=*y*1,<=*x*2,<=*y*2) so that it contains the given point (*x*,<=*y*), and its length-width ratio is exactly (*a*,<=*b*). In other words the following conditions must hold: 0<=≀<=*x*1<=≀<=*x*<=≀<=*x*2<=≀<=*n*, 0<=≀<=*y*1<=≀<=*y*<=≀<=*y*2<=≀<=*m*, . The sides of this sub-rectangle should be parallel to the axes. And values *x*1,<=*y*1,<=*x*2,<=*y*2 should be integers. If there are multiple solutions, find the rectangle which is closest to (*x*,<=*y*). Here "closest" means the Euclid distance between (*x*,<=*y*) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (*x*1,<=*y*1,<=*x*2,<=*y*2), so we can choose the lexicographically minimum one.
The first line contains six integers *n*,<=*m*,<=*x*,<=*y*,<=*a*,<=*b* (1<=≀<=*n*,<=*m*<=≀<=109,<=0<=≀<=*x*<=≀<=*n*,<=0<=≀<=*y*<=≀<=*m*,<=1<=≀<=*a*<=≀<=*n*,<=1<=≀<=*b*<=≀<=*m*).
Print four integers *x*1,<=*y*1,<=*x*2,<=*y*2, which represent the founded sub-rectangle whose left-bottom point is (*x*1,<=*y*1) and right-up point is (*x*2,<=*y*2).
[ "9 9 5 5 2 1\n", "100 100 52 50 46 56\n" ]
[ "1 3 9 7\n", "17 8 86 92\n" ]
none
[ { "input": "9 9 5 5 2 1", "output": "1 3 9 7" }, { "input": "100 100 52 50 46 56", "output": "17 8 86 92" }, { "input": "100 100 16 60 42 75", "output": "0 0 56 100" }, { "input": "100 100 28 22 47 50", "output": "0 0 94 100" }, { "input": "100 100 44 36 96 21", "output": "0 25 96 46" }, { "input": "100 100 56 46 1 47", "output": "55 0 57 94" }, { "input": "100 100 20 53 6 22", "output": "6 1 33 100" }, { "input": "100 100 32 63 2 41", "output": "30 18 34 100" }, { "input": "100 100 48 73 63 16", "output": "16 65 79 81" }, { "input": "100 100 13 59 14 20", "output": "0 0 70 100" }, { "input": "36830763 28058366 30827357 20792295 11047103 20670351", "output": "25303805 7388015 36350908 28058366" }, { "input": "87453374 60940601 74141787 32143714 78082907 33553425", "output": "9370467 15367001 87453374 48920426" }, { "input": "71265727 62692710 12444778 3479306 21442685 5463351", "output": "0 0 64328055 16390053" }, { "input": "48445042 43730155 14655564 6244917 43454856 2866363", "output": "0 4811735 43454856 7678098" }, { "input": "85759276 82316701 8242517 1957176 10225118 547026", "output": "0 0 81800944 4376208" }, { "input": "64748258 21983760 9107246 2437546 11247507 8924750", "output": "0 0 22495014 17849500" }, { "input": "6561833 24532010 2773123 457562 6225818 23724637", "output": "0 0 6225818 23724637" }, { "input": "33417574 19362112 17938303 4013355 10231192 2596692", "output": "166200 0 33417574 8439249" }, { "input": "98540143 28776614 12080542 1456439 96484500 3125739", "output": "0 0 96484500 3125739" }, { "input": "75549175 99860242 42423626 6574859 73199290 26030615", "output": "2349885 0 75549175 26030615" }, { "input": "4309493 76088457 2523467 46484812 909115 53662610", "output": "1887086 960803 3159847 76088457" }, { "input": "99373741 10548319 82293354 9865357 58059929 5328757", "output": "41313812 5219562 99373741 10548319" }, { "input": "81460 7041354 53032 1297536 41496 5748697", "output": "27916 0 78148 6958949" }, { "input": "5664399 63519726 1914884 13554302 2435218 44439020", "output": "697275 0 3132493 44439020" }, { "input": "19213492 76256257 10302871 19808004 19174729 55280126", "output": "38763 0 19213492 55280126" }, { "input": "61430678 95017800 11901852 27772249 25202227 87778634", "output": "0 0 25202227 87778634" }, { "input": "1063740 2675928 277215 2022291 204933 298547", "output": "0 1183193 1024665 2675928" }, { "input": "71580569 68590917 4383746 13851161 9868376 8579752", "output": "0 0 71545726 62203202" }, { "input": "17818532 82586436 8482338 54895799 12444902 11112345", "output": "2259887 49339626 14704789 60451971" }, { "input": "63651025 50179036 16141802 24793214 28944209 13993078", "output": "0 10800136 57888418 38786292" }, { "input": "11996821 42550832 8901163 19214381 3510233 20406511", "output": "4976355 0 11996821 40813022" }, { "input": "27048166 72584165 4785744 2001800 24615554 27645416", "output": "0 0 24615554 27645416" }, { "input": "47001271 53942737 7275347 1652337 33989593 48660013", "output": "0 0 33989593 48660013" }, { "input": "51396415 50182729 20810973 38206844 17823753 2905275", "output": "0 34333144 47530008 42080544" }, { "input": "27087649 52123970 20327636 19640608 8481031 14569965", "output": "1644556 0 27087649 43709895" }, { "input": "41635044 16614992 36335190 11150551 30440245 13728274", "output": "11194799 2886718 41635044 16614992" }, { "input": "97253692 35192249 21833856 26094161 41611668 32149284", "output": "0 363858 45079307 35192249" }, { "input": "60300478 3471217 11842517 3192374 27980820 507119", "output": "0 2456979 55961640 3471217" }, { "input": "69914272 30947694 58532705 25740028 30431847 27728130", "output": "39482425 3219564 69914272 30947694" }, { "input": "83973381 91192149 19059738 26429459 49573749 78006738", "output": "0 0 49573749 78006738" }, { "input": "1000000000 1000000000 286536427 579261823 230782719 575570138", "output": "171145067 291476754 401927786 867046892" }, { "input": "1000000000 1000000000 42362139 725664533 91213476 617352813", "output": "0 176862916 121617968 1000000000" }, { "input": "1000000000 1000000000 503220555 167034539 244352073 511651840", "output": "276322201 0 730118908 950210560" }, { "input": "1000000000 1000000000 259046267 313437250 252266478 848401810", "output": "132913028 0 385179506 848401810" }, { "input": "1000000000 1000000000 867388331 312356312 405405075 887925029", "output": "594594925 0 1000000000 887925029" }, { "input": "1000000000 1000000000 623214043 753726318 970868535 929707704", "output": "29131465 70292296 1000000000 1000000000" }, { "input": "1000000000 1000000000 84072459 754904836 124007132 824006731", "output": "22068893 175993269 146076025 1000000000" }, { "input": "1000000000 1000000000 839898171 196274842 131921537 865789406", "output": "773937402 0 905858939 865789406" }, { "input": "1000000000 1000000000 448240235 342677552 992352294 907572080", "output": "0 0 992352294 907572080" }, { "input": "1000000000 1000000000 837887296 643696230 478881476 45404539", "output": "42237048 598291691 1000000000 689100769" }, { "input": "1000000000 500 1000 400 11 122", "output": "978 12 1022 500" }, { "input": "1000000000 1000000000 1000000000 1000000000 1 1", "output": "0 0 1000000000 1000000000" }, { "input": "1000000000 1000000000 1000000000 1000000000 1000000000 1", "output": "0 999999999 1000000000 1000000000" }, { "input": "1000000000 999999999 1000 1000 1000000000 999999999", "output": "0 0 1000000000 999999999" }, { "input": "70 10 20 5 5 3", "output": "12 0 27 9" }, { "input": "1000000000 1000000000 500000000 500000000 500000000 500000001", "output": "250000000 249999999 750000000 750000000" } ]
109
0
0
35,280
653
Paper task
[ "data structures", "string suffix structures", "strings" ]
null
null
Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time. For the purpose of this problem we consider only strings consisting of opening and closing round brackets, that is characters '(' and ')'. The sequence of brackets is called correct if: 1. it's empty; 1. it's a correct sequence of brackets, enclosed in a pair of opening and closing brackets; 1. it's a concatenation of two correct sequences of brackets. For example, the sequences "()()" and "((()))(())" are correct, while ")(()", "(((((" and "())" are not. Alex took a piece of paper, wrote a string *s* consisting of brackets and asked Valentina to count the number of distinct non-empty substrings of *s* that are correct sequences of brackets. In other words, her task is to count the number of non-empty correct sequences of brackets that occur in a string *s* as a substring (don't mix up with subsequences). When Valentina finished the task, Alex noticed he doesn't know the answer. Help him don't loose face in front of Valentina and solve the problem!
The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=500<=000)Β β€” the length of the string *s*. The second line contains a string *s* of length *n* consisting of only '(' and ')'.
Print the number of distinct non-empty correct sequences that occur in *s* as substring.
[ "10\n()()()()()\n", "7\n)(())()\n" ]
[ "5\n", "3\n" ]
In the first sample, there are 5 distinct substrings we should count: "()", "()()", "()()()", "()()()()" and "()()()()()". In the second sample, there are 3 distinct substrings we should count: "()", "(())" and "(())()".
[ { "input": "10\n()()()()()", "output": "5" }, { "input": "7\n)(())()", "output": "3" }, { "input": "1\n(", "output": "0" }, { "input": "2\n))", "output": "0" }, { "input": "15\n(())(()())(()()", "output": "5" }, { "input": "30\n()(())(())(())()(())()()()(()(", "output": "34" }, { "input": "100\n(((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))", "output": "50" }, { "input": "1\n)", "output": "0" }, { "input": "2\n)(", "output": "0" }, { "input": "2\n((", "output": "0" }, { "input": "3\n(()", "output": "1" }, { "input": "3\n()(", "output": "1" }, { "input": "5\n()(()", "output": "1" }, { "input": "7\n(()(())", "output": "3" }, { "input": "10\n()()((())(", "output": "3" }, { "input": "10\n((((()))))", "output": "5" }, { "input": "20\n()()((()())())()()((", "output": "13" }, { "input": "20\n(((((((((())))))))))", "output": "10" }, { "input": "20\n))(())))))((((()))((", "output": "3" }, { "input": "50\n()(())()()()(()())()(())()()()()(())()()(())()()()", "output": "142" }, { "input": "50\n((((((((((((((((((((((((()))))))))))))))))))))))))", "output": "25" }, { "input": "50\n)))(()(())())())(())()())(())()((()()))(()(()(((()", "output": "13" }, { "input": "100\n)(()))))))(())()))())())(())())))))))()())))()())()((()))())((((()()((()((()((((((((()(((()())(((()(", "output": "9" }, { "input": "500\n()(()()()()()(())())((()(()))()()(())())()(())(()()())()()(())(())(())(())(())()()(())((()))()()()()()(())()()()()((())())()(())(())(())()((())(()))(())(()()()()(())())((()()(())()))(())(()()()((()))())((())(())(())())()((()(()))())()(())((())()()(()))()(()(())()((()))()())(())()((()))()()(())(((()())())()())((()()(())))()(())((())())()()()((())()(())()())((()))(())(())()()((())()()()(())())()()(()()((())()))()()()((())()()()(()))()(()()())()()()()((())())()()(())((()))()()(()()()()()()())()()((", "output": "4051" }, { "input": "500\n(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))", "output": "250" }, { "input": "500\n)()))))()())))))(())))))))()))))))())))))))()))))))))))()))()))()))(())(()))()())()(()))))()))))))))()))))())))))))))))))(()()))))))))()())))))))()))))()))))))()))())))))))))()))))()))))))))()))))()))))()()))))())))))))())(()()))))))))())))))()())))))((()((((())(()(((((()((((((((((((((()(()((((((((((((((()((((()()))(((((((()((()()(((((((()(((()((((()(((()(((((((((((((((()((()(()((())(()))()(()(((()((((((((()((()(((((((()(((((((()(((((())()())()((((((()(((()(())))((((((()(()((((())(((()((((((()()", "output": "17" } ]
124
0
0
35,375
314
Sereja and Subsequences
[ "data structures", "dp" ]
null
null
Sereja has a sequence that consists of *n* positive integers, *a*1,<=*a*2,<=...,<=*a**n*. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence *a*. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not exceed it. A sequence of positive integers *x*<==<=*x*1,<=*x*2,<=...,<=*x**r* doesn't exceed a sequence of positive integers *y*<==<=*y*1,<=*y*2,<=...,<=*y**r*, if the following inequation holds: *x*1<=≀<=*y*1,<=*x*2<=≀<=*y*2,<=...,<=*x**r*<=≀<=*y**r*. Now Sereja wonders, how many sequences are written on the lines piece of paper. Help Sereja, find the required quantity modulo 1000000007 (109<=+<=7).
The first line contains integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=106).
In the single line print the answer to the problem modulo 1000000007 (109<=+<=7).
[ "1\n42\n", "3\n1 2 2\n", "5\n1 2 3 4 5\n" ]
[ "42\n", "13\n", "719\n" ]
none
[ { "input": "1\n42", "output": "42" }, { "input": "3\n1 2 2", "output": "13" }, { "input": "5\n1 2 3 4 5", "output": "719" }, { "input": "4\n11479 29359 26963 24465", "output": "927446239" }, { "input": "5\n5706 28146 23282 16828 9962", "output": "446395832" }, { "input": "6\n492 2996 11943 4828 5437 32392", "output": "405108414" }, { "input": "7\n14605 3903 154 293 12383 17422 18717", "output": "975867090" }, { "input": "8\n19719 19896 5448 21727 14772 11539 1870 19913", "output": "937908482" }, { "input": "9\n3 3 2 2 3 2 1 1 2", "output": "93" }, { "input": "10\n3 3 3 2 1 2 3 2 3 1", "output": "529" }, { "input": "42\n8 5 1 10 5 9 9 3 5 6 6 2 8 2 2 6 3 8 7 2 5 3 4 3 3 2 7 9 6 8 7 2 9 10 3 8 10 6 5 4 2 3", "output": "608660833" }, { "input": "42\n68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 48 27 72 39 70 13 68 100 36 95 4 12 23", "output": "56277550" }, { "input": "42\n18468 6335 26501 19170 15725 11479 29359 26963 24465 5706 28146 23282 16828 9962 492 2996 11943 4828 5437 32392 14605 3903 154 293 12383 17422 18717 19719 19896 5448 21727 14772 11539 1870 19913 25668 26300 17036 9895 28704 23812 31323", "output": "955898058" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1000000", "output": "1000000" } ]
62
0
0
35,403
584
Marina and Vasya
[ "constructive algorithms", "greedy", "strings" ]
null
null
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly *t* characters. Help Vasya find at least one such string. More formally, you are given two strings *s*1, *s*2 of length *n* and number *t*. Let's denote as *f*(*a*,<=*b*) the number of characters in which strings *a* and *b* are different. Then your task will be to find any string *s*3 of length *n*, such that *f*(*s*1,<=*s*3)<==<=*f*(*s*2,<=*s*3)<==<=*t*. If there is no such string, print <=-<=1.
The first line contains two integers *n* and *t* (1<=≀<=*n*<=≀<=105, 0<=≀<=*t*<=≀<=*n*). The second line contains string *s*1 of length *n*, consisting of lowercase English letters. The third line contain string *s*2 of length *n*, consisting of lowercase English letters.
Print a string of length *n*, differing from string *s*1 and from *s*2 in exactly *t* characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
[ "3 2\nabc\nxyc\n", "1 0\nc\nb\n" ]
[ "ayd", "-1\n" ]
none
[ { "input": "3 2\nabc\nxyc", "output": "bac" }, { "input": "1 0\nc\nb", "output": "-1" }, { "input": "1 1\na\na", "output": "b" }, { "input": "2 1\naa\naa", "output": "ab" }, { "input": "3 1\nbcb\nbca", "output": "bcc" }, { "input": "4 3\nccbb\ncaab", "output": "cbca" }, { "input": "4 2\nacbc\nacba", "output": "acab" }, { "input": "4 1\nbcbc\nacab", "output": "-1" }, { "input": "4 2\nacbb\nbabc", "output": "aaba" }, { "input": "5 2\nabaac\nbbbaa", "output": "abbab" }, { "input": "5 2\nabbab\nacbab", "output": "aabaa" }, { "input": "5 3\nbcaaa\ncbacc", "output": "bbabb" }, { "input": "5 3\ncbacb\ncbacb", "output": "cbbaa" }, { "input": "5 1\ncbabb\nbabaa", "output": "-1" }, { "input": "1 0\na\na", "output": "a" }, { "input": "2 2\nbb\ncb", "output": "aa" }, { "input": "2 1\ncc\nba", "output": "ca" }, { "input": "2 0\nbb\nab", "output": "-1" }, { "input": "3 3\naac\nabc", "output": "bca" }, { "input": "1 1\na\nc", "output": "b" }, { "input": "3 0\ncba\ncca", "output": "-1" }, { "input": "2 1\niy\niy", "output": "ia" }, { "input": "2 2\nfg\nfn", "output": "aa" }, { "input": "2 1\npd\nke", "output": "pe" }, { "input": "3 3\nyva\nyvq", "output": "aab" }, { "input": "3 2\npxn\ngxn", "output": "axa" }, { "input": "3 1\nlos\nlns", "output": "las" }, { "input": "4 2\nhbnx\nhwmm", "output": "hbma" }, { "input": "4 4\nqtto\nqtto", "output": "aaaa" }, { "input": "4 3\nchqt\nchet", "output": "caaa" }, { "input": "5 3\nwzcre\nwzcrp", "output": "wzaaa" }, { "input": "5 1\nicahj\nxdvch", "output": "-1" }, { "input": "5 1\npmesm\npzeaq", "output": "-1" }, { "input": "7 4\nycgdbph\nfdtapch", "output": "yctaaah" }, { "input": "10 6\nrnsssbuiaq\npfsbsbuoay", "output": "aasasbuaba" }, { "input": "20 5\ndsjceiztjkrqgpqpnakr\nyijdvcjtjnougpqprrkr", "output": "-1" }, { "input": "100 85\njknccpmanwhxqnxivdgguahjcuyhdrazmbfwoptatlgytakxsfvdzzcsglhmswfxafxyregdbeiwpawrjgwcqrkbhmrfcscgoszf\nhknccpmanwhxjnxivdggeahjcuyhdrazmbfwoqtatlgytdkxsfvdztcsglhmssfxsfxyrngdbeiwpawrjgwcqrkbhmrfcsckoskf", "output": "aknccpmanwhxanxivaaaabaaaaaaaabaaaaaaaabaaaaabaaaaaaaaaaaaaaaaaabaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "1 0\nz\nz", "output": "z" }, { "input": "1 1\nz\ny", "output": "a" }, { "input": "1 1\nz\nz", "output": "a" }, { "input": "1 0\nz\ny", "output": "-1" }, { "input": "10 1\ngjsywvenzc\nfssywvenzc", "output": "gssywvenzc" }, { "input": "20 2\nywpcwcwgkhdeonzbeamf\ngdcmwcwgkhdeonzbeamf", "output": "ywcmwcwgkhdeonzbeamf" } ]
748
11,059,200
3
35,444
390
Inna, Dima and Song
[ "implementation" ]
null
null
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the *i*-th note at volume *v* (1<=≀<=*v*<=≀<=*a**i*; *v* is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the *i*-th note was played on the guitar and the piano must equal *b**i*. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the *i*-th note at volumes *x**i* and *y**i* (*x**i*<=+<=*y**i*<==<=*b**i*) correspondingly, Sereja's joy rises by *x**i*Β·*y**i*. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
The first line of the input contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of notes in the song. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=106). The third line contains *n* integers *b**i* (1<=≀<=*b**i*<=≀<=106).
In a single line print an integer β€” the maximum possible joy Sereja feels after he listens to a song.
[ "3\n1 1 2\n2 2 3\n", "1\n2\n5\n" ]
[ "4\n", "-1\n" ]
In the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1Β·1 + 1Β·1 + 1Β·2 = 4. In the second sample, there is no such pair (*x*, *y*), that 1 ≀ *x*, *y* ≀ 2, *x* + *y* = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
[ { "input": "3\n1 1 2\n2 2 3", "output": "4" }, { "input": "1\n2\n5", "output": "-1" }, { "input": "10\n2 2 3 4 5 6 7 8 9 10\n2 2 3 4 5 6 7 8 9 10", "output": "96" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "output": "94" }, { "input": "3\n10000 10000 10000\n5000 5000 1", "output": "12499999" }, { "input": "2\n1 1\n2 1", "output": "0" } ]
140
0
0
35,459
241
Mirror Box
[ "geometry", "implementation" ]
null
null
Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100 cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly small holes in the opposite sides of the box at heights *h**l* and *h**r* centimeters above the floor. The picture below shows what the box looks like. In the game, you will be given a laser gun to shoot once. The laser beam must enter from one hole and exit from the other one. Each mirror has a preset number *v**i*, which shows the number of points players gain if their laser beam hits that mirror. Also β€” to make things even funnier β€” the beam must not hit any mirror more than once. Given the information about the box, your task is to find the maximum score a player may gain. Please note that the reflection obeys the law "the angle of incidence equals the angle of reflection".
The first line of the input contains three space-separated integers *h**l*,<=*h**r*,<=*n* (0<=&lt;<=*h**l*,<=*h**r*<=&lt;<=100, 0<=≀<=*n*<=≀<=100) β€” the heights of the holes and the number of the mirrors. Next *n* lines contain the descriptions of the mirrors. The *i*-th line contains space-separated *v**i*,<=*c**i*,<=*a**i*,<=*b**i*; the integer *v**i* (1<=≀<=*v**i*<=≀<=1000) is the score for the *i*-th mirror; the character *c**i* denotes *i*-th mirror's position β€” the mirror is on the ceiling if *c**i* equals "T" and on the floor if *c**i* equals "F"; integers *a**i* and *b**i* (0<=≀<=*a**i*<=&lt;<=*b**i*<=≀<=105) represent the *x*-coordinates of the beginning and the end of the mirror. No two mirrors will share a common point. Consider that the *x* coordinate increases in the direction from left to right, so the border with the hole at height *h**l* has the *x* coordinate equal to 0 and the border with the hole at height *h**r* has the *x* coordinate equal to 105.
The only line of output should contain a single integer β€” the maximum possible score a player could gain.
[ "50 50 7\n10 F 1 80000\n20 T 1 80000\n30 T 81000 82000\n40 T 83000 84000\n50 T 85000 86000\n60 T 87000 88000\n70 F 81000 89000\n", "80 72 9\n15 T 8210 15679\n10 F 11940 22399\n50 T 30600 44789\n50 F 32090 36579\n5 F 45520 48519\n120 F 49250 55229\n8 F 59700 80609\n35 T 61940 64939\n2 T 92540 97769\n" ]
[ "100\n", "120\n" ]
The second sample is depicted above. The red beam gets 10 + 50 + 5 + 35 + 8 + 2 = 110 points and the blue one gets 120. The red beam on the picture given in the statement shows how the laser beam can go approximately, this is just illustration how the laser beam can gain score. So for the second sample there is no such beam that gain score 110.
[]
60
0
0
35,614
671
Robin Hood
[ "binary search", "greedy" ]
null
null
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to the poorest person (poorest person right after taking richest's 1 coin). In case the choice is not unique, he will select one among them at random. Sadly, Robin Hood is old and want to retire in *k* days. He decided to spend these last days with helping poor people. After taking his money are taken by Robin Hood richest person may become poorest person as well, and it might even happen that Robin Hood will give his money back. For example if all people have same number of coins, then next day they will have same number of coins too. Your task is to find the difference between richest and poorest persons wealth after *k* days. Note that the choosing at random among richest and poorest doesn't affect the answer.
The first line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=500<=000,<=0<=≀<=*k*<=≀<=109)Β β€” the number of citizens in Kekoland and the number of days left till Robin Hood's retirement. The second line contains *n* integers, the *i*-th of them is *c**i* (1<=≀<=*c**i*<=≀<=109)Β β€” initial wealth of the *i*-th person.
Print a single line containing the difference between richest and poorest peoples wealth.
[ "4 1\n1 1 4 2\n", "3 1\n2 2 2\n" ]
[ "2\n", "0\n" ]
Lets look at how wealth changes through day in the first sample. 1. [1, 1, 4, 2] 1. [2, 1, 3, 2] or [1, 2, 3, 2] So the answer is 3 - 1 = 2 In second sample wealth will remain the same for each person.
[ { "input": "4 1\n1 1 4 2", "output": "2" }, { "input": "3 1\n2 2 2", "output": "0" }, { "input": "10 20\n6 4 7 10 4 5 5 3 7 10", "output": "1" }, { "input": "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2", "output": "2" }, { "input": "2 0\n182 2", "output": "180" }, { "input": "123 54564\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94 57 65 85 64 47 24 20 34 86 26 91 98 12 36 96 80 4 70 40 95 38 70 22 58 50 34 84 80 45 14 60 61 43 11 56 19 59 50 63 21 15 97 98 27 13 9 71 32 18 90 10 2 99 75 87 74 83 79 37 89 3 49 27 92 95 49 1 26 50 72 75 81 37 60 98 28 28 10 93 99 63 14 26 69 51 47 59 42 7 20 17 75 44 44 20 44 85 27 32 65 95 47 46 12 22 64 77 21", "output": "1" }, { "input": "111 10\n2 8 6 1 3 5 8 3 8 2 9 9 6 9 8 8 5 2 3 8 8 3 8 3 7 9 4 3 9 7 1 8 3 1 5 5 5 8 2 4 2 7 9 1 4 4 3 1 6 7 7 4 1 3 5 3 9 4 4 4 8 8 7 3 5 6 3 3 8 2 8 4 5 8 1 8 4 1 7 1 4 9 8 9 7 6 5 6 3 7 4 8 9 3 8 9 9 3 5 9 1 3 6 8 9 1 1 3 8 7 6", "output": "8" }, { "input": "10 1000000\n307196 650096 355966 710719 99165 959865 500346 677478 614586 6538", "output": "80333" }, { "input": "5 1000000\n145119584 42061308 953418415 717474449 57984109", "output": "909357107" }, { "input": "100 20\n2 5 3 3 2 7 6 2 2 2 6 7 2 1 8 10 2 4 10 6 10 2 1 1 4 7 1 2 9 7 5 3 7 4 6 3 10 10 3 7 6 8 2 2 10 3 1 2 1 3 1 6 3 1 4 10 3 10 9 5 10 4 3 10 3 3 5 3 10 2 1 5 10 7 8 7 7 2 4 2 1 3 3 8 8 5 7 3 1 1 8 10 5 7 4 4 7 7 1 9", "output": "7" }, { "input": "10 1000\n1000000000 999999994 999999992 1000000000 999999994 999999999 999999990 999999997 999999995 1000000000", "output": "1" }, { "input": "2 100000\n1 3", "output": "0" }, { "input": "4 0\n1 4 4 4", "output": "3" }, { "input": "4 42\n1 1 1 1000000000", "output": "999999943" }, { "input": "3 4\n1 2 7", "output": "1" }, { "input": "4 100\n1 1 10 10", "output": "1" } ]
202
5,120,000
0
35,651
750
New Year and North Pole
[ "geometry", "implementation" ]
null
null
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40<=000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20<=000 kilometers. Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of *n* parts. In the *i*-th part of his journey, Limak should move *t**i* kilometers in the direction represented by a string *dir**i* that is one of: "North", "South", "West", "East". Limak isn’t sure whether the description is valid. You must help him to check the following conditions: - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. - The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=50). The *i*-th of next *n* lines contains an integer *t**i* and a string *dir**i* (1<=≀<=*t**i*<=≀<=106, )Β β€” the length and the direction of the *i*-th part of the journey, according to the description Limak got.
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
[ "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n", "2\n15000 South\n4000 East\n", "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North\n", "3\n20000 South\n10 East\n20000 North\n", "2\n1000 North\n1000 South\n", "4\n50 South\n50 North\n15000 South\n15000 North\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n" ]
Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.
[ { "input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES" }, { "input": "2\n15000 South\n4000 East", "output": "NO" }, { "input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES" }, { "input": "3\n20000 South\n10 East\n20000 North", "output": "NO" }, { "input": "2\n1000 North\n1000 South", "output": "NO" }, { "input": "4\n50 South\n50 North\n15000 South\n15000 North", "output": "YES" }, { "input": "1\n1 South", "output": "NO" }, { "input": "1\n1 East", "output": "NO" }, { "input": "2\n1000000 South\n1000000 North", "output": "NO" }, { "input": "1\n149 South", "output": "NO" }, { "input": "1\n16277 East", "output": "NO" }, { "input": "1\n19701 South", "output": "NO" }, { "input": "1\n3125 South", "output": "NO" }, { "input": "1\n6549 South", "output": "NO" }, { "input": "1\n2677 South", "output": "NO" }, { "input": "1\n6101 South", "output": "NO" }, { "input": "1\n9525 South", "output": "NO" }, { "input": "1\n5653 South", "output": "NO" }, { "input": "2\n15072 South\n15072 North", "output": "YES" }, { "input": "2\n11200 South\n11200 North", "output": "YES" }, { "input": "2\n14624 South\n14624 North", "output": "YES" }, { "input": "2\n18048 South\n15452 West", "output": "NO" }, { "input": "2\n1472 West\n4930 North", "output": "NO" }, { "input": "2\n17600 South\n17600 North", "output": "YES" }, { "input": "2\n8320 East\n16589 East", "output": "NO" }, { "input": "2\n4448 South\n4448 North", "output": "YES" }, { "input": "2\n576 South\n576 North", "output": "YES" }, { "input": "3\n14186 South\n2291 West\n14186 North", "output": "YES" }, { "input": "3\n10314 South\n15961 North\n5647 South", "output": "NO" }, { "input": "3\n1035 East\n18143 South\n18143 North", "output": "NO" }, { "input": "3\n17163 South\n7620 East\n17163 North", "output": "YES" }, { "input": "3\n587 South\n17098 North\n16511 South", "output": "NO" }, { "input": "3\n16715 North\n6576 West\n12132 South", "output": "NO" }, { "input": "3\n7435 South\n245 North\n7190 North", "output": "YES" }, { "input": "3\n3563 South\n2427 South\n5990 North", "output": "YES" }, { "input": "3\n6987 South\n11904 East\n19951 East", "output": "NO" }, { "input": "4\n13301 South\n5948 East\n9265 East\n6891 North", "output": "NO" }, { "input": "4\n16725 South\n8129 South\n19530 West\n24854 North", "output": "NO" }, { "input": "4\n149 South\n17607 West\n18306 South\n18455 North", "output": "YES" }, { "input": "4\n16277 South\n19789 North\n4379 South\n867 North", "output": "NO" }, { "input": "4\n19701 South\n13458 South\n3156 North\n30003 North", "output": "NO" }, { "input": "4\n3125 South\n15640 East\n6125 East\n19535 South", "output": "NO" }, { "input": "4\n6549 East\n5118 North\n12198 East\n5118 South", "output": "NO" }, { "input": "4\n2677 East\n1891 West\n10974 West\n7511 North", "output": "NO" }, { "input": "4\n6102 South\n8265 East\n13943 South\n20045 North", "output": "NO" }, { "input": "5\n12416 South\n18116 North\n10553 West\n18435 West\n5700 South", "output": "NO" }, { "input": "5\n15840 South\n7594 South\n13522 South\n2423 South\n3334 West", "output": "NO" }, { "input": "5\n19264 East\n13968 East\n19595 North\n19115 North\n38710 South", "output": "NO" }, { "input": "5\n15392 South\n3445 North\n18372 East\n10399 North\n4403 South", "output": "NO" }, { "input": "5\n18816 South\n5627 West\n14045 East\n7091 East\n18816 North", "output": "YES" }, { "input": "5\n2240 South\n15104 North\n118 West\n11079 East\n12864 South", "output": "NO" }, { "input": "5\n5664 South\n1478 South\n18894 South\n2363 West\n26036 North", "output": "NO" }, { "input": "5\n1792 South\n10956 East\n9159 South\n19055 West\n10951 North", "output": "YES" }, { "input": "5\n12512 South\n13137 North\n7936 North\n7235 South\n1326 South", "output": "NO" }, { "input": "6\n14635 North\n14477 South\n17250 North\n14170 East\n15166 South\n2242 South", "output": "NO" }, { "input": "6\n10763 North\n3954 West\n7515 North\n18158 West\n6644 South\n11634 South", "output": "NO" }, { "input": "6\n14187 South\n13432 North\n6292 East\n14850 West\n10827 South\n9639 East", "output": "NO" }, { "input": "6\n10315 South\n15614 South\n5069 West\n6134 South\n7713 North\n24350 North", "output": "NO" }, { "input": "6\n1035 South\n9283 East\n15333 South\n2826 South\n19191 North\n3 North", "output": "YES" }, { "input": "6\n17163 West\n11465 North\n14110 South\n6814 North\n3373 East\n4169 South", "output": "NO" }, { "input": "6\n587 South\n942 West\n183 North\n18098 North\n260 East\n17694 South", "output": "NO" }, { "input": "6\n16715 West\n3124 East\n3152 East\n14790 East\n11738 West\n11461 East", "output": "NO" }, { "input": "6\n7435 South\n12602 South\n1929 East\n6074 East\n15920 West\n20037 North", "output": "NO" }, { "input": "7\n13750 South\n6645 South\n18539 East\n5713 North\n1580 North\n10012 West\n13102 North", "output": "NO" }, { "input": "7\n9878 West\n8827 East\n1508 West\n9702 North\n5763 North\n9755 North\n10034 South", "output": "NO" }, { "input": "7\n13302 West\n2496 North\n284 West\n6394 East\n9945 North\n12603 West\n12275 North", "output": "NO" }, { "input": "7\n16726 East\n19270 West\n6357 South\n17678 East\n14127 East\n12347 South\n6005 East", "output": "NO" }, { "input": "7\n150 South\n1452 North\n9326 North\n1666 West\n18309 East\n19386 East\n8246 West", "output": "NO" }, { "input": "7\n16278 South\n10929 South\n8103 East\n18358 West\n2492 West\n11834 South\n39041 North", "output": "NO" }, { "input": "7\n19702 South\n13111 East\n6880 East\n9642 South\n6674 West\n18874 East\n1112 North", "output": "NO" }, { "input": "7\n3126 South\n6780 North\n9848 West\n6334 North\n10856 West\n14425 West\n10649 East", "output": "NO" }, { "input": "7\n6550 South\n8962 West\n15921 South\n17618 North\n15038 South\n1465 North\n18426 North", "output": "NO" }, { "input": "8\n12864 South\n3005 West\n16723 West\n17257 West\n12187 East\n12976 South\n1598 North\n24242 North", "output": "NO" }, { "input": "8\n8992 South\n12483 North\n15500 South\n1245 South\n9073 East\n12719 East\n3839 East\n7130 South", "output": "NO" }, { "input": "8\n12416 North\n14665 South\n14277 North\n2129 South\n13255 East\n19759 South\n10272 West\n9860 North", "output": "NO" }, { "input": "8\n15840 South\n4142 East\n17246 North\n13413 North\n4733 West\n15311 North\n12514 South\n17616 South", "output": "NO" }, { "input": "8\n19264 South\n10516 North\n3319 East\n17401 East\n1620 West\n2350 West\n6243 North\n2505 North", "output": "YES" }, { "input": "8\n15392 South\n7290 West\n2096 West\n14093 East\n5802 South\n2094 North\n8484 East\n19100 North", "output": "NO" }, { "input": "8\n6113 South\n16767 East\n5064 South\n5377 West\n17280 South\n1838 West\n2213 West\n28457 North", "output": "NO" }, { "input": "8\n2241 West\n18949 South\n11137 South\n2069 West\n14166 South\n1581 South\n4455 South\n50288 North", "output": "NO" }, { "input": "8\n5665 South\n8426 East\n9914 North\n13353 South\n18349 North\n4429 East\n18184 North\n27429 South", "output": "NO" }, { "input": "9\n11979 South\n2470 East\n10716 North\n12992 East\n15497 West\n15940 North\n8107 West\n18934 East\n6993 South", "output": "NO" }, { "input": "9\n8107 South\n4652 North\n9493 North\n16980 West\n12383 West\n2980 West\n17644 South\n11043 West\n11447 North", "output": "NO" }, { "input": "9\n18827 South\n18321 West\n8270 East\n968 West\n16565 West\n15427 North\n4077 North\n18960 North\n19006 West", "output": "NO" }, { "input": "9\n14955 West\n503 North\n18535 West\n4956 South\n8044 South\n2467 East\n13615 East\n6877 East\n3460 North", "output": "NO" }, { "input": "9\n18379 South\n9980 South\n17311 West\n8944 South\n4930 South\n18019 South\n48 West\n14794 South\n75046 North", "output": "NO" }, { "input": "9\n14507 East\n12162 East\n16088 South\n5636 North\n9112 North\n5058 East\n9585 South\n2712 East\n10925 North", "output": "NO" }, { "input": "9\n5227 East\n8936 North\n6353 North\n16920 North\n591 North\n4802 South\n8722 North\n3333 West\n36720 South", "output": "NO" }, { "input": "9\n1355 North\n15309 West\n17834 North\n13612 East\n17477 North\n4546 North\n18260 East\n15442 North\n56654 South", "output": "NO" }, { "input": "9\n4779 South\n4787 East\n3907 East\n4896 East\n1659 East\n4289 West\n4693 West\n3359 East\n4779 North", "output": "YES" }, { "input": "1\n80000 South", "output": "NO" }, { "input": "2\n40000 South\n20000 North", "output": "NO" }, { "input": "1\n40000 South", "output": "NO" }, { "input": "2\n20001 South\n20001 North", "output": "NO" }, { "input": "4\n10000 South\n20000 South\n10000 North\n20000 North", "output": "NO" }, { "input": "3\n10 South\n20 North\n10 North", "output": "NO" }, { "input": "3\n1000 South\n1001 North\n1 North", "output": "NO" }, { "input": "2\n20000 South\n20000 West", "output": "NO" }, { "input": "3\n10000 South\n20000 South\n10000 North", "output": "NO" }, { "input": "2\n1 East\n1 North", "output": "NO" }, { "input": "2\n20000 West\n20000 West", "output": "NO" }, { "input": "2\n80000 South\n20000 North", "output": "NO" }, { "input": "2\n19999 South\n20001 South", "output": "NO" }, { "input": "3\n500 South\n1000 North\n500 North", "output": "NO" }, { "input": "1\n400000 South", "output": "NO" }, { "input": "2\n40000 South\n80000 North", "output": "NO" }, { "input": "2\n100 West\n100 North", "output": "NO" }, { "input": "2\n40000 South\n40000 North", "output": "NO" }, { "input": "2\n30000 South\n10000 North", "output": "NO" }, { "input": "2\n20000 South\n40000 North", "output": "NO" }, { "input": "10\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North", "output": "YES" }, { "input": "2\n40001 South\n40001 North", "output": "NO" }, { "input": "2\n40001 South\n1 North", "output": "NO" }, { "input": "2\n50000 South\n50000 North", "output": "NO" }, { "input": "2\n30000 South\n30000 South", "output": "NO" }, { "input": "2\n10000 South\n50000 North", "output": "NO" }, { "input": "4\n15000 South\n15000 South\n15000 North\n15000 North", "output": "NO" }, { "input": "3\n50 South\n100 North\n50 North", "output": "NO" }, { "input": "2\n20001 South\n1 North", "output": "NO" }, { "input": "3\n5 South\n6 North\n1 South", "output": "NO" }, { "input": "1\n20000 South", "output": "NO" }, { "input": "4\n1 South\n20000 South\n1 North\n20000 North", "output": "NO" }, { "input": "2\n30000 South\n30000 North", "output": "NO" }, { "input": "3\n1 South\n2 North\n1 South", "output": "NO" }, { "input": "2\n60000 South\n60000 North", "output": "NO" }, { "input": "2\n50000 South\n10000 North", "output": "NO" }, { "input": "1\n5 North", "output": "NO" }, { "input": "2\n20010 South\n19990 North", "output": "NO" }, { "input": "3\n20000 South\n1 South\n20000 North", "output": "NO" }, { "input": "3\n1 South\n2 North\n39999 North", "output": "NO" }, { "input": "3\n10 South\n20 North\n10 South", "output": "NO" }, { "input": "3\n1 South\n2 North\n1 North", "output": "NO" }, { "input": "3\n2000 South\n19000 South\n19000 South", "output": "NO" }, { "input": "6\n15000 South\n15000 South\n15000 South\n15000 North\n15000 North\n15000 North", "output": "NO" }, { "input": "3\n1 South\n1 North\n1 East", "output": "NO" }, { "input": "2\n1 West\n1 North", "output": "NO" }, { "input": "3\n1 South\n123456 West\n1 North", "output": "YES" } ]
62
0
0
35,698
0
none
[ "none" ]
null
null
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*<=&gt;<=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.
[ "1 4\n", "2 2\n", "3 2\n" ]
[ "3B\n", "Impossible\n", "1A1B\n" ]
In the first sample, if the row contained three cards with letter 'B', then Bob should give one apple to Alice three times. So, in the end of the game Alice has one orange and three apples, and Bob has one apple, in total it is one orange and four apples. In second sample, there is no answer since one card is not enough for game to finish, and two cards will produce at least three apples or three oranges. In the third sample, cards contain letters 'AB', so after removing the first card Bob has one orange and one apple, and after removal of second card Alice has two oranges and one apple. So, in total it is three oranges and two apples.
[ { "input": "1 4", "output": "3B" }, { "input": "2 2", "output": "Impossible" }, { "input": "3 2", "output": "1A1B" }, { "input": "2 1", "output": "1A" }, { "input": "5 3", "output": "1A1B1A" }, { "input": "5 2", "output": "2A1B" }, { "input": "8 5", "output": "1A1B1A1B" }, { "input": "97 101", "output": "1B24A3B" }, { "input": "1 3", "output": "2B" }, { "input": "1000000000000000000 999999999999999999", "output": "1A999999999999999998B" }, { "input": "55 89", "output": "1B1A1B1A1B1A1B1A1B" }, { "input": "610 987", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A" }, { "input": "4181 6765", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A" }, { "input": "46368 75025", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "832040 514229", "output": "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "5702887 9227465", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "701408733 433494437", "output": "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "956722026041 591286729879", "output": "1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A" }, { "input": "498454011879264 806515533049393", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "420196140727489673 679891637638612258", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B" }, { "input": "1000000000000000000 1000000000000000000", "output": "Impossible" }, { "input": "1000000000000000000 1", "output": "999999999999999999A" }, { "input": "2 1000000000000000000", "output": "Impossible" }, { "input": "999999999999999999 999999999999999998", "output": "1A999999999999999997B" }, { "input": "616274828435574301 10268395600356301", "output": "60A60B60A60B60A60B60A60B60A60B" }, { "input": "10808314049304201 270039182096201", "output": "40A40B40A40B40A40B40A40B40A40B" }, { "input": "1000100020001 100010001", "output": "10000A10000B10000A" }, { "input": "152139002499 367296043199", "output": "2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A2B2A" }, { "input": "25220791 839761", "output": "30A30B30A30B30A" }, { "input": "27961 931", "output": "30A30B30A" }, { "input": "127601 6382601", "output": "50B50A50B50A" }, { "input": "1 1000000000000000000", "output": "999999999999999999B" }, { "input": "242 100", "output": "Impossible" }, { "input": "507769900974602687 547261784951014891", "output": "Impossible" }, { "input": "585026192452577797 570146946822492493", "output": "1A38B3A7B23A2B1A1B1A8B2A1B5A117B2A1B1A2B12A3B10A5B3A2B3A11B2A1B7A" }, { "input": "568679881256193737 513570106829158157", "output": "1A9B3A7B2A3B1A1B1A2B3A2B1A3B2A82B1A7B2A14B2A1B1A4B5A3B2A1B9A1B2A1B4A1B3A1B3A2B" }, { "input": "567036128564717939 510505130335113937", "output": "1A9B32A1B2A1B368A1B1A1B2A4B1A1B23A14B21A5B1A1B2A4B1A1B3A1B1A1B3A1B5A1B1A9B" }, { "input": "519421744863260201 572972909476222789", "output": "1B9A1B2A3B21A1B1A21B2A1B2A12B1A4B1A1B5A160B4A1B1A138B1A1B9A4B3A2B6A" }, { "input": "529495319593227313 631186172547690847", "output": "1B5A4B1A4B1A76B3A2B11A3B7A5B1A1B2A2B7A2B2A8B5A3B143A1B3A8B1A5B1A" }, { "input": "540431588408227541 540431588408227541", "output": "Impossible" }, { "input": "410218934960967047 378596216455001869", "output": "Impossible" }, { "input": "395130552422107969 382562323268297483", "output": "Impossible" }, { "input": "416445288135075809 416445288135075809", "output": "Impossible" }, { "input": "402725448165665593 481342602240996343", "output": "1B5A8B6A2B2A1B20A3B9A5B2A1B4A5B2A4B1A268B9A4B1A1B4A3B2A2B1A2B1A1B3A" }, { "input": "412177780967225699 432177937877609093", "output": "1B20A1B1A1B1A3B1A58B1A4B1A13B206A2B2A5B5A22B3A45B1A7B5A1B1A6B1A1B" }, { "input": "423506197818989927 442863139846534733", "output": "1B21A1B7A4B76A1B3A2B82A1B18A4B1A13B1A3B6A1B1A2B1A22B1A3B2A1B1A2B27A" }, { "input": "453151988636162147 474019690903735841", "output": "1B21A1B2A1B1A16B1A1B1A4B300A1B4A1B11A47B1A6B8A1B1A1B1A2B2A5B3A2B1A7B1A5B1A" }, { "input": "408962762283480959 444443583457646111", "output": "1B11A1B1A9B253A1B5A22B6A1B11A4B3A2B1A1B4A1B13A2B4A1B50A1B6A1B5A3B" }, { "input": "976540997167958951 969335176443917693", "output": "1A134B1A1B11A3B26A2B3A1B1A2B22A1B3A3B1A1B66A63B36A2B1A13B5A3B" }, { "input": "957591654759084713 981022104435698593", "output": "1B40A1B6A1B1A1B68A1B18A2B3A1B2A2B2A1B1A4B1A3B2A1B12A3B604A5B1A1B39A1B1A" }, { "input": "962890278562476113 969978235623119279", "output": "1B135A1B5A1B1A1B1A2B1A1B3A4B2A1B2A2B1A5B3A1B2A2B2A1B2A1B3A2B67A1B1A6B3A1B14A1B3A19B" }, { "input": "963716517445592213 976351630941239591", "output": "1B76A3B1A1B1A52B1A6B2A7B35A1B1A2B17A5B5A4B5A9B3A2B13A1B2A3B1A7B" }, { "input": "964542760623675601 965233603018687501", "output": "1B1396A5B2A4B2A2B1A18B4A1B1A1B2A3B3A1B10A2B3A1B3A1B5A1B1A1B2A10B3A9B1A1B3A2B" }, { "input": "977367244641009653 977367244641009653", "output": "Impossible" } ]
62
0
3
35,705
555
Case of a Top Secret
[ "binary search", "implementation", "math" ]
null
null
Andrewid the Android is a galaxy-famous detective. Now he is busy with a top secret case, the details of which are not subject to disclosure. However, he needs help conducting one of the investigative experiment. There are *n* pegs put on a plane, they are numbered from 1 to *n*, the coordinates of the *i*-th of them are (*x**i*,<=0). Then, we tie to the bottom of one of the pegs a weight on a tight rope of length *l* (thus, its coordinates will be equal to (*x**i*,<=<=-<=*l*), where *i* is the number of the used peg). Then the weight is pushed to the right, so that it starts to rotate counterclockwise. At the same time, if the weight during rotation touches some of the other pegs, it then begins to rotate around that peg. Suppose that each peg itself is very thin and does not affect the rope length while weight is rotating around it. More formally, if at some moment the segment of the rope contains one or more pegs in addition to the peg around which the weight is rotating, the weight will then rotate around the farthermost one of them on a shorter segment of a rope. In particular, if the segment of the rope touches some peg by its endpoint, it is considered that the weight starts to rotate around that peg on a segment of the rope of length 0. At some moment the weight will begin to rotate around some peg, without affecting the rest of the pegs. Andrewid interested in determining the number of this peg. Andrewid prepared *m* queries containing initial conditions for pushing the weight, help him to determine for each of them, around what peg the weight will eventually rotate.
The first line contains integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the number of pegs and queries. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≀<=*x**i*<=≀<=109) β€” the coordinates of the pegs. It is guaranteed that the coordinates of all the pegs are distinct integers. Next *m* lines contain the descriptions of the queries of pushing the weight, each consists of two integers *a**i* (1<=≀<=*a**i*<=≀<=*n*) and *l**i* (1<=≀<=*l**i*<=≀<=109) β€” the number of the starting peg and the length of the rope.
Print *m* lines, the *i*-th line should contain the number of the peg around which the weight will eventually rotate after the *i*-th push.
[ "3 2\n0 3 5\n2 3\n1 8\n", "4 4\n1 5 7 15\n1 4\n2 15\n3 16\n1 28\n" ]
[ "3\n2\n", "2\n4\n3\n1\n" ]
Picture to the first sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/8bc7392d3f6441884836fdead4a4afbac2a19f49.png" style="max-width: 100.0%;max-height: 100.0%;"/> Picture to the second sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/abef521ff4b500a39098df2ced95cb992c1845ed.png" style="max-width: 100.0%;max-height: 100.0%;"/> Note that in the last query weight starts to rotate around the peg 1 attached to a rope segment of length 0.
[]
2,000
0
0
35,718
209
Pixels
[ "constructive algorithms", "math" ]
null
null
Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors *x* and *y* (*x*<=β‰ <=*y*) meet in a violent fight, then the pixel that survives the fight immediately changes its color to *z* (*z*<=β‰ <=*x*;Β *z*<=β‰ <=*y*). Pixels of the same color are friends, so they don't fight. The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous.
The first line contains three space-separated integers *a*, *b* and *c* (0<=≀<=*a*,<=*b*,<=*c*<=≀<=231;Β *a*<=+<=*b*<=+<=*c*<=&gt;<=0) β€” the number of red, green and blue pixels, correspondingly.
Print a single number β€” the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.
[ "1 1 1\n", "3 1 0\n" ]
[ "1\n", "3\n" ]
In the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels. In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left.
[ { "input": "1 1 1", "output": "1" }, { "input": "3 1 0", "output": "3" }, { "input": "1 4 4", "output": "4" }, { "input": "5 10 6", "output": "10" }, { "input": "6 8 10", "output": "8" }, { "input": "1 10 2", "output": "10" }, { "input": "10 6 8", "output": "8" }, { "input": "18 67 5", "output": "67" }, { "input": "67 81 1", "output": "67" }, { "input": "51 10 91", "output": "91" }, { "input": "48 6 7", "output": "48" }, { "input": "8 97 83", "output": "97" }, { "input": "2 7 95", "output": "95" }, { "input": "772486757 1747374885 377299255", "output": "772486757" }, { "input": "1358352906 27037371 1947040615", "output": "1947040615" }, { "input": "1944219055 454183506 1369298327", "output": "1944219055" }, { "input": "382601556 881329640 791556039", "output": "881329640" }, { "input": "246543403 71853598 1504509195", "output": "1504509195" }, { "input": "50606342 2 1134945035", "output": "50606342" }, { "input": "9 530792195 6", "output": "530792195" }, { "input": "1016450951 2 9", "output": "1016450951" }, { "input": "3 10 1007169359", "output": "1007169359" }, { "input": "0 1 0", "output": "0" }, { "input": "1 0 0", "output": "0" }, { "input": "0 0 1", "output": "0" }, { "input": "3 2 0", "output": "2" }, { "input": "0 3 2", "output": "2" }, { "input": "3 0 2", "output": "2" }, { "input": "10 10 0", "output": "10" }, { "input": "0 0 10", "output": "0" }, { "input": "2 2 0", "output": "2" }, { "input": "0 2 10", "output": "2" }, { "input": "5 0 5", "output": "5" }, { "input": "5 9 0", "output": "9" }, { "input": "2147483648 2147483648 2147483648", "output": "2147483648" }, { "input": "2147483648 2147483647 2147483648", "output": "2147483648" }, { "input": "2147483648 0 0", "output": "0" }, { "input": "2147483648 2147483648 0", "output": "2147483648" }, { "input": "2147483648 0 2147483647", "output": "2147483648" }, { "input": "2147483630 2147483642 2147483610", "output": "2147483630" }, { "input": "1 4 3", "output": "3" }, { "input": "1 2 3", "output": "3" }, { "input": "1 0 1", "output": "1" }, { "input": "92134834 23742837 92374737", "output": "92374737" }, { "input": "92134834 23742837 92374738", "output": "92374738" }, { "input": "92134834 23742837 92374739", "output": "92374739" }, { "input": "9214834 2742837 9234739", "output": "9234739" }, { "input": "914835 2742837 9234739", "output": "2742837" }, { "input": "1 2 2147483648", "output": "2147483648" }, { "input": "0 0 58", "output": "0" } ]
92
0
0
35,773
1,003
Tree Constructing
[ "constructive algorithms", "graphs" ]
null
null
You are given three integers $n$, $d$ and $k$. Your task is to construct an undirected tree on $n$ vertices with diameter $d$ and degree of each vertex at most $k$, or say that it is impossible. An undirected tree is a connected undirected graph with $n - 1$ edges. Diameter of a tree is the maximum length of a simple path (a path in which each vertex appears at most once) between all pairs of vertices of this tree. Degree of a vertex is the number of edges incident to this vertex (i.e. for a vertex $u$ it is the number of edges $(u, v)$ that belong to the tree, where $v$ is any other vertex of a tree).
The first line of the input contains three integers $n$, $d$ and $k$ ($1 \le n, d, k \le 4 \cdot 10^5$).
If there is no tree satisfying the conditions above, print only one word "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), and then print $n - 1$ lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from $1$ to $n$. You can print edges and vertices connected by an edge in any order. If there are multiple answers, print any of them.1
[ "6 3 3\n", "6 2 3\n", "10 4 3\n", "8 5 3\n" ]
[ "YES\n3 1\n4 1\n1 2\n5 2\n2 6\n", "NO\n", "YES\n2 9\n2 10\n10 3\n3 1\n6 10\n8 2\n4 3\n5 6\n6 7\n", "YES\n2 5\n7 2\n3 7\n3 1\n1 6\n8 7\n4 3\n" ]
none
[ { "input": "6 3 3", "output": "YES\n2 5\n4 2\n3 4\n2 1\n4 6" }, { "input": "6 2 3", "output": "NO" }, { "input": "10 4 3", "output": "YES\n2 9\n2 10\n10 3\n3 1\n6 10\n8 2\n4 3\n5 6\n6 7" }, { "input": "8 5 3", "output": "YES\n2 5\n7 2\n3 7\n3 1\n1 6\n8 7\n4 3" }, { "input": "8 3 3", "output": "NO" }, { "input": "5 4 2", "output": "YES\n5 2\n4 2\n3 4\n1 3" }, { "input": "5 4 3", "output": "YES\n5 2\n4 2\n3 4\n1 3" }, { "input": "5 5 2", "output": "NO" }, { "input": "5 5 3", "output": "NO" }, { "input": "6 4 2", "output": "NO" }, { "input": "6 4 3", "output": "YES\n2 5\n4 2\n3 4\n1 3\n4 6" }, { "input": "6 5 2", "output": "YES\n2 5\n4 2\n3 4\n1 3\n6 1" }, { "input": "6 5 3", "output": "YES\n2 5\n4 2\n3 4\n1 3\n6 1" }, { "input": "7 4 2", "output": "NO" }, { "input": "7 4 3", "output": "YES\n2 5\n7 2\n3 7\n1 3\n6 7\n4 2" }, { "input": "7 5 2", "output": "NO" }, { "input": "7 5 3", "output": "YES\n2 5\n7 2\n3 7\n1 3\n1 6\n4 7" }, { "input": "1 1 1", "output": "NO" }, { "input": "400000 400000 400000", "output": "NO" }, { "input": "400000 399999 400000", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n369864 390352\n390352 248461\n370606 248461\n370606 351606\n351606 364642\n382629 364642\n382629 394005\n370914 394005\n353389 370914\n353389 369488\n371995 369488\n371995 384721\n393313 384721\n362866 393313\n362866 320713\n388369 320713\n388369 377899\n377899 394962\n394962 349876\n394602 349876\n371684 394602\n371684 393902\n393902 351453\n351453 379210\n379210 397121\n392715 397121\n365647 392715\n365647 395009\n394457 395009\n394457 370769\n370769 3836..." }, { "input": "400000 399999 2", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n369864 390352\n390352 248461\n370606 248461\n370606 351606\n351606 364642\n382629 364642\n382629 394005\n370914 394005\n353389 370914\n353389 369488\n371995 369488\n371995 384721\n393313 384721\n362866 393313\n362866 320713\n388369 320713\n388369 377899\n377899 394962\n394962 349876\n394602 349876\n371684 394602\n371684 393902\n393902 351453\n351453 379210\n379210 397121\n392715 397121\n365647 392715\n365647 395009\n394457 395009\n394457 370769\n370769 3836..." }, { "input": "200000 100000 3", "output": "YES\n136472 197381\n136472 160228\n160228 128766\n128766 197225\n160133 197225\n105707 160133\n105707 66465\n199512 66465\n185463 199512\n185463 176514\n175293 176514\n178768 175293\n178768 158873\n199518 158873\n161400 199518\n172476 161400\n172476 188761\n197795 188761\n152286 197795\n152286 177332\n177332 197463\n197463 161665\n161665 180449\n106803 180449\n106803 194630\n187605 194630\n194497 187605\n194497 183891\n183891 59711\n198028 59711\n198028 80060\n174725 80060\n174725 117415\n191746 117415\n15..." }, { "input": "200000 100000 2", "output": "NO" }, { "input": "400000 2 399999", "output": "YES\n333661 353275\n353275 388507\n353275 369864\n390352 353275\n248461 353275\n353275 370606\n351606 353275\n364642 353275\n353275 382629\n394005 353275\n353275 370914\n353275 353389\n369488 353275\n353275 371995\n384721 353275\n353275 393313\n353275 362866\n320713 353275\n353275 388369\n377899 353275\n394962 353275\n349876 353275\n353275 394602\n353275 371684\n393902 353275\n351453 353275\n379210 353275\n397121 353275\n353275 392715\n353275 365647\n395009 353275\n353275 394457\n370769 353275\n383674 3532..." }, { "input": "400000 100 399999", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n369864 390352\n390352 248461\n370606 248461\n370606 351606\n351606 364642\n382629 364642\n382629 394005\n370914 394005\n353389 370914\n353389 369488\n371995 369488\n371995 384721\n393313 384721\n362866 393313\n362866 320713\n388369 320713\n388369 377899\n377899 394962\n394962 349876\n394602 349876\n371684 394602\n371684 393902\n393902 351453\n351453 379210\n379210 397121\n392715 397121\n365647 392715\n365647 395009\n394457 395009\n394457 370769\n370769 3836..." }, { "input": "400000 2 399998", "output": "NO" }, { "input": "400000 3 399998", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n390352 353275\n248461 353275\n353275 370606\n351606 353275\n364642 353275\n353275 382629\n394005 353275\n353275 370914\n353275 353389\n369488 353275\n353275 371995\n384721 353275\n353275 393313\n353275 362866\n320713 353275\n353275 388369\n377899 353275\n394962 353275\n349876 353275\n353275 394602\n353275 371684\n393902 353275\n351453 353275\n379210 353275\n397121 353275\n353275 392715\n353275 365647\n395009 353275\n353275 394457\n370769 353275\n383674 3532..." }, { "input": "400000 3 200000", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n390352 353275\n248461 353275\n353275 370606\n351606 353275\n364642 353275\n353275 382629\n394005 353275\n353275 370914\n353275 353389\n369488 353275\n353275 371995\n384721 353275\n353275 393313\n353275 362866\n320713 353275\n353275 388369\n377899 353275\n394962 353275\n349876 353275\n353275 394602\n353275 371684\n393902 353275\n351453 353275\n379210 353275\n397121 353275\n353275 392715\n353275 365647\n395009 353275\n353275 394457\n370769 353275\n383674 3532..." }, { "input": "400000 3 199999", "output": "NO" }, { "input": "20 6 3", "output": "YES\n2 13\n2 10\n3 10\n1 3\n1 12\n8 12\n3 20\n5 10\n1 16\n20 19\n6 20\n15 2\n12 14\n11 5\n5 17\n7 16\n16 4\n9 19\n18 19" }, { "input": "15 5 3", "output": "NO" }, { "input": "5 4 1", "output": "NO" }, { "input": "100000 25 25", "output": "YES\n74835 85030\n28368 85030\n68215 28368\n68215 92388\n79089 92388\n36904 79089\n66465 36904\n93241 66465\n93241 87962\n87962 95370\n61859 95370\n61859 66251\n66251 30174\n31110 30174\n31110 53487\n53487 85715\n81833 85715\n87215 81833\n92843 87215\n92843 85032\n85032 87899\n87899 99445\n99445 84738\n84503 84738\n84503 76645\n94396 66251\n91977 66251\n66251 82366\n66251 59711\n61520 66251\n80060 66251\n28431 66251\n91060 66251\n85596 66251\n92952 66251\n70793 66251\n66251 63335\n66251 74450\n66251 97238\n..." }, { "input": "2 1 1", "output": "YES\n1 2" }, { "input": "21 6 3", "output": "YES\n13 2\n10 2\n3 10\n3 1\n12 1\n8 12\n20 3\n10 5\n1 16\n19 20\n6 20\n2 15\n14 12\n5 11\n17 5\n16 7\n4 16\n21 19\n18 19\n6 9" }, { "input": "3 2 1", "output": "NO" }, { "input": "3 1 1", "output": "NO" }, { "input": "22 6 3", "output": "YES\n2 13\n10 2\n10 3\n1 3\n12 1\n12 8\n3 22\n10 5\n16 1\n19 22\n22 6\n15 2\n12 14\n11 5\n5 17\n7 16\n4 16\n21 19\n19 18\n9 6\n20 6" }, { "input": "2 3 3", "output": "NO" }, { "input": "2 1 3", "output": "YES\n1 2" }, { "input": "7 6 1", "output": "NO" }, { "input": "400000 255 366", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n369864 390352\n390352 248461\n370606 248461\n370606 351606\n351606 364642\n382629 364642\n382629 394005\n370914 394005\n353389 370914\n353389 369488\n371995 369488\n371995 384721\n393313 384721\n362866 393313\n362866 320713\n388369 320713\n388369 377899\n377899 394962\n394962 349876\n394602 349876\n371684 394602\n371684 393902\n393902 351453\n351453 379210\n379210 397121\n392715 397121\n365647 392715\n365647 395009\n394457 395009\n394457 370769\n370769 3836..." }, { "input": "14 5 3", "output": "YES\n13 2\n2 10\n10 3\n3 1\n12 1\n8 10\n3 4\n5 2\n1 7\n8 9\n6 8\n4 11\n4 14" }, { "input": "3 1 3", "output": "NO" }, { "input": "4 3 1", "output": "NO" }, { "input": "9 8 1", "output": "NO" }, { "input": "26 5 4", "output": "YES\n2 13\n2 10\n25 10\n1 25\n1 12\n26 10\n10 22\n5 25\n25 16\n19 2\n2 6\n15 1\n14 1\n24 26\n26 17\n7 26\n4 22\n22 21\n18 22\n9 5\n5 20\n23 5\n11 16\n3 16\n16 8" }, { "input": "6 5 1", "output": "NO" }, { "input": "2 1 15", "output": "YES\n1 2" }, { "input": "10 9 1", "output": "NO" }, { "input": "2 1 4", "output": "YES\n1 2" }, { "input": "2 10 1", "output": "NO" }, { "input": "400000 300000 262144", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n369864 390352\n390352 248461\n370606 248461\n370606 351606\n351606 364642\n382629 364642\n382629 394005\n370914 394005\n353389 370914\n353389 369488\n371995 369488\n371995 384721\n393313 384721\n362866 393313\n362866 320713\n388369 320713\n388369 377899\n377899 394962\n394962 349876\n394602 349876\n371684 394602\n371684 393902\n393902 351453\n351453 379210\n379210 397121\n392715 397121\n365647 392715\n365647 395009\n394457 395009\n394457 370769\n370769 3836..." }, { "input": "400000 150000 200000", "output": "YES\n333661 353275\n353275 388507\n369864 388507\n369864 390352\n390352 248461\n370606 248461\n370606 351606\n351606 364642\n382629 364642\n382629 394005\n370914 394005\n353389 370914\n353389 369488\n371995 369488\n371995 384721\n393313 384721\n362866 393313\n362866 320713\n388369 320713\n388369 377899\n377899 394962\n394962 349876\n394602 349876\n371684 394602\n371684 393902\n393902 351453\n351453 379210\n379210 397121\n392715 397121\n365647 392715\n365647 395009\n394457 395009\n394457 370769\n370769 3836..." }, { "input": "2 2 1", "output": "NO" }, { "input": "2 1 2", "output": "YES\n1 2" }, { "input": "2 3 1", "output": "NO" }, { "input": "2 11 1", "output": "NO" }, { "input": "4 543 7", "output": "NO" } ]
202
2,048,000
-1
35,867
305
Olya and Graph
[ "combinatorics", "math" ]
null
null
Olya has got a directed non-weighted graph, consisting of *n* vertexes and *m* edges. We will consider that the graph vertexes are indexed from 1 to *n* in some manner. Then for any graph edge that goes from vertex *v* to vertex *u* the following inequation holds: *v*<=&lt;<=*u*. Now Olya wonders, how many ways there are to add an arbitrary (possibly zero) number of edges to the graph so as the following conditions were met: 1. You can reach vertexes number *i*<=+<=1,<=*i*<=+<=2,<=...,<=*n* from any vertex number *i* (*i*<=&lt;<=*n*). 1. For any graph edge going from vertex *v* to vertex *u* the following inequation fulfills: *v*<=&lt;<=*u*. 1. There is at most one edge between any two vertexes. 1. The shortest distance between the pair of vertexes *i*,<=*j* (*i*<=&lt;<=*j*), for which *j*<=-<=*i*<=≀<=*k* holds, equals *j*<=-<=*i* edges. 1. The shortest distance between the pair of vertexes *i*,<=*j* (*i*<=&lt;<=*j*), for which *j*<=-<=*i*<=&gt;<=*k* holds, equals either *j*<=-<=*i* or *j*<=-<=*i*<=-<=*k* edges. We will consider two ways distinct, if there is the pair of vertexes *i*,<=*j* (*i*<=&lt;<=*j*), such that first resulting graph has an edge from *i* to *j* and the second one doesn't have it. Help Olya. As the required number of ways can be rather large, print it modulo 1000000007 (109<=+<=7).
The first line contains three space-separated integers *n*,<=*m*,<=*k* (2<=≀<=*n*<=≀<=106,<=0<=≀<=*m*<=≀<=105,<=1<=≀<=*k*<=≀<=106). The next *m* lines contain the description of the edges of the initial graph. The *i*-th line contains a pair of space-separated integers *u**i*,<=*v**i* (1<=≀<=*u**i*<=&lt;<=*v**i*<=≀<=*n*) β€” the numbers of vertexes that have a directed edge from *u**i* to *v**i* between them. It is guaranteed that any pair of vertexes *u**i*,<=*v**i* has at most one edge between them. It also is guaranteed that the graph edges are given in the order of non-decreasing *u**i*. If there are multiple edges going from vertex *u**i*, then it is guaranteed that these edges are given in the order of increasing *v**i*.
Print a single integer β€” the answer to the problem modulo 1000000007 (109<=+<=7).
[ "7 8 2\n1 2\n2 3\n3 4\n3 6\n4 5\n4 7\n5 6\n6 7\n", "7 0 2\n", "7 2 1\n1 3\n3 5\n" ]
[ "2\n", "12\n", "0\n" ]
In the first sample there are two ways: the first way is not to add anything, the second way is to add a single edge from vertex 2 to vertex 5.
[]
60
0
0
35,874
827
Rusty String
[ "fft", "math", "strings" ]
null
null
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length *n* and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was written. Grigory couldn't understand for a long time what these letters remind him of, so he became interested in the following question: if we put a letter "V" or "K" on each unreadable position, which values can the period of the resulting string be equal to? A period of a string is such an integer *d* from 1 to the length of the string that if we put the string shifted by *d* positions to the right on itself, then all overlapping letters coincide. For example, 3 and 5 are periods of "VKKVK".
There are several (at least one) test cases in the input. The first line contains single integerΒ β€” the number of test cases. There is an empty line before each test case. Each test case is described in two lines: the first line contains single integer *n* (1<=≀<=*n*<=≀<=5Β·105)Β β€” the length of the string, the second line contains the string of length *n*, consisting of letters "V", "K" and characters "?". The latter means the letter on its position is unreadable. It is guaranteed that the sum of lengths among all test cases doesn't exceed 5Β·105. For hacks you can only use tests with one test case.
For each test case print two lines. In the first line print the number of possible periods after we replace each unreadable letter with "V" or "K". In the next line print all these values in increasing order.
[ "3\nΒ \n5\nV??VK\nΒ \n6\n??????\nΒ \n4\n?VK?\n" ]
[ "2\n3 5\n6\n1 2 3 4 5 6\n3\n2 3 4\n" ]
In the first test case from example we can obtain, for example, "VKKVK", which has periods 3 and 5. In the second test case we can obtain "VVVVVV" which has all periods from 1 to 6. In the third test case string "KVKV" has periods 2 and 4, and string "KVKK" has periods 3 and 4.
[]
15
0
-1
35,901
113
Double Happiness
[ "brute force", "math", "number theory" ]
C. Double Happiness
3
128
On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number *t* is his lucky number, if it can be represented as: Now, the boys decided to find out how many days of the interval [*l*,<=*r*] (*l*<=≀<=*r*) are suitable for pair programming. They decided that the day *i* (*l*<=≀<=*i*<=≀<=*r*) is suitable for pair programming if and only if the number *i* is lucky for Peter and lucky for Bob at the same time. Help the boys to find the number of such days.
The first line of the input contains integer numbers *l*,<=*r* (1<=≀<=*l*,<=*r*<=≀<=3Β·108).
In the only line print the number of days on the segment [*l*,<=*r*], which are lucky for Peter and Bob at the same time.
[ "3 5\n", "6 66\n" ]
[ "1\n", "7\n" ]
none
[]
2,635
6,963,200
0
35,978
803
Periodic RMQ Problem
[ "data structures" ]
null
null
You are given an array *a* consisting of positive integers and *q* queries to this array. There are two types of queries: - 1 *l* *r* *x* β€” for each index *i* such that *l*<=≀<=*i*<=≀<=*r* set *a**i*<==<=*x*. - 2 *l* *r* β€” find the minimum among such *a**i* that *l*<=≀<=*i*<=≀<=*r*. We decided that this problem is too easy. So the array *a* is given in a compressed form: there is an array *b* consisting of *n* elements and a number *k* in the input, and before all queries *a* is equal to the concatenation of *k* arrays *b* (so the size of *a* is *n*Β·*k*).
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105, 1<=≀<=*k*<=≀<=104). The second line contains *n* integers β€” elements of the array *b* (1<=≀<=*b**i*<=≀<=109). The third line contains one integer *q* (1<=≀<=*q*<=≀<=105). Then *q* lines follow, each representing a query. Each query is given either as 1 *l* *r* *x* β€” set all elements in the segment from *l* till *r* (including borders) to *x* (1<=≀<=*l*<=≀<=*r*<=≀<=*n*Β·*k*, 1<=≀<=*x*<=≀<=109) or as 2 *l* *r* β€” find the minimum among all elements in the segment from *l* till *r* (1<=≀<=*l*<=≀<=*r*<=≀<=*n*Β·*k*).
For each query of type 2 print the answer to this query β€” the minimum on the corresponding segment.
[ "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3\n", "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6\n" ]
[ "1\n3\n", "1\n5\n1\n" ]
none
[ { "input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3" }, { "input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1" }, { "input": "10 10\n10 8 10 9 2 2 4 6 10 1\n10\n1 17 87 5\n2 31 94\n1 5 56 8\n1 56 90 10\n1 25 93 6\n1 11 32 4\n2 20 49\n1 46 87 8\n2 14 48\n2 40 48", "output": "1\n4\n4\n6" }, { "input": "10 10\n4 2 3 8 1 2 1 7 5 4\n10\n2 63 87\n2 2 48\n2 5 62\n2 33 85\n2 30 100\n2 38 94\n2 7 81\n2 13 16\n2 26 36\n2 64 96", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1" } ]
1,013
1,331,200
0
36,054
792
Mages and Monsters
[ "data structures", "geometry" ]
null
null
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values *x**i* and *y**i* β€” damage per second and mana cost per second, respectively. Vova doesn't have to use a spell for an integer amount of seconds. More formally, if he uses a spell with damage *x* and mana cost *y* for *z* seconds, then he will deal *x*Β·*z* damage and spend *y*Β·*z* mana (no rounding). If there is no mana left (mana amount is set in the start of the game and it remains the same at the beginning of every fight), then character won't be able to use any spells. It is prohibited to use multiple spells simultaneously. Also Vova can fight monsters. Every monster is characterized by two values *t**j* and *h**j* β€” monster kills Vova's character in *t**j* seconds and has *h**j* health points. Mana refills after every fight (or Vova's character revives with full mana reserve), so previous fights have no influence on further ones. Vova's character kills a monster, if he deals *h**j* damage to it in no more than *t**j* seconds using his spells (it is allowed to use more than one spell in a fight) and spending no more mana than he had at the beginning of the fight. If monster's health becomes zero exactly in *t**j* seconds (it means that the monster and Vova's character kill each other at the same time), then Vova wins the fight. You have to write a program which can answer two types of queries: - 1 *x* *y* β€” Vova's character learns new spell which deals *x* damage per second and costs *y* mana per second. - 2 *t* *h* β€” Vova fights the monster which kills his character in *t* seconds and has *h* health points. Note that queries are given in a different form. Also remember that Vova's character knows no spells at the beginning of the game. For every query of second type you have to determine if Vova is able to win the fight with corresponding monster.
The first line contains two integer numbers *q* and *m* (2<=≀<=*q*<=≀<=105,<=1<=≀<=*m*<=≀<=1012) β€” the number of queries and the amount of mana at the beginning of every fight. *i*-th of each next *q* lines contains three numbers *k**i*, *a**i* and *b**i* (1<=≀<=*k**i*<=≀<=2,<=1<=≀<=*a**i*,<=*b**i*<=≀<=106). Using them you can restore queries this way: let *j* be the index of the last query of second type with positive answer (*j*<==<=0 if there were none of these). - If *k**i*<==<=1, then character learns spell with *x*<==<=(*a**i*<=+<=*j*) *mod* 106<=+<=1, *y*<==<=(*b**i*<=+<=*j*) *mod* 106<=+<=1. - If *k**i*<==<=2, then you have to determine if Vova is able to win the fight against monster with *t*<==<=(*a**i*<=+<=*j*) *mod* 106<=+<=1, *h*<==<=(*b**i*<=+<=*j*) *mod* 106<=+<=1.
For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise.
[ "3 100\n1 4 9\n2 19 49\n2 19 49\n" ]
[ "YES\nNO\n" ]
In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with only 100 mana.
[ { "input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO" }, { "input": "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49", "output": "NO\nYES\nYES\nYES\nYES\nYES\nYES" }, { "input": "2 424978864039\n2 7 3\n2 10 8", "output": "NO\nNO" }, { "input": "3 10\n1 1 1\n2 1 1\n2 999999 999999", "output": "YES\nYES" }, { "input": "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n2 999991 11\n2 999991 10", "output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES" }, { "input": "15 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n1 2 999992\n2 6 256\n2 7 256\n1 2 999988\n2 2 252", "output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nYES" }, { "input": "3 12\n1 99 9\n1 49 1\n2 1 149", "output": "YES" } ]
0
0
-1
36,172
645
Cowslip Collections
[ "combinatorics", "math", "number theory" ]
null
null
In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must have the exact same arrangement of flowers. Initially, Farmer John has *n* different species of flowers he can plant, with *a**i* flowers of the *i*-th species. On each of the next *q* days, Farmer John will receive a batch of flowers of a new species. On day *j*, he will receive *c**j* flowers of the same species, but of a different species from those Farmer John already has. Farmer John, knowing the right balance between extravagance and minimalism, wants exactly *k* species of flowers to be used. Furthermore, to reduce waste, each flower of the *k* species Farmer John chooses must be planted in some garden. And each of the gardens must be identical; that is to say that each of the *k* chosen species should have an equal number of flowers in each garden. As Farmer John is a proponent of national equality, he would like to create the greatest number of gardens possible. After receiving flowers on each of these *q* days, Farmer John would like to know the sum, over all possible choices of *k* species, of the maximum number of gardens he could create. Since this could be a large number, you should output your result modulo 109<=+<=7.
The first line of the input contains three integers *n*, *k* and *q* (1<=≀<=*k*<=≀<=*n*<=≀<=100<=000, 1<=≀<=*q*<=≀<=100<=000). The *i*-th (1<=≀<=*i*<=≀<=*n*) of the next *n* lines of the input contains an integer *a**i* (1<=≀<=*a**i*<=≀<=1<=000<=000), the number of flowers of species *i* Farmer John has initially. The *j*-th (1<=≀<=*j*<=≀<=*q*) of the next *q* lines of the input contains an integer *c**j* (1<=≀<=*c**j*<=≀<=1<=000<=000), the number of flowers of a new species Farmer John receives on day *j*.
After each of the *q* days, output the sum of the maximum possible number of gardens, where the sum is taken over all possible choices of *k* species, modulo 109<=+<=7.
[ "3 3 2\n4\n6\n9\n8\n6\n", "4 1 2\n6\n5\n4\n3\n2\n1\n" ]
[ "5\n16\n", "20\n21\n" ]
In the first sample case, after the first day Farmer John has (4, 6, 9, 8) of each type of flower, and *k* = 3. Choosing (4, 6, 8) lets him make 2 gardens, each with (2, 3, 4) of each flower, respectively. Choosing (4, 6, 9), (4, 9, 8) and (6, 9, 8) each only let him make one garden, since there is no number of gardens that each species can be evenly split into. So the sum over all choices of *k* = 3 flowers is 2 + 1 + 1 + 1 = 5. After the second day, Farmer John has (4, 6, 9, 8, 6) of each flower. The sum over all choices is 1 + 2 + 2 + 1 + 1 + 2 + 2 + 3 + 1 + 1 = 16. In the second sample case, *k* = 1. With *x* flowers Farmer John can make *x* gardens. So the answers to the queries are 6 + 5 + 4 + 3 + 2 = 20 and 6 + 5 + 4 + 3 + 2 + 1 = 21.
[ { "input": "3 3 2\n4\n6\n9\n8\n6", "output": "5\n16" }, { "input": "4 1 2\n6\n5\n4\n3\n2\n1", "output": "20\n21" }, { "input": "3 3 3\n6\n8\n10\n12\n14\n16", "output": "8\n20\n42" }, { "input": "1 1 1\n1\n1", "output": "2" }, { "input": "10 10 10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10", "output": "110\n660\n2860\n10010\n30030\n80080\n194480\n437580\n923780\n1847560" }, { "input": "7 1 9\n3\n6\n7\n2\n10\n8\n1\n3\n9\n2\n9\n10\n2\n4\n5\n2", "output": "40\n49\n51\n60\n70\n72\n76\n81\n83" }, { "input": "5 1 7\n10\n8\n4\n5\n8\n3\n9\n3\n9\n3\n10\n1", "output": "38\n47\n50\n59\n62\n72\n73" }, { "input": "7 2 8\n2\n5\n7\n9\n6\n2\n5\n2\n8\n7\n10\n8\n8\n5\n7", "output": "40\n52\n67\n90\n113\n144\n169\n195" }, { "input": "9 8 10\n10\n9\n6\n8\n8\n8\n8\n6\n2\n7\n1\n9\n5\n10\n8\n1\n1\n6\n10", "output": "46\n166\n496\n1288\n3012\n6480\n12915\n24355\n43923\n76077" } ]
46
0
0
36,251
418
Tricky Password
[ "data structures" ]
null
null
In order to ensure confidentiality, the access to the "Russian Code Cup" problems is password protected during the problem development process. To select a password, the jury can generate a special table that contains *n* columns and the infinite number of rows. To construct a table, the first row is fixed, and all the others are obtained by the following rule: In the row *i* at position *p* there is a number equal to the number of times *a*[*i*<=-<=1][*p*] occurs on the prefix *a*[*i*<=-<=1][1... *p*]. To ensure the required level of confidentiality, the jury must be able to perform the following operations: - Replace number *a*[1][*p*] by *v* and rebuild the table. - Find the number *a*[*x*][*y*], which will be the new password. Doing all these steps manually is very tedious, so the jury asks you to help him. Write a program that responds to the request of the jury.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100000) β€” the number of columns. The second line contains the description of the first row of the table, that is, *n* integers, which are not less than 1 and do not exceed 109. The third line of the input contains an integer *m* (1<=≀<=*m*<=≀<=100000) β€” the number of requests. Next, each row contains a description of the request, which consists of three integers: - If the first number is equal to 1, then the remaining two numbers are *v*, *p* (1<=≀<=*v*<=≀<=109; 1<=≀<=*p*<=≀<=*n*). So, you should put value *v* in the position *p* in the first row. - If the first number is equal to 2, then the remaining two numbers are *x*, *y* (1<=≀<=*x*<=≀<=105; 1<=≀<=*y*<=≀<=*n*) β€” the row and column of the table cell from which you want to get value.
Print an answer for each request of the second type in the order you receive them.
[ "6\n1 2 2 2 3 1\n3\n2 2 3\n1 3 3\n2 3 4\n" ]
[ "2\n1\n" ]
none
[]
15
0
0
36,266
838
Diverging Directions
[ "data structures", "dfs and similar", "trees" ]
null
null
You are given a directed weighted graph with *n* nodes and 2*n*<=-<=2 edges. The nodes are labeled from 1 to *n*, while the edges are labeled from 1 to 2*n*<=-<=2. The graph's edges can be split into two parts. - The first *n*<=-<=1 edges will form a rooted spanning tree, with node 1 as the root. All these edges will point away from the root. - The last *n*<=-<=1 edges will be from node *i* to node 1, for all 2<=≀<=*i*<=≀<=*n*. You are given *q* queries. There are two types of queries - 1 *i* *w*: Change the weight of the *i*-th edge to *w* - 2 *u* *v*: Print the length of the shortest path between nodes *u* to *v* Given these queries, print the shortest path lengths.
The first line of input will contain two integers *n*,<=*q* (2<=≀<=*n*,<=*q*<=≀<=200<=000), the number of nodes, and the number of queries, respectively. The next 2*n*<=-<=2 integers will contain 3 integers *a**i*,<=*b**i*,<=*c**i*, denoting a directed edge from node *a**i* to node *b**i* with weight *c**i*. The first *n*<=-<=1 of these lines will describe a rooted spanning tree pointing away from node 1, while the last *n*<=-<=1 of these lines will have *b**i*<==<=1. More specifically, - The edges (*a*1,<=*b*1),<=(*a*2,<=*b*2),<=... (*a**n*<=-<=1,<=*b**n*<=-<=1) will describe a rooted spanning tree pointing away from node 1. - *b**j*<==<=1 for *n*<=≀<=*j*<=≀<=2*n*<=-<=2. - *a**n*,<=*a**n*<=+<=1,<=...,<=*a*2*n*<=-<=2 will be distinct and between 2 and *n*. The next *q* lines will contain 3 integers, describing a query in the format described in the statement. All edge weights will be between 1 and 106.
For each type 2 query, print the length of the shortest path in its own line.
[ "5 9\n1 3 1\n3 2 2\n1 4 3\n3 5 4\n5 1 5\n3 1 6\n2 1 7\n4 1 8\n2 1 1\n2 1 3\n2 3 5\n2 5 2\n1 1 100\n2 1 3\n1 8 30\n2 4 2\n2 2 4\n" ]
[ "0\n1\n4\n8\n100\n132\n10\n" ]
none
[]
46
0
0
36,369
455
Function
[ "data structures" ]
null
null
Serega and Fedor play with functions. One day they came across a very interesting function. It looks like that: - *f*(1,<=*j*)<==<=*a*[*j*], 1<=≀<=*j*<=≀<=*n*. - *f*(*i*,<=*j*)<==<=*min*(*f*(*i*<=-<=1,<=*j*),<=*f*(*i*<=-<=1,<=*j*<=-<=1))<=+<=*a*[*j*], 2<=≀<=*i*<=≀<=*n*, *i*<=≀<=*j*<=≀<=*n*. Here *a* is an integer array of length *n*. Serega and Fedya want to know what values this function takes at some points. But they don't want to calculate the values manually. So they ask you to help them.
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the length of array *a*. The next line contains *n* integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≀<=*a*[*i*]<=≀<=104). The next line contains integer *m* (1<=≀<=*m*<=≀<=105) β€” the number of queries. Each of the next *m* lines contains two integers: *x**i*, *y**i* (1<=≀<=*x**i*<=≀<=*y**i*<=≀<=*n*). Each line means that Fedor and Serega want to know the value of *f*(*x**i*,<=*y**i*).
Print *m* lines β€” the answers to the guys' queries.
[ "6\n2 2 3 4 3 4\n4\n4 5\n3 4\n3 4\n2 3\n", "7\n1 3 2 3 4 0 2\n4\n4 5\n2 3\n1 4\n4 6\n" ]
[ "12\n9\n9\n5\n", "11\n4\n3\n0\n" ]
none
[]
15
0
0
36,427
632
Thief in a Shop
[ "divide and conquer", "dp", "fft", "math" ]
null
null
A thief made his way to a shop. As usual he has his lucky knapsack with him. The knapsack can contain *k* objects. There are *n* kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind *i* is *a**i*. The thief is greedy, so he will take exactly *k* products (it's possible for some kinds to take several products of that kind). Find all the possible total costs of products the thief can nick into his knapsack.
The first line contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=1000) β€” the number of kinds of products and the number of products the thief will take. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=1000) β€” the costs of products for kinds from 1 to *n*.
Print the only line with all the possible total costs of stolen products, separated by a space. The numbers should be printed in the ascending order.
[ "3 2\n1 2 3\n", "5 5\n1 1 1 1 1\n", "3 3\n3 5 11\n" ]
[ "2 3 4 5 6\n", "5\n", "9 11 13 15 17 19 21 25 27 33\n" ]
none
[ { "input": "3 2\n1 2 3", "output": "2 3 4 5 6" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "3 3\n3 5 11", "output": "9 11 13 15 17 19 21 25 27 33" }, { "input": "10 3\n3 4 12 5 7 13 5 6 1 6", "output": "3 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 36 37 38 39" }, { "input": "10 3\n1 2 3 4 5 6 7 8 9 10", "output": "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" }, { "input": "10 1000\n630 764 679 16 34 691 778 366 982 30", "output": "16000 16014 16018 16028 16032 16036 16042 16046 16050 16054 16056 16060 16064 16068 16070 16072 16074 16078 16082 16084 16086 16088 16090 16092 16096 16098 16100 16102 16104 16106 16108 16110 16112 16114 16116 16118 16120 16122 16124 16126 16128 16130 16132 16134 16136 16138 16140 16142 16144 16146 16148 16150 16152 16154 16156 16158 16160 16162 16164 16166 16168 16170 16172 16174 16176 16178 16180 16182 16184 16186 16188 16190 16192 16194 16196 16198 16200 16202 16204 16206 16208 16210 16212 16214 16216 1..." }, { "input": "3 1000\n674 751 563", "output": "563000 563111 563188 563222 563299 563333 563376 563410 563444 563487 563521 563555 563564 563598 563632 563666 563675 563709 563743 563752 563777 563786 563820 563854 563863 563888 563897 563931 563940 563965 563974 563999 564008 564042 564051 564076 564085 564110 564119 564128 564153 564162 564187 564196 564221 564230 564239 564264 564273 564298 564307 564316 564332 564341 564350 564375 564384 564409 564418 564427 564443 564452 564461 564486 564495 564504 564520 564529 564538 564554 564563 564572 564597 ..." }, { "input": "13 1000\n494 391 821 980 716 237 801 893 765 946 338 656 698", "output": "237000 237101 237154 237202 237255 237257 237303 237308 237356 237358 237404 237409 237411 237419 237457 237459 237461 237462 237479 237505 237510 237512 237514 237520 237528 237558 237560 237562 237563 237564 237565 237573 237580 237584 237606 237611 237613 237615 237616 237621 237629 237633 237656 237659 237661 237663 237664 237665 237666 237668 237674 237676 237681 237682 237685 237707 237709 237712 237714 237716 237717 237718 237719 237722 237727 237730 237734 237736 237738 237743 237757 237760 237762 ..." }, { "input": "4 973\n40 32 21 21", "output": "20433 20444 20452 20455 20463 20466 20471 20474 20477 20482 20485 20488 20490 20493 20496 20499 20501 20504 20507 20509 20510 20512 20515 20518 20520 20521 20523 20526 20528 20529 20531 20532 20534 20537 20539 20540 20542 20543 20545 20547 20548 20550 20551 20553 20554 20556 20558 20559 20561 20562 20564 20565 20566 20567 20569 20570 20572 20573 20575 20576 20577 20578 20580 20581 20583 20584 20585 20586 20587 20588 20589 20591 20592 20594 20595 20596 20597 20598 20599 20600 20602 20603 20604 20605 20606 2..." }, { "input": "100 100\n6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55", "output": "100 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229..." }, { "input": "50 50\n27 4 35 30 19 8 26 22 18 35 32 9 15 27 33 5 9 29 33 24 49 39 16 22 49 2 50 22 19 23 30 50 17 3 24 42 39 5 10 28 46 46 50 11 3 26 7 17 22 18", "output": "100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227..." }, { "input": "25 25\n6 3 16 25 2 25 17 11 24 1 1 13 9 16 6 20 21 9 17 16 23 4 9 23 9", "output": "25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 17..." }, { "input": "8 75\n1 2 500 482 470 453 434 426", "output": "75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 ..." }, { "input": "8 61\n1 2 482 475 471 480 460 450", "output": "61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 58..." }, { "input": "41 1000\n900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940", "output": "900000 900001 900002 900003 900004 900005 900006 900007 900008 900009 900010 900011 900012 900013 900014 900015 900016 900017 900018 900019 900020 900021 900022 900023 900024 900025 900026 900027 900028 900029 900030 900031 900032 900033 900034 900035 900036 900037 900038 900039 900040 900041 900042 900043 900044 900045 900046 900047 900048 900049 900050 900051 900052 900053 900054 900055 900056 900057 900058 900059 900060 900061 900062 900063 900064 900065 900066 900067 900068 900069 900070 900071 900072 ..." }, { "input": "8 73\n1 2 492 477 464 499 461 429", "output": "73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 56..." } ]
5,000
9,523,200
0
36,500
258
Little Elephant and Elections
[ "brute force", "combinatorics", "dp" ]
null
null
There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names. Political parties find their number in the ballot highly important. Overall there are *m* possible numbers: 1,<=2,<=...,<=*m*. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number. The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties. Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109<=+<=7).
A single line contains a single positive integer *m* (7<=≀<=*m*<=≀<=109) β€” the number of possible numbers in the ballot.
In a single line print a single integer β€” the answer to the problem modulo 1000000007 (109<=+<=7).
[ "7\n", "8\n" ]
[ "0\n", "1440\n" ]
none
[ { "input": "7", "output": "0" }, { "input": "8", "output": "1440" }, { "input": "47", "output": "907362803" }, { "input": "10", "output": "40320" }, { "input": "9", "output": "10080" }, { "input": "11", "output": "120960" }, { "input": "25", "output": "139536000" }, { "input": "74", "output": "257814864" }, { "input": "128", "output": "879893164" }, { "input": "1000000000", "output": "14594961" }, { "input": "458754", "output": "667496909" }, { "input": "987549745", "output": "206294274" }, { "input": "15478459", "output": "638813679" }, { "input": "674810014", "output": "550536983" }, { "input": "245", "output": "528398086" }, { "input": "1000", "output": "193577116" }, { "input": "10000", "output": "726889821" }, { "input": "100000", "output": "459307763" }, { "input": "1000000", "output": "638519268" }, { "input": "100000000", "output": "133127802" }, { "input": "10000000", "output": "994715261" }, { "input": "54785", "output": "118850209" }, { "input": "68745844", "output": "739902866" }, { "input": "545794012", "output": "829479797" }, { "input": "301542785", "output": "763583849" }, { "input": "794512405", "output": "90508418" }, { "input": "30", "output": "581454720" }, { "input": "40", "output": "771100852" }, { "input": "44", "output": "359621144" }, { "input": "42", "output": "831345485" } ]
218
21,606,400
0
36,506
364
Matrix
[ "combinatorics", "data structures", "implementation" ]
null
null
You have a string of decimal digits *s*. Let's define *b**ij*<==<=*s**i*Β·*s**j*. Find in matrix *b* the number of such rectangles that the sum *b**ij* for all cells (*i*,<=*j*) that are the elements of the rectangle equals *a* in each rectangle. A rectangle in a matrix is a group of four integers (*x*,<=*y*,<=*z*,<=*t*) (*x*<=≀<=*y*,<=*z*<=≀<=*t*). The elements of the rectangle are all cells (*i*,<=*j*) such that *x*<=≀<=*i*<=≀<=*y*,<=*z*<=≀<=*j*<=≀<=*t*.
The first line contains integer *a* (0<=≀<=*a*<=≀<=109), the second line contains a string of decimal integers *s* (1<=≀<=|*s*|<=≀<=4000).
Print a single integer β€” the answer to a problem. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "10\n12345\n", "16\n439873893693495623498263984765\n" ]
[ "6\n", "40\n" ]
none
[ { "input": "10\n12345", "output": "6" }, { "input": "16\n439873893693495623498263984765", "output": "40" }, { "input": "0\n1230", "output": "19" }, { "input": "8398\n67950927224842887617892831243606761170908507858527", "output": "0" }, { "input": "2\n11", "output": "4" }, { "input": "4\n111", "output": "4" }, { "input": "0\n0", "output": "1" }, { "input": "1\n0", "output": "0" }, { "input": "0\n1", "output": "0" }, { "input": "0\n0000", "output": "100" }, { "input": "1\n00", "output": "0" }, { "input": "1\n000", "output": "0" }, { "input": "1\n11111", "output": "25" }, { "input": "700\n100101011011001100111101100101000100000000011001111000111110001011011100010110000000000100100000001100000011110011101110011101101110111011011100001001101011000100000000000110001000101001100011111110011010101011010100010100001011011111001011000101001101000111010100110000100100110011111100010111100010000101001110111101110011111000111011011110111", "output": "3390908" }, { "input": "1000000000\n769416574772919262229125278908144478541501489034872535880758612234526208997051461441045410435259231256676917086438172075984271711722261161236033705315696117638300191007208614272746181036958213963736353682247646595587613148679926094811", "output": "0" }, { "input": "10000\n011111011000110010011010001011101100110111000100111110011100010001111010010010", "output": "0" }, { "input": "5\n1010100010101000010101001010102020201010100101020", "output": "14288" }, { "input": "0\n0001001001011001100101100001111111001010011111000100000000011000001010110111100100000000001110110101010010001010100110011100001010001", "output": "3559240" }, { "input": "0\n11002201122211202102", "output": "2484" }, { "input": "0\n3123232011321302332331322102332011002122123113023032320333332330233131131123012232200000120323200110", "output": "322176" }, { "input": "2\n21111102201122101122", "output": "532" }, { "input": "3\n0130301201202102033203302203131122023031112010202333033033021210331110110022230021013231130200102022", "output": "7980" }, { "input": "0\n5054451336060064631662402176557747457153065525132775141002773502671221320017407134475306346213334141573052346075726400141731757473641", "output": "373821" }, { "input": "1\n14230330640346634338", "output": "1" }, { "input": "2\n5101140593483723176811719219208813520975285810392000077455984289096240663245004460322003001554026756", "output": "800" }, { "input": "1000000000\n00000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "0\n00000000000000000000000000000000000000000000000000", "output": "1625625" }, { "input": "1\n00000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "2\n000000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "0\n01111111011001011100010000101111101111010101110011", "output": "75600" }, { "input": "1\n11110110111010001000100010010101001111111001100100001000", "output": "17956" }, { "input": "0\n02102110221221211102011211200110110222121101121110", "output": "30456" }, { "input": "1\n12200220101112112102221202012201210000010112000102121022", "output": "2500" }, { "input": "0\n32365690899439422959451631777149229543849097266521", "output": "5096" }, { "input": "1\n39568795337451783387623217888229492030389256605973002137", "output": "9" }, { "input": "0\n1011101100010110010111010", "output": "9525" }, { "input": "1\n210120001002121211101002102001010012221102201222121011102210110002222001222", "output": "4761" }, { "input": "0\n000000000000000000000000000000000", "output": "314721" }, { "input": "0\n32251032040000365150463055464352624561315100524465", "output": "43061" }, { "input": "1\n43561243107434624503740444753362003764016311724140063706", "output": "64" }, { "input": "0\n24225680092188869135902902675995827895766459740919", "output": "15264" }, { "input": "0\n01", "output": "5" }, { "input": "0\n101", "output": "11" }, { "input": "0\n010", "output": "20" }, { "input": "0\n1235456416548", "output": "0" }, { "input": "0\n0011", "output": "51" } ]
1,000
124,006,400
0
36,513
44
Hyperdrive
[ "math" ]
D. Hyperdrive
2
256
In a far away galaxy there are *n* inhabited planets, numbered with numbers from 1 to *n*. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, *n*<=-<=1 spaceships were built on the planet number 1, and those ships were sent to other planets to inform about the revolutionary invention. Paradoxical thought it may be, but the hyperspace is represented as simple three-dimensional Euclidean space. The inhabited planets may be considered fixed points in it, and no two points coincide and no three points lie on the same straight line. The movement of a ship with a hyperdrive between two planets is performed along a straight line at the constant speed, the same for all the ships. That's why the distance in the hyperspace are measured in hyperyears (a ship with a hyperdrive covers a distance of *s* hyperyears in *s* years). When the ship reaches an inhabited planet, the inhabitants of the planet dissemble it, make *n*<=-<=2 identical to it ships with a hyperdrive and send them to other *n*<=-<=2 planets (except for the one from which the ship arrived). The time to make a new ship compared to the time in which they move from one planet to another is so small that it can be disregarded. New ships are absolutely identical to the ones sent initially: they move at the same constant speed along a straight line trajectory and, having reached a planet, perform the very same mission, i.e. are dissembled to build new *n*<=-<=2 ships and send them to all the planets except for the one from which the ship arrived. Thus, the process of spreading the important news around the galaxy continues. However the hyperdrive creators hurried to spread the news about their invention so much that they didn't study completely what goes on when two ships collide in the hyperspace. If two moving ships find themselves at one point, they provoke an explosion of colossal power, leading to the destruction of the galaxy! Your task is to find the time the galaxy will continue to exist from the moment of the ships' launch from the first planet.
The first line contains a number *n* (3<=≀<=*n*<=≀<=5000) β€” the number of inhabited planets in the galaxy. The next *n* lines contain integer coordinates of the planets in format "*x**i* *y**i* *z**i*" (<=-<=104<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=104).
Print the single number β€” the solution to the task with an absolute or relative error not exceeding 10<=-<=6.
[ "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n" ]
[ "1.7071067812\n" ]
none
[ { "input": "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0", "output": "1.7071067812" }, { "input": "3\n5 -5 4\n-5 -4 2\n-1 1 2", "output": "12.6839364452" }, { "input": "3\n28 -69 72\n-36 9 -49\n94 83 95", "output": "266.2401228107" }, { "input": "4\n-7 -72 93\n-40 42 49\n31 76 -36\n-56 12 -1", "output": "161.1452860862" }, { "input": "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7", "output": "166.1019364256" }, { "input": "10\n-3461 4259 -7268\n9964 2370 6622\n4530 5607 -6609\n-3777 4888 6057\n-5403 7982 -651\n4828 -6712 1070\n9886 -1287 -6864\n-369 -7105 1602\n-7603 5424 -3396\n1202 9528 9042", "output": "8987.4152877289" }, { "input": "15\n-4743 -119 3104\n8014 4585 -1756\n-360 4466 -4425\n7157 -5142 -2483\n1691 -505 5849\n9632 6178 4631\n4531 -3438 -4361\n-172 1508 4593\n198 8647 3400\n6904 -188 4830\n-7101 -7911 -4407\n-4366 3174 8353\n4636 -9577 -4017\n1055 5875 1289\n-7014 -7983 1874", "output": "7548.8503523162" }, { "input": "25\n-10000 10000 -10000\n9979 -9960 9950\n9996 -9986 9952\n9953 -9961 9978\n9999 -9981 9967\n9953 -9983 9982\n9974 -9959 9972\n9960 -9956 9983\n9955 -9991 9952\n9976 -9987 9967\n9960 -9973 9987\n9998 -9952 9968\n9964 -9958 9961\n9957 -9984 9982\n9966 -9986 9963\n9985 -9997 9967\n9993 -9979 9953\n9979 -9965 9975\n9979 -9965 9983\n9997 -9989 9957\n9983 -9996 9969\n9959 -9962 9952\n9986 -9966 9966\n9980 -9961 9975\n9965 -9960 9950", "output": "34571.5878668720" }, { "input": "20\n-10000 10000 -10000\n9940 -9947 10000\n9968 -9977 9918\n9975 -9908 9901\n9948 -9923 9989\n10000 -9966 9906\n9981 -9910 9911\n9962 -9905 9999\n9981 -9977 9949\n9974 -9956 9952\n9986 -9942 9937\n9922 -9913 9984\n9978 -9925 9945\n9974 -9962 9990\n9921 -9985 9998\n9949 -9976 9924\n9991 -9946 9920\n9966 -9987 9993\n9910 -9930 9914\n9927 -9937 9915", "output": "34515.4142208477" }, { "input": "20\n-10000 10000 -10000\n9973 -9963 9996\n9968 -9972 9968\n9958 -9956 9991\n9982 -9971 9958\n9975 -9957 9985\n9971 -9950 9986\n9996 -9956 9985\n9952 -9977 9989\n9996 -10000 9961\n9971 -9969 9967\n9984 -10000 9973\n9962 -9993 9992\n9951 -9970 9987\n9969 -9970 9962\n9979 -9953 9981\n9975 -9950 9986\n9971 -9973 9954\n9954 -9973 9962\n9993 -9953 9976", "output": "34587.3817821709" }, { "input": "8\n-10000 -10000 -10000\n-10000 -10000 10000\n-10000 10000 -10000\n-10000 10000 10000\n10000 -10000 -10000\n10000 -10000 10000\n10000 10000 -10000\n10000 10000 10000", "output": "34142.1356237310" } ]
124
0
0
36,585
121
Lucky Array
[ "data structures" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has an array consisting of *n* numbers. He wants to perform *m* operations of two types: - add *l* *r* *d* β€” add an integer *d* to all elements whose indexes belong to the interval from *l* to *r*, inclusive (1<=≀<=*l*<=≀<=*r*<=≀<=*n*,<=1<=≀<=*d*<=≀<=104); - count *l* *r* β€” find and print on the screen how many lucky numbers there are among elements with indexes that belong to the interval from *l* to *r* inclusive (1<=≀<=*l*<=≀<=*r*<=≀<=*n*). Each lucky number should be counted as many times as it appears in the interval. Petya has a list of all operations. The operations are such that after all additions the array won't have numbers that would exceed 104. Help Petya write a program that would perform these operations.
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=105) β€” the number of numbers in the array and the number of operations correspondingly. The second line contains *n* positive integers, none of which exceeds 104 β€” those are the array numbers. Next *m* lines contain operations, one per line. They correspond to the description given in the statement. It is guaranteed that after all operations are fulfilled each number in the array will not exceed 104.
For each operation of the second type print the single number on the single line β€” the number of lucky numbers in the corresponding interval.
[ "3 6\n2 3 4\ncount 1 3\ncount 1 2\nadd 1 3 2\ncount 1 3\nadd 2 3 3\ncount 1 3\n", "4 5\n4 4 4 4\ncount 1 4\nadd 1 4 3\ncount 1 4\nadd 2 3 40\ncount 1 4\n" ]
[ "1\n0\n1\n1\n", "4\n4\n4\n" ]
In the first sample after the first addition the array will look in the following manner: 4 5 6 After the second addition: 4 8 9 The second sample after the first addition: 7 7 7 7 After the second addition: 7 47 47 7
[]
154
4,198,400
0
36,837
0
none
[ "none" ]
null
null
Radewoosh is playing a computer game. There are *n* levels, numbered 1 through *n*. Levels are divided into *k* regions (groups). Each region contains some positive number of consecutive levels. The game repeats the the following process: 1. If all regions are beaten then the game ends immediately. Otherwise, the system finds the first region with at least one non-beaten level. Let *X* denote this region.1. The system creates an empty bag for tokens. Each token will represent one level and there may be many tokens representing the same level. For each already beaten level *i* in the region *X*, the system adds *t**i* tokens to the bag (tokens representing the *i*-th level). 1. Let *j* denote the first non-beaten level in the region *X*. The system adds *t**j* tokens to the bag. 1. Finally, the system takes a uniformly random token from the bag and a player starts the level represented by the token. A player spends one hour and beats the level, even if he has already beaten it in the past. Given *n*, *k* and values *t*1,<=*t*2,<=...,<=*t**n*, your task is to split levels into regions. Each level must belong to exactly one region, and each region must contain non-empty consecutive set of levels. What is the minimum possible expected number of hours required to finish the game?
The first line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=200<=000, 1<=≀<=*k*<=≀<=*min*(50,<=*n*))Β β€” the number of levels and the number of regions, respectively. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=100<=000).
Print one real numberΒ β€” the minimum possible expected value of the number of hours spent to finish the game if levels are distributed between regions in the optimal way. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "4 2\n100 3 5 7\n", "6 2\n1 2 4 8 16 32\n" ]
[ "5.7428571429\n", "8.5000000000\n" ]
In the first sample, we are supposed to split 4 levels into 2 regions. It's optimal to create the first region with only one level (it must be the first level). Then, the second region must contain other three levels. In the second sample, it's optimal to split levels into two regions with 3 levels each.
[]
3,000
53,555,200
0
36,864
65
Harry Potter and the Golden Snitch
[ "binary search", "geometry" ]
C. Harry Potter and the Golden Snitch
2
256
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at the points (*x*0,<=*y*0,<=*z*0), (*x*1,<=*y*1,<=*z*1), ..., (*x**n*,<=*y**n*,<=*z**n*). At the beginning of the game the snitch is positioned at the point (*x*0,<=*y*0,<=*z*0), and then moves along the polyline at the constant speed *v**s*. The twins have not yet found out how the snitch behaves then. Nevertheless, they hope that the retrieved information will help Harry Potter and his team in the upcoming match against Slytherin. Harry Potter learned that at the beginning the game he will be at the point (*P**x*,<=*P**y*,<=*P**z*) and his super fast Nimbus 2011 broom allows him to move at the constant speed *v**p* in any direction or remain idle. *v**p* is not less than the speed of the snitch *v**s*. Harry Potter, of course, wants to catch the snitch as soon as possible. Or, if catching the snitch while it is moving along the polyline is impossible, he wants to hurry the Weasley brothers with their experiments. Harry Potter catches the snitch at the time when they are at the same point. Help Harry.
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=10000). The following *n*<=+<=1 lines contain the coordinates *x**i*, *y**i*, *z**i*, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities *v**p* and *v**s*, the last line contains *P**x*, *P**y*, *P**z*, separated by single spaces. All the numbers in the input are integers, their absolute value does not exceed 104. The speeds are strictly positive. It is guaranteed that *v**s*<=≀<=*v**p*.
If Harry Potter can catch the snitch while it is moving along the polyline (including the end (*x**n*,<=*y**n*,<=*z**n*)), print "YES" in the first line (without the quotes). Print in the second line *t*, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers *X*, *Y*, *Z*, the coordinates of the point at which this happens. The absolute or relative error in the answer should not exceed 10<=-<=6. If Harry is not able to catch the snitch during its moving along the described polyline, print "NO".
[ "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25\n", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50\n", "1\n1 2 3\n4 5 6\n20 10\n1 2 3\n" ]
[ "YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000\n", "NO\n", "YES\n0.0000000000\n1.0000000000 2.0000000000 3.0000000000\n" ]
none
[ { "input": "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "output": "YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000" }, { "input": "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "output": "NO" }, { "input": "1\n1 2 3\n4 5 6\n20 10\n1 2 3", "output": "YES\n0.0000000000\n1.0000000000 2.0000000000 3.0000000000" }, { "input": "4\n0 0 0\n0 1 0\n1 1 0\n1 0 0\n0 0 0\n10 5\n0 0 8", "output": "YES\n0.8000000000\n0.0000000000 0.0000000000 0.0000000000" }, { "input": "4\n1 0 0\n0 1 0\n-1 0 0\n0 -1 0\n1 0 0\n10 5\n9 0 -8", "output": "YES\n1.1313708499\n1.0000000000 0.0000000000 0.0000000000" }, { "input": "5\n32 -5 -42\n-25 -38 -6\n-13 41 25\n21 -25 -32\n43 35 -19\n-38 -12 -48\n3 2\n182 -210 32", "output": "YES\n97.5061769956\n-0.5611252637 16.8539490414 4.1465923539" }, { "input": "10\n-20 28 4\n-12 -34 49\n3 -11 25\n-35 -46 25\n4 29 -15\n17 16 -10\n40 -35 16\n-15 -25 10\n-2 40 20\n-26 18 -49\n14 8 -44\n3 1\n-877 450 899", "output": "YES\n437.7804049730\n-6.8291526407 15.8542367965 16.2852671995" }, { "input": "1\n5 -22 -3\n31 -41 -35\n4 4\n139 -86 -115", "output": "NO" }, { "input": "2\n-34 37 40\n24 -28 7\n-20 -14 -25\n1 1\n-69 -28 -70", "output": "YES\n107.2130636667\n12.9900466281 -24.4968330180 -1.0072388159" }, { "input": "3\n-38 -39 -19\n-49 -16 50\n-3 -7 5\n28 -15 41\n1 1\n-100 -139 -33", "output": "NO" }, { "input": "15\n-17 -8 7\n-50 -28 8\n13 -38 -17\n27 -49 15\n34 49 17\n-17 36 25\n-10 -15 28\n-15 -36 32\n-8 47 26\n-19 18 -25\n44 36 -16\n4 -46 49\n46 20 -13\n21 -37 -8\n35 -38 -26\n-26 46 12\n4 1\n-1693 1363 2149", "output": "YES\n768.5953048926\n37.0198725921 5.8883712161 0.2563785546" }, { "input": "20\n26 47 23\n1 -2 17\n-14 -22 46\n19 34 -18\n22 -10 -34\n15 14 -48\n-30 -12 -12\n-23 40 -48\n-50 -41 -35\n48 -5 46\n-2 -11 10\n-49 47 -15\n31 6 10\n-41 35 15\n28 28 25\n43 -7 -10\n-19 -48 49\n-10 -29 28\n0 -10 28\n41 12 -26\n-14 40 17\n3 2\n-115 1407 1434", "output": "YES\n659.9757793192\n-5.2872973659 35.5644422954 10.1882506679" }, { "input": "1\n0 0 0\n0 0 1\n10000 10000\n0 0 1", "output": "YES\n0.0000500000\n0.0000000000 0.0000000000 0.5000000000" }, { "input": "1\n10000 -10000 10000\n-10000 10000 -10000\n1 1\n10000 10000 10000", "output": "YES\n17320.5080756888\n0.0000000000 0.0000000000 0.0000000000" }, { "input": "1\n10000 -10000 10000\n-10000 10000 -10000\n10000 1\n10000 10000 10000", "output": "YES\n1.9998845433\n9998.8453661206 -9998.8453661206 9998.8453661206" }, { "input": "1\n0 0 -1\n0 0 1\n10000 1\n0 0 10000", "output": "YES\n1.0000000000\n0.0000000000 0.0000000000 0.0000000000" }, { "input": "1\n0 0 0\n-1 0 0\n10000 1\n10000 0 0", "output": "NO" }, { "input": "2\n10000 10000 10000\n10000 10000 -10000\n10000 -10000 -10000\n1 1\n-10000 -10000 10000", "output": "YES\n30000.0000000000\n10000.0000000000 0.0000000000 -10000.0000000000" }, { "input": "4\n10000 9999 10000\n10000 9999 9999\n10000 10000 9999\n10000 10000 10000\n10000 9999 10000\n10000 1\n-10000 -10000 -10000", "output": "YES\n3.4640748220\n10000.0000000000 9999.5359251780 10000.0000000000" }, { "input": "3\n10000 9999 10000\n10000 9999 9999\n10000 10000 9999\n10000 10000 10000\n10000 1\n-10000 -10000 -10000", "output": "NO" } ]
248
3,891,200
3.930752
36,928
59
Title
[ "expression parsing" ]
C. Title
2
256
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first *k* Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left. Vasya has already composed the approximate variant of the title. You are given the title template *s* consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.
The first line contains an integer *k* (1<=≀<=*k*<=≀<=26) which is the number of allowed alphabet letters. The second line contains *s* which is the given template. In *s* only the first *k* lowercase letters of Latin alphabet and question marks can be present, the length of *s* is from 1 to 100 characters inclusively.
If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first *k* letters of the Latin alphabet. At that, each of those *k* letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one. The lexicographical comparison is performed by the standard &lt; operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if exists such an *i* (1<=≀<=*i*<=≀<=|*s*|), that *a**i*<=&lt;<=*b**i*, and for any *j* (1<=≀<=*j*<=&lt;<=*i*) *a**j*<==<=*b**j*. |*s*| stands for the length of the given template.
[ "3\na?c\n", "2\na??a\n", "2\n?b?a\n" ]
[ "IMPOSSIBLE\n", "abba\n", "abba\n" ]
none
[ { "input": "3\na?c", "output": "IMPOSSIBLE" }, { "input": "2\na??a", "output": "abba" }, { "input": "2\n?b?a", "output": "abba" }, { "input": "3\n????", "output": "IMPOSSIBLE" }, { "input": "2\n????", "output": "abba" }, { "input": "1\n?", "output": "a" }, { "input": "2\n?", "output": "IMPOSSIBLE" }, { "input": "6\nabcdeffcdfda", "output": "IMPOSSIBLE" }, { "input": "1\n?a", "output": "aa" }, { "input": "23\napfpbfgmiko?mno?qre??cv?wvjt?r?foqm??op?g?udcfa", "output": "IMPOSSIBLE" }, { "input": "16\n?bc??f?hi?k??n??hb??liiglal???npi???b???p?n?j?al????j???ponmlkjih??e??b?", "output": "abcaefahijklmnophbajliiglaljannpiadbbdaipnnajlalgiiljabhponmlkjihafeacba" }, { "input": "23\na??d??g?i????n????????wj?spqbfr?wp?ob?g??h??r?????orf?q?s??w?u?srqp?n??kj?h????cb?", "output": "abcdaaghijkaanapqrseulwjmspqbfrowptobrgvhhvgrbotpworfbqpsmjwluesrqpanaakjihgaadcba" }, { "input": "9\na??d?fgh???????beaabaih????c??", "output": "aacdafghiabaaebbeaabaihgfadcaa" }, { "input": "20\nabcdefg?ij????opq?ste?dfr?ol?ef?fb?djaajd?b?kfea?okrfdl?ts???onm?kj?h??ed??a", "output": "abcdefghijkamnopqasteldfrkolaefkfbadjaajdabfkfealokrfdletsaqponmakjihgfedcba" }, { "input": "21\nabc???gh??kl??j??r?tuak???d??q?dd?d????p???u??p?njl?i??bq?g??h?k??t?rq?on?l????gf????a", "output": "IMPOSSIBLE" }, { "input": "17\na?c?e?gh?j?lm?????k?k?j?????h??c???????a?h????c????f????????pon?l?ji????dc?a", "output": "aacdeaghijalmnopaakakajafaaahcacaahbaqqabhaacachaaafajakakaaponmlajihgaedcaa" }, { "input": "18\nab?d?f????klm?o?qrc???rq?o?ml?j????e??ba", "output": "abadefaghjklmionqrcppcrqnoimlkjhgafedaba" }, { "input": "26\nabcdefghijklmnopqrstuvwxyzfgvnsltvvohywvqhuhtydghtthgdythuhqvwyhovvtlsnvgfzyxwvutsrqponmlkjihgfedcba", "output": "abcdefghijklmnopqrstuvwxyzfgvnsltvvohywvqhuhtydghtthgdythuhqvwyhovvtlsnvgfzyxwvutsrqponmlkjihgfedcba" }, { "input": "26\nabcdefghijklmnopqrstuvwxyzdqnxgfgubupwlqakrteeazzffzzaeetrka?lwpubugfgxnqdzyxwvutsrqponmlkjihgfedcba", "output": "abcdefghijklmnopqrstuvwxyzdqnxgfgubupwlqakrteeazzffzzaeetrkaqlwpubugfgxnqdzyxwvutsrqponmlkjihgfedcba" }, { "input": "26\n??cdef?h?j?l??o?qrs?uvw?yz??xo?a?ryolathxp????pex?ixe?w??u?xh?a?oyri????q???xwvut?r??onmlkji??fedcb?", "output": "abcdefahijklmnoaqrstuvwxyzaqxoaairyolathxpuagwpexiixepwgaupxhtaloyriaaoxqazyxwvutsrqaonmlkjihafedcba" }, { "input": "26\nab?defg??j??mnopqrs?uv?x???u?vpd??s?s??s?t?v?vp?is?iqp??v??ush?s??aadp?t?r?y?wv???rqp??mlk?ihgfe?c?a", "output": "abcdefghijklmnopqrsauvwxyarutvpdaasasahsutavzvpqissiqpvzvatushasasaadpvturayxwvuasrqponmlkjihgfedcba" }, { "input": "26\n?bc?ef?hijklmnopqrst?????z?lc?z?r?zszzd?u?xc??udjppjdu????iub???szkr???cl?z??w?uts??po?m?k???gf??cba", "output": "abcaefghijklmnopqrstuawaazalcazarkzszzdbuixcvyudjppjduyvcxiubdzzszkrazaclazaawautsrqponmlkjihgfeacba" }, { "input": "26\n?b?def????????o?q???u??x????hv???pl?v?e???k??no??pp?y????k??ied??l??z?????z??w?ut??q???m?k??????dc?a", "output": "abcdefaaaakamaoaqaatuawxazaahvazaplavdeiagkjrnoysppsyonrjkgaiedvalpazavhaazaxwautaaqaoamakaaaafedcba" }, { "input": "26\nabcd?f??ijklm????rst????y??bn???jw?????v?????j?oevv??????s???y?????jy?j??zz????u????pon???????f?????", "output": "abcdafaaijklmnoparstuaaayzzbnjayjwaaaayvagshqjxoevveoxjqhsgavyaaaawjyajnbzzyaaautsraponmlkjiaafadcba" }, { "input": "26\nabcdefghijklmnopqrstuvwxyzticrsbwgheuvpptmqlpilntftnliplqmtppvuehgwbsrcitzyxwvutsrqponmlkjihgfedcba", "output": "abcdefghijklmnopqrstuvwxyzticrsbwgheuvpptmqlpilntftnliplqmtppvuehgwbsrcitzyxwvutsrqponmlkjihgfedcba" }, { "input": "26\nabcdefghijklmnopqrstuvwxyzjxeludiwenknpgqienv?myfvfympvneiqgpnknewidulexjzyxwvutsrqponmlkjihgfedcba", "output": "abcdefghijklmnopqrstuvwxyzjxeludiwenknpgqienvpmyfvfympvneiqgpnknewidulexjzyxwvutsrqponmlkjihgfedcba" }, { "input": "26\n?b?d?f?h?jk??nopqrst???xyz?u?wobc??cyr?mdmtq?r?kzbzko?oq?m?myr??yocbowwu??yx???t????o???k?i?gfedc??", "output": "abcdefghijkaanopqrstaalxyzvuwwobcoycyrymdmtqorokzbzkoroqtmdmyrycyocbowwuvzyxlaatsrqponaakjihgfedcba" }, { "input": "26\n?b??ef??i?klmn?pqrst?vwxyzmkvg?g?t?ajr?x?oe?nq???pcc?????obx???aztx?g???m?yx?vu??rq????l?ji?gf?d?ba", "output": "abadefgaijklmnapqrstuvwxyzmkvgggxtzajraxboeanqhccpcchqnaeobxarjaztxgggvkmzyxwvutsrqpanmlkjiagfedaba" }, { "input": "26\nabc??fg?i?klm?o?q?stuv?????zp?bfg?l?g??qzii?kur?bxb?ruk?iizqa???lrg??o?z???x??ut?rqpo????jihgfedcb?", "output": "abcdefghijklmaopqrstuvaxaaazpobfgrlagnaqziiwkurybxbyrukwiizqangalrgfbopzaaaxavutsrqpoamlkjihgfedcba" }, { "input": "26\n?b????g????l?????rs???????s?f?ceiww??ok????u??qwm???q?fu??wkkoh??wie??f???yx?vuts?q??nm?????g??dc??", "output": "abcdaagaaaalmnaaqrstuvaxyasafaceiwwahokkwajufpqwmzmwqpfujawkkohawwiecafasayxavutsrqaanmlaaaagaadcba" }, { "input": "26\n????e???i????no??r??????????????k?hx???z????i?qsddd?q???m??zl?d?????ehmg??yxw?????q??n??k?i??fed???", "output": "aaadefaaiakaanoaqraaaawxyaagmhebkchxdjlzptmuivqsdddsqviumtpzljdxhckbehmgaayxwaaaarqaonaakaiaafedaaa" }, { "input": "5\nabcdeeecdabbaaaeeedebedacccdebacbaeceaaeddabbaaeaccaeaabbaddeaaeceabcabedcccadebedeeeaaabbadceeedcba", "output": "abcdeeecdabbaaaeeedebedacccdebacbaeceaaeddabbaaeaccaeaabbaddeaaeceabcabedcccadebedeeeaaabbadceeedcba" }, { "input": "2\nababaaaababaaaababbaaabaabaaaabbbabaababababaaaaaaaaaaaababababaababbbaaaabaabaaabbabaaa?babaaaababa", "output": "ababaaaababaaaababbaaabaabaaaabbbabaababababaaaaaaaaaaaababababaababbbaaaabaabaaabbabaaaababaaaababa" }, { "input": "13\na?c??fghij?lmdla?ilg?d??gda?d??djc??g?afedkd?bgj?d?cj?b?dkd???igkkcj???d?????fdh?lij???mlkj?h?f??c??", "output": "aacaafghijklmdlajilghdfagdaadaadjckkgiafedkdabgjcddcjgbadkdefaigkkcjdaadaadgafdhglijaldmlkjihgfaacaa" }, { "input": "9\na?c???ghib??f????g?ee?ecc?eeg?gbih???????ccaeecggddg???e?ccbig?eh?h?bgi??eeccei?e?gb??a?cbb?hg?????a", "output": "aacaaaghibbcfaaabgaeeiecceeegigbihaheagibccaeecggddggceeaccbigaehahibgigeeecceieeagbaaafcbbihgaaacaa" }, { "input": "16\n?bcde?gh??k?mn??i?lih?aamkfi??adfep??g?b??gphekeo?a???eh??mmbo???p?f?a?b?fkm????ilcipo??lkjih??edc?a", "output": "abcdeaghijklmnopiclihaaamkfibaadfepaagobmmgphekeoaaoekehpgmmbogaapefdaabifkmaaahilciponmlkjihgaedcba" }, { "input": "24\na????fg??jk?m??p???tuvw??wk?cj??q??t?????if?s????o????n?e??i??b????qh?j??k?c?w??t?????????j???f?d???", "output": "aaadafgaajkamaapaaatuvwacwkacjahqaatabaaiifesnlrxooxrlnsefiiaabataaqhajcakwcawvutaaapaamakjaagfadaaa" }, { "input": "21\nab??????????m????r?tuure?d???kc???b?k??fhs????????????s????hfn???bt?????o????r?uts?qp??ml?????f???b?", "output": "abaaafaaaaalmaapqrstuureadaoakcaatbakanfhsaaasagijjigasaaashfnakabtaackaoadaeruutsrqpaamlaaaaafaaaba" }, { "input": "7\nabcdefggfedegbfggbfeacdddcdccbdfccaeddgcgddgcedabdbadecgddgcgddeaccfdbccdcdddcaefbggfbgedefggfedcba", "output": "abcdefggfedegbfggbfeacdddcdccbdfccaeddgcgddgcedabdbadecgddgcgddeaccfdbccdcdddcaefbggfbgedefggfedcba" }, { "input": "9\nabcdefghiiabddfhbfeaeifeibcdbbgbidbbgdhbccgdbedghdhgdebdgccbhdgbbdibgbb?cbiefieaefbhfddbaiihgfedcba", "output": "abcdefghiiabddfhbfeaeifeibcdbbgbidbbgdhbccgdbedghdhgdebdgccbhdgbbdibgbbdcbiefieaefbhfddbaiihgfedcba" }, { "input": "3\n??cb?c??ab?aaccab??cbb?abb?accbab?c?c?aba?b??ba?c???a?b?bcab????ca?a???aabba?bb??bba?c?a??acacabcb?", "output": "abcbacacabaaaccabbacbbaabbaaccbabacacaabacbabbaacacaabbabcabaacacababccaabbaabbcabbaccaaabacacabcba" }, { "input": "6\na?cdef?ecde?f??d??eeedf??e?bbdff?ecb??daeb?e?????e?aa?a?e??ade?b?eb??dbb?e?cf?e?e?b?a??ce???efe?cba", "output": "abcdefeecdecfaadbaeeedfcaeabbdffbecbaedaebeeaaaaaeaaaaaeebeadeabcebffdbbaeacfdeeeabdaafcedceefedcba" }, { "input": "19\na???efghi?k?mn?pqrshar?ib?jl?c?poh??lih?j?nr?jd????mdj??n??????s?ho????l?pb???ahsr?ponmlkji??fe?c?a", "output": "aacaefghijklmnopqrsharaibpjlacapohaslihajanrajdmaaamdjarnajahilsahopacaljpbiarahsrqponmlkjihgfeacaa" }, { "input": "26\n??cdef??i??lmn?pq??tuv???z?u????b??no??????vhv?v?w?v?vh????????????n???u?z??wv?ts????nm???ih?f???b?", "output": "abcdefahiaalmnapqastuvwaazauaaanbaanoaagjkrvhvxvywyvxvhvrkjgaaonaabnaaauazaawvutsaqpanmlaaihafedcba" }, { "input": "19\nab????g??j??????????????????g??i???q?rb?lr?rnfl?mk????n??r?j?rr??g????????mb?????rqp?n??k??????d?b?", "output": "abadaagaajkaanapqraaaaabmaaagacieghqrrbjlrornflsmkmslfnrorljbrrqhgeicagaaambaaaaarqpanaakjaagaadaba" }, { "input": "23\n?bc???gh?j?lm????rs????????v?cwqh?dh?vd????j??e??p???????k?v??vt???h?wc???l?t?vut??q??nm??????f??cba", "output": "abcaafghajalmnaaqrstuvatalavacwqhadhtvdavakjaaeioppoieaajkavadvthdahqwcavalatavutsrqaanmlajahgfaacba" }, { "input": "3\n?bc?b??ac??c?bcb?c?b?cbb????ca????c??a?c?abb?ba?aba??b?bb????a?acbb?a??ab?cbb??a?ccb??bc???ab???cba", "output": "IMPOSSIBLE" }, { "input": "22\n??cdefg?if???n????????n??ov?nq??n??ae??kl?g?????o?????fg???hi???bn?g???vo?fn?????q??nmlkj??g?????a", "output": "IMPOSSIBLE" }, { "input": "3\n?b??a??bcb??b?cc??b?b??ba?c?b?abcccaba??c??ac?bbaab?bc??bc??", "output": "abcbaacbcbaabbccaabcbaabacccbaabcccabaabcbaaccbbaabcbcaabcba" }, { "input": "18\nebcdefghijknmnodqroohmcicajbcikaiibrghrcccroprabiagegbjhcickhopmqponmakjnhgfedcbg", "output": "IMPOSSIBLE" }, { "input": "9\nf??e?f", "output": "IMPOSSIBLE" }, { "input": "25\no??p?nd?ff?yxy??oa?l?j??o?g??of??ilgaor??x?i??udncp???", "output": "IMPOSSIBLE" }, { "input": "5\na?e?c?", "output": "IMPOSSIBLE" }, { "input": "13\neb?iklf?hk?eikiik?e?khbfl?i?be", "output": "IMPOSSIBLE" }, { "input": "23\nnkcip???????cn??cco?i??n", "output": "IMPOSSIBLE" }, { "input": "26\n??tnlrco?b?lsvpvsl??voc?l?t?c", "output": "IMPOSSIBLE" }, { "input": "18\nl??e?l??el?????hadq??le?p??ed??", "output": "IMPOSSIBLE" }, { "input": "17\nhdhjqblhfcf?phjoeiieojhp?fc?hlbqjhdh", "output": "IMPOSSIBLE" }, { "input": "12\ncgcbabdhiejjeihdbabcgc", "output": "IMPOSSIBLE" }, { "input": "19\ncspcnshermeaangqpkc??c?bsn?jons?qcdcckpqgn?aemrehsncpsc", "output": "IMPOSSIBLE" }, { "input": "16\n?????????????????g???????b????", "output": "IMPOSSIBLE" }, { "input": "21\n??c??????????i???q???????????n?????????", "output": "IMPOSSIBLE" }, { "input": "26\n??????????k?????????????????????vp????????l????l????", "output": "IMPOSSIBLE" }, { "input": "25\n???e???k?d?v?????????????c??????????????????o???????????????????", "output": "aaaeaaakadavbfghijlomnpqrcstuwxyyxwutscrqpnmoljihgfbvadakaaaeaaa" }, { "input": "5\ne??e???????????????e?????????????????e?????????????a????????????????????????????b????????", "output": "IMPOSSIBLE" }, { "input": "13\n???b?????????????????????????????????????????????????????", "output": "aaabaaaaaaaaaaaaaacdefghijklmlkjihgfedcaaaaaaaaaaaaaabaaa" }, { "input": "9\nhbe??ec??????????", "output": "IMPOSSIBLE" }, { "input": "2\n??????", "output": "aabbaa" }, { "input": "1\na", "output": "a" }, { "input": "3\n????????", "output": "aabccbaa" }, { "input": "3\n????????????????????????????????????????", "output": "aaaaaaaaaaaaaaaaaabccbaaaaaaaaaaaaaaaaaa" }, { "input": "2\n??????????????????????????????????????????????????????????????????????????????????????????", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "4\nb???c?c???b", "output": "baaacdcaaab" }, { "input": "5\na???????????????????a", "output": "aaaaaaabcdedcbaaaaaaa" }, { "input": "5\nacde????edca", "output": "acdeabbaedca" }, { "input": "3\nb????????????????????b", "output": "baaaaaaaaaccaaaaaaaaab" } ]
248
20,172,800
3.900425
36,929
840
On the Bench
[ "combinatorics", "dp" ]
null
null
A year ago on the bench in public park Leha found an array of *n* numbers. Leha believes that permutation *p* is right if for all 1<=≀<=*i*<=&lt;<=*n* condition, that *a**p**i*Β·*a**p**i*<=+<=1 is not perfect square, holds. Leha wants to find number of right permutations modulo 109<=+<=7.
First line of input data contains single integer *n* (1<=≀<=*n*<=≀<=300) β€” length of the array. Next line contains *n* integers *a*1,<=*a*2,<=... ,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” found array.
Output single integer β€” number of right permutations modulo 109<=+<=7.
[ "3\n1 2 4\n", "7\n5 2 4 2 4 1 1\n" ]
[ "2\n", "144\n" ]
For first example: [1, 2, 4] β€” right permutation, because 2 and 8 are not perfect squares. [1, 4, 2] β€” wrong permutation, because 4 is square of 2. [2, 1, 4] β€” wrong permutation, because 4 is square of 2. [2, 4, 1] β€” wrong permutation, because 4 is square of 2. [4, 1, 2] β€” wrong permutation, because 4 is square of 2. [4, 2, 1] β€” right permutation, because 8 and 2 are not perfect squares.
[ { "input": "3\n1 2 4", "output": "2" }, { "input": "7\n5 2 4 2 4 1 1", "output": "144" }, { "input": "10\n3 1 1 2 1 3 4 4 1 4", "output": "0" }, { "input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393", "output": "714022784" }, { "input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52", "output": "714022784" } ]
93
307,200
-1
37,039
288
Polo the Penguin and Trees
[ "combinatorics", "dfs and similar", "trees" ]
null
null
Little penguin Polo has got a tree β€” a non-directed connected acyclic graph, containing *n* nodes and *n*<=-<=1 edges. We will consider the tree nodes numbered by integers from 1 to *n*. Today Polo wonders, how to find the number of pairs of paths that don't have common nodes. More formally, he should find the number of groups of four integers *a*,<=*b*,<=*c* and *d* such that: - 1<=≀<=*a*<=&lt;<=*b*<=≀<=*n*; - 1<=≀<=*c*<=&lt;<=*d*<=≀<=*n*; - there's no such node that lies on both the shortest path from node *a* to node *b* and from node *c* to node *d*. The shortest path betweem two nodes is the path that is shortest in the number of edges. Help Polo solve this problem.
The first line contains integer *n* (1<=≀<=*n*<=≀<=80000) β€” the number of tree nodes. Each of the following *n*<=-<=1 lines contains a pair of integers *u**i* and *v**i* (1<=≀<=*u**i*,<=*v**i*<=≀<=*n*;Β *u**i*<=β‰ <=*v**i*) β€” the *i*-th edge of the tree. It is guaranteed that the given graph is a tree.
In a single line print a single integer β€” the answer to the problem. Please do not use the %lld specificator to read or write 64-bit numbers in Π‘++. It is recommended to use the cin, cout streams or the %I64d specificator.
[ "4\n1 2\n2 3\n3 4\n" ]
[ "2\n" ]
none
[]
1,340
58,060,800
-1
37,062
208
Blood Cousins
[ "binary search", "data structures", "dfs and similar", "trees" ]
null
null
Polycarpus got hold of a family relationship tree. The tree describes family relationships of *n* people, numbered 1 through *n*. Each person in the tree has no more than one parent. Let's call person *a* a 1-ancestor of person *b*, if *a* is the parent of *b*. Let's call person *a* a *k*-ancestor (*k*<=&gt;<=1) of person *b*, if person *b* has a 1-ancestor, and *a* is a (*k*<=-<=1)-ancestor of *b*'s 1-ancestor. Family relationships don't form cycles in the found tree. In other words, there is no person who is his own ancestor, directly or indirectly (that is, who is an *x*-ancestor for himself, for some *x*, *x*<=&gt;<=0). Let's call two people *x* and *y* (*x*<=β‰ <=*y*) *p*-th cousins (*p*<=&gt;<=0), if there is person *z*, who is a *p*-ancestor of *x* and a *p*-ancestor of *y*. Polycarpus wonders how many counsins and what kinds of them everybody has. He took a piece of paper and wrote *m* pairs of integers *v**i*, *p**i*. Help him to calculate the number of *p**i*-th cousins that person *v**i* has, for each pair *v**i*, *p**i*.
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of people in the tree. The next line contains *n* space-separated integers *r*1,<=*r*2,<=...,<=*r**n*, where *r**i* (1<=≀<=*r**i*<=≀<=*n*) is the number of person *i*'s parent or 0, if person *i* has no parent. It is guaranteed that family relationships don't form cycles. The third line contains a single number *m* (1<=≀<=*m*<=≀<=105) β€” the number of family relationship queries Polycarus has. Next *m* lines contain pairs of space-separated integers. The *i*-th line contains numbers *v**i*, *p**i* (1<=≀<=*v**i*,<=*p**i*<=≀<=*n*).
Print *m* space-separated integers β€” the answers to Polycarpus' queries. Print the answers to the queries in the order, in which the queries occur in the input.
[ "6\n0 1 1 0 4 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1\n" ]
[ "0 0 1 0 0 1 1 \n" ]
none
[ { "input": "6\n0 1 1 0 4 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "output": "0 0 1 0 0 1 1 " }, { "input": "1\n0\n20\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "2\n0 1\n20\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 1\n1 1\n1 1\n2 1\n1 1\n2 1\n2 1\n2 1\n1 1\n2 1\n2 1\n1 1\n1 1\n2 1", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "3\n0 0 2\n20\n2 1\n1 1\n1 1\n2 1\n2 1\n1 1\n3 1\n1 1\n2 1\n1 1\n3 1\n2 1\n3 1\n1 1\n3 1\n1 1\n2 1\n3 1\n1 1\n2 1", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "3\n0 0 1\n20\n3 1\n1 1\n3 1\n1 1\n3 1\n1 1\n3 1\n1 1\n3 1\n1 1\n3 1\n1 1\n2 1\n3 1\n2 1\n3 1\n1 1\n1 1\n1 1\n2 1", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "4\n0 1 1 0\n20\n3 1\n1 1\n1 1\n3 1\n4 1\n3 1\n3 1\n4 1\n2 1\n1 1\n4 1\n4 1\n2 1\n2 1\n3 1\n4 1\n4 1\n1 1\n2 1\n4 1", "output": "1 0 0 1 0 1 1 0 1 0 0 0 1 1 1 0 0 0 1 0 " }, { "input": "4\n0 0 0 1\n20\n2 1\n2 1\n3 1\n2 1\n4 1\n3 1\n1 1\n3 1\n2 1\n2 1\n3 1\n1 1\n1 1\n1 1\n2 1\n4 1\n4 1\n3 1\n1 1\n2 1", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " } ]
1,466
109,772,800
3
37,083
81
Polycarp's Picture Gallery
[ "constructive algorithms", "greedy" ]
D. Polycarp's Picture Gallery
2
256
Polycarp loves not only to take pictures, but also to show his photos to friends. On his personal website he has recently installed a widget that can display *n* photos with the scroll option. At each moment of time the widget displays exactly one photograph with the option showing the previous/next one. From the first photo, you can switch to the second one or to the *n*-th one, from the second photo you can switch to the third one or to the first one, etc. Thus, navigation is performed in a cycle. Polycarp's collection consists of *m* photo albums, the *i*-th album contains *a**i* photos. Polycarp wants to choose *n* photos and put them on a new widget. To make watching the photos interesting to the visitors, he is going to post pictures so that no two photos from one album were neighboring (each photo will have exactly two neighbors, the first photo's neighbors are the second and the *n*-th one). Help Polycarp compile a photo gallery. Select *n* photos from his collection and put them in such order that no two photos from one album went one after the other.
The first line contains two integers *n* and *m* (3<=≀<=*n*<=≀<=1000, 1<=≀<=*m*<=≀<=40), where *n* is the number of photos on the widget, and *m* is the number of albums. The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≀<=*a**i*<=≀<=1000), where *a**i* is the number of photos in the *i*-th album.
Print the single number -1 if there is no solution. Otherwise, print *n* numbers *t*1,<=*t*2,<=...,<=*t**n*, where *t**i* represents the number of the album of the *i*-th picture in the widget. The albums are numbered from 1 in the order of their appearance in the input. If there are several solutions, print any of them.
[ "4 3\n1 3 5\n", "10 2\n5 5\n", "10 3\n1 10 3\n" ]
[ "3 1 3 2\n", "2 1 2 1 2 1 2 1 2 1\n", "-1\n" ]
none
[]
186
0
0
37,196
505
Mr. Kitayuta's Technology
[ "dfs and similar" ]
null
null
Shuseki Kingdom is the world's leading nation for innovation and technology. There are *n* cities in the kingdom, numbered from 1 to *n*. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, that is, a teleportation pipe from city *x* to city *y* cannot be used to travel from city *y* to city *x*. The transportation within each city is extremely developed, therefore if a pipe from city *x* to city *y* and a pipe from city *y* to city *z* are both constructed, people will be able to travel from city *x* to city *z* instantly. Mr. Kitayuta is also involved in national politics. He considers that the transportation between the *m* pairs of city (*a**i*,<=*b**i*) (1<=≀<=*i*<=≀<=*m*) is important. He is planning to construct teleportation pipes so that for each important pair (*a**i*,<=*b**i*), it will be possible to travel from city *a**i* to city *b**i* by using one or more teleportation pipes (but not necessarily from city *b**i* to city *a**i*). Find the minimum number of teleportation pipes that need to be constructed. So far, no teleportation pipe has been constructed, and there is no other effective transportation between cities.
The first line contains two space-separated integers *n* and *m* (2<=≀<=*n*<=≀<=105,<=1<=≀<=*m*<=≀<=105), denoting the number of the cities in Shuseki Kingdom and the number of the important pairs, respectively. The following *m* lines describe the important pairs. The *i*-th of them (1<=≀<=*i*<=≀<=*m*) contains two space-separated integers *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*,<=*a**i*<=β‰ <=*b**i*), denoting that it must be possible to travel from city *a**i* to city *b**i* by using one or more teleportation pipes (but not necessarily from city *b**i* to city *a**i*). It is guaranteed that all pairs (*a**i*,<=*b**i*) are distinct.
Print the minimum required number of teleportation pipes to fulfill Mr. Kitayuta's purpose.
[ "4 5\n1 2\n1 3\n1 4\n2 3\n2 4\n", "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4\n" ]
[ "3\n", "4\n" ]
For the first sample, one of the optimal ways to construct pipes is shown in the image below: For the second sample, one of the optimal ways is shown below:
[ { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "output": "3" }, { "input": "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4", "output": "4" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "3" }, { "input": "3 6\n1 2\n1 3\n2 1\n2 3\n3 1\n3 2", "output": "3" }, { "input": "8 12\n6 1\n7 5\n2 5\n4 1\n6 3\n4 3\n5 7\n1 3\n5 2\n2 7\n4 6\n7 2", "output": "6" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "10 4\n8 4\n9 8\n2 8\n8 1", "output": "4" }, { "input": "8 7\n6 3\n2 4\n3 7\n8 2\n4 8\n7 6\n3 2", "output": "6" }, { "input": "10 10\n10 6\n9 4\n7 8\n1 5\n3 10\n2 1\n4 9\n5 2\n10 3\n6 3", "output": "9" }, { "input": "7 8\n4 6\n2 1\n2 5\n7 4\n7 1\n7 2\n1 4\n2 4", "output": "5" }, { "input": "9 10\n6 4\n7 5\n9 3\n7 6\n4 8\n4 2\n9 8\n1 3\n5 1\n4 7", "output": "9" }, { "input": "10 4\n7 4\n6 8\n2 3\n3 8", "output": "4" }, { "input": "7 13\n6 1\n7 2\n3 7\n6 5\n3 6\n7 4\n3 5\n4 1\n3 1\n1 5\n1 6\n6 2\n2 4", "output": "7" }, { "input": "5 7\n4 3\n2 5\n2 1\n3 2\n1 3\n3 4\n1 4", "output": "5" }, { "input": "6 7\n5 4\n3 1\n4 2\n2 1\n5 2\n2 3\n2 6", "output": "5" }, { "input": "9 5\n5 8\n7 4\n7 2\n9 8\n9 5", "output": "4" }, { "input": "5 4\n2 5\n4 3\n5 2\n5 1", "output": "4" }, { "input": "7 7\n7 3\n5 4\n4 7\n5 7\n6 3\n5 6\n3 4", "output": "5" }, { "input": "8 5\n3 1\n7 5\n2 5\n8 6\n1 3", "output": "5" }, { "input": "5 3\n4 2\n2 1\n5 4", "output": "3" } ]
62
0
0
37,206
573
Bear and Bowling
[ "data structures", "greedy" ]
null
null
Limak is an old brown bear. He often goes bowling with his friends. Today he feels really good and tries to beat his own record! For rolling a ball one gets a score β€” an integer (maybe negative) number of points. Score for *i*-th roll is multiplied by *i* and scores are summed up. So, for *k* rolls with scores *s*1,<=*s*2,<=...,<=*s**k*, total score is . Total score is 0 if there were no rolls. Limak made *n* rolls and got score *a**i* for *i*-th of them. He wants to maximize his total score and he came up with an interesting idea. He will cancel some rolls, saying that something distracted him or there was a strong wind. Limak is able to cancel any number of rolls, maybe even all or none of them. Total score is calculated as if there were only non-canceled rolls. Look at the sample tests for clarification. What maximum total score can Limak get?
The first line contains single integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≀<=107) - scores for Limak's rolls.
Print the maximum possible total score after choosing rolls to cancel.
[ "5\n-2 -8 0 5 -3\n", "6\n-10 20 -30 40 -50 60\n" ]
[ "13\n", "400\n" ]
In first sample Limak should cancel rolls with scores  - 8 and  - 3. Then he is left with three rolls with scores  - 2, 0, 5. Total score is 1Β·( - 2) + 2Β·0 + 3Β·5 = 13. In second sample Limak should cancel roll with score  - 50. Total score is 1Β·( - 10) + 2Β·20 + 3Β·( - 30) + 4Β·40 + 5Β·60 = 400.
[]
46
0
-1
37,321
79
Beaver
[ "data structures", "dp", "greedy", "hashing", "strings", "two pointers" ]
C. Beaver
2
256
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string *s*, and she tried to remember the string *s* correctly. However, Ciel feels *n* strings *b*1,<=*b*2,<=... ,<=*b**n* are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of *s*. Determine the longest contiguous substring of *s* that does not contain any boring string, so that she can remember the longest part of Taro's response.
In the first line there is a string *s*. The length of *s* will be between 1 and 105, inclusive. In the second line there is a single integer *n* (1<=≀<=*n*<=≀<=10). Next *n* lines, there is a string *b**i* (1<=≀<=*i*<=≀<=*n*). Each length of *b**i* will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
Output in the first line two space-separated integers *len* and *pos*: the length of the longest contiguous substring of *s* that does not contain any *b**i*, and the first position of the substring (0-indexed). The position *pos* must be between 0 and |*s*|<=-<=*len* inclusive, where |*s*| is the length of string *s*. If there are several solutions, output any.
[ "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse\n", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd\n", "unagioisii\n2\nioi\nunagi\n" ]
[ "12 4\n", "0 0\n", "5 5\n" ]
In the first sample, the solution is traight_alon. In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on. In the third sample, the solution is either nagio or oisii.
[ { "input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "output": "12 4" }, { "input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "output": "0 0" }, { "input": "unagioisii\n2\nioi\nunagi", "output": "5 5" }, { "input": "abcabcabcabc\n3\nabcabca\nbcab\ncabc", "output": "4 6" }, { "input": "ThankYouForParticipatingRound71\n6\nForP\noun\nnkYouForP\nTha\nouForP\nound7", "output": "18 9" }, { "input": "WishYourSolutionPassesFinalTests\n10\nrSoluti\ninal\nolutionPas\nassesFin\nourSo\nonP\nWishYourSo\nsFinalTes\nhYourSolut\nonPas", "output": "9 15" }, { "input": "9\n1\n9", "output": "0 0" }, { "input": "Z\n1\na", "output": "1 0" }, { "input": "12abcdefghijklmnop\n10\nabcd\nabc\nab\na\nklmn\nlmn\nmn\nn\nop\n12", "output": "12 3" }, { "input": "12abcdefghijklmnop\n10\na\nop\nab\nabc\nabcd\nn\nmn\n12\nlmn\nklmn", "output": "12 3" }, { "input": "12abcdefghijklmnop\n10\nlmn\nabc\na\nklmn\nn\nabcd\nop\nmn\nab\n12", "output": "12 3" }, { "input": "x5x5\n10\nx5\nx5x\nx5x5\nx5\nx5\nQyBa0yZO_c\n_troGKxtGQ\nRItOLVC3ok\niD_57rFYR1\nvZhgXwTnE4", "output": "2 1" }, { "input": "aaaay\n10\naa\naa\naaa\nay\naaay\ndltfBoU4nF\nYhImrXw62Y\nwswb4v7CRb\npjxxEE3S26\nwxDxW1MRaI", "output": "1 4" }, { "input": "iiiiii\n10\nii\niiii\niiiii\niii\niiii\n5avjcwIsDh\nGgiVQ9ylRz\newWmNAJAL9\nk83baq5H2U\nXRX3fJ4dH8", "output": "1 5" }, { "input": "ffBBfBB\n10\nBBfB\nffBBfB\nffBBf\nffBBf\nBfB\n1ehoxM6CU8\ntvB4q05iuU\nEYGkY6VxQO\nbKbE2ajjBW\nhqTKbQUZds", "output": "4 1" }, { "input": "aaUUUUaa\n10\naUUU\naaU\naUU\nUUUU\nUU\neV1R6e2tCQ\nmwseAsylFZ\njkfXnCVagR\nRGPm9O09J8\nVBRpGUFrDB", "output": "3 5" }, { "input": "1111e1e1e\n10\n11\n1111e\n1111\ne1e1e\n1e1\npuCrQxcVPh\nfnbEroh3w4\nyie11ihNIi\n2_23hx3yX9\noPKXwByQLT", "output": "3 6" }, { "input": "aMaMaMMaaM\n10\nMMaaM\nMMaaM\naa\naMaMMaa\nMaMa\nWoEVf7UuGQ\n2q8cm0_WfI\nZR63WSVBlC\ndtO9nmkXsc\ntHL2amBqOS", "output": "6 2" }, { "input": "NNNIIIIIINN\n10\nNNIIIIIIN\nIIIINN\nIIIINN\nNNIIIII\nNNII\nlHJxS_HfkO\nPsss2tjeao\nY4Adt_8FXb\nkc9mq2vWmZ\nVJYusUjoTq", "output": "8 2" }, { "input": "cCCcCCCcCccc\n10\ncC\nCCcCCCcCc\nCCcC\ncCc\ncCCC\npUKBhDtW8W\n0ap4vlgGej\nk059r28XMJ\nySQTZIOz3r\nFHn5rVpM8G", "output": "4 8" }, { "input": "7hh77hhhhhh7h\n10\nhhhh7\nhh77hhhhh\n7hhhhh\nhh7\nh77hhhhhh7\nC_t1uIxLWp\nHwH5EkVGCt\nyUgWASGwfR\nRfah5Fa12E\nS9CmGvTVKM", "output": "7 2" }, { "input": "3cc3\n10\ncc\nc3\n3c\ncc\ncc\n3cc3\n3cc3\n3cc\nc3\njLnOy3kI3M", "output": "1 3" }, { "input": "70aa70a\n10\n70\n0aa70\n0aa70\naa70\n70aa\n70aa\n70aa70a\naa7\n70aa7\nicHuodu1Ux", "output": "3 1" }, { "input": "YUYEYEUUEU\n10\nYEYEUUEU\nEUUE\nUU\nYEYEUUE\nYEYE\nUU\nEY\nEYEUU\nYEYEUU\niBXoTbQ7X3", "output": "4 0" }, { "input": "wwwwDwwwwD\n10\nwD\nDwww\nwD\nDwwww\nwwwwD\nDww\nwD\nwwDww\nwwww\nwwww", "output": "3 6" }, { "input": "4tg4ttgg47t44tg4ttgg47t4\n10\n47t44tg4tt\nttgg4\ng4ttgg47t4\ng47t44t\ntg4ttg\n44tg4ttg\nttgg47\nt44tg\ng47t44tg\n4ttgg47t4", "output": "8 5" }, { "input": "g0sg00AAA0Asggss0sAg0sg00AAA0Asggss0sA\n10\nAg0sg00AAA\nAsggss\nsAg\nAsggss0s\nggss0sAg\nsAg0sg\nggss0sA\n0sg00AA\nAAA0A\nAA0", "output": "8 18" }, { "input": "000gooo0g0vgovvv0oggv0v0go000gooo0g0vgovvv0oggv0v0go\n10\ngv0v0go\n0gooo0g\ngooo0g0v\no000\ngooo0g0v\nv0go000go\ngo000gooo0\nv0v0go00\nvv\nggv0v0", "output": "10 30" }, { "input": "B2KR\n10\nB2\n2KR\nB2KR\n2K\n2KR\nKR\n2KR\nB2KR\n2K\n2KR", "output": "1 3" }, { "input": "dxY_8\n10\nxY_8\ndxY\ndx\nY_\nxY_\ndx\nxY\ndx\nxY_8\ndxY", "output": "2 3" }, { "input": "umi4qX\n10\nqX\num\n4qX\nqX\numi4qX\numi4\numi4\numi4q\nmi4q\numi4q", "output": "3 2" }, { "input": "4stuNRe\n10\n4stu\nstuN\nstuNRe\n4stu\ntuNRe\nst\ntuNR\n4stuN\ntuN\n4stu", "output": "4 3" }, { "input": "bTnstTqbTnstTq\n10\nbTnstTq\nnstTqbT\nTqbT\nbTns\nTqbT\nTns\nTnstT\nTnstTqb\nnstT\nstT", "output": "4 6" }, { "input": "Oq02utSVOq02utSV\n10\n2utSVOq\n2utSVO\n02utS\nSVOq0\nut\nOq\nOq\nq02utSVO\nOq02utSV\nVOq0", "output": "4 9" }, { "input": "DpGGt6_wGLPDpGGt6_wGLP\n10\n6_wGL\nGLPDpGG\nt6_wG\nPDpGGt6_\nwGLPDpGGt6\n6_\n_wGL\npGGt6_\n6_wGLPD\n6_wGLPDpG", "output": "8 9" }, { "input": "7QTfE4ALvzkzzD4j7QTfE4ALvzkzzD4j\n10\nvzkzzD4j7\nE4AL\nTfE4ALv\nzzD4j7QT\nzkzzD4j7\n4AL\nj7Q\nE4ALvzkzzD\nvzkzzD4j\n4ALvzk", "output": "9 22" }, { "input": "6CLznedj88834gqTIhMTPjm_3DbkQpuYkBvU3o55h79ntRqjHTOu3WWNNGLyQSZ_o45mK5mMtRJmWUq2twqWP10OlnDAB1EP2rG\n10\n834gqTI\n_o4\nvU3o55h79n\nvLwlk3PY7Z\nk8PnkBpRYB\nqdkB9b_SS2\nkY4mBeAdgK\nb577cjQiSx\nyOFiEkP1sD\noYOqd8uuTt", "output": "35 64" }, { "input": "JroK3tfp941zeUovVIqCV7Sv2elf6TN8QRl8mhxQWgoQRXOLkcUjK29Ed2gBDR1TLdZeLUi9zJyBayrNlWgW0iPSG26DuJ9QK95\n10\nroK\novVI\nLUi9\nLUi\nTLd\nelf6\n9zJyBa\nDR1\ndZe\n8mhxQWgo", "output": "27 72" }, { "input": "p7B41t9y83IghcJG8zgWzCSATkkvQQhvqm7j_4ffUPbriGW57mbGPzqiuMEmJevfIhX2FNLFBxAGm3vLXRPOdphoWkCquDjAsW9\n10\n1t9y83\nBxAGm3v\nG8z\nCSATk\ncJG\nIhX2FNLF\nzqiuME\np7B4\nkkvQ\nPbriGW57m", "output": "26 73" }, { "input": "r5oW1NW2kr193KwV_eASuj9Jq0q0Kmt2EUD1R72p2nPuxNpIqi7o_KuxldYjLJmiXj93JUxRTniFzKkXxHwXDZCzC76klFnfjAQ\n10\np2nPuxN\n93J\nNpIqi7o_K\niXj93JUxRT\n1NW2kr19\n0Kmt2EUD1\nTniFzKkXxH\niXj93JU\nNW2kr19\n3KwV_", "output": "26 73" }, { "input": "hb\n1\nAa", "output": "2 0" }, { "input": "unagioisiiqqqqqqqqqqqq\n2\nioi\nunagi", "output": "17 5" }, { "input": "abababab\n3\nab\nba\na", "output": "1 7" }, { "input": "abcdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n2\nabcd\nabcd", "output": "50 1" }, { "input": "abababababababababababababababababababababababababababababab\n1\na", "output": "1 59" }, { "input": "abc\n2\na\nb", "output": "1 2" }, { "input": "abcde\n1\nf", "output": "5 0" }, { "input": "ahmed\n5\nahmed\nhmed\nmed\ned\nd", "output": "4 0" }, { "input": "abc\n1\nb", "output": "1 2" } ]
310
4,608,000
0
37,408
725
Contest Balloons
[ "data structures", "greedy" ]
null
null
One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there are seven teams with more balloons, you get the eight place. Ties are allowed. You should know that it's important to eat before a contest. If the number of balloons of a team is greater than the weight of this team, the team starts to float in the air together with their workstation. They eventually touch the ceiling, what is strictly forbidden by the rules. The team is then disqualified and isn't considered in the standings. A contest has just finished. There are *n* teams, numbered 1 through *n*. The *i*-th team has *t**i* balloons and weight *w**i*. It's guaranteed that *t**i* doesn't exceed *w**i* so nobody floats initially. Limak is a member of the first team. He doesn't like cheating and he would never steal balloons from other teams. Instead, he can give his balloons away to other teams, possibly making them float. Limak can give away zero or more balloons of his team. Obviously, he can't give away more balloons than his team initially has. What is the best place Limak can get?
The first line of the standard input contains one integer *n* (2<=≀<=*n*<=≀<=300<=000)Β β€” the number of teams. The *i*-th of *n* following lines contains two integers *t**i* and *w**i* (0<=≀<=*t**i*<=≀<=*w**i*<=≀<=1018)Β β€” respectively the number of balloons and the weight of the *i*-th team. Limak is a member of the first team.
Print one integer denoting the best place Limak can get.
[ "8\n20 1000\n32 37\n40 1000\n45 50\n16 16\n16 16\n14 1000\n2 1000\n", "7\n4 4\n4 4\n4 4\n4 4\n4 4\n4 4\n5 5\n", "7\n14000000003 1000000000000000000\n81000000000 88000000000\n5000000000 7000000000\n15000000000 39000000000\n46000000000 51000000000\n0 1000000000\n0 0\n" ]
[ "3\n", "2\n", "2\n" ]
In the first sample, Limak has 20 balloons initially. There are three teams with more balloons (32, 40 and 45 balloons), so Limak has the fourth place initially. One optimal strategy is: 1. Limak gives 6 balloons away to a team with 32 balloons and weight 37, which is just enough to make them fly. Unfortunately, Limak has only 14 balloons now and he would get the fifth place.1. Limak gives 6 balloons away to a team with 45 balloons. Now they have 51 balloons and weight 50 so they fly and get disqualified.1. Limak gives 1 balloon to each of two teams with 16 balloons initially.1. Limak has 20 - 6 - 6 - 1 - 1 = 6 balloons.1. There are three other teams left and their numbers of balloons are 40, 14 and 2.1. Limak gets the third place because there are two teams with more balloons. In the second sample, Limak has the second place and he can't improve it. In the third sample, Limak has just enough balloons to get rid of teams 2, 3 and 5 (the teams with 81 000 000 000, 5 000 000 000 and 46 000 000 000 balloons respectively). With zero balloons left, he will get the second place (ex-aequo with team 6 and team 7).
[ { "input": "8\n20 1000\n32 37\n40 1000\n45 50\n16 16\n16 16\n14 1000\n2 1000", "output": "3" }, { "input": "7\n4 4\n4 4\n4 4\n4 4\n4 4\n4 4\n5 5", "output": "2" }, { "input": "7\n14000000003 1000000000000000000\n81000000000 88000000000\n5000000000 7000000000\n15000000000 39000000000\n46000000000 51000000000\n0 1000000000\n0 0", "output": "2" }, { "input": "2\n100 150\n5 100000", "output": "1" }, { "input": "9\n4 70\n32 56\n32 65\n77 78\n5 29\n72 100\n0 55\n42 52\n66 72", "output": "7" }, { "input": "3\n1 2\n12 19\n25 45", "output": "3" }, { "input": "5\n2 23\n1 13\n3 9\n0 20\n6 7", "output": "3" }, { "input": "10\n19 22\n10 77\n3 52\n16 42\n25 67\n14 42\n44 85\n37 39\n36 62\n6 85", "output": "4" }, { "input": "15\n143 698\n269 879\n100 728\n86 855\n368 478\n174 368\n442 980\n812 825\n121 220\n137 198\n599 706\n423 586\n96 647\n177 439\n54 620", "output": "9" }, { "input": "3\n1000 1000\n1001 1001\n700 1000000", "output": "1" }, { "input": "5\n4 100\n10 11\n10 11\n3 3\n3 3", "output": "2" } ]
3,000
57,446,400
0
37,473
42
Strange town
[ "constructive algorithms", "math" ]
D. Strange town
2
256
Volodya has recently visited a very odd town. There are *N* tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price (natural number) assigned to it and all prices are distinct. But the most striking thing about this town is that each city sightseeing tour has the same total price! That is, if we choose any city sightseeing tour β€” a cycle which visits every attraction exactly once β€” the sum of the costs of the tour roads is independent of the tour. Volodya is curious if you can find such price system with all road prices not greater than 1000.
Input contains just one natural number (3<=≀<=*N*<=≀<=20) β€” the number of town attractions.
Output should contain *N* rows containing *N* positive integer numbers each β€” the adjacency matrix of the prices graph (thus, *j*-th number in *i*-th row should be equal to the price of the road between the *j*-th and the *i*-th attraction). Diagonal numbers should be equal to zero. All numbers should not be greater than 1000. All prices should be positive and pairwise distinct. If there are several solutions, output any of them.
[ "3\n" ]
[ "0 3 4 \n3 0 5 \n4 5 0 \n" ]
none
[ { "input": "3", "output": "0 3 4 \n3 0 5 \n4 5 0 " }, { "input": "4", "output": "0 3 4 6 \n3 0 5 7 \n4 5 0 8 \n6 7 8 0 " }, { "input": "5", "output": "0 3 4 6 9 \n3 0 5 7 10 \n4 5 0 8 11 \n6 7 8 0 13 \n9 10 11 13 0 " }, { "input": "6", "output": "0 3 4 6 9 14 \n3 0 5 7 10 15 \n4 5 0 8 11 16 \n6 7 8 0 13 18 \n9 10 11 13 0 21 \n14 15 16 18 21 0 " }, { "input": "7", "output": "0 3 4 6 9 14 22 \n3 0 5 7 10 15 23 \n4 5 0 8 11 16 24 \n6 7 8 0 13 18 26 \n9 10 11 13 0 21 29 \n14 15 16 18 21 0 34 \n22 23 24 26 29 34 0 " }, { "input": "8", "output": "0 3 4 6 9 14 22 31 \n3 0 5 7 10 15 23 32 \n4 5 0 8 11 16 24 33 \n6 7 8 0 13 18 26 35 \n9 10 11 13 0 21 29 38 \n14 15 16 18 21 0 34 43 \n22 23 24 26 29 34 0 51 \n31 32 33 35 38 43 51 0 " }, { "input": "9", "output": "0 3 4 6 9 14 22 31 40 \n3 0 5 7 10 15 23 32 41 \n4 5 0 8 11 16 24 33 42 \n6 7 8 0 13 18 26 35 44 \n9 10 11 13 0 21 29 38 47 \n14 15 16 18 21 0 34 43 52 \n22 23 24 26 29 34 0 51 60 \n31 32 33 35 38 43 51 0 69 \n40 41 42 44 47 52 60 69 0 " }, { "input": "10", "output": "0 3 4 6 9 14 22 31 40 54 \n3 0 5 7 10 15 23 32 41 55 \n4 5 0 8 11 16 24 33 42 56 \n6 7 8 0 13 18 26 35 44 58 \n9 10 11 13 0 21 29 38 47 61 \n14 15 16 18 21 0 34 43 52 66 \n22 23 24 26 29 34 0 51 60 74 \n31 32 33 35 38 43 51 0 69 83 \n40 41 42 44 47 52 60 69 0 92 \n54 55 56 58 61 66 74 83 92 0 " }, { "input": "11", "output": "0 3 4 6 9 14 22 31 40 54 75 \n3 0 5 7 10 15 23 32 41 55 76 \n4 5 0 8 11 16 24 33 42 56 77 \n6 7 8 0 13 18 26 35 44 58 79 \n9 10 11 13 0 21 29 38 47 61 82 \n14 15 16 18 21 0 34 43 52 66 87 \n22 23 24 26 29 34 0 51 60 74 95 \n31 32 33 35 38 43 51 0 69 83 104 \n40 41 42 44 47 52 60 69 0 92 113 \n54 55 56 58 61 66 74 83 92 0 127 \n75 76 77 79 82 87 95 104 113 127 0 " }, { "input": "12", "output": "0 3 4 6 9 14 22 31 40 54 75 96 \n3 0 5 7 10 15 23 32 41 55 76 97 \n4 5 0 8 11 16 24 33 42 56 77 98 \n6 7 8 0 13 18 26 35 44 58 79 100 \n9 10 11 13 0 21 29 38 47 61 82 103 \n14 15 16 18 21 0 34 43 52 66 87 108 \n22 23 24 26 29 34 0 51 60 74 95 116 \n31 32 33 35 38 43 51 0 69 83 104 125 \n40 41 42 44 47 52 60 69 0 92 113 134 \n54 55 56 58 61 66 74 83 92 0 127 148 \n75 76 77 79 82 87 95 104 113 127 0 169 \n96 97 98 100 103 108 116 125 134 148 169 0 " }, { "input": "13", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 \n3 0 5 7 10 15 23 32 41 55 76 97 130 \n4 5 0 8 11 16 24 33 42 56 77 98 131 \n6 7 8 0 13 18 26 35 44 58 79 100 133 \n9 10 11 13 0 21 29 38 47 61 82 103 136 \n14 15 16 18 21 0 34 43 52 66 87 108 141 \n22 23 24 26 29 34 0 51 60 74 95 116 149 \n31 32 33 35 38 43 51 0 69 83 104 125 158 \n40 41 42 44 47 52 60 69 0 92 113 134 167 \n54 55 56 58 61 66 74 83 92 0 127 148 181 \n75 76 77 79 82 87 95 104 113 127 0 169 202 \n96 97 98 100 103 108 116 125 134 148 169 0 223 \n129 130 131..." }, { "input": "14", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 \n31 32 33 35 38 43 51 0 69 83 104 125 158 182 \n40 41 42 44 47 52 60 69 0 92 113 134 167 191 \n54 55 56 58 61 66 74 83 92 0 127 148 181 205 \n75 76 77 79 82 87 95 104 113 127 0 169 202 226 \n96 97 98 100 103..." }, { "input": "15", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 183 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 184 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 185 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 187 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 190 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 195 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 203 \n31 32 33 35 38 43 51 0 69 83 104 125 158 182 212 \n40 41 42 44 47 52 60 69 0 92 113 134 167 191 221 \n54 55 56 58 61 66 74 83 92 0 127 148 181 205 235 \n75 76 77 79 82 87 95 104 ..." }, { "input": "16", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 183 213 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 184 214 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 185 215 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 187 217 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 190 220 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 195 225 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 203 233 \n31 32 33 35 38 43 51 0 69 83 104 125 158 182 212 242 \n40 41 42 44 47 52 60 69 0 92 113 134 167 191 221 251 \n54 55 56 58 61 66 74 83 92 0 127 148 181..." }, { "input": "17", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 183 213 259 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 184 214 260 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 185 215 261 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 187 217 263 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 190 220 266 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 195 225 271 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 203 233 279 \n31 32 33 35 38 43 51 0 69 83 104 125 158 182 212 242 288 \n40 41 42 44 47 52 60 69 0 92 113 134 167 191 221 251 297 \n54 5..." }, { "input": "18", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 183 213 259 317 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 184 214 260 318 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 185 215 261 319 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 187 217 263 321 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 190 220 266 324 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 195 225 271 329 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 203 233 279 337 \n31 32 33 35 38 43 51 0 69 83 104 125 158 182 212 242 288 346 \n40 41 42 44 47 52 60 69 0 92 11..." }, { "input": "19", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 183 213 259 317 375 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 184 214 260 318 376 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 185 215 261 319 377 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 187 217 263 321 379 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 190 220 266 324 382 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 195 225 271 329 387 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 203 233 279 337 395 \n31 32 33 35 38 43 51 0 69 83 104 125 158 182 212 242 288 346 404 \n..." }, { "input": "20", "output": "0 3 4 6 9 14 22 31 40 54 75 96 129 153 183 213 259 317 375 414 \n3 0 5 7 10 15 23 32 41 55 76 97 130 154 184 214 260 318 376 415 \n4 5 0 8 11 16 24 33 42 56 77 98 131 155 185 215 261 319 377 416 \n6 7 8 0 13 18 26 35 44 58 79 100 133 157 187 217 263 321 379 418 \n9 10 11 13 0 21 29 38 47 61 82 103 136 160 190 220 266 324 382 421 \n14 15 16 18 21 0 34 43 52 66 87 108 141 165 195 225 271 329 387 426 \n22 23 24 26 29 34 0 51 60 74 95 116 149 173 203 233 279 337 395 434 \n31 32 33 35 38 43 51 0 69 83 104 125 1..." } ]
30
0
0
37,511
286
Shifting
[ "implementation" ]
null
null
John Doe has found the beautiful permutation formula. Let's take permutation *p*<==<=*p*1,<=*p*2,<=...,<=*p**n*. Let's define transformation *f* of this permutation: where *k* (*k*<=&gt;<=1) is an integer, the transformation parameter, *r* is such maximum integer that *rk*<=≀<=*n*. If *rk*<==<=*n*, then elements *p**rk*<=+<=1,<=*p**rk*<=+<=2 and so on are omitted. In other words, the described transformation of permutation *p* cyclically shifts to the left each consecutive block of length *k* and the last block with the length equal to the remainder after dividing *n* by *k*. John Doe thinks that permutation *f*(*f*(Β ...Β *f*(*p*<==<=[1,<=2,<=...,<=*n*],<=2)Β ...Β ,<=*n*<=-<=1),<=*n*) is beautiful. Unfortunately, he cannot quickly find the beautiful permutation he's interested in. That's why he asked you to help him. Your task is to find a beautiful permutation for the given *n*. For clarifications, see the notes to the third sample.
A single line contains integer *n* (2<=≀<=*n*<=≀<=106).
Print *n* distinct space-separated integers from 1 to *n* β€” a beautiful permutation of size *n*.
[ "2\n", "3\n", "4\n" ]
[ "2 1 \n", "1 3 2 \n", "4 2 3 1 \n" ]
A note to the third test sample: - *f*([1, 2, 3, 4], 2) = [2, 1, 4, 3] - *f*([2, 1, 4, 3], 3) = [1, 4, 2, 3] - *f*([1, 4, 2, 3], 4) = [4, 2, 3, 1]
[]
62
0
0
37,602
884
Bertown Subway
[ "dfs and similar", "greedy", "math" ]
null
null
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station. Its destination station is *p**i*, possibly *p**i*<==<=*i*; 1. For each station *i* there exists exactly one station *j* such that *p**j*<==<=*i*. The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (*x*,<=*y*) such that person can start at station *x* and, after taking some subway trains (possibly zero), arrive at station *y* (1<=≀<=*x*,<=*y*<=≀<=*n*). The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of *p**i* for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes. The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!
The first line contains one integer number *n* (1<=≀<=*n*<=≀<=100000) β€” the number of stations. The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≀<=*p**i*<=≀<=*n*) β€” the current structure of the subway. All these numbers are distinct.
Print one number β€” the maximum possible value of convenience.
[ "3\n2 1 3\n", "5\n1 5 4 3 2\n" ]
[ "9\n", "17\n" ]
In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3). In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<sub class="lower-index">3</sub> to 5.
[ { "input": "3\n2 1 3", "output": "9" }, { "input": "5\n1 5 4 3 2", "output": "17" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 2", "output": "4" }, { "input": "2\n2 1", "output": "4" }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "5416" }, { "input": "5\n1 4 2 3 5", "output": "17" }, { "input": "6\n5 3 6 1 4 2", "output": "36" }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "82" }, { "input": "20\n1 6 15 9 18 17 7 8 3 19 2 13 11 12 14 4 5 20 16 10", "output": "326" }, { "input": "3\n1 2 3", "output": "5" } ]
46
716,800
-1
37,669
105
Dark Assembly
[ "brute force", "probabilities" ]
B. Dark Assembly
2
256
Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed. The Dark Assembly consists of *n* senators. Each of them is characterized by his level and loyalty to the player. The level is a positive integer which reflects a senator's strength. Loyalty is the probability of a positive decision in the voting, which is measured as a percentage with precision of up to 10%. Senators make decisions by voting. Each of them makes a positive or negative decision in accordance with their loyalty. If strictly more than half of the senators take a positive decision, the player's proposal is approved. If the player's proposal is not approved after the voting, then the player may appeal against the decision of the Dark Assembly. To do that, player needs to kill all the senators that voted against (there's nothing wrong in killing senators, they will resurrect later and will treat the player even worse). The probability that a player will be able to kill a certain group of senators is equal to *A*<=/<=(*A*<=+<=*B*), where *A* is the sum of levels of all player's characters and *B* is the sum of levels of all senators in this group. If the player kills all undesired senators, then his proposal is approved. Senators are very fond of sweets. They can be bribed by giving them candies. For each received candy a senator increases his loyalty to the player by 10%. It's worth to mention that loyalty cannot exceed 100%. The player can take no more than *k* sweets to the courtroom. Candies should be given to the senators before the start of voting. Determine the probability that the Dark Assembly approves the player's proposal if the candies are distributed among the senators in the optimal way.
The first line contains three integers *n*, *k* and *A* (1<=≀<=*n*,<=*k*<=≀<=8, 1<=≀<=*A*<=≀<=9999). Then *n* lines follow. The *i*-th of them contains two numbers β€” *b**i* and *l**i* β€” the *i*-th senator's level and his loyalty. The levels of all senators are integers in range from 1 to 9999 (inclusive). The loyalties of all senators are integers in range from 0 to 100 (inclusive) and all of them are divisible by 10.
Print one real number with precision 10<=-<=6 β€” the maximal possible probability that the Dark Assembly approves the player's proposal for the best possible distribution of candies among the senators.
[ "5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70\n", "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70\n", "1 3 20\n20 20\n" ]
[ "1.0000000000\n", "0.9628442962\n", "0.7500000000\n" ]
In the first sample the best way of candies' distribution is giving them to first three of the senators. It ensures most of votes. It the second sample player should give all three candies to the fifth senator.
[ { "input": "5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70", "output": "1.0000000000" }, { "input": "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70", "output": "0.9628442962" }, { "input": "1 3 20\n20 20", "output": "0.7500000000" }, { "input": "4 3 40\n10 40\n11 50\n10 50\n9 50", "output": "0.7721162701" }, { "input": "4 4 60\n10 40\n11 50\n10 50\n12 30", "output": "0.8031237097" }, { "input": "2 7 20\n10 40\n10 50", "output": "0.8733333333" }, { "input": "2 1 25\n10 40\n12 50", "output": "0.7329105397" }, { "input": "3 3 31\n10 40\n12 50\n15 0", "output": "0.6940741814" }, { "input": "1 3 40\n10 0", "output": "0.8600000000" }, { "input": "1 4 30\n10 20", "output": "0.9000000000" }, { "input": "1 7 10\n40 40", "output": "1.0000000000" }, { "input": "1 8 1\n1000 100", "output": "1.0000000000" }, { "input": "1 1 1\n9999 0", "output": "0.1000900000" }, { "input": "1 1 9999\n1 0", "output": "0.9999100000" }, { "input": "2 4 345\n323 40\n234 20", "output": "0.6289385114" }, { "input": "2 7 43\n3435 90\n6443 0", "output": "0.6327854764" }, { "input": "8 8 10\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0", "output": "0.5829886291" }, { "input": "5 5 1000\n2 90\n5 60\n13 70\n80 30\n1024 70", "output": "0.9950914339" }, { "input": "8 8 1\n6776 80\n2346 70\n7890 30\n4567 90\n9032 30\n8092 80\n1567 90\n5678 80", "output": "1.0000000000" }, { "input": "8 1 1\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0", "output": "0.0000126797" }, { "input": "8 1 9999\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0", "output": "0.9992105456" }, { "input": "8 8 686\n654 100\n15 100\n954 100\n14 100\n9601 100\n986 100\n236 100\n1 100", "output": "1.0000000000" }, { "input": "8 8 9999\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0\n9999 0", "output": "0.1237784500" }, { "input": "8 8 1\n1 90\n2 0\n3 80\n4 0\n5 80\n6 0\n7 80\n8 90", "output": "1.0000000000" }, { "input": "8 7 1\n1 90\n2 0\n3 80\n4 0\n5 80\n6 0\n7 80\n8 90", "output": "0.9071428571" }, { "input": "8 7 1\n1 90\n2 70\n3 80\n4 10\n5 80\n6 50\n7 80\n8 90", "output": "0.9874642857" }, { "input": "8 8 1\n1 90\n2 50\n3 80\n4 70\n5 80\n6 70\n7 80\n8 90", "output": "1.0000000000" }, { "input": "1 1 2910\n1 80", "output": "0.9999656475" }, { "input": "1 2 240\n5 20", "output": "0.9877551020" }, { "input": "1 3 734\n3 0", "output": "0.9971506106" }, { "input": "2 1 7316\n3 0\n8 20", "output": "0.9988261248" }, { "input": "2 2 843\n2 30\n3 20", "output": "0.9962225651" }, { "input": "3 1 4887\n5 60\n9 80\n6 40", "output": "0.9992612205" }, { "input": "3 2 1446\n8 60\n3 0\n2 50", "output": "0.9969756430" }, { "input": "2 8 2218\n2 10\n1 40", "output": "0.9996395665" }, { "input": "5 3 128\n15 50\n19 0\n17 20\n12 20\n17 10", "output": "0.7071002446" }, { "input": "8 8 2899\n3701 20\n5168 80\n7885 60\n4696 80\n1798 90\n7545 80\n5414 80\n4851 30", "output": "0.9806726602" }, { "input": "8 7 2965\n593 60\n2963 20\n4016 60\n3076 100\n780 0\n8207 40\n6093 0\n6609 50", "output": "0.4380079393" }, { "input": "8 6 4614\n7484 90\n758 70\n146 80\n1455 100\n1344 50\n7286 90\n6773 50\n8366 70", "output": "0.9950379538" }, { "input": "8 5 4680\n4376 20\n8552 30\n6276 0\n9834 0\n327 70\n7948 50\n7452 100\n8542 100", "output": "0.4717698635" }, { "input": "8 4 6328\n1268 50\n6348 80\n2406 20\n8214 0\n9308 90\n7027 10\n8132 20\n300 10", "output": "0.3102731277" }, { "input": "8 3 6395\n8159 90\n4143 50\n6954 50\n5011 20\n9872 10\n7689 90\n8811 70\n2058 10", "output": "0.5175644027" }, { "input": "8 2 6461\n5051 10\n1938 100\n3084 70\n3391 40\n8854 30\n6769 30\n1073 0\n3815 40", "output": "0.3586379660" }, { "input": "8 1 8109\n1944 40\n9732 40\n9214 80\n1770 40\n7837 50\n7430 100\n1753 30\n3991 60", "output": "0.6441514424" } ]
2,000
4,915,200
0
37,731
41
Pawn
[ "dp" ]
D. Pawn
2
256
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having collected as many peas as possible. As there it will have to divide the peas between itself and its *k* brothers, the number of peas must be divisible by *k*<=+<=1. Find the maximal number of peas it will be able to collect and which moves it should make to do it. The pawn cannot throw peas away or leave the board. When a pawn appears in some square of the board (including the first and last square of the way), it necessarily takes all the peas.
The first line contains three integers *n*, *m*, *k* (2<=≀<=*n*,<=*m*<=≀<=100,<=0<=≀<=*k*<=≀<=10) β€” the number of rows and columns on the chessboard, the number of the pawn's brothers. Then follow *n* lines containing each *m* numbers from 0 to 9 without spaces β€” the chessboard's description. Each square is described by one number β€” the number of peas in it. The first line corresponds to the uppermost row and the last line β€” to the lowest row.
If it is impossible to reach the highest row having collected the number of peas divisible by *k*<=+<=1, print -1. Otherwise, the first line must contain a single number β€” the maximal number of peas the pawn can collect given that the number must be divisible by *k*<=+<=1. The second line must contain a single number β€” the number of the square's column in the lowest row, from which the pawn must start its journey. The columns are numbered from the left to the right with integral numbers starting from 1. The third line must contain a line consisting of *n*<=-<=1 symbols β€” the description of the pawn's moves. If the pawn must move upwards and leftwards, print L, if it must move upwards and rightwards, print R. If there are several solutions to that problem, print any of them.
[ "3 3 1\n123\n456\n789\n", "3 3 0\n123\n456\n789\n", "2 2 10\n98\n75\n" ]
[ "16\n2\nRL\n", "17\n3\nLR\n", "-1\n" ]
none
[ { "input": "3 3 1\n123\n456\n789", "output": "16\n2\nRL" }, { "input": "3 3 0\n123\n456\n789", "output": "17\n3\nLR" }, { "input": "2 2 10\n98\n75", "output": "-1" }, { "input": "3 4 2\n8244\n4768\n4474", "output": "18\n3\nLR" }, { "input": "4 3 10\n194\n707\n733\n633", "output": "22\n3\nLLR" }, { "input": "5 6 0\n564132\n152314\n382748\n956060\n261008", "output": "31\n2\nLRRL" }, { "input": "2 4 2\n3916\n9593", "output": "18\n3\nL" }, { "input": "5 5 6\n78237\n84658\n09523\n48007\n70591", "output": "21\n3\nRLLL" }, { "input": "6 6 0\n962504\n555826\n306365\n336593\n304184\n461978", "output": "42\n4\nRLLLL" }, { "input": "7 7 8\n9178611\n1154936\n5736233\n3683401\n5972844\n1538360\n8915609", "output": "45\n4\nLLRLRR" }, { "input": "10 5 5\n57903\n23822\n16074\n14758\n17503\n85862\n22741\n24624\n91349\n59483", "output": "60\n5\nLLRLLRLRL" }, { "input": "3 10 5\n5982103711\n7068791203\n1573073434", "output": "18\n4\nLL" }, { "input": "22 13 9\n8184281791532\n5803370774001\n6603582781635\n2483939348867\n0830296902280\n3551639607305\n3444831623227\n3091545622824\n6913003961993\n3133646154943\n1940360624827\n6753210603109\n0151850545919\n3740837541625\n5803839641354\n8646937392812\n0603155734470\n7315747209948\n5161762550888\n5911134989142\n5126602312630\n9357303282764", "output": "140\n11\nLLLLLLRRLLRRRLRLLRRRL" }, { "input": "14 23 8\n68504025976030072501641\n56458987321578480010382\n46062870778554718112548\n81908609966761024372750\n76848590874509200408274\n37285110415074847067321\n66805521560779398220121\n50385391753925080239043\n49514980743485792107357\n72577075816570740728649\n39689681512498117328584\n91073140452682825237396\n40514188871545939304976\n13697029058487784430451", "output": "99\n8\nLLLLRLLRRRRRR" }, { "input": "23 2 6\n00\n47\n52\n36\n01\n01\n39\n04\n69\n93\n77\n72\n33\n95\n13\n50\n23\n48\n79\n98\n05\n63\n17", "output": "-1" }, { "input": "23 2 6\n00\n47\n52\n36\n01\n01\n39\n04\n69\n93\n77\n72\n33\n95\n13\n50\n23\n48\n79\n98\n05\n63\n17", "output": "-1" }, { "input": "2 2 3\n15\n52", "output": "-1" }, { "input": "2 2 0\n02\n64", "output": "8\n1\nR" }, { "input": "2 2 9\n82\n68", "output": "-1" }, { "input": "40 10 1\n3662957315\n8667652926\n0833069659\n7030124763\n0285674766\n3253847205\n3183518599\n6584668288\n6016531609\n4094512804\n8169065529\n5526028299\n1251249986\n3970729176\n7534232301\n4643554614\n8544233598\n3618335000\n4458737272\n2014874848\n2052050286\n2523863039\n3367463306\n7570627477\n6504863662\n5673627493\n9683553049\n5087433832\n4895351652\n8976415673\n7744852982\n8880573285\n8601062585\n9914945591\n6101306342\n4477024828\n6711693809\n9518645171\n0320790840\n1660676034", "output": "258\n7\nLLRRRRLRLRLRRLLLLLRLLRLRRRRRRLRLLLLRLLR" }, { "input": "100 2 7\n18\n70\n19\n42\n74\n37\n47\n43\n71\n66\n25\n64\n60\n45\n90\n54\n38\n35\n92\n79\n19\n94\n76\n61\n30\n49\n95\n72\n57\n05\n71\n10\n18\n40\n63\n01\n75\n44\n65\n47\n27\n37\n84\n30\n06\n15\n55\n19\n49\n00\n80\n77\n20\n78\n33\n67\n29\n20\n98\n28\n19\n00\n42\n88\n11\n58\n57\n69\n58\n92\n90\n73\n65\n09\n85\n08\n93\n83\n38\n54\n41\n20\n66\n99\n41\n01\n91\n91\n39\n60\n66\n82\n77\n25\n02\n55\n32\n64\n56\n30", "output": "-1" }, { "input": "100 3 4\n644\n861\n478\n250\n560\n998\n141\n162\n386\n778\n123\n811\n602\n533\n391\n515\n898\n215\n965\n556\n446\n883\n256\n195\n573\n889\n515\n240\n179\n339\n258\n593\n930\n730\n735\n949\n522\n067\n549\n366\n452\n405\n473\n188\n488\n994\n000\n046\n930\n217\n897\n580\n509\n032\n343\n722\n176\n925\n728\n717\n851\n925\n901\n665\n469\n029\n264\n801\n841\n196\n415\n923\n390\n832\n322\n616\n074\n238\n927\n350\n952\n060\n575\n355\n307\n971\n787\n796\n822\n080\n265\n609\n389\n851\n533\n061\n424\n517\n498\n623", "output": "545\n1\nRLRRLLRRLLRLRLRRLLRLRRLLRLRLRRLLRRLLRLRLRLRLRRLLRRLRLLRRLRLRLRLLRLRLRRLLRRLRLLRRLRLLRLRLRRLRLLRLRLR" }, { "input": "2 100 7\n9360286883185741015657297578030499122983212716269549322423994405864643235893094083435861617948832932\n6890233971690210653206070772331643207659524060492980513060276541348578771750981091169346350950048601", "output": "16\n92\nL" }, { "input": "3 100 2\n9274856291089022402330510299964972078374631084698909589848378120688833406094439833480605688734822538\n8559432619222401260831250315191045571941748630289435997646309147962549951488150729159571611224761557\n7459677994197468453434072563284883271493313149578657711970598092555372522009834711876673556425273784", "output": "27\n9\nRL" }, { "input": "4 100 8\n8197214719753093689382933229185566015858043325014460546254750743412353547105592762535428651419733324\n9148500337546694884364549640851337857223054489296090301133259534376331231215539538042806982497493773\n8861823647111079235007692880873989283264269770396047900111206380618089276133969173551645794471217161\n7380214222723596011942700126524470827522028978818427297837353995903366375498632353149447411505503535", "output": "27\n91\nLLL" }, { "input": "3 10 0\n1230000123\n4560000456\n7890000789", "output": "17\n10\nLR" }, { "input": "100 2 1\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99", "output": "900\n2\nLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL" }, { "input": "2 100 5\n9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "18\n100\nL" }, { "input": "100 2 8\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00", "output": "0\n2\nLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL" }, { "input": "2 100 2\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "0\n100\nL" } ]
122
5,836,800
0
37,762
855
Harry Vs Voldemort
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
After destroying all of Voldemort's Horcruxes, Harry and Voldemort are up for the final battle. They each cast spells from their wands and the spells collide. The battle scene is Hogwarts, which can be represented in the form of a tree. There are, in total, *n* places in Hogwarts joined using *n*<=-<=1 undirected roads. Ron, who was viewing this battle between Harry and Voldemort, wondered how many triplets of places (*u*,<=*v*,<=*w*) are there such that if Harry is standing at place *u* and Voldemort is standing at place *v*, their spells collide at a place *w*. This is possible for a triplet only when *u*, *v* and *w* are distinct, and there exist paths from *u* to *w* and from *v* to *w* which do not pass through the same roads. Now, due to the battle havoc, new paths are being added all the time. You have to tell Ron the answer after each addition. Formally, you are given a tree with *n* vertices and *n*<=-<=1 edges. *q* new edges are being added between the nodes of the tree. After each addition you need to tell the number of triplets (*u*,<=*v*,<=*w*) such that *u*, *v* and *w* are distinct and there exist two paths, one between *u* and *w*, another between *v* and *w* such that these paths do not have an edge in common.
First line contains an integer *n* (1<=≀<=*n*<=≀<=105), the number of places in Hogwarts. Each of the next *n*<=-<=1 lines contains two space separated integers *u* and *v* (1<=≀<=*u*,<=*v*<=≀<=*n*) indicating a road between places *u* and *v*. It is guaranteed that the given roads form a connected tree. Next line contains a single integer *q* (1<=≀<=*q*<=≀<=105), the number of new edges being added. Each of the next *q* lines contains two space separated integers *u* and *v* (1<=≀<=*u*,<=*v*<=≀<=*n*) representing the new road being added. Note that it is possible that a newly added road connects places that were connected by a road before. Also, a newly added road may connect a place to itself.
In the first line print the value for the number of triplets before any changes occurred. After that print *q* lines, a single integer *ans**i* in each line containing the value for the number of triplets after *i*-th edge addition.
[ "3\n1 2\n2 3\n1\n2 3\n", "4\n1 2\n2 3\n2 4\n2\n1 4\n3 4\n", "5\n1 2\n2 3\n3 4\n4 5\n1\n1 5\n" ]
[ "2\n4\n", "6\n18\n24\n", "20\n60\n" ]
In the first sample case, for the initial tree, we have (1, 3, 2) and (3, 1, 2) as the only possible triplets (*u*, *v*, *w*). After addition of edge from 2 to 3, we have (1, 3, 2), (3, 1, 2), (1, 2, 3) and (2, 1, 3) as the possible triplets.
[]
31
0
0
37,790
241
Race
[ "brute force", "implementation" ]
null
null
The Old City is a rectangular city represented as an *m*<=Γ—<=*n* grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the streets have width of one block and are either vertical or horizontal. There is a junction on both sides of each street. We call two blocks adjacent if and only if they share a common side. No two blocks of different streets are adjacent and no two junctions are adjacent. There is an annual festival and as a part of it, The Old Peykan follows a special path in the city. This path starts from a block in a street, continues with many junctions and ends in a block of some street. For each street block, we know how much time it takes for the Old Peykan to go from this block to an adjacent block. Also the Old Peykan can go from each junction to its adjacent street blocks in one minute. Of course Old Peykan can't go to building blocks. We know the initial position of the Old Peykan and the sequence of junctions that it passes to reach its destination. After passing all the junctions and reaching the destination, it will stay there forever. Your task is to find out where will the Old Peykan be *k* minutes after it starts moving. Consider that The Old Peykan always follows the shortest path that passes through the given sequence of junctions and reaches the destination. Note that the Old Peykan may visit some blocks more than once.
The first line of input contains three integers *m*, *n* and *k* (3<=≀<=*m*,<=*n*<=≀<=100,<=1<=≀<=*k*<=≀<=100000). Next *m* lines are representing the city's map. Each of them containts *n* characters, each character is a block: - Character "#" represents a building. - Digits "1", "2", ..., "9" represent a block of an street and this digit means the number of minutes it takes for the Old Peykan to pass this block. - Characters "a", "b", ..., "z" means that this block is a junction and this character is it's name. All the junction names are unique. Consider that all blocks have the coordinates: the *j*-th in the *i*-th line have coordinates (*i*,<=*j*) (1<=≀<=*i*<=≀<=*m*,<=1<=≀<=*j*<=≀<=*n*). The (*m*<=+<=2)th line contains two integers *r**s* and *c**s* (1<=≀<=*r**s*<=≀<=*m*,<=1<=≀<=*c**s*<=≀<=*n*), string *s* and another two integers *r**e* and *c**e* (1<=≀<=*r**e*<=≀<=*m*,<=1<=≀<=*c**e*<=≀<=*n*). The path starts from block (*r**s*,<=*c**s*), continues through junctions in the order that is specified by *s* and will end in block (*r**e*,<=*c**e*). Length of *s* is between 1 and 1000. It's guaranteed that string *s* denotes a correct path from the start position to the end position and string *s* doesn't contain two consecutive equal letters. Also start position (*r**s*,<=*c**s*) and the end position (*r**e*,<=*c**e*) are street blocks.
In a single line print two integers *r**f* and *c**f* β€” (*r**f*,<=*c**f*) being the position of the Old Peykan after exactly *k* minutes.
[ "3 10 12\n##########\n#z1a1111b#\n##########\n2 3 ab 2 8\n", "10 3 5\n###\n#w#\n#1#\n#a#\n#1#\n#1#\n#1#\n#1#\n#b#\n###\n3 2 abababababababab 6 2\n", "3 10 6\n##########\n#z1a1311b#\n##########\n2 3 ab 2 8\n" ]
[ "2 8\n", "8 2\n", "2 7\n" ]
none
[ { "input": "3 10 12\n##########\n#z1a1111b#\n##########\n2 3 ab 2 8", "output": "2 8" }, { "input": "10 3 5\n###\n#w#\n#1#\n#a#\n#1#\n#1#\n#1#\n#1#\n#b#\n###\n3 2 abababababababab 6 2", "output": "8 2" }, { "input": "3 10 6\n##########\n#z1a1311b#\n##########\n2 3 ab 2 8", "output": "2 7" }, { "input": "14 14 187\n##############\n##############\n##############\n##############\n#####a5284b7c#\n#####1####7#7#\n#####d4343e1f#\n##########9#5#\n##########8#3#\n##########9#3#\n##########8#4#\n##########g1h#\n##############\n##############\n6 11 efcfedadabedadadegh 10 13", "output": "10 13" }, { "input": "20 20 244\n####################\n###########a96b449c#\n###########5##6###1#\n###########1##2###6#\n###########7##1###7#\n###########3##4###2#\n###########1##1###5#\n###########d47e679f#\n####################\n####################\n####################\n####################\n####################\n####################\n####################\n####################\n####################\n####################\n####################\n####################\n4 15 bcfefcbebcfcbabebab 2 13", "output": "2 15" }, { "input": "20 20 387\n####################\n####################\n####################\n####################\n####################\n########a7b32137c###\n########7#8#####1###\n########8#7#####8###\n########8#1#####4###\n########5#5#####8###\n########d6e69515f###\n########5#5#####7###\n########2#5#####1###\n########7#3#####8###\n########6#8#####4###\n########8#8#####4###\n########g6h82878i###\n####################\n####################\n####################\n15 11 efifihedadebcfihgda 6 10", "output": "16 9" } ]
154
2,150,400
3
37,832
526
Pudding Monsters
[ "data structures", "divide and conquer" ]
null
null
In this problem you will meet the simplified model of game Pudding Monsters. An important process in developing any game is creating levels. A game field in Pudding Monsters is an *n*<=Γ—<=*n* rectangular grid, *n* of its cells contain monsters and some other cells contain game objects. The gameplay is about moving the monsters around the field. When two monsters are touching each other, they glue together into a single big one (as they are from pudding, remember?). Statistics showed that the most interesting maps appear if initially each row and each column contains exactly one monster and the rest of map specifics is set up by the correct positioning of the other game objects. A technique that's widely used to make the development process more efficient is reusing the available resources. For example, if there is a large *n*<=Γ—<=*n* map, you can choose in it a smaller *k*<=Γ—<=*k* square part, containing exactly *k* monsters and suggest it as a simplified version of the original map. You wonder how many ways there are to choose in the initial map a *k*<=Γ—<=*k* (1<=≀<=*k*<=≀<=*n*) square fragment, containing exactly *k* pudding monsters. Calculate this number.
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=3<=Γ—<=105) β€” the size of the initial field. Next *n* lines contain the coordinates of the cells initially containing monsters. The *i*-th of the next lines contains two numbers *r**i*,<=*c**i* (1<=≀<=*r**i*,<=*c**i*<=≀<=*n*) β€” the row number and the column number of the cell that initially contains the *i*-th monster. It is guaranteed that all *r**i* are distinct numbers and all *c**i* are distinct numbers.
Print the number of distinct square fragments of the original field that can form a new map.
[ "5\n1 1\n4 3\n3 2\n2 4\n5 5\n" ]
[ "10\n" ]
none
[]
30
0
0
37,873
282
Painting Eggs
[ "greedy", "math" ]
null
null
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.
[ "2\n1 999\n999 1\n", "3\n400 600\n400 600\n400 600\n" ]
[ "AG\n", "AGA\n" ]
none
[ { "input": "2\n1 999\n999 1", "output": "AG" }, { "input": "3\n400 600\n400 600\n400 600", "output": "AGA" }, { "input": "2\n500 500\n500 500", "output": "AG" }, { "input": "1\n1 999", "output": "A" }, { "input": "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999", "output": "AAAAAAAAAA" }, { "input": "2\n499 501\n501 499", "output": "AG" }, { "input": "3\n500 500\n1 999\n400 600", "output": "AGA" }, { "input": "1\n0 1000", "output": "A" }, { "input": "1\n500 500", "output": "A" }, { "input": "1\n1000 0", "output": "G" } ]
3,898
156,057,600
3
37,986