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
0
none
[ "none" ]
null
null
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's interval. When Liss occupies the interval [*k*<=-<=*d*,<=*k*<=+<=*d*] and a stone falls to *k*, she will escape to the left or to the right. If she escapes to the left, her new interval will be [*k*<=-<=*d*,<=*k*]. If she escapes to the right, her new interval will be [*k*,<=*k*<=+<=*d*]. You are given a string *s* of length *n*. If the *i*-th character of *s* is "l" or "r", when the *i*-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the *n* stones falls.
The input consists of only one line. The only line contains the string *s* (1<=≀<=|*s*|<=≀<=106). Each character in *s* will be either "l" or "r".
Output *n* lines β€” on the *i*-th line you should print the *i*-th stone's number from the left.
[ "llrlr\n", "rrlll\n", "lrlrr\n" ]
[ "3\n5\n4\n2\n1\n", "1\n2\n5\n4\n3\n", "2\n4\n5\n3\n1\n" ]
In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1.
[ { "input": "llrlr", "output": "3\n5\n4\n2\n1" }, { "input": "rrlll", "output": "1\n2\n5\n4\n3" }, { "input": "lrlrr", "output": "2\n4\n5\n3\n1" }, { "input": "lllrlrllrl", "output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1" }, { "input": "llrlrrrlrr", "output": "3\n5\n6\n7\n9\n10\n8\n4\n2\n1" }, { "input": "rlrrrllrrr", "output": "1\n3\n4\n5\n8\n9\n10\n7\n6\n2" }, { "input": "lrrlrrllrrrrllllllrr", "output": "2\n3\n5\n6\n9\n10\n11\n12\n19\n20\n18\n17\n16\n15\n14\n13\n8\n7\n4\n1" }, { "input": "rlrrrlrrrllrrllrlrll", "output": "1\n3\n4\n5\n7\n8\n9\n12\n13\n16\n18\n20\n19\n17\n15\n14\n11\n10\n6\n2" }, { "input": "lllrrlrlrllrrrrrllrl", "output": "4\n5\n7\n9\n12\n13\n14\n15\n16\n19\n20\n18\n17\n11\n10\n8\n6\n3\n2\n1" }, { "input": "rrrllrrrlllrlllrlrrr", "output": "1\n2\n3\n6\n7\n8\n12\n16\n18\n19\n20\n17\n15\n14\n13\n11\n10\n9\n5\n4" }, { "input": "rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrrlrlrllrlrlrrlrrllrrrlrlrlllrrllllrl", "output": "1\n2\n6\n7\n8\n10\n11\n13\n14\n15\n19\n21\n23\n24\n25\n29\n32\n33\n36\n39\n40\n42\n44\n45\n50\n52\n53\n54\n55\n57\n61\n63\n64\n65\n67\n69\n72\n74\n76\n77\n79\n80\n83\n84\n85\n87\n89\n93\n94\n99\n100\n98\n97\n96\n95\n92\n91\n90\n88\n86\n82\n81\n78\n75\n73\n71\n70\n68\n66\n62\n60\n59\n58\n56\n51\n49\n48\n47\n46\n43\n41\n38\n37\n35\n34\n31\n30\n28\n27\n26\n22\n20\n18\n17\n16\n12\n9\n5\n4\n3" }, { "input": "llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrrrrrlllrrlrrrrrlrrrlrlrlrrlllllrrrrllrrlrlrrrllllrlrrlrrlrlrrll", "output": "3\n5\n9\n10\n13\n18\n20\n21\n23\n25\n26\n29\n31\n33\n34\n36\n37\n38\n39\n40\n41\n45\n46\n48\n49\n50\n51\n52\n54\n55\n56\n58\n60\n62\n63\n69\n70\n71\n72\n75\n76\n78\n80\n81\n82\n87\n89\n90\n92\n93\n95\n97\n98\n100\n99\n96\n94\n91\n88\n86\n85\n84\n83\n79\n77\n74\n73\n68\n67\n66\n65\n64\n61\n59\n57\n53\n47\n44\n43\n42\n35\n32\n30\n28\n27\n24\n22\n19\n17\n16\n15\n14\n12\n11\n8\n7\n6\n4\n2\n1" }, { "input": "llrrrrllrrlllrlrllrlrllllllrrrrrrrrllrrrrrrllrlrrrlllrrrrrrlllllllrrlrrllrrrllllrrlllrrrlrlrrlrlrllr", "output": "3\n4\n5\n6\n9\n10\n14\n16\n19\n21\n28\n29\n30\n31\n32\n33\n34\n35\n38\n39\n40\n41\n42\n43\n46\n48\n49\n50\n54\n55\n56\n57\n58\n59\n67\n68\n70\n71\n74\n75\n76\n81\n82\n86\n87\n88\n90\n92\n93\n95\n97\n100\n99\n98\n96\n94\n91\n89\n85\n84\n83\n80\n79\n78\n77\n73\n72\n69\n66\n65\n64\n63\n62\n61\n60\n53\n52\n51\n47\n45\n44\n37\n36\n27\n26\n25\n24\n23\n22\n20\n18\n17\n15\n13\n12\n11\n8\n7\n2\n1" }, { "input": "lllllrllrrlllrrrllrrrrlrrlrllllrrrrrllrlrllllllrrlrllrlrllrlrrlrlrrlrrrlrrrrllrlrrrrrrrllrllrrlrllrl", "output": "6\n9\n10\n14\n15\n16\n19\n20\n21\n22\n24\n25\n27\n32\n33\n34\n35\n36\n39\n41\n48\n49\n51\n54\n56\n59\n61\n62\n64\n66\n67\n69\n70\n71\n73\n74\n75\n76\n79\n81\n82\n83\n84\n85\n86\n87\n90\n93\n94\n96\n99\n100\n98\n97\n95\n92\n91\n89\n88\n80\n78\n77\n72\n68\n65\n63\n60\n58\n57\n55\n53\n52\n50\n47\n46\n45\n44\n43\n42\n40\n38\n37\n31\n30\n29\n28\n26\n23\n18\n17\n13\n12\n11\n8\n7\n5\n4\n3\n2\n1" }, { "input": "llrlrlrlrlrlrrlllllllrllllrllrrrlllrrllrllrrlllrrlllrlrrllllrrlllrrllrrllllrrlllrlllrrrllrrrrrrllrrl", "output": "3\n5\n7\n9\n11\n13\n14\n22\n27\n30\n31\n32\n36\n37\n40\n43\n44\n48\n49\n53\n55\n56\n61\n62\n66\n67\n70\n71\n76\n77\n81\n85\n86\n87\n90\n91\n92\n93\n94\n95\n98\n99\n100\n97\n96\n89\n88\n84\n83\n82\n80\n79\n78\n75\n74\n73\n72\n69\n68\n65\n64\n63\n60\n59\n58\n57\n54\n52\n51\n50\n47\n46\n45\n42\n41\n39\n38\n35\n34\n33\n29\n28\n26\n25\n24\n23\n21\n20\n19\n18\n17\n16\n15\n12\n10\n8\n6\n4\n2\n1" }, { "input": "l", "output": "1" }, { "input": "r", "output": "1" } ]
1,107
29,388,800
3
2,944
375
Maximum Submatrix 2
[ "data structures", "dp", "implementation", "sortings" ]
null
null
You are given a matrix consisting of digits zero and one, its size is *n*<=Γ—<=*m*. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations? Let's assume that the rows of matrix *a* are numbered from 1 to *n* from top to bottom and the columns are numbered from 1 to *m* from left to right. A matrix cell on the intersection of the *i*-th row and the *j*-th column can be represented as (*i*,<=*j*). Formally, a submatrix of matrix *a* is a group of four integers *d*,<=*u*,<=*l*,<=*r* (1<=≀<=*d*<=≀<=*u*<=≀<=*n*;Β 1<=≀<=*l*<=≀<=*r*<=≀<=*m*). We will assume that the submatrix contains cells (*i*,<=*j*) (*d*<=≀<=*i*<=≀<=*u*;Β *l*<=≀<=*j*<=≀<=*r*). The area of the submatrix is the number of cells it contains.
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=5000). Next *n* lines contain *m* characters each β€” matrix *a*. Matrix *a* only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
Print a single integer β€” the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
[ "1 1\n1\n", "2 2\n10\n11\n", "4 3\n100\n011\n000\n101\n" ]
[ "1\n", "2\n", "2\n" ]
none
[ { "input": "1 1\n1", "output": "1" }, { "input": "2 2\n10\n11", "output": "2" }, { "input": "4 3\n100\n011\n000\n101", "output": "2" }, { "input": "11 16\n0111110101100011\n1000101100010000\n0010110110010101\n0110110010110010\n0011101101110000\n1001100011010111\n0010011111111000\n0100100100111110\n1001000000100111\n0110000011001000\n1011111011010000", "output": "9" }, { "input": "19 12\n110001100110\n100100000000\n101011001111\n010111110001\n011000100100\n011111010000\n010011101100\n011010011110\n011001111110\n010111110001\n010000010111\n001111110100\n100100110001\n100110000000\n110000010010\n111101011101\n010111100000\n100000011010\n000100100101", "output": "16" }, { "input": "13 19\n0000111111111111011\n0111000001110001101\n1110100110111011101\n0001101011100001110\n1101100100010000101\n1010100011110011010\n1010011101010000001\n1011101000001111000\n1101110001101011110\n0110101010001111100\n0001011010100111001\n1111101000110001000\n0010010000011100010", "output": "14" }, { "input": "8 5\n00000\n00000\n00000\n00000\n00000\n00000\n00000\n00000", "output": "0" }, { "input": "15 18\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111", "output": "270" }, { "input": "1 1\n0", "output": "0" } ]
2,000
268,185,600
0
2,948
651
Joysticks
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≀<=*a*1,<=*a*2<=≀<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", "output": "0" }, { "input": "8 8", "output": "13" }, { "input": "7 2", "output": "7" }, { "input": "24 15", "output": "36" }, { "input": "19 30", "output": "47" }, { "input": "15 31", "output": "44" }, { "input": "14 15", "output": "27" }, { "input": "58 33", "output": "89" }, { "input": "15 25", "output": "38" }, { "input": "59 45", "output": "102" }, { "input": "3 73", "output": "74" }, { "input": "48 1", "output": "47" }, { "input": "100 25", "output": "122" }, { "input": "40 49", "output": "86" }, { "input": "85 73", "output": "155" }, { "input": "29 1", "output": "28" }, { "input": "74 25", "output": "97" }, { "input": "24 57", "output": "78" }, { "input": "23 12", "output": "33" }, { "input": "2 99", "output": "99" }, { "input": "98 2", "output": "97" }, { "input": "2 97", "output": "97" }, { "input": "30 54", "output": "81" }, { "input": "32 53", "output": "82" }, { "input": "32 54", "output": "84" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 3", "output": "2" }, { "input": "3 1", "output": "2" }, { "input": "1 4", "output": "2" }, { "input": "2 3", "output": "3" }, { "input": "3 2", "output": "3" } ]
46
0
0
2,965
592
The Monster and the Squirrel
[ "math" ]
null
null
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel. Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,<=3,<=...,<=*n* (in this particular order). And then she puts a walnut in each region inside the polygon. Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner. Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
The first and only line of the input contains a single integer *n* (3<=≀<=*n*<=≀<=54321) - the number of vertices of the regular polygon drawn by Ari.
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
[ "5\n", "3\n" ]
[ "9\n", "1\n" ]
One of the possible solutions for the first sample is shown on the picture above.
[ { "input": "5", "output": "9" }, { "input": "3", "output": "1" }, { "input": "54321", "output": "2950553761" }, { "input": "4", "output": "4" }, { "input": "6", "output": "16" }, { "input": "7", "output": "25" }, { "input": "8", "output": "36" }, { "input": "9", "output": "49" }, { "input": "10", "output": "64" }, { "input": "54320", "output": "2950445124" }, { "input": "54319", "output": "2950336489" }, { "input": "54318", "output": "2950227856" }, { "input": "54317", "output": "2950119225" }, { "input": "54316", "output": "2950010596" }, { "input": "54315", "output": "2949901969" }, { "input": "54314", "output": "2949793344" }, { "input": "8153", "output": "66438801" }, { "input": "51689", "output": "2671545969" }, { "input": "16659", "output": "277455649" }, { "input": "47389", "output": "2245527769" }, { "input": "314", "output": "97344" }, { "input": "23481", "output": "551263441" }, { "input": "20380", "output": "415262884" }, { "input": "1994", "output": "3968064" } ]
61
0
3
2,972
217
Ice Skating
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates.
The first line of input contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=1000) β€” the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459", "output": "21" }, { "input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815", "output": "16" }, { "input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663", "output": "10" }, { "input": "1\n321 88", "output": "0" }, { "input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689", "output": "7" }, { "input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510", "output": "6" }, { "input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888", "output": "5" }, { "input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802", "output": "13" }, { "input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662", "output": "11" }, { "input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786", "output": "38" }, { "input": "3\n175 201\n907 909\n388 360", "output": "2" }, { "input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86", "output": "6" }, { "input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820", "output": "16" }, { "input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901", "output": "31" }, { "input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210", "output": "29" }, { "input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894", "output": "29" }, { "input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823", "output": "13" }, { "input": "5\n175 158\n16 2\n397 381\n668 686\n957 945", "output": "4" }, { "input": "5\n312 284\n490 509\n730 747\n504 497\n782 793", "output": "4" }, { "input": "2\n802 903\n476 348", "output": "1" }, { "input": "4\n325 343\n425 442\n785 798\n275 270", "output": "3" }, { "input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653", "output": "25" }, { "input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124", "output": "34" }, { "input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255", "output": "29" }, { "input": "5\n664 666\n951 941\n739 742\n844 842\n2 2", "output": "4" }, { "input": "3\n939 867\n411 427\n757 708", "output": "2" }, { "input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636", "output": "34" }, { "input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195", "output": "28" }, { "input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488", "output": "22" }, { "input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235", "output": "8" }, { "input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621", "output": "22" }, { "input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461", "output": "22" }, { "input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924", "output": "6" }, { "input": "3\n1 1\n2 1\n2 2", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "5\n1 1\n1 2\n2 2\n3 1\n3 3", "output": "0" }, { "input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3", "output": "0" }, { "input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10", "output": "1" }, { "input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11", "output": "1" }, { "input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11", "output": "3" }, { "input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25", "output": "7" }, { "input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28", "output": "5" }, { "input": "3\n1 2\n2 1\n2 2", "output": "0" }, { "input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "3\n1 1\n2 2\n1 2", "output": "0" }, { "input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4", "output": "1" }, { "input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100", "output": "6" }, { "input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4", "output": "0" }, { "input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3", "output": "0" }, { "input": "4\n3 1\n2 1\n2 2\n1 2", "output": "0" }, { "input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3", "output": "0" }, { "input": "3\n1 2\n1 3\n1 4", "output": "0" }, { "input": "4\n1 1\n2 2\n1 2\n2 1", "output": "0" }, { "input": "4\n1 3\n2 1\n3 2\n3 1", "output": "1" }, { "input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4", "output": "0" }, { "input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700", "output": "2" }, { "input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9", "output": "1" }, { "input": "4\n1 1\n2 2\n3 2\n3 1", "output": "0" }, { "input": "3\n1 2\n3 4\n3 2", "output": "0" }, { "input": "3\n1 1\n1 2\n2 2", "output": "0" }, { "input": "4\n5 5\n5 4\n6 3\n6 4", "output": "0" }, { "input": "3\n1 1\n2 2\n2 1", "output": "0" } ]
248
0
0
2,976
0
none
[ "none" ]
null
null
You are given an array *a* with *n* distinct integers. Construct an array *b* by permuting *a* such that for every non-empty subset of indices *S*<==<={*x*1,<=*x*2,<=...,<=*x**k*} (1<=≀<=*x**i*<=≀<=*n*, 0<=&lt;<=*k*<=&lt;<=*n*) the sums of elements on that positions in *a* and *b* are different, i.Β e.
The first line contains one integer *n* (1<=≀<=*n*<=≀<=22)Β β€” the size of the array. The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=109)Β β€” the elements of the array.
If there is no such array *b*, print -1. Otherwise in the only line print *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n*. Note that *b* must be a permutation of *a*. If there are multiple answers, print any of them.
[ "2\n1 2\n", "4\n1000 100 10 1\n" ]
[ "2 1 \n", "100 1 1000 10\n" ]
An array *x* is a permutation of *y*, if we can shuffle elements of *y* such that it will coincide with *x*. Note that the empty subset and the subset containing all indices are not counted.
[ { "input": "2\n1 2", "output": "2 1 " }, { "input": "4\n1000 100 10 1", "output": "100 1 1000 10" }, { "input": "5\n1 3 4 5 2", "output": "5 2 3 4 1 " }, { "input": "1\n10000000", "output": "10000000 " }, { "input": "4\n1 5 8 4", "output": "8 4 5 1 " }, { "input": "3\n1 3 2", "output": "3 2 1 " }, { "input": "4\n3 1 2 4", "output": "2 4 1 3 " }, { "input": "12\n7 1 62 12 3 5 8 9 10 22 23 0", "output": "5 0 23 10 1 3 7 8 9 12 22 62 " }, { "input": "17\n1 3 2 5 4 6 7 8 10 9 13 11 12 14 15 16 18", "output": "18 2 1 4 3 5 6 7 9 8 12 10 11 13 14 15 16 " }, { "input": "22\n1 3 5 7 22 2 4 6 8 9 10 11 12 13 15 14 17 18 16 20 19 23", "output": "23 2 4 6 20 1 3 5 7 8 9 10 11 12 14 13 16 17 15 19 18 22 " }, { "input": "22\n17 6 1 22 9 23 38 40 10 20 29 11 12 39 3 32 26 4 13 36 14 35", "output": "14 4 40 20 6 22 36 39 9 17 26 10 11 38 1 29 23 3 12 35 13 32 " }, { "input": "22\n27 21 12 14 8 40 47 45 24 49 36 37 17 32 42 13 35 10 18 2 5 30", "output": "24 18 10 13 5 37 45 42 21 47 35 36 14 30 40 12 32 8 17 49 2 27 " }, { "input": "22\n33 2 19 26 18 13 27 9 25 35 6 24 20 22 11 5 1 30 17 15 7 29", "output": "30 1 18 25 17 11 26 7 24 33 5 22 19 20 9 2 35 29 15 13 6 27 " }, { "input": "22\n18 37 15 33 35 5 14 1 0 27 22 11 40 20 13 2 30 21 8 25 32 16", "output": "16 35 14 32 33 2 13 0 40 25 21 8 37 18 11 1 27 20 5 22 30 15 " }, { "input": "22\n4 24 22 18 28 3 17 8 29 20 11 15 13 2 19 26 5 36 33 14 30 25", "output": "3 22 20 17 26 2 15 5 28 19 8 14 11 36 18 25 4 33 30 13 29 24 " }, { "input": "22\n28 40 5 38 29 12 21 24 2 33 35 17 30 11 16 0 8 27 34 14 19 36", "output": "27 38 2 36 28 11 19 21 0 30 34 16 29 8 14 40 5 24 33 12 17 35 " }, { "input": "22\n25 12 38 5 6 20 30 27 4 19 8 18 10 17 26 32 43 14 40 35 1 22", "output": "22 10 35 4 5 19 27 26 1 18 6 17 8 14 25 30 40 12 38 32 43 20 " }, { "input": "22\n2 22 21 19 3 25 28 11 10 9 14 37 18 38 15 23 20 34 7 30 31 4", "output": "38 21 20 18 2 23 25 10 9 7 11 34 15 37 14 22 19 31 4 28 30 3 " }, { "input": "22\n7 0 23 37 20 18 46 26 2 24 44 13 47 15 32 5 35 30 39 41 27 10", "output": "5 47 20 35 18 15 44 24 0 23 41 10 46 13 30 2 32 27 37 39 26 7 " }, { "input": "22\n36 5 7 22 33 30 14 8 25 24 28 12 19 29 37 2 20 15 10 17 13 21", "output": "33 2 5 21 30 29 13 7 24 22 25 10 17 28 36 37 19 14 8 15 12 20 " }, { "input": "22\n23 32 13 39 29 41 40 6 21 10 38 42 4 8 20 35 31 26 15 2 17 5", "output": "21 31 10 38 26 40 39 5 20 8 35 41 2 6 17 32 29 23 13 42 15 4 " }, { "input": "22\n41 12 14 36 16 21 0 2 18 22 39 29 40 31 37 25 28 9 4 34 6 43", "output": "40 9 12 34 14 18 43 0 16 21 37 28 39 29 36 22 25 6 2 31 4 41 " }, { "input": "22\n32 43 3 37 29 42 40 12 28 1 14 25 34 46 8 35 5 17 2 23 20 9", "output": "29 42 2 35 28 40 37 9 25 46 12 23 32 43 5 34 3 14 1 20 17 8 " }, { "input": "22\n17 10 24 44 41 33 48 6 30 27 38 19 16 46 22 8 35 13 5 9 4 1", "output": "16 9 22 41 38 30 46 5 27 24 35 17 13 44 19 6 33 10 4 8 1 48 " }, { "input": "22\n16 11 29 30 12 5 3 2 13 6 17 15 9 24 25 35 1 27 0 23 20 33", "output": "15 9 27 29 11 3 2 1 12 5 16 13 6 23 24 33 0 25 35 20 17 30 " }, { "input": "22\n12 38 6 37 14 26 2 0 9 17 28 33 3 11 15 8 31 21 29 34 18 24", "output": "11 37 3 34 12 24 0 38 8 15 26 31 2 9 14 6 29 18 28 33 17 21 " }, { "input": "22\n20 38 26 32 36 8 44 0 40 41 35 21 11 17 29 33 1 42 24 14 5 3", "output": "17 36 24 29 35 5 42 44 38 40 33 20 8 14 26 32 0 41 21 11 3 1 " }, { "input": "22\n7 10 1 25 42 8 39 35 6 19 31 24 16 0 21 32 11 28 13 4 37 22", "output": "6 8 0 24 39 7 37 32 4 16 28 22 13 42 19 31 10 25 11 1 35 21 " }, { "input": "22\n9 13 7 20 38 40 27 12 31 25 1 23 46 35 45 29 19 16 33 4 42 39", "output": "7 12 4 19 35 39 25 9 29 23 46 20 45 33 42 27 16 13 31 1 40 38 " }, { "input": "22\n13 2 10 25 5 34 19 18 16 9 7 22 28 20 31 38 36 35 1 26 6 23", "output": "10 1 9 23 2 31 18 16 13 7 6 20 26 19 28 36 35 34 38 25 5 22 " }, { "input": "22\n106855341 41953605 16663229 140358177 145011760 49391214 42672526 1000000000 173686818 18529133 155326121 177597841 65855243 125680752 111261017 47020618 35558283 100881772 149421816 84207033 181739589 185082482", "output": "100881772 35558283 1000000000 125680752 140358177 47020618 41953605 185082482 155326121 16663229 149421816 173686818 49391214 111261017 106855341 42672526 18529133 84207033 145011760 65855243 177597841 181739589 " }, { "input": "22\n177663922 168256855 139197944 78700101 93490895 127229611 46317725 84284513 48674853 66142856 29224095 1000000000 138390832 117500569 98525700 100418194 44827621 151960474 43225995 16918107 53307514 48861499", "output": "168256855 151960474 138390832 66142856 84284513 117500569 44827621 78700101 46317725 53307514 16918107 177663922 127229611 100418194 93490895 98525700 43225995 139197944 29224095 1000000000 48861499 48674853 " }, { "input": "22\n83255567 39959119 124812899 157774437 12694468 89732189 102545715 67019496 110206980 98186415 63181429 141617294 177406424 195504716 158928060 64956133 67949891 31436243 155002729 1000000000 128745406 52504492", "output": "67949891 31436243 110206980 155002729 1000000000 83255567 98186415 64956133 102545715 89732189 52504492 128745406 158928060 177406424 157774437 63181429 67019496 12694468 141617294 195504716 124812899 39959119 " }, { "input": "22\n138499935 195582510 159774498 12295611 37071371 91641202 167958938 119995178 19438466 182405139 207729895 56797798 79876605 152841775 1000000000 149079380 158867321 154637978 72179187 75460169 145092927 103227705", "output": "119995178 182405139 158867321 1000000000 19438466 79876605 159774498 103227705 12295611 167958938 195582510 37071371 75460169 149079380 207729895 145092927 154637978 152841775 56797798 72179187 138499935 91641202 " }, { "input": "22\n133295371 188010892 71730560 209842234 193069109 184556873 87395258 234247052 230809052 211444018 148989732 17810977 158722706 11753932 100093528 1000000000 43672080 61357581 171830832 13873487 34865589 114340079", "output": "114340079 184556873 61357581 193069109 188010892 171830832 71730560 230809052 211444018 209842234 133295371 13873487 148989732 1000000000 87395258 234247052 34865589 43672080 158722706 11753932 17810977 100093528 " }, { "input": "22\n94506085 195061283 78884975 27418524 41348358 185397891 151515774 66605535 170723638 212843258 218566729 7450050 21809921 1000000000 146101141 132453297 228865386 240705035 57636433 114219677 158240908 228428432", "output": "78884975 185397891 66605535 21809921 27418524 170723638 146101141 57636433 158240908 195061283 212843258 1000000000 7450050 240705035 132453297 114219677 228428432 228865386 41348358 94506085 151515774 218566729 " }, { "input": "22\n116213533 171312666 76695399 60099180 30779320 43431323 146620629 15321904 71245898 94843310 56549974 104020167 84091716 134384095 24383373 83975332 1000000000 101710173 188076412 199811222 153566780 115893674", "output": "115893674 153566780 71245898 56549974 24383373 30779320 134384095 1000000000 60099180 84091716 43431323 101710173 83975332 116213533 15321904 76695399 199811222 94843310 171312666 188076412 146620629 104020167 " }, { "input": "22\n79749952 42551386 1000000000 60427603 50702468 16899307 85913428 116634789 151569595 100251788 152378664 96284924 60769416 136345503 59995727 88224321 29257228 64921932 77805288 126026727 103477637 115959196", "output": "77805288 29257228 152378664 59995727 42551386 1000000000 79749952 115959196 136345503 96284924 151569595 88224321 60427603 126026727 50702468 85913428 16899307 60769416 64921932 116634789 100251788 103477637 " }, { "input": "22\n32119698 129510003 107370317 182795872 160438101 17245069 117836566 141016185 196664039 215252245 170450315 18866624 68629021 47385728 77249092 89835593 132769095 95649030 48749357 126701972 40219294 1000000000", "output": "18866624 126701972 95649030 170450315 141016185 1000000000 107370317 132769095 182795872 196664039 160438101 17245069 48749357 40219294 68629021 77249092 129510003 89835593 47385728 117836566 32119698 215252245 " }, { "input": "22\n148671024 180468173 99388811 78666746 187172484 157360521 112604605 2988530 60271244 163263697 27469084 166381131 1000000000 125847469 137766458 198740424 88387613 15152912 200315776 149201551 45997250 36252057", "output": "137766458 166381131 88387613 60271244 180468173 149201551 99388811 1000000000 45997250 157360521 15152912 163263697 200315776 112604605 125847469 187172484 78666746 2988530 198740424 148671024 36252057 27469084 " } ]
62
0
-1
2,978
12
Correct Solution?
[ "implementation", "sortings" ]
B. Correct Solution?
2
256
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: β€”Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes. β€”No problem! β€” said Bob and immediately gave her an answer. Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
The first line contains one integer *n* (0<=≀<=*n*<=≀<=109) without leading zeroes. The second lines contains one integer *m* (0<=≀<=*m*<=≀<=109) β€” Bob's answer, possibly with leading zeroes.
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
[ "3310\n1033\n", "4\n5\n" ]
[ "OK\n", "WRONG_ANSWER\n" ]
none
[ { "input": "3310\n1033", "output": "OK" }, { "input": "4\n5", "output": "WRONG_ANSWER" }, { "input": "40\n04", "output": "WRONG_ANSWER" }, { "input": "12\n12", "output": "OK" }, { "input": "432\n234", "output": "OK" }, { "input": "17109\n01179", "output": "WRONG_ANSWER" }, { "input": "888\n888", "output": "OK" }, { "input": "912\n9123", "output": "WRONG_ANSWER" }, { "input": "0\n00", "output": "WRONG_ANSWER" }, { "input": "11110\n1111", "output": "WRONG_ANSWER" }, { "input": "7391\n1397", "output": "WRONG_ANSWER" }, { "input": "201\n102", "output": "OK" }, { "input": "111111111\n111111111", "output": "OK" }, { "input": "32352320\n22203335", "output": "WRONG_ANSWER" }, { "input": "1000000000\n1", "output": "WRONG_ANSWER" }, { "input": "994321\n123499", "output": "OK" }, { "input": "10101\n10101", "output": "WRONG_ANSWER" }, { "input": "666\n0666", "output": "WRONG_ANSWER" }, { "input": "2\n02", "output": "WRONG_ANSWER" }, { "input": "313\n133", "output": "OK" }, { "input": "987235645\n234556789", "output": "OK" }, { "input": "90812\n010289", "output": "WRONG_ANSWER" }, { "input": "123\n321", "output": "WRONG_ANSWER" }, { "input": "707\n770", "output": "WRONG_ANSWER" }, { "input": "77774444\n47474747", "output": "WRONG_ANSWER" }, { "input": "1270\n1027", "output": "OK" }, { "input": "320\n23", "output": "WRONG_ANSWER" }, { "input": "123456789\n123456789", "output": "OK" }, { "input": "918273645\n546372819", "output": "WRONG_ANSWER" }, { "input": "300000003\n30000003", "output": "WRONG_ANSWER" }, { "input": "0\n0", "output": "OK" }, { "input": "0\n7", "output": "WRONG_ANSWER" } ]
0
0
-1
2,979
7
Palindrome Degree
[ "hashing", "strings" ]
D. Palindrome Degree
1
256
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For example, "abaaba" has degree equals to 3. You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.
The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5Β·106. The string is case-sensitive.
Output the only number β€” the sum of the polindrome degrees of all the string's prefixes.
[ "a2A\n", "abacaba\n" ]
[ "1", "6" ]
none
[ { "input": "a2A", "output": "1" }, { "input": "abacaba", "output": "6" }, { "input": "CCeCeCCCee", "output": "4" }, { "input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop", "output": "3" }, { "input": "odribmizzsgholprdsth", "output": "1" }, { "input": "z", "output": "1" } ]
92
4,608,000
0
2,984
976
Well played!
[ "greedy", "sortings" ]
null
null
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns *n* creatures, *i*-th of them can be described with two numbers β€” its health *hp**i* and its damage *dmg**i*. Max also has two types of spells in stock: 1. Doubles health of the creature (*hp**i* := *hp**i*Β·2); 1. Assigns value of health of the creature to its damage (*dmg**i* := *hp**i*). Spell of first type can be used no more than *a* times in total, of the second type β€” no more than *b* times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells. Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.
The first line contains three integers *n*, *a*, *b* (1<=≀<=*n*<=≀<=2Β·105, 0<=≀<=*a*<=≀<=20, 0<=≀<=*b*<=≀<=2Β·105) β€” the number of creatures, spells of the first type and spells of the second type, respectively. The *i*-th of the next *n* lines contain two number *hp**i* and *dmg**i* (1<=≀<=*hp**i*,<=*dmg**i*<=≀<=109) β€” description of the *i*-th creature.
Print single integer β€” maximum total damage creatures can deal.
[ "2 1 1\n10 15\n6 1\n", "3 0 3\n10 8\n7 11\n5 2\n" ]
[ "27\n", "26\n" ]
In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6Β·2 = 27. In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.
[ { "input": "2 1 1\n10 15\n6 1", "output": "27" }, { "input": "3 0 3\n10 8\n7 11\n5 2", "output": "26" }, { "input": "1 0 0\n2 1", "output": "1" }, { "input": "1 0 200000\n1 2", "output": "2" }, { "input": "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88", "output": "3533" }, { "input": "7 6 7\n11 75\n61 90\n22 14\n100 36\n29 48\n69 52\n16 3", "output": "6720" }, { "input": "7 8 7\n88 29\n30 44\n14 1\n83 95\n73 88\n10 42\n29 26", "output": "22840" }, { "input": "12 7 7\n78 189\n614 271\n981 510\n37 762\n803 106\n78 369\n787 54\n768 159\n238 111\n107 54\n207 72\n485 593", "output": "130952" }, { "input": "12 20 4\n852 935\n583 820\n969 197\n219 918\n547 842\n615 163\n704 377\n326 482\n183 833\n884 994\n886 581\n909 450", "output": "1016078777" }, { "input": "2 13 2\n208637 682633\n393097 724045", "output": "3220933257" }, { "input": "1 0 200000\n42 1", "output": "42" }, { "input": "1 6 200000\n42 1", "output": "2688" }, { "input": "1 0 200000\n1 42", "output": "42" }, { "input": "1 6 200000\n1 42", "output": "64" }, { "input": "3 1 1\n10 9\n8 6\n7 5", "output": "31" }, { "input": "1 1 0\n10 1", "output": "1" }, { "input": "1 1 0\n3 4", "output": "4" }, { "input": "3 20 0\n1 5\n5 1\n5 1", "output": "7" }, { "input": "2 5 1\n10 1\n20 20", "output": "641" }, { "input": "3 20 0\n3 2\n4 3\n5 4", "output": "9" }, { "input": "2 1 0\n10 15\n6 1", "output": "16" }, { "input": "5 10 0\n20 1\n22 1\n30 1\n30 5\n40 6", "output": "14" }, { "input": "1 20 0\n1 5", "output": "5" }, { "input": "2 3 14\n28 5\n32 47", "output": "284" }, { "input": "3 1 2\n20 10\n5 1\n25 25", "output": "71" }, { "input": "2 3 3\n28 5\n32 47", "output": "284" }, { "input": "2 2 1\n10 15\n6 1", "output": "41" }, { "input": "2 1 2\n20 1\n22 23", "output": "64" }, { "input": "10 7 2\n8 6\n5 5\n3 7\n7 7\n3 8\n6 1\n10 9\n4 6\n9 5\n7 9", "output": "1339" }, { "input": "3 8 1\n6 6\n7 9\n2 5", "output": "1803" }, { "input": "10 4 4\n5 5\n8 1\n10 10\n3 1\n7 10\n1 7\n8 7\n5 9\n3 3\n1 1", "output": "214" }, { "input": "4 8 3\n1 6\n10 10\n4 8\n9 4", "output": "2583" }, { "input": "8 18 1\n8 6\n6 8\n1 7\n7 2\n5 1\n10 5\n8 3\n9 3", "output": "2621470" }, { "input": "2 11 1\n1 4\n1 5", "output": "2053" }, { "input": "2 19 2\n9 3\n7 2", "output": "4718599" }, { "input": "5 13 0\n4 4\n8 10\n1 8\n3 9\n4 6", "output": "37" }, { "input": "5 8 0\n10 7\n6 6\n6 5\n7 9\n10 7", "output": "34" }, { "input": "5 20 2\n1 10\n7 8\n10 1\n6 5\n2 1", "output": "10485785" }, { "input": "2 1 0\n5 6\n8 8", "output": "14" }, { "input": "7 3 5\n2 6\n5 9\n5 5\n4 10\n5 7\n7 8\n3 10", "output": "103" }, { "input": "10 9 0\n620118469 704168608\n528098892 341451371\n15150469 449838744\n960504540 722185004\n271837337 344050133\n940943201 419522619\n85569623 788965215\n161962866 563795701\n943389281 445744350\n610994199 473866838", "output": "5253588583" }, { "input": "10 11 1\n7 3\n9 4\n1 5\n10 3\n6 1\n10 7\n8 5\n7 6\n1 4\n9 9", "output": "20524" }, { "input": "2 1 200000\n44 42\n1000 1001", "output": "2044" }, { "input": "5 12 2\n5 9\n8 9\n4 1\n2 5\n1 8", "output": "32794" }, { "input": "4 8 1\n9 9\n7 6\n2 4\n6 10", "output": "2324" }, { "input": "2 1 1\n292725479 742903381\n239450691 307356865", "output": "1221804763" } ]
93
7,065,600
-1
2,993
814
An express train to reveries
[ "constructive algorithms" ]
null
null
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of integers from 1 to *n* inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with *n* meteorids, colours of which being integer sequences *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* respectively. Meteoroids' colours were also between 1 and *n* inclusive, and the two sequences were not identical, that is, at least one *i* (1<=≀<=*i*<=≀<=*n*) exists, such that *a**i*<=β‰ <=*b**i* holds. Well, she almost had it all β€” each of the sequences *a* and *b* matched exactly *n*<=-<=1 elements in Sengoku's permutation. In other words, there is exactly one *i* (1<=≀<=*i*<=≀<=*n*) such that *a**i*<=β‰ <=*p**i*, and exactly one *j* (1<=≀<=*j*<=≀<=*n*) such that *b**j*<=β‰ <=*p**j*. For now, Sengoku is able to recover the actual colour sequences *a* and *b* through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.
The first line of input contains a positive integer *n* (2<=≀<=*n*<=≀<=1<=000) β€” the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the sequence of colours in the first meteor outburst. The third line contains *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≀<=*b**i*<=≀<=*n*) β€” the sequence of colours in the second meteor outburst. At least one *i* (1<=≀<=*i*<=≀<=*n*) exists, such that *a**i*<=β‰ <=*b**i* holds.
Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
[ "5\n1 2 3 4 3\n1 2 5 4 5\n", "5\n4 4 2 3 1\n5 4 5 3 1\n", "4\n1 1 3 4\n1 4 3 4\n" ]
[ "1 2 5 4 3\n", "5 4 2 3 1\n", "1 2 3 4\n" ]
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[ { "input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3" }, { "input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1" }, { "input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4" }, { "input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10", "output": "1 2 3 4 5 6 7 8 9 10" }, { "input": "10\n1 2 3 4 5 6 7 8 7 10\n1 2 3 4 5 6 7 8 9 9", "output": "1 2 3 4 5 6 7 8 9 10" }, { "input": "10\n1 2 3 4 5 6 7 8 4 10\n1 2 3 4 5 6 7 6 9 10", "output": "1 2 3 4 5 6 7 8 9 10" }, { "input": "10\n8 6 1 7 9 3 5 2 10 9\n8 6 1 7 4 3 5 2 10 4", "output": "8 6 1 7 4 3 5 2 10 9" }, { "input": "10\n2 9 7 7 8 5 4 10 6 1\n2 8 7 3 8 5 4 10 6 1", "output": "2 9 7 3 8 5 4 10 6 1" }, { "input": "2\n2 2\n1 1", "output": "1 2" }, { "input": "3\n1 2 2\n1 3 3", "output": "1 3 2" }, { "input": "3\n2 2 3\n1 2 1", "output": "1 2 3" }, { "input": "3\n1 3 3\n1 1 3", "output": "1 2 3" }, { "input": "3\n2 1 1\n2 3 3", "output": "2 3 1" }, { "input": "3\n3 3 2\n1 1 2", "output": "1 3 2" }, { "input": "3\n1 3 3\n3 3 2", "output": "1 3 2" }, { "input": "4\n3 2 3 4\n1 2 1 4", "output": "1 2 3 4" }, { "input": "4\n2 2 3 4\n1 2 3 2", "output": "1 2 3 4" }, { "input": "4\n1 2 4 4\n2 2 3 4", "output": "1 2 3 4" }, { "input": "4\n4 1 3 4\n2 1 3 2", "output": "2 1 3 4" }, { "input": "4\n3 2 1 3\n4 2 1 2", "output": "4 2 1 3" }, { "input": "4\n1 4 1 3\n2 4 1 4", "output": "2 4 1 3" }, { "input": "4\n1 3 4 4\n3 3 2 4", "output": "1 3 2 4" }, { "input": "5\n5 4 5 3 1\n4 4 2 3 1", "output": "5 4 2 3 1" }, { "input": "5\n4 1 2 4 5\n3 1 2 5 5", "output": "3 1 2 4 5" }, { "input": "3\n2 2 3\n1 3 3", "output": "1 2 3" }, { "input": "3\n1 1 3\n2 3 3", "output": "2 1 3" }, { "input": "5\n5 4 5 3 1\n2 4 4 3 1", "output": "2 4 5 3 1" }, { "input": "3\n3 3 1\n2 1 1", "output": "2 3 1" }, { "input": "5\n5 4 3 5 2\n5 4 1 1 2", "output": "5 4 3 1 2" }, { "input": "6\n1 2 3 4 2 5\n1 6 3 4 4 5", "output": "1 6 3 4 2 5" }, { "input": "4\n1 3 2 1\n2 3 2 1", "output": "4 3 2 1" }, { "input": "4\n1 3 3 4\n1 4 3 4", "output": "1 2 3 4" }, { "input": "11\n1 2 3 4 5 6 7 8 9 10 10\n1 2 3 4 5 6 7 8 9 10 3", "output": "1 2 3 4 5 6 7 8 9 10 11" }, { "input": "5\n1 2 3 2 5\n1 4 3 3 5", "output": "1 4 3 2 5" }, { "input": "5\n1 2 3 4 3\n1 2 5 4 2", "output": "1 2 5 4 3" }, { "input": "5\n1 2 3 4 4\n1 2 3 4 3", "output": "1 2 3 4 5" }, { "input": "4\n1 3 1 4\n1 3 4 4", "output": "1 3 2 4" }, { "input": "5\n2 5 3 2 1\n4 5 3 3 1", "output": "4 5 3 2 1" }, { "input": "5\n1 2 3 2 5\n1 3 3 4 5", "output": "1 2 3 4 5" }, { "input": "5\n5 2 3 4 5\n2 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "5\n5 4 1 1 2\n5 4 3 5 2", "output": "5 4 3 1 2" }, { "input": "4\n1 4 3 4\n1 3 3 4", "output": "1 2 3 4" }, { "input": "4\n1 2 3 1\n1 2 3 2", "output": "1 2 3 4" }, { "input": "5\n4 5 3 3 1\n2 5 3 2 1", "output": "4 5 3 2 1" }, { "input": "5\n1 2 3 5 5\n1 2 3 4 3", "output": "1 2 3 4 5" }, { "input": "4\n2 3 3 4\n2 4 3 4", "output": "2 1 3 4" } ]
62
0
0
3,008
816
Karen and Coffee
[ "binary search", "data structures", "implementation" ]
null
null
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste. Karen thinks that a temperature is admissible if at least *k* recipes recommend it. Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range?
The first line of input contains three integers, *n*, *k* (1<=≀<=*k*<=≀<=*n*<=≀<=200000), and *q* (1<=≀<=*q*<=≀<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive. The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≀<=*a*<=≀<=*b*<=≀<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
[ "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n", "2 1 1\n1 1\n200000 200000\n90 100\n" ]
[ "3\n3\n0\n4\n", "0\n" ]
In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature is admissible if at least 2 recipes recommend it. She asks 4 questions. In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible. In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible. In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none. In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible. In the second test case, Karen knows 2 recipes. 1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees. A temperature is admissible if at least 1 recipe recommends it. In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
[ { "input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "output": "3\n3\n0\n4" }, { "input": "2 1 1\n1 1\n200000 200000\n90 100", "output": "0" }, { "input": "1 1 1\n1 1\n1 1", "output": "1" }, { "input": "1 1 1\n200000 200000\n200000 200000", "output": "1" } ]
2,500
149,401,600
0
3,012
357
Group of Students
[ "brute force", "greedy", "implementation" ]
null
null
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got 1 point, *c*2 children got 2 points, ..., *c**m* children got *m* points. Now you need to set the passing rate *k* (integer from 1 to *m*): all schoolchildren who got less than *k* points go to the beginner group and those who get at strictly least *k* points go to the intermediate group. We know that if the size of a group is more than *y*, then the university won't find a room for them. We also know that if a group has less than *x* schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from *x* to *y*, inclusive. Help the university pick the passing rate in a way that meets these requirements.
The first line contains integer *m* (2<=≀<=*m*<=≀<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≀<=*c**i*<=≀<=100). The third line contains two space-separated integers *x* and *y* (1<=≀<=*x*<=≀<=*y*<=≀<=10000). At least one *c**i* is greater than 0.
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* β€” the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
[ "5\n3 4 3 2 1\n6 8\n", "5\n0 3 3 4 2\n3 10\n", "2\n2 5\n3 6\n" ]
[ "3\n", "4\n", "0\n" ]
In the first sample the beginner group has 7 students, the intermediate group has 6 of them. In the second sample another correct answer is 3.
[ { "input": "5\n3 4 3 2 1\n6 8", "output": "3" }, { "input": "5\n0 3 3 4 2\n3 10", "output": "4" }, { "input": "2\n2 5\n3 6", "output": "0" }, { "input": "3\n0 1 0\n2 10", "output": "0" }, { "input": "5\n2 2 2 2 2\n5 5", "output": "0" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1\n1 10", "output": "10" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1\n5 5", "output": "6" }, { "input": "6\n0 0 1 1 0 0\n1 6", "output": "4" }, { "input": "7\n3 2 3 3 2 1 1\n5 10", "output": "4" }, { "input": "4\n1 0 0 100\n1 100", "output": "4" }, { "input": "100\n46 6 71 27 94 59 99 82 5 41 18 89 86 2 31 35 52 18 1 14 54 11 28 83 42 15 13 77 22 70 87 65 79 35 44 71 79 9 95 57 5 59 42 62 66 26 33 66 67 45 39 17 97 28 36 100 52 23 68 29 83 6 61 85 71 2 85 98 85 65 95 53 35 96 29 28 82 80 52 60 61 46 46 80 11 3 35 6 12 10 64 7 7 7 65 93 58 85 20 12\n2422 2429", "output": "52" }, { "input": "10\n3 6 1 5 3 7 0 1 0 8\n16 18", "output": "6" }, { "input": "10\n3 3 0 4 0 5 2 10 7 0\n10 24", "output": "8" }, { "input": "10\n9 4 7 7 1 3 7 3 8 5\n23 31", "output": "7" }, { "input": "10\n9 6 9 5 5 4 3 3 9 10\n9 54", "output": "10" }, { "input": "10\n2 4 8 5 2 2 2 5 6 2\n14 24", "output": "7" }, { "input": "10\n10 58 86 17 61 12 75 93 37 30\n10 469", "output": "10" }, { "input": "10\n56 36 0 28 68 54 34 48 28 92\n92 352", "output": "10" }, { "input": "10\n2 81 94 40 74 62 39 70 87 86\n217 418", "output": "8" }, { "input": "10\n48 93 9 96 70 14 100 93 44 79\n150 496", "output": "8" }, { "input": "10\n94 85 4 9 30 45 90 76 0 65\n183 315", "output": "7" }, { "input": "100\n1 0 7 9 0 4 3 10 9 4 9 7 4 4 7 7 6 1 3 3 8 1 4 3 5 8 0 0 6 2 3 5 0 1 5 8 6 3 2 4 9 5 8 6 0 2 5 1 9 5 9 0 6 0 4 5 9 7 1 4 7 5 4 5 6 8 2 3 3 2 8 2 9 5 9 2 4 7 7 8 10 1 3 0 8 0 9 1 1 7 7 8 9 3 5 9 9 8 0 8\n200 279", "output": "63" }, { "input": "100\n5 4 9 7 8 10 7 8 10 0 10 9 7 1 0 7 8 5 5 8 7 7 7 2 5 8 0 7 5 7 1 7 6 5 4 10 6 1 4 4 8 7 0 3 2 10 8 6 1 3 2 6 8 1 9 3 9 5 2 0 3 6 7 5 10 0 2 8 3 10 1 3 8 8 0 2 10 3 4 4 0 7 4 0 9 7 10 2 7 10 9 9 6 6 8 1 10 1 2 0\n52 477", "output": "91" }, { "input": "100\n5 1 6 6 5 4 5 8 0 2 10 1 10 0 6 6 0 1 5 7 10 5 8 4 4 5 10 4 10 3 0 10 10 1 2 6 2 6 3 9 4 4 5 5 7 7 7 4 3 2 1 4 5 0 2 1 8 5 4 5 10 7 0 3 5 4 10 4 10 7 10 1 8 3 9 8 6 9 5 7 3 4 7 8 4 0 3 4 4 1 6 6 2 0 1 5 3 3 9 10\n22 470", "output": "98" }, { "input": "100\n73 75 17 93 35 7 71 88 11 58 78 33 7 38 14 83 30 25 75 23 60 10 100 7 90 51 82 0 78 54 61 32 20 90 54 45 100 62 40 99 43 86 87 64 10 41 29 51 38 22 5 63 10 64 90 20 100 33 95 72 40 82 92 30 38 3 71 85 99 66 4 26 33 41 85 14 26 61 21 96 29 40 25 14 48 4 30 44 6 41 71 71 4 66 13 50 30 78 64 36\n2069 2800", "output": "57" }, { "input": "100\n86 19 100 37 9 49 97 9 70 51 14 31 47 53 76 65 10 40 4 92 2 79 22 70 85 58 73 96 89 91 41 88 70 31 53 33 22 51 10 56 90 39 70 38 86 15 94 63 82 19 7 65 22 83 83 71 53 6 95 89 53 41 95 11 32 0 7 84 39 11 37 73 20 46 18 28 72 23 17 78 37 49 43 62 60 45 30 69 38 41 71 43 47 80 64 40 77 99 36 63\n1348 3780", "output": "74" }, { "input": "100\n65 64 26 48 16 90 68 32 95 11 27 29 87 46 61 35 24 99 34 17 79 79 11 66 14 75 31 47 43 61 100 32 75 5 76 11 46 74 81 81 1 25 87 45 16 57 24 76 58 37 42 0 46 23 75 66 75 11 50 5 10 11 43 26 38 42 88 15 70 57 2 74 7 72 52 8 72 19 37 38 66 24 51 42 40 98 19 25 37 7 4 92 47 72 26 76 66 88 53 79\n1687 2986", "output": "65" }, { "input": "100\n78 43 41 93 12 76 62 54 85 5 42 61 93 37 22 6 50 80 63 53 66 47 0 60 43 93 90 8 97 64 80 22 23 47 30 100 80 75 84 95 35 69 36 20 58 99 78 88 1 100 10 69 57 77 68 61 62 85 4 45 24 4 24 74 65 73 91 47 100 35 25 53 27 66 62 55 38 83 56 20 62 10 71 90 41 5 75 83 36 75 15 97 79 52 88 32 55 42 59 39\n873 4637", "output": "85" }, { "input": "100\n12 25 47 84 72 40 85 37 8 92 85 90 12 7 45 14 98 62 31 62 10 89 37 65 77 29 5 3 21 21 10 98 44 37 37 37 50 15 69 27 19 99 98 91 63 42 32 68 77 88 78 35 13 44 4 82 42 76 28 50 65 64 88 46 94 37 40 7 10 58 21 31 17 91 75 86 3 9 9 14 72 20 40 57 11 75 91 48 79 66 53 24 93 16 58 4 10 89 75 51\n666 4149", "output": "88" }, { "input": "10\n8 0 2 2 5 1 3 5 2 2\n13 17", "output": "6" }, { "input": "10\n10 4 4 6 2 2 0 5 3 7\n19 24", "output": "5" }, { "input": "10\n96 19 75 32 94 16 81 2 93 58\n250 316", "output": "6" }, { "input": "10\n75 65 68 43 89 57 7 58 51 85\n258 340", "output": "6" }, { "input": "100\n59 51 86 38 90 10 36 3 97 35 32 20 25 96 49 39 66 44 64 50 97 68 50 79 3 33 72 96 32 74 67 9 17 77 67 15 1 100 99 81 18 1 15 36 7 34 30 78 10 97 7 19 87 47 62 61 40 29 1 34 6 77 76 21 66 11 65 96 82 54 49 65 56 90 29 75 48 77 48 53 91 21 98 26 80 44 57 97 11 78 98 45 40 88 27 27 47 5 26 6\n2479 2517", "output": "53" }, { "input": "100\n5 11 92 53 49 42 15 86 31 10 30 49 21 66 14 13 80 25 21 25 86 20 86 83 36 81 21 23 0 30 64 85 15 33 74 96 83 51 84 4 35 65 10 7 11 11 41 80 51 51 74 52 43 83 88 38 77 20 14 40 37 25 27 93 27 77 48 56 93 65 79 33 91 14 9 95 13 36 24 2 66 31 56 28 49 58 74 17 88 36 46 73 54 18 63 22 2 41 8 50\n2229 2279", "output": "52" }, { "input": "2\n0 1\n1 1", "output": "0" }, { "input": "4\n1 0 0 4\n1 3", "output": "0" }, { "input": "4\n1 0 0 0\n1 10", "output": "0" }, { "input": "3\n2 1 4\n3 3", "output": "0" }, { "input": "5\n2 0 2 0 0\n2 2", "output": "3" }, { "input": "4\n1 2 3 4\n1 7", "output": "4" }, { "input": "2\n7 1\n1 6", "output": "0" }, { "input": "5\n1 3 7 8 9\n4 6", "output": "0" }, { "input": "2\n5 2\n5 6", "output": "0" }, { "input": "2\n1 0\n1 2", "output": "0" }, { "input": "4\n2 3 9 10\n5 14", "output": "4" }, { "input": "3\n1 2 1\n1 1", "output": "0" }, { "input": "4\n2 3 9 50\n5 30", "output": "0" }, { "input": "3\n7 1 1\n6 8", "output": "0" }, { "input": "6\n1 1 2 3 4 5\n3 9", "output": "5" }, { "input": "3\n4 5 5\n4 9", "output": "3" }, { "input": "6\n1 2 3 4 5 6\n1 3", "output": "0" }, { "input": "5\n3 4 3 2 10\n6 8", "output": "0" }, { "input": "5\n1 1 3 4 6\n2 2", "output": "0" }, { "input": "5\n5 3 5 8 10\n2 20", "output": "4" }, { "input": "4\n0 0 5 0\n3 6", "output": "0" }, { "input": "8\n1 1 1 1 2 2 2 1\n3 7", "output": "6" }, { "input": "3\n1 100 100\n101 200", "output": "0" } ]
109
307,200
3
3,019
453
Little Pony and Expected Maximum
[ "probabilities" ]
null
null
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
A single line contains two integers *m* and *n* (1<=≀<=*m*,<=*n*<=≀<=105).
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
[ "6 1\n", "6 3\n", "2 2\n" ]
[ "3.500000000000\n", "4.958333333333\n", "1.750000000000\n" ]
Consider the third test example. If you've made two tosses: 1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2. The probability of each outcome is 0.25, that is expectation equals to: You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
[ { "input": "6 1", "output": "3.500000000000" }, { "input": "6 3", "output": "4.958333333333" }, { "input": "2 2", "output": "1.750000000000" }, { "input": "5 4", "output": "4.433600000000" }, { "input": "5 8", "output": "4.814773760000" }, { "input": "3 10", "output": "2.982641534996" }, { "input": "3 6", "output": "2.910836762689" }, { "input": "1 8", "output": "1.000000000000" }, { "input": "24438 9", "output": "21994.699969310015" }, { "input": "94444 9", "output": "85000.099992058866" }, { "input": "8 66716", "output": "8.000000000000" }, { "input": "4 25132", "output": "4.000000000000" }, { "input": "51520 73331", "output": "51519.682650242677" }, { "input": "54230 31747", "output": "54228.743352775018" }, { "input": "24236 90163", "output": "24235.975171545670" }, { "input": "26946 99523", "output": "26945.974480086279" }, { "input": "50323 7", "output": "44033.124988408454" }, { "input": "53033 3", "output": "39775.249995286234" }, { "input": "55743 5", "output": "46452.999992525307" }, { "input": "59964 79", "output": "59214.949890211828" }, { "input": "1 1", "output": "1.000000000000" }, { "input": "1 1", "output": "1.000000000000" }, { "input": "3 1", "output": "2.000000000000" }, { "input": "1 2", "output": "1.000000000000" }, { "input": "53513 34040", "output": "53511.875329020870" }, { "input": "100000 100000", "output": "99999.418033254507" }, { "input": "1 100000", "output": "1.000000000000" }, { "input": "100000 1", "output": "50000.499999999935" }, { "input": "2 100000", "output": "2.000000000000" }, { "input": "100000 2", "output": "66667.166665000332" }, { "input": "50000 100000", "output": "49999.843487110789" }, { "input": "99999 1111", "output": "99909.571915885972" }, { "input": "99999 99999", "output": "99998.418033254609" }, { "input": "1000 1000", "output": "999.419018443269" }, { "input": "50000 50000", "output": "49999.418043215679" }, { "input": "88888 88888", "output": "88887.418034499773" }, { "input": "99999 100000", "output": "99998.418042461126" }, { "input": "100000 555", "output": "99820.643422392372" }, { "input": "10000 10000", "output": "9999.418122897887" }, { "input": "100000 5001", "output": "99980.503829474910" }, { "input": "100000 1000", "output": "99900.599066768002" } ]
187
0
3
3,023
293
Cube Problem
[ "brute force", "math", "number theory" ]
null
null
Yaroslav, Andrey and Roman love playing cubes. Sometimes they get together and play cubes for hours and hours! Today they got together again and they are playing cubes. Yaroslav took unit cubes and composed them into an *a*<=Γ—<=*a*<=Γ—<=*a* cube, Andrey made a *b*<=Γ—<=*b*<=Γ—<=*b* cube and Roman made a *c*<=Γ—<=*c*<=Γ—<=*c* cube. After that the game was finished and the guys left. But later, Vitaly entered the room. He saw the cubes and wanted to make a cube as well. But what size should the cube be? Of course it should be a large cube with the side of length *a*<=+<=*b*<=+<=*c*. Besides, Vitaly decided to decompose the cubes built by Yaroslav, Andrey and Roman and compose his own large cube out of them. However, it turned out that the unit cubes he got from destroying the three cubes just weren't enough to make a large cube. We know that Vitaly was short of exactly *n* cubes. Vitaly got upset, demolished everything and left. As he was leaving, he met Petya and told him that there had been three cubes in the room and that he needed another *n* unit cubes to make his own large cube. Petya entered the room and saw the messily scattered cubes. He wanted to make it neat and orderly again. But he only knows that there had been three cubes, made of small unit cubes and that Vitaly needed *n* more unit cubes to make a large one! Help Petya understand, how many ways of sizes *a*, *b*, *c* are there to restore Yaroslav's, Andrey's and Roman's cubes.
The single line of the input contains integer *n* (1<=≀<=*n*<=≀<=1014). We know that all numbers *a*, *b*, *c* are positive integers. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
In the single line print the required number of ways. If it turns out that there isn't a single way of suitable sizes of *a*, *b*, *c*, print 0.
[ "24\n", "648\n", "5\n", "93163582512000\n" ]
[ "1\n", "7\n", "0\n", "39090\n" ]
none
[ { "input": "24", "output": "1" }, { "input": "648", "output": "7" }, { "input": "5", "output": "0" }, { "input": "93163582512000", "output": "39090" }, { "input": "1260", "output": "0" }, { "input": "1680", "output": "0" }, { "input": "2520", "output": "6" }, { "input": "1081080", "output": "108" }, { "input": "110270160", "output": "444" }, { "input": "1102701600", "output": "1290" }, { "input": "97821761637600", "output": "38298" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "0" }, { "input": "12", "output": "0" }, { "input": "24", "output": "1" }, { "input": "36", "output": "0" }, { "input": "48", "output": "0" }, { "input": "60", "output": "0" }, { "input": "120", "output": "0" }, { "input": "180", "output": "6" }, { "input": "128501493120", "output": "5160" }, { "input": "146659312800", "output": "5796" }, { "input": "160626866400", "output": "5070" }, { "input": "240940299600", "output": "5526" }, { "input": "293318625600", "output": "8124" }, { "input": "321253732800", "output": "7158" }, { "input": "481880599200", "output": "8352" }, { "input": "642507465600", "output": "9996" }, { "input": "963761198400", "output": "11700" }, { "input": "1124388064800", "output": "9222" }, { "input": "1606268664000", "output": "11022" }, { "input": "1686582097200", "output": "9918" }, { "input": "1927522396800", "output": "15726" }, { "input": "2248776129600", "output": "13146" }, { "input": "3212537328000", "output": "15018" }, { "input": "3373164194400", "output": "14892" }, { "input": "4497552259200", "output": "17844" }, { "input": "6746328388800", "output": "21318" }, { "input": "8995104518400", "output": "23544" }, { "input": "9316358251200", "output": "18222" }, { "input": "13492656777600", "output": "29070" }, { "input": "18632716502400", "output": "24822" }, { "input": "26985313555200", "output": "37926" }, { "input": "27949074753600", "output": "29556" }, { "input": "32607253879200", "output": "23586" }, { "input": "46581791256000", "output": "28422" }, { "input": "48910880818800", "output": "25422" }, { "input": "55898149507200", "output": "40080" }, { "input": "65214507758400", "output": "34044" }, { "input": "100000000000000", "output": "0" }, { "input": "30000000000000", "output": "72" }, { "input": "90000000000000", "output": "129" }, { "input": "128397219837", "output": "0" }, { "input": "100000000000000", "output": "0" }, { "input": "99999999999999", "output": "0" }, { "input": "99999999999998", "output": "0" }, { "input": "99999999999997", "output": "0" }, { "input": "99999999999996", "output": "0" }, { "input": "12121382", "output": "0" }, { "input": "7", "output": "0" }, { "input": "1000000009", "output": "0" }, { "input": "1018081", "output": "0" } ]
0
0
-1
3,034
388
Fox and Minimal path
[ "bitmasks", "constructive algorithms", "graphs", "implementation", "math" ]
null
null
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with *n* vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to *k*?
The first line contains a single integer *k* (1<=≀<=*k*<=≀<=109).
You should output a graph *G* with *n* vertexes (2<=≀<=*n*<=≀<=1000). There must be exactly *k* shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer *n*. Then adjacency matrix *G* with *n* rows and *n* columns must follow. Each element of the matrix must be 'N' or 'Y'. If *G**ij* is 'Y', then graph *G* has a edge connecting vertex *i* and vertex *j*. Consider the graph vertexes are numbered from 1 to *n*. The graph must be undirected and simple: *G**ii* = 'N' and *G**ij*<==<=*G**ji* must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them.
[ "2", "9", "1" ]
[ "4\nNNYY\nNNYY\nYYNN\nYYNN", "8\nNNYYYNNN\nNNNNNYYY\nYNNNNYYY\nYNNNNYYY\nYNNNNYYY\nNYYYYNNN\nNYYYYNNN\nNYYYYNNN", "2\nNY\nYN" ]
In first example, there are 2 shortest paths: 1-3-2 and 1-4-2. In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
[ { "input": "2", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "9", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "1", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "7", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "10", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "16", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "27", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "29", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "31", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "1000000", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "167959139", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "641009859", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "524125987", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "702209411", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "585325539", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "58376259", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "941492387", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "824608515", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "2691939", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "802030518", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "685146646", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "863230070", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "41313494", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "219396918", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "102513046", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "985629174", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "458679894", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "341796022", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "519879446", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "452405440", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "999999999", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "1000000000", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "9999991", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "999999937", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "536870911", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "73939133", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "999999997", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "1000003", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "999983", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "666013", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "29000087", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "13567", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "15485863", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "601258359", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "987654323", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "387420488", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." }, { "input": "268435455", "output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..." } ]
62
0
0
3,035
710
Optimal Point on a Line
[ "brute force", "sortings" ]
null
null
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
The first line contains integer *n* (1<=≀<=*n*<=≀<=3Β·105) β€” the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≀<=*x**i*<=≀<=109) β€” the coordinates of the given *n* points.
Print the only integer *x* β€” the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
[ "4\n1 2 3 4\n" ]
[ "2\n" ]
none
[ { "input": "4\n1 2 3 4", "output": "2" }, { "input": "5\n-1 -10 2 6 7", "output": "2" }, { "input": "10\n-68 10 87 22 30 89 82 -97 -52 25", "output": "22" }, { "input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424", "output": "64" }, { "input": "2\n-1 0", "output": "-1" }, { "input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981", "output": "15" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "4\n-1 -1 0 1", "output": "-1" }, { "input": "10\n0 0 0 0 0 0 0 0 0 1000000000", "output": "0" }, { "input": "2\n1 -1", "output": "-1" }, { "input": "2\n100 50", "output": "50" }, { "input": "2\n1 2", "output": "1" }, { "input": "1\n10", "output": "10" }, { "input": "3\n606194955 -856471310 117647402", "output": "117647402" }, { "input": "2\n615002717 -843553590", "output": "-843553590" }, { "input": "2\n-1 2", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "1\n2", "output": "2" }, { "input": "5\n-638512131 348325781 -550537933 -618161835 -567935532", "output": "-567935532" }, { "input": "1\n120", "output": "120" }, { "input": "2\n-1000000000 1000000000", "output": "-1000000000" }, { "input": "1\n618309368", "output": "618309368" } ]
342
22,937,600
3
3,039
767
The Queue
[ "brute force", "greedy" ]
null
null
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He knows that the receptionist starts working after *t**s* minutes have passed after midnight and closes after *t**f* minutes have passed after midnight (so that (*t**f*<=-<=1) is the last minute when the receptionist is still working). The receptionist spends exactly *t* minutes on each person in the queue. If the receptionist would stop working within *t* minutes, he stops serving visitors (other than the one he already serves). Vasya also knows that exactly *n* visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately. For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them. Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!
The first line contains three integers: the point of time when the receptionist begins to work *t**s*, the point of time when the receptionist stops working *t**f* and the time the receptionist spends on each visitor *t*. The second line contains one integer *n*Β β€” the amount of visitors (0<=≀<=*n*<=≀<=100<=000). The third line contains positive integers in non-decreasing orderΒ β€” the points of time when the visitors arrive to the passport office. All times are set in minutes and do not exceed 1012; it is guaranteed that *t**s*<=&lt;<=*t**f*. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.
Print single non-negative integerΒ β€” the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.
[ "10 15 2\n2\n10 13\n", "8 17 3\n4\n3 4 5 8\n" ]
[ "12", "2" ]
In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight. In the second example, Vasya has to come before anyone else to be served.
[ { "input": "10 15 2\n2\n10 13", "output": "12" }, { "input": "8 17 3\n4\n3 4 5 8", "output": "2" }, { "input": "7 14 3\n2\n1 2", "output": "0" }, { "input": "30 70 10\n3\n30 32 35", "output": "60" }, { "input": "21 56 7\n5\n1 2 3 4 5", "output": "0" }, { "input": "10 1000000000 25\n20\n1 1 5 7 8 10 12 22 44 47 73 77 82 83 89 141 142 168 195 199", "output": "510" }, { "input": "30 60 3\n10\n1 5 6 10 12 13 18 23 24 25", "output": "4" }, { "input": "61 1000000000 13\n55\n29 72 85 94 103 123 125 144 147 153 154 184 189 192 212 234 247 265 292 296 299 304 309 365 378 379 393 401 414 417 421 427 439 441 480 500 509 515 522 539 571 582 623 630 634 635 643 649 654 679 680 686 747 748 775", "output": "360" }, { "input": "117 120 3\n0", "output": "117" }, { "input": "37 3813 32\n117\n1 1 4 5 6 8 10 13 13 16 18 19 20 23 30 32 33 38 49 59 66 69 96 157 160 183 205 292 301 320 349 360 370 372 384 400 410 413 423 434 434 445 451 463 464 490 494 496 497 517 528 532 556 572 607 647 668 689 708 729 748 806 819 879 905 905 915 925 928 931 959 970 1133 1146 1150 1156 1172 1189 1193 1218 1228 1233 1247 1297 1383 1447 1468 1512 1539 1550 1634 1635 1702 1836 1845 1866 1880 2068 2082 2143 2146 2167 2234 2239 2277 2331 2351 2432 2478 2592 2684 2863 2885 3043 3141 3258 3426", "output": "3781" }, { "input": "100000000000 200000000000 10000000000\n10\n1 1 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000", "output": "109999999999" }, { "input": "1 2 1\n0", "output": "1" }, { "input": "50 230 10\n20\n50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240", "output": "49" }, { "input": "100000000000 100000000005 2\n0", "output": "100000000000" }, { "input": "333 500 5\n1\n3000", "output": "333" } ]
77
3,379,200
-1
3,053
158
Next Round
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=β‰₯<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=β‰₯<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "26" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "50 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
92
0
3
3,056
545
Woodcutters
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≀<=*x**i*,<=*h**i*<=≀<=109) β€” the coordinate and the height of the *Ρ–*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Print a single number β€” the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] - fell the 2-nd tree to the right β€” now it occupies segment [2;3] - leave the 3-rd tree β€” it occupies point 5 - leave the 4-th tree β€” it occupies point 10 - fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4", "output": "10" }, { "input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1", "output": "2" }, { "input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8", "output": "5" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1", "output": "9" }, { "input": "3\n1 1\n1000 1000\n1000000000 1000000000", "output": "3" }, { "input": "2\n1 999999999\n1000000000 1000000000", "output": "2" }, { "input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000", "output": "2" }, { "input": "2\n100000000 1000000000\n1000000000 1000000000", "output": "2" } ]
217
9,011,200
0
3,059
29
Mail Stamps
[ "data structures", "dfs and similar", "graphs", "implementation" ]
C. Mail Stamps
2
256
One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city Β«AΒ» to city Β«BΒ», they stamp it with Β«A BΒ», or Β«B AΒ». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately. There are *n* stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter.
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” amount of mail stamps on the envelope. Then there follow *n* lines with two integers each β€” description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city.
Output *n*<=+<=1 numbers β€” indexes of cities in one of the two possible routes of the letter.
[ "2\n1 100\n100 2\n", "3\n3 1\n100 2\n3 2\n" ]
[ "2 100 1 ", "100 2 3 1 " ]
none
[ { "input": "2\n1 100\n100 2", "output": "2 100 1 " }, { "input": "3\n3 1\n100 2\n3 2", "output": "100 2 3 1 " }, { "input": "3\n458744979 589655889\n248228386 824699605\n458744979 824699605", "output": "589655889 458744979 824699605 248228386 " }, { "input": "4\n90104473 221011623\n18773664 221011623\n90104473 74427905\n74427905 186329050", "output": "186329050 74427905 90104473 221011623 18773664 " }, { "input": "5\n695442143 421284135\n641835294 542627184\n852367357 120042890\n641835294 852367357\n542627184 421284135", "output": "695442143 421284135 542627184 641835294 852367357 120042890 " }, { "input": "6\n264896923 2497658\n57071588 447086061\n2497658 483723090\n57071588 264896923\n158310110 483723090\n158310110 72866107", "output": "447086061 57071588 264896923 2497658 483723090 158310110 72866107 " }, { "input": "1\n1 1000000000", "output": "1000000000 1 " }, { "input": "1\n1000000000 999999999", "output": "1000000000 999999999 " }, { "input": "10\n661239801 721746596\n225324231 116454751\n687002568 865423160\n799202882 865423160\n661239801 116454751\n387882517 687002568\n748798833 721746596\n179630172 225324231\n945958362 387882517\n179630172 945958362", "output": "799202882 865423160 687002568 387882517 945958362 179630172 225324231 116454751 661239801 721746596 748798833 " }, { "input": "21\n280810160 291988863\n760364563 140163983\n16417017 364832782\n400253359 677358550\n597688496 794948223\n400253359 603304541\n589408417 603304541\n385039298 307729574\n293170375 805849550\n140163983 219301181\n732214548 760364563\n307729574 280810160\n131915938 219301181\n4615652 347722938\n396478457 805849550\n16417017 732214548\n4615652 677358550\n131915938 589408417\n291988863 364832782\n396478457 794948223\n385039298 597688496", "output": "347722938 4615652 677358550 400253359 603304541 589408417 131915938 219301181 140163983 760364563 732214548 16417017 364832782 291988863 280810160 307729574 385039298 597688496 794948223 396478457 805849550 293170375 " }, { "input": "1\n2105127 227379126", "output": "227379126 2105127 " } ]
1,154
20,992,000
3.672399
3,061
990
Graph And Its Complement
[ "constructive algorithms", "graphs", "implementation" ]
null
null
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes. In an undirected graph loops (edges from a vertex to itself) are not allowed. It can be at most one edge between a pair of vertices. The adjacency matrix of an undirected graph is a square matrix of size $n$ consisting only of "0" and "1", where $n$ is the number of vertices of the graph and the $i$-th row and the $i$-th column correspond to the $i$-th vertex of the graph. The cell $(i,j)$ of the adjacency matrix contains $1$ if and only if the $i$-th and $j$-th vertices in the graph are connected by an edge. A connected component is a set of vertices $X$ such that for every two vertices from this set there exists at least one path in the graph connecting this pair of vertices, but adding any other vertex to $X$ violates this rule. The complement or inverse of a graph $G$ is a graph $H$ on the same vertices such that two distinct vertices of $H$ are adjacent if and only if they are not adjacent in $G$.
In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement.
If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes). Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$ in $G$ (and $0$ otherwise). Note that the matrix must be symmetric, and all digits on the main diagonal must be zeroes. If there are several matrices that satisfy the conditions β€” output any of them.
[ "3 1 2\n", "3 3 3\n" ]
[ "YES\n001\n001\n110\n", "NO\n" ]
none
[ { "input": "3 1 2", "output": "YES\n001\n001\n110" }, { "input": "3 3 3", "output": "NO" }, { "input": "5 1 1", "output": "YES\n01000\n10100\n01010\n00101\n00010" }, { "input": "123 1 84", "output": "YES\n001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n100011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111000..." }, { "input": "2 1 1", "output": "NO" }, { "input": "1 1 1", "output": "YES\n0" }, { "input": "3 1 1", "output": "NO" }, { "input": "5 2 2", "output": "NO" }, { "input": "1000 734 1", "output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "1000 1 1000", "output": "YES\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "1000 1 1", "output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "4 1 1", "output": "YES\n0100\n1010\n0101\n0010" }, { "input": "4 4 1", "output": "YES\n0000\n0000\n0000\n0000" }, { "input": "3 1 3", "output": "YES\n011\n101\n110" }, { "input": "2 1 2", "output": "YES\n01\n10" }, { "input": "101 1 1", "output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n10100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n01010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "102 1 1", "output": "YES\n010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "103 1 1", "output": "YES\n0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00010100000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "104 1 1", "output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n10100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n01010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0001010000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "6 1 1", "output": "YES\n010000\n101000\n010100\n001010\n000101\n000010" }, { "input": "3 2 1", "output": "YES\n010\n100\n000" }, { "input": "5 1 2", "output": "YES\n00111\n00011\n10001\n11001\n11110" }, { "input": "4 1 2", "output": "YES\n0011\n0001\n1001\n1110" }, { "input": "2 2 1", "output": "YES\n00\n00" }, { "input": "3 3 1", "output": "YES\n000\n000\n000" }, { "input": "2 2 2", "output": "NO" }, { "input": "1 1 1", "output": "YES\n0" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "YES\n01\n10" }, { "input": "2 2 1", "output": "YES\n00\n00" }, { "input": "2 2 2", "output": "NO" }, { "input": "3 1 1", "output": "NO" }, { "input": "3 1 2", "output": "YES\n001\n001\n110" }, { "input": "3 1 3", "output": "YES\n011\n101\n110" }, { "input": "3 2 1", "output": "YES\n010\n100\n000" }, { "input": "3 2 2", "output": "NO" }, { "input": "3 2 3", "output": "NO" }, { "input": "3 3 1", "output": "YES\n000\n000\n000" }, { "input": "3 3 2", "output": "NO" }, { "input": "3 3 3", "output": "NO" }, { "input": "4 1 1", "output": "YES\n0100\n1010\n0101\n0010" }, { "input": "4 1 2", "output": "YES\n0011\n0001\n1001\n1110" }, { "input": "4 1 3", "output": "YES\n0011\n0011\n1101\n1110" }, { "input": "4 1 4", "output": "YES\n0111\n1011\n1101\n1110" }, { "input": "4 2 1", "output": "YES\n0100\n1010\n0100\n0000" }, { "input": "4 2 2", "output": "NO" }, { "input": "4 2 3", "output": "NO" }, { "input": "4 2 4", "output": "NO" }, { "input": "4 3 1", "output": "YES\n0100\n1000\n0000\n0000" }, { "input": "4 3 2", "output": "NO" }, { "input": "4 3 3", "output": "NO" }, { "input": "4 3 4", "output": "NO" }, { "input": "4 4 1", "output": "YES\n0000\n0000\n0000\n0000" }, { "input": "4 4 2", "output": "NO" }, { "input": "4 4 3", "output": "NO" }, { "input": "4 4 4", "output": "NO" } ]
0
0
-1
3,062
678
Joty and Chocolate
[ "implementation", "math", "number theory" ]
null
null
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximumΒ number of chocolates Joty can get.
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≀<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≀<=109).
Print the only integer *s* β€” the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "5 2 3 12 15\n", "20 2 3 3 5\n" ]
[ "39\n", "51\n" ]
none
[ { "input": "5 2 3 12 15", "output": "39" }, { "input": "20 2 3 3 5", "output": "51" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1 2 2 2 2", "output": "0" }, { "input": "2 1 3 3 3", "output": "6" }, { "input": "3 1 1 3 3", "output": "9" }, { "input": "4 1 5 4 3", "output": "16" }, { "input": "8 8 1 1 1", "output": "8" }, { "input": "15 14 32 65 28", "output": "65" }, { "input": "894 197 325 232 902", "output": "2732" }, { "input": "8581 6058 3019 2151 4140", "output": "10431" }, { "input": "41764 97259 54586 18013 75415", "output": "0" }, { "input": "333625 453145 800800 907251 446081", "output": "0" }, { "input": "4394826 2233224 609367 3364334 898489", "output": "9653757" }, { "input": "13350712 76770926 61331309 8735000 9057368", "output": "0" }, { "input": "142098087 687355301 987788392 75187408 868856364", "output": "0" }, { "input": "1000000000 1 3 1000000000 999999999", "output": "1000000000000000000" }, { "input": "6 6 2 8 2", "output": "12" }, { "input": "500 8 4 4 5", "output": "625" }, { "input": "20 4 6 2 3", "output": "17" }, { "input": "10 3 9 1 2", "output": "4" }, { "input": "120 18 6 3 5", "output": "100" }, { "input": "30 4 6 2 2", "output": "20" }, { "input": "1000000000 7171 2727 191 272", "output": "125391842" }, { "input": "5 2 2 4 1", "output": "8" }, { "input": "1000000000 2 2 3 3", "output": "1500000000" }, { "input": "24 4 6 5 7", "output": "48" }, { "input": "216 6 36 10 100", "output": "900" }, { "input": "100 12 6 1 10", "output": "160" }, { "input": "1000 4 8 3 5", "output": "1000" }, { "input": "10 2 4 3 6", "output": "21" }, { "input": "1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "10 5 10 2 3", "output": "5" }, { "input": "100000 3 9 1 2", "output": "44444" }, { "input": "10 2 4 1 100", "output": "203" }, { "input": "20 6 4 2 3", "output": "19" }, { "input": "1200 4 16 2 3", "output": "675" }, { "input": "7 2 4 7 9", "output": "23" }, { "input": "24 6 4 15 10", "output": "100" }, { "input": "50 2 8 15 13", "output": "375" }, { "input": "100 4 6 12 15", "output": "444" }, { "input": "56756 9 18 56 78", "output": "422502" }, { "input": "10000 4 6 10 12", "output": "36662" }, { "input": "20 2 4 3 5", "output": "40" }, { "input": "24 4 6 10 100", "output": "440" }, { "input": "12 2 4 5 6", "output": "33" }, { "input": "100 2 4 1 100", "output": "2525" }, { "input": "1000 4 6 50 50", "output": "16650" }, { "input": "60 12 6 12 15", "output": "150" }, { "input": "1000 2 4 5 6", "output": "2750" }, { "input": "1000000000 1 1 9999 5555", "output": "9999000000000" }, { "input": "50 2 2 4 5", "output": "125" }, { "input": "14 4 2 2 3", "output": "21" }, { "input": "100 3 9 1 2", "output": "44" }, { "input": "1000000000 4 6 1 1000000000", "output": "166666666166666667" }, { "input": "12 3 3 45 4", "output": "180" }, { "input": "12 2 4 5 9", "output": "42" }, { "input": "1000000000 2 2 1000000000 1000000000", "output": "500000000000000000" }, { "input": "50 4 8 5 6", "output": "66" }, { "input": "32 4 16 6 3", "output": "48" }, { "input": "10000 2 4 1 1", "output": "5000" }, { "input": "8 2 4 100 1", "output": "400" }, { "input": "20 4 2 10 1", "output": "55" }, { "input": "5 2 2 12 15", "output": "30" }, { "input": "20 2 12 5 6", "output": "51" }, { "input": "10 2 4 1 2", "output": "7" }, { "input": "32 4 16 3 6", "output": "30" }, { "input": "50 2 8 13 15", "output": "337" }, { "input": "12 6 4 10 9", "output": "38" }, { "input": "1000000000 999999998 999999999 999999998 999999999", "output": "1999999997" }, { "input": "20 2 4 10 20", "output": "150" }, { "input": "13 4 6 12 15", "output": "54" }, { "input": "30 3 6 5 7", "output": "60" }, { "input": "7 2 4 2 1", "output": "6" }, { "input": "100000 32 16 2 3", "output": "18750" }, { "input": "6 2 6 1 1", "output": "3" }, { "input": "999999999 180 192 46642017 28801397", "output": "399129078526502" }, { "input": "12 4 6 1 1", "output": "4" }, { "input": "10 2 4 10 5", "output": "50" }, { "input": "1000000 4 6 12 14", "output": "4333328" }, { "input": "2000 20 30 3 5", "output": "531" }, { "input": "1000000000 1 2 1 1", "output": "1000000000" }, { "input": "30 3 15 10 3", "output": "100" }, { "input": "1000 2 4 1 100", "output": "25250" }, { "input": "6 3 3 12 15", "output": "30" }, { "input": "24 4 6 1 1", "output": "8" }, { "input": "20 2 12 4 5", "output": "41" }, { "input": "1000000000 9 15 10 10", "output": "1555555550" }, { "input": "16 2 4 1 2", "output": "12" }, { "input": "100000 4 6 12 14", "output": "433328" }, { "input": "24 6 4 1 1", "output": "8" }, { "input": "1000000 4 6 12 15", "output": "4499994" }, { "input": "100 2 4 5 6", "output": "275" }, { "input": "10 3 9 12 15", "output": "39" }, { "input": "1000000000 1 1 999999999 999999999", "output": "999999999000000000" }, { "input": "6 2 4 2 3", "output": "7" }, { "input": "2 2 2 2 2", "output": "2" }, { "input": "6 6 2 1 1", "output": "3" }, { "input": "100 2 4 3 7", "output": "250" }, { "input": "1000000 32 16 2 5", "output": "312500" }, { "input": "100 20 15 50 25", "output": "375" }, { "input": "1000000000 100000007 100000013 10 3", "output": "117" }, { "input": "1000000000 9999999 99999998 3 3", "output": "330" }, { "input": "10077696 24 36 10 100", "output": "30792960" }, { "input": "392852503 148746166 420198270 517065752 906699795", "output": "1034131504" }, { "input": "536870912 60000 72000 271828 314159", "output": "4369119072" }, { "input": "730114139 21550542 204644733 680083361 11353255", "output": "22476810678" }, { "input": "538228881 766493289 791886544 468896052 600136703", "output": "0" }, { "input": "190 20 50 84 172", "output": "1188" }, { "input": "1000 5 10 80 90", "output": "17000" }, { "input": "99999999 999999998 1 271828 314159", "output": "31415899685841" }, { "input": "22 3 6 1243 1", "output": "8701" }, { "input": "15 10 5 2 2", "output": "6" }, { "input": "1000000000 1000000000 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "62 62 42 78 124", "output": "202" }, { "input": "2 2 2 2 1", "output": "2" }, { "input": "864351351 351 313 531 11", "output": "1337898227" }, { "input": "26 3 6 1244 1", "output": "9952" }, { "input": "1000 4 6 7 3", "output": "1999" }, { "input": "134312 3 6 33333 1", "output": "1492318410" }, { "input": "100 4 6 17 18", "output": "577" }, { "input": "6 2 4 5 6", "output": "16" }, { "input": "8 2 4 10 1", "output": "40" }, { "input": "10 2 4 3 3", "output": "15" }, { "input": "1000 1000 1000 1000 1000", "output": "1000" }, { "input": "123123 3 6 34312 2", "output": "1408198792" }, { "input": "1000000000 25 5 999 999", "output": "199800000000" }, { "input": "100 4 2 5 12", "output": "600" }, { "input": "50 2 4 4 5", "output": "112" }, { "input": "24 4 6 100 333", "output": "1732" }, { "input": "216 24 36 10 100", "output": "660" }, { "input": "50 6 4 3 8", "output": "108" }, { "input": "146 76 2 178 192", "output": "14016" }, { "input": "55 8 6 11 20", "output": "224" }, { "input": "5 2 4 6 16", "output": "22" }, { "input": "54 2 52 50 188", "output": "1488" }, { "input": "536870912 60000000 72000000 271828 314159", "output": "4101909" }, { "input": "1000000000 1000000000 1 1 100", "output": "100000000000" }, { "input": "50 4 2 4 5", "output": "125" }, { "input": "198 56 56 122 118", "output": "366" }, { "input": "5 1000000000 1 12 15", "output": "75" }, { "input": "1000 6 12 5 6", "output": "913" }, { "input": "50 3 6 12 15", "output": "216" }, { "input": "333 300 300 300 300", "output": "300" }, { "input": "1 1000000000 1 1 2", "output": "2" }, { "input": "188 110 110 200 78", "output": "200" }, { "input": "100000 20 10 3 2", "output": "25000" }, { "input": "100 2 4 1 10", "output": "275" }, { "input": "1000000000 2 1000000000 1 1000000", "output": "500999999" }, { "input": "20 3 6 5 7", "output": "36" }, { "input": "50 4 6 4 5", "output": "72" }, { "input": "96 46 4 174 156", "output": "3936" }, { "input": "5 2 4 12 15", "output": "27" }, { "input": "12 3 6 100 1", "output": "400" }, { "input": "100 4 2 10 32", "output": "1600" }, { "input": "1232 3 6 30000 3", "output": "12300000" }, { "input": "20 3 6 5 4", "output": "30" }, { "input": "100 6 15 11 29", "output": "317" }, { "input": "10000000 4 8 100 200", "output": "375000000" }, { "input": "1000000000 12 24 2 4", "output": "249999998" }, { "input": "123 3 6 3000 1", "output": "123000" }, { "input": "401523968 1536 2664 271828 314159", "output": "117768531682" }, { "input": "9 2 4 3 5", "output": "16" }, { "input": "999999999 724362018 772432019 46201854 20017479", "output": "66219333" }, { "input": "100 2 4 1 1000", "output": "25025" }, { "input": "50 2 4 1 1000", "output": "12013" }, { "input": "1000000000 2 1 2 1", "output": "1500000000" }, { "input": "1000000000 2005034 2005046 15 12", "output": "13446" }, { "input": "1000000000 999999999 1000000000 1 1", "output": "2" }, { "input": "999999999 500000000 1 100 1000", "output": "999999999000" }, { "input": "50 8 6 3 4", "output": "44" }, { "input": "1000000000 1 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "1000000000 999999862 999999818 15 12", "output": "27" }, { "input": "1000000000 10000019 10000019 21 17", "output": "2079" }, { "input": "20 6 4 8 2", "output": "32" }, { "input": "1000000000 1000000000 1 1 1", "output": "1000000000" }, { "input": "1000000000 12345678 123456789 1000000000 999999999", "output": "88999999992" }, { "input": "1000000000 2 999999937 100000000 100000000", "output": "50000000100000000" }, { "input": "1000000000 1 1 1000000000 999999999", "output": "1000000000000000000" }, { "input": "1000000000 50001 100003 10 10", "output": "299980" }, { "input": "1000000000 1000000000 3 1 1", "output": "333333334" }, { "input": "10000 44 49 114 514", "output": "130278" }, { "input": "30 5 15 2 1", "output": "12" }, { "input": "20 2 4 1 1", "output": "10" }, { "input": "100 8 12 5 6", "output": "88" } ]
1,000
1,740,800
0
3,067
257
View Angle
[ "brute force", "geometry", "math" ]
null
null
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of mannequins. Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≀<=1000) β€” the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane.
Print a single real number β€” the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6.
[ "2\n2 0\n0 2\n", "3\n2 0\n0 2\n-2 2\n", "4\n2 0\n0 2\n-2 0\n0 -2\n", "2\n2 1\n1 2\n" ]
[ "90.0000000000\n", "135.0000000000\n", "270.0000000000\n", "36.8698976458\n" ]
Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
[ { "input": "2\n2 0\n0 2", "output": "90.0000000000" }, { "input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000" }, { "input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000" }, { "input": "2\n2 1\n1 2", "output": "36.8698976458" }, { "input": "1\n1 1", "output": "0.0000000000" }, { "input": "10\n9 7\n10 7\n6 5\n6 10\n7 6\n5 10\n6 7\n10 9\n5 5\n5 8", "output": "28.4429286244" }, { "input": "10\n-1 28\n1 28\n1 25\n0 23\n-1 24\n-1 22\n1 27\n0 30\n1 22\n1 21", "output": "5.3288731964" }, { "input": "10\n-5 9\n-10 6\n-8 8\n-9 9\n-6 5\n-8 9\n-5 7\n-6 6\n-5 10\n-8 7", "output": "32.4711922908" }, { "input": "10\n6 -9\n9 -5\n10 -5\n7 -5\n8 -7\n8 -10\n8 -5\n6 -10\n7 -6\n8 -9", "output": "32.4711922908" }, { "input": "10\n-5 -7\n-8 -10\n-9 -5\n-5 -9\n-9 -8\n-7 -7\n-6 -8\n-6 -10\n-10 -7\n-9 -6", "output": "31.8907918018" }, { "input": "10\n-1 -29\n-1 -26\n1 -26\n-1 -22\n-1 -24\n-1 -21\n1 -24\n-1 -20\n-1 -23\n-1 -25", "output": "5.2483492565" }, { "input": "10\n21 0\n22 1\n30 0\n20 0\n28 0\n29 0\n21 -1\n30 1\n24 1\n26 0", "output": "5.3288731964" }, { "input": "10\n-20 0\n-22 1\n-26 0\n-22 -1\n-30 -1\n-30 0\n-28 0\n-24 1\n-23 -1\n-29 1", "output": "5.2051244050" }, { "input": "10\n-5 -5\n5 -5\n-4 -5\n4 -5\n1 -5\n0 -5\n3 -5\n-2 -5\n2 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n-5 -5\n-4 -5\n-2 -5\n4 -5\n5 -5\n3 -5\n2 -5\n-1 -5\n-3 -5\n0 -5", "output": "90.0000000000" }, { "input": "10\n-1 -5\n-5 -5\n2 -5\n-2 -5\n1 -5\n5 -5\n0 -5\n3 -5\n-4 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n-1 -5\n-5 -5\n-4 -5\n3 -5\n0 -5\n4 -5\n1 -5\n-2 -5\n5 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n5 -5\n4 -5\n-1 -5\n1 -5\n-4 -5\n3 -5\n0 -5\n-5 -5\n-2 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n2 -5\n-4 -5\n-2 -5\n4 -5\n-5 -5\n-1 -5\n0 -5\n-3 -5\n3 -5\n1 -5", "output": "83.6598082541" }, { "input": "5\n2 1\n0 1\n2 -1\n-2 -1\n2 0", "output": "233.1301023542" }, { "input": "5\n-2 -2\n2 2\n2 -1\n-2 0\n1 -1", "output": "225.0000000000" }, { "input": "5\n0 -2\n-2 -1\n-1 2\n0 -1\n-1 0", "output": "153.4349488229" }, { "input": "5\n-1 -1\n-2 -1\n1 0\n-1 -2\n-1 1", "output": "225.0000000000" }, { "input": "5\n1 -1\n0 2\n-2 2\n-2 1\n2 1", "output": "198.4349488229" }, { "input": "5\n2 2\n1 2\n-2 -1\n1 1\n-2 -2", "output": "180.0000000000" }, { "input": "2\n1 1\n2 2", "output": "0.0000000000" }, { "input": "27\n-592 -96\n-925 -150\n-111 -18\n-259 -42\n-370 -60\n-740 -120\n-629 -102\n-333 -54\n-407 -66\n-296 -48\n-37 -6\n-999 -162\n-222 -36\n-555 -90\n-814 -132\n-444 -72\n-74 -12\n-185 -30\n-148 -24\n-962 -156\n-777 -126\n-518 -84\n-888 -144\n-666 -108\n-481 -78\n-851 -138\n-703 -114", "output": "0.0000000000" }, { "input": "38\n96 416\n24 104\n6 26\n12 52\n210 910\n150 650\n54 234\n174 754\n114 494\n18 78\n90 390\n36 156\n222 962\n186 806\n126 546\n78 338\n108 468\n180 780\n120 520\n84 364\n66 286\n138 598\n30 130\n228 988\n72 312\n144 624\n198 858\n60 260\n48 208\n102 442\n42 182\n162 702\n132 572\n156 676\n204 884\n216 936\n168 728\n192 832", "output": "0.0000000000" }, { "input": "14\n-2 -134\n-4 -268\n-11 -737\n-7 -469\n-14 -938\n-10 -670\n-3 -201\n-1 -67\n-9 -603\n-6 -402\n-13 -871\n-12 -804\n-8 -536\n-5 -335", "output": "0.0000000000" }, { "input": "14\n588 938\n420 670\n210 335\n252 402\n504 804\n126 201\n42 67\n546 871\n294 469\n84 134\n336 536\n462 737\n168 268\n378 603", "output": "0.0000000000" }, { "input": "20\n-45 147\n-240 784\n-135 441\n-60 196\n-105 343\n-285 931\n-195 637\n-300 980\n-165 539\n-210 686\n-75 245\n-15 49\n-30 98\n-270 882\n-120 392\n-90 294\n-150 490\n-180 588\n-255 833\n-225 735", "output": "0.0000000000" }, { "input": "2\n1 1\n1 -1", "output": "90.0000000000" } ]
1,714
30,003,200
0
3,069
73
FreeDiv
[ "dfs and similar", "graphs", "greedy" ]
D. FreeDiv
5
256
Vasya plays FreeDiv. In this game he manages a huge state, which has *n* cities and *m* two-way roads between them. Unfortunately, not from every city you can reach any other one moving along these roads. Therefore Vasya decided to divide the state into provinces so that in every province, one could reach from every city all the cities of the province, but there are no roads between provinces. Unlike other turn-based strategies, in FreeDiv a player has the opportunity to build tunnels between cities. The tunnels are two-way roads along which one can move armies undetected by the enemy. However, no more than one tunnel can be connected to each city. As for Vasya, he wants to build a network of tunnels so that any pair of cities in his state were reachable by some path consisting of roads and a tunnels. But at that no more than *k* tunnels are connected to each province (otherwise, the province will be difficult to keep in case other provinces are captured by enemy armies). Vasya discovered that maybe he will not be able to build such a network for the current condition of the state. Maybe he'll have first to build several roads between cities in different provinces to merge the provinces. Your task is to determine the minimum number of roads Vasya needs to build so that it was possible to build the required network of tunnels in the resulting state.
The first line contains three integers *n*, *m* and *k* (1<=≀<=*n*,<=*k*<=≀<=106,<=0<=≀<=*m*<=≀<=106). Each of the next *m* lines contains two integers. They are the numbers of cities connected by a corresponding road. No road connects city to itself and there is at most one road between each pair of cities.
Print a single number, the minimum number of additional roads.
[ "3 3 2\n1 2\n2 3\n3 1\n", "4 2 2\n1 2\n3 4\n", "4 0 2\n" ]
[ "0", "0", "1" ]
In the first example only one province exists, so it is not necessary to build any tunnels or roads. In the second example two provinces exist. It is possible to merge the provinces by building a tunnel between cities 1 and 3. In the third example at least one additional road is necessary. For example it is possible to build additional road between cities 1 and 2 and build two tunnels between cities 1 and 3, 2 and 4 after that.
[ { "input": "3 3 2\n1 2\n2 3\n3 1", "output": "0" }, { "input": "4 2 2\n1 2\n3 4", "output": "0" }, { "input": "4 0 2", "output": "1" }, { "input": "4 0 3", "output": "1" }, { "input": "8 3 4\n1 4\n4 8\n8 1", "output": "1" }, { "input": "8 3 2\n1 4\n4 8\n8 1", "output": "2" }, { "input": "8 3 3\n1 4\n4 8\n8 1", "output": "1" }, { "input": "8 0 3", "output": "3" }, { "input": "50 0 50", "output": "24" }, { "input": "50 0 2", "output": "24" }, { "input": "50 0 100", "output": "24" }, { "input": "100 0 1", "output": "98" }, { "input": "3289 0 2", "output": "1644" }, { "input": "1000000 0 1", "output": "999998" }, { "input": "1000000 0 2", "output": "499999" }, { "input": "1000000 0 1000000", "output": "499999" }, { "input": "1000000 0 100", "output": "499999" }, { "input": "999999 0 1", "output": "999997" }, { "input": "999999 0 2", "output": "499999" }, { "input": "999999 0 999999", "output": "499999" }, { "input": "102 1 1\n23 58", "output": "99" }, { "input": "102 1 2\n1 62", "output": "49" }, { "input": "102 1 10000\n66 45", "output": "49" }, { "input": "1000000 1 1\n663349 495214", "output": "999997" }, { "input": "1000000 1 2\n998708 47343", "output": "499998" }, { "input": "1000000 1 5\n789076 458264", "output": "499998" }, { "input": "11 5 1\n8 11\n11 2\n2 5\n5 7\n8 2", "output": "5" }, { "input": "11 5 2\n1 6\n6 7\n7 2\n2 11\n2 1", "output": "2" }, { "input": "11 5 3\n2 7\n7 9\n9 8\n8 3\n8 7", "output": "2" }, { "input": "11 5 4\n9 8\n8 4\n4 1\n1 10\n8 1", "output": "1" }, { "input": "11 5 5\n10 8\n8 7\n7 11\n11 6\n10 7", "output": "1" }, { "input": "11 5 6\n10 1\n1 8\n8 7\n7 3\n10 7", "output": "1" }, { "input": "3 2 1\n1 2\n2 3", "output": "0" }, { "input": "2 0 1", "output": "0" }, { "input": "1 0 1", "output": "0" }, { "input": "3 0 1", "output": "1" }, { "input": "4 0 1", "output": "2" }, { "input": "4 1 1\n1 2", "output": "1" }, { "input": "4 2 1\n1 2\n3 4", "output": "0" }, { "input": "4 3 1\n1 2\n2 3\n3 4", "output": "0" }, { "input": "2 1 1\n1 2", "output": "0" }, { "input": "5 0 1", "output": "3" }, { "input": "5 1 1\n1 2", "output": "2" }, { "input": "5 2 1\n1 2\n2 3", "output": "1" }, { "input": "5 2 1\n1 2\n3 4", "output": "1" }, { "input": "5 3 1\n1 2\n2 3\n4 5", "output": "0" }, { "input": "10 0 1", "output": "8" } ]
92
0
0
3,076
771
Bear and Different Names
[ "constructive algorithms", "greedy" ]
null
null
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed *n* soldiers standing in a row, numbered 1 through *n*. The general wants to choose a group of *k* consecutive soldiers. For every *k* consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1, each either "YES" or "NO". - The string *s*1 describes a group of soldiers 1 through *k* ("YES" if the group is effective, and "NO" otherwise). - The string *s*2 describes a group of soldiers 2 through *k*<=+<=1. - And so on, till the string *s**n*<=-<=*k*<=+<=1 that describes a group of soldiers *n*<=-<=*k*<=+<=1 through *n*. Your task is to find possible names of *n* soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing namesΒ β€” it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution.
The first line of the input contains two integers *n* and *k* (2<=≀<=*k*<=≀<=*n*<=≀<=50)Β β€” the number of soldiers and the size of a group respectively. The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k*<=-<=1 is effective, and "NO" otherwise.
Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them.
[ "8 3\nNO NO YES YES YES NO\n", "9 8\nYES NO\n", "3 2\nNO NO\n" ]
[ "Adam Bob Bob Cpqepqwer Limak Adam Bob Adam", "R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc", "Na Na Na" ]
In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: - First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string *s*<sub class="lower-index">1</sub> is "NO". - Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string *s*<sub class="lower-index">2</sub> is "NO". - Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string *s*<sub class="lower-index">3</sub> is "YES". - ..., - Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string *s*<sub class="lower-index">6</sub> is "NO".
[ { "input": "8 3\nNO NO YES YES YES NO", "output": "Ab Ac Ab Ac Af Ag Ah Ag " }, { "input": "9 8\nYES NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Ac " }, { "input": "3 2\nNO NO", "output": "Ab Ab Ab " }, { "input": "2 2\nYES", "output": "Ab Ac " }, { "input": "2 2\nNO", "output": "Ab Ab " }, { "input": "7 2\nYES NO YES YES NO YES", "output": "Ab Ac Ac Ae Af Af Ah " }, { "input": "18 7\nYES YES YES YES YES YES YES NO NO NO NO NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ai Aj Ak Al Am " }, { "input": "50 3\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO", "output": "Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Bx Ac " }, { "input": "19 15\nNO YES YES YES NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ab Aq Ar As Af " }, { "input": "3 2\nNO NO", "output": "Ab Ab Ab " }, { "input": "3 2\nNO YES", "output": "Ab Ab Ad " }, { "input": "3 2\nYES NO", "output": "Ab Ac Ac " }, { "input": "3 2\nYES YES", "output": "Ab Ac Ad " }, { "input": "26 17\nNO YES YES YES NO YES NO YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ab As At Au Af Aw Ah Ay Az Ba " }, { "input": "12 2\nYES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am " }, { "input": "16 2\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO", "output": "Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab " }, { "input": "42 20\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq " }, { "input": "37 14\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al " }, { "input": "29 10\nYES NO YES NO YES NO YES YES YES YES YES NO NO NO NO NO YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Ac Am Ae Ao Ag Aq Ar As At Au Am Ae Ao Ag Aq Ba Bb Bc Bd " }, { "input": "37 3\nYES NO YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES NO NO YES YES YES YES NO", "output": "Ab Ac Ad Ac Af Ac Ah Ac Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Ba Bb Be Bb Be Bh Bi Bj Bk Bj " }, { "input": "44 11\nNO NO YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES NO NO YES NO NO YES YES YES NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Ab Ac An Ae Ap Ag Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Au Bf Bg Bh Bi Bj Ba Bb Bm Bd Au Bp Bq Br Bi " }, { "input": "50 49\nNO YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ab By " }, { "input": "50 49\nYES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "50 49\nNO NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ab Ac " }, { "input": "50 49\nYES NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ac " }, { "input": "46 42\nNO YES YES YES NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Ab Br Bs Bt Af " }, { "input": "45 26\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt " }, { "input": "45 26\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au " }, { "input": "50 3\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES", "output": "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak Ab Am Ab Ao Ab Aq Ab As Ab Au Ab Aw Ab Ay Ab Ba Ab Bc Ab Be Ab Bg Ab Bi Ab Bk Ab Bm Ab Bo Ab Bq Ab Bs Ab Bu Ab Bw Ab By " }, { "input": "50 2\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO", "output": "Ab Ab Ad Ad Af Af Ah Ah Aj Aj Al Al An An Ap Ap Ar Ar At At Av Av Ax Ax Az Az Bb Bb Bd Bd Bf Bf Bh Bh Bj Bj Bl Bl Bn Bn Bp Bp Br Br Bt Bt Bv Bv Bx Bx " }, { "input": "50 3\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES YES YES YES YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES", "output": "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak Ab Am Ab Ao Ab Aq Ab As Ab Au Ab Aw Ab Ay Ab Ba Ab Bc Bd Be Bf Bg Bf Bi Bf Bk Bf Bm Bf Bo Bf Bq Bf Bs Bf Bu Bf Bw Bf By " }, { "input": "49 2\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO NO NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES", "output": "Ab Ab Ad Ad Af Af Ah Ah Aj Aj Al Al An An Ap Ap Ar Ar At At Av Av Ax Ax Ax Ax Bb Bb Bd Bd Bf Bf Bh Bh Bj Bj Bl Bl Bn Bn Bp Bp Br Br Bt Bt Bv Bv Bx " }, { "input": "35 22\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao " }, { "input": "46 41\nYES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu " }, { "input": "12 4\nYES YES NO NO NO NO NO YES YES", "output": "Ab Ac Ad Ae Af Ad Ae Af Ad Ae Al Am " }, { "input": "50 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "50 4\nYES YES YES YES YES NO YES YES YES YES NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Ag Ak Al Am An Al Am Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bc Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "34 5\nYES YES YES YES YES NO YES YES YES YES NO NO YES YES YES NO NO YES NO YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ag Al Am An Ao Al Am Ar As At Am Ar Aw At Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi " }, { "input": "50 43\nYES NO YES NO YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Ac Bt Ae Bv Bw Bx By " }, { "input": "38 30\nNO NO YES NO YES NO NO NO NO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Ab Ac Bg Ae Bi Ag Ah Ai Aj " }, { "input": "50 50\nNO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ab " }, { "input": "50 50\nYES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "5 3\nYES NO YES", "output": "Ab Ac Ad Ac Af " }, { "input": "30 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be " }, { "input": "50 50\nYES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "27 27\nYES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb " }, { "input": "28 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc " }, { "input": "50 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "8 3\nYES NO YES NO YES NO", "output": "Ab Ac Ad Ac Af Ac Ah Ac " }, { "input": "42 30\nNO YES YES NO NO YES NO YES NO YES NO NO YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Ab Bf Bg Ae Af Bj Ah Bl Aj Bn Al Am Bq " }, { "input": "50 49\nYES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "50 3\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By " }, { "input": "7 5\nYES NO YES", "output": "Ab Ac Ad Ae Af Ac Ah " }, { "input": "8 4\nNO YES NO YES NO", "output": "Ab Ac Ad Ab Af Ad Ah Af " }, { "input": "50 50\nNO", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ab " }, { "input": "50 48\nYES NO YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ac By " }, { "input": "29 14\nYES NO YES NO NO YES YES NO NO YES YES NO NO YES YES YES", "output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ac Aq Ae Af At Au Ai Aj Ax Ay Am An Bb Bc Bd " }, { "input": "10 3\nNO YES NO YES NO YES NO YES", "output": "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak " }, { "input": "10 5\nYES NO YES NO YES NO", "output": "Ab Ac Ad Ae Af Ac Ah Ae Aj Ac " } ]
62
4,608,000
3
3,085
856
Set Theory
[ "brute force", "constructive algorithms" ]
null
null
Masha and Grisha like studying sets of positive integers. One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that all *n*2 integers that can be obtained by summing up *a**i* and *b**j* for all possible pairs of *i* and *j* are different. Both Masha and Grisha don't like big numbers, so all numbers in *A* are from 1 to 106, and all numbers in *B* must also be in the same range. Help Masha to create the set *B* that satisfies Grisha's requirement.
Input data contains multiple test cases. The first line contains an integer *t*Β β€” the number of test cases (1<=≀<=*t*<=≀<=100). Each test case is described in the following way: the first line of the description contains one integer *n*Β β€” the number of elements in *A* (1<=≀<=*n*<=≀<=100). The second line contains *n* integers *a**i*Β β€” the elements of *A* (1<=≀<=*a**i*<=≀<=106).
For each test first print the answer: - NO, if Masha's task is impossible to solve, there is no way to create the required set *B*. - YES, if there is the way to create the required set. In this case the second line must contain *n* different positive integers *b**j*Β β€” elements of *B* (1<=≀<=*b**j*<=≀<=106). If there are several possible sets, output any of them.
[ "3\n3\n1 10 100\n1\n1\n2\n2 4\n" ]
[ "YES\n1 2 3 \nYES\n1 \nYES\n1 2 \n" ]
none
[ { "input": "3\n3\n1 10 100\n1\n1\n2\n2 4", "output": "YES\n1 2 3 \nYES\n1 \nYES\n1 2 " }, { "input": "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41 19 35 16 88 27 99 40 62 95 70 18 46 21 53 59 37 6 61 71 2 4 52 28 97 25 29 51 7 33 80 83 72 10 75 94 43 84 54 55", "output": "YES\n1 101 201 301 401 501 601 701 801 901 1001 1101 1201 1301 1401 1501 1601 1701 1801 1901 2001 2101 2201 2301 2401 2501 2601 2701 2801 2901 3001 3101 3201 3301 3401 3501 3601 3701 3801 3901 4001 4101 4201 4301 4401 4501 4601 4701 4801 4901 5001 5101 5201 5301 5401 5501 5601 5701 5801 5901 6001 6101 6201 6301 6401 6501 6601 6701 6801 6901 7001 7101 7201 7301 7401 7501 7601 7701 7801 7901 8001 8101 8201 8301 8401 8501 8601 8701 8801 8901 9001 9101 9201 9301 9401 9501 9601 9701 9801 9901 " } ]
1,000
0
0
3,091
865
Save the problem!
[ "constructive algorithms" ]
null
null
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change? As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.
Input will consist of a single integer *A* (1<=≀<=*A*<=≀<=105), the desired number of ways.
In the first line print integers *N* and *M* (1<=≀<=*N*<=≀<=106,<=1<=≀<=*M*<=≀<=10), the amount of change to be made, and the number of denominations, respectively. Then print *M* integers *D*1,<=*D*2,<=...,<=*D**M* (1<=≀<=*D**i*<=≀<=106), the denominations of the coins. All denominations must be distinct: for any *i*<=β‰ <=*j* we must have *D**i*<=β‰ <=*D**j*. If there are multiple tests, print any of them. You can print denominations in atbitrary order.
[ "18\n", "3\n", "314\n" ]
[ "30 4\n1 5 10 25\n", "20 2\n5 2\n", "183 4\n6 5 2 139\n" ]
none
[ { "input": "18", "output": "30 4\n1 5 10 25" }, { "input": "3", "output": "20 2\n5 2" }, { "input": "314", "output": "183 4\n6 5 2 139" }, { "input": "1023", "output": "2045 2\n1 2" }, { "input": "100000", "output": "199999 2\n1 2" }, { "input": "1", "output": "1 2\n1 2" }, { "input": "2", "output": "3 2\n1 2" }, { "input": "3", "output": "20 2\n5 2" }, { "input": "4", "output": "7 2\n1 2" }, { "input": "5", "output": "9 2\n1 2" }, { "input": "6", "output": "11 2\n1 2" }, { "input": "7", "output": "13 2\n1 2" }, { "input": "8", "output": "15 2\n1 2" }, { "input": "9", "output": "17 2\n1 2" }, { "input": "10", "output": "19 2\n1 2" }, { "input": "11", "output": "21 2\n1 2" }, { "input": "12", "output": "23 2\n1 2" }, { "input": "13", "output": "25 2\n1 2" }, { "input": "14", "output": "27 2\n1 2" }, { "input": "15", "output": "29 2\n1 2" }, { "input": "16", "output": "31 2\n1 2" }, { "input": "17", "output": "33 2\n1 2" }, { "input": "18", "output": "30 4\n1 5 10 25" }, { "input": "19", "output": "37 2\n1 2" }, { "input": "20", "output": "39 2\n1 2" }, { "input": "239", "output": "477 2\n1 2" }, { "input": "4063", "output": "8125 2\n1 2" }, { "input": "65536", "output": "131071 2\n1 2" }, { "input": "65535", "output": "131069 2\n1 2" }, { "input": "65537", "output": "131073 2\n1 2" }, { "input": "99991", "output": "199981 2\n1 2" }, { "input": "99990", "output": "199979 2\n1 2" }, { "input": "99992", "output": "199983 2\n1 2" }, { "input": "99971", "output": "199941 2\n1 2" }, { "input": "99990", "output": "199979 2\n1 2" }, { "input": "2", "output": "3 2\n1 2" }, { "input": "99991", "output": "199981 2\n1 2" } ]
109
0
3
3,094
0
none
[ "none" ]
null
null
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time. Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
The first line contains single integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≀<=*h**i*<=≀<=109) β€” sizes of towers.
Print the number of operations needed to destroy all towers.
[ "6\n2 1 4 6 2 2\n", "7\n3 3 3 1 3 3 3\n" ]
[ "3\n", "2\n" ]
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
[ { "input": "6\n2 1 4 6 2 2", "output": "3" }, { "input": "7\n3 3 3 1 3 3 3", "output": "2" }, { "input": "7\n5128 5672 5805 5452 5882 5567 5032", "output": "4" }, { "input": "10\n1 2 2 3 5 5 5 4 2 1", "output": "5" }, { "input": "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20", "output": "5" }, { "input": "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4", "output": "4" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1000000000", "output": "1" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1049 1098", "output": "1" }, { "input": "2\n100 100", "output": "1" }, { "input": "5\n1 2 3 2 1", "output": "3" }, { "input": "15\n2 2 1 1 2 2 2 2 2 2 2 2 2 1 2", "output": "2" }, { "input": "28\n415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 2 802811737 802811737 802811737 802811737 802811737 802811737 802811737 802811737 1 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901", "output": "6" }, { "input": "45\n3 12 13 11 13 13 10 11 14 15 15 13 14 12 13 11 14 10 10 14 14 11 10 12 11 11 13 14 10 11 14 13 14 11 11 11 12 15 1 10 15 12 14 14 14", "output": "13" }, { "input": "84\n1 3 4 5 6 5 6 7 8 9 7 4 5 4 2 5 1 1 1 3 2 7 7 8 10 9 5 6 5 2 3 3 3 3 3 2 4 8 6 5 8 9 8 7 9 3 4 4 4 2 2 1 6 4 9 5 9 9 10 7 10 4 5 4 2 4 3 3 4 4 6 6 6 9 10 12 7 5 9 8 5 3 3 2", "output": "8" }, { "input": "170\n1 2 1 2 1 1 1 1 2 3 2 1 1 2 2 1 2 1 2 1 1 2 3 3 2 1 1 1 1 1 1 1 1 2 1 2 3 3 2 1 2 2 1 2 3 2 1 1 2 3 2 1 2 1 1 1 2 3 3 2 1 2 1 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 2 1 2 3 2 1 1 2 3 4 4 3 2 1 2 1 2 1 2 3 3 2 1 2 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 3 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 3 2 1 2 1 1 1 2 3 4 5 4 3 2 1 1 2 1 2 3 4 3 2 1", "output": "5" }, { "input": "1\n5", "output": "1" } ]
218
9,113,600
3
3,096
161
Dress'em in Vests!
[ "binary search", "brute force", "greedy", "two pointers" ]
null
null
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the *i*-th soldier indicated size *a**i*. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from *a**i*<=-<=*x* to *a**i*<=+<=*y*, inclusive (numbers *x*,<=*y*<=β‰₯<=0 are specified). The Two-dimensional kingdom has *m* vests at its disposal, the *j*-th vest's size equals *b**j*. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The *i*-th soldier can put on the *j*-th vest, if *a**i*<=-<=*x*<=≀<=*b**j*<=≀<=*a**i*<=+<=*y*.
The first input line contains four integers *n*, *m*, *x* and *y* (1<=≀<=*n*,<=*m*<=≀<=105, 0<=≀<=*x*,<=*y*<=≀<=109) β€” the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) in non-decreasing order, separated by single spaces β€” the desired sizes of vests. The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≀<=*b**j*<=≀<=109) in non-decreasing order, separated by single spaces β€” the sizes of the available vests.
In the first line print a single integer *k* β€” the maximum number of soldiers equipped with bulletproof vests. In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order. If there are multiple optimal answers, you are allowed to print any of them.
[ "5 3 0 0\n1 2 3 3 4\n1 3 5\n", "3 3 2 2\n1 5 9\n3 5 7\n" ]
[ "2\n1 1\n3 2\n", "3\n1 1\n2 2\n3 3\n" ]
In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one. In the second sample the vest size can differ from the desired size by at most 2 sizes, so all soldiers can be equipped.
[ { "input": "5 3 0 0\n1 2 3 3 4\n1 3 5", "output": "2\n1 1\n3 2" }, { "input": "3 3 2 2\n1 5 9\n3 5 7", "output": "3\n1 1\n2 2\n3 3" }, { "input": "1 1 0 0\n1\n1", "output": "1\n1 1" }, { "input": "1 1 0 0\n1\n2", "output": "0" }, { "input": "2 3 1 4\n1 5\n1 2 2", "output": "1\n1 1" }, { "input": "20 30 1 4\n1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22" }, { "input": "33 23 17 2\n1 1 2 2 2 3 3 3 3 3 3 4 4 4 4 4 5 5 5 6 6 7 7 7 8 8 8 8 8 9 9 10 10\n1 1 3 3 4 4 4 5 5 6 6 6 7 8 8 8 8 8 8 9 9 10 10", "output": "23\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n12 10\n13 11\n14 12\n17 13\n20 14\n21 15\n22 16\n23 17\n24 18\n25 19\n26 20\n27 21\n28 22\n29 23" }, { "input": "2 2 1 4\n1 4\n3 6", "output": "2\n1 1\n2 2" }, { "input": "20 20 1 4\n1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 5 5\n3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 6 6 7 7", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20" }, { "input": "33 23 17 2\n1 1 1 2 3 3 3 3 3 4 4 4 4 5 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 8 10 10\n10 10 10 11 12 12 12 12 12 13 13 13 13 14 15 15 15 15 15 15 16 16 16", "output": "5\n26 1\n27 2\n28 3\n32 4\n33 5" }, { "input": "1 1 1 2\n783266931\n783266932", "output": "1\n1 1" }, { "input": "2 3 1 4\n1 1\n3 3 4", "output": "2\n1 1\n2 2" }, { "input": "20 30 1 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20" }, { "input": "33 23 17 2\n1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5\n10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 13 13 13", "output": "0" }, { "input": "10 1 1 1\n1 1 1 5 5 7 7 8 8 8\n3", "output": "0" }, { "input": "10 1 2 1\n1 2 5 8 9 9 9 10 10 10\n7", "output": "1\n4 1" }, { "input": "1 1 2 1\n7\n8", "output": "1\n1 1" }, { "input": "1 1 0 2\n9\n7", "output": "0" }, { "input": "2 2 0 2\n2 8\n3 5", "output": "1\n1 1" }, { "input": "2 2 1 0\n5 5\n6 7", "output": "0" }, { "input": "2 2 3 0\n8 9\n1 5", "output": "1\n1 2" } ]
1,028
15,155,200
3
3,107
0
none
[ "none" ]
null
null
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination. Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet. Determine for which values $d$ Natasha can make the Martians happy. Natasha can use only her banknotes. Martians don't give her change.
The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$)Β β€” the number of denominations of banknotes and the base of the number system on Mars. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$)Β β€” denominations of banknotes on Mars. All numbers are given in decimal notation.
On the first line output the number of values $d$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation.
[ "2 8\n12 20\n", "3 10\n10 20 30\n" ]
[ "2\n0 4 ", "1\n0 " ]
Consider the first test case. It uses the octal number system. If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$. If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it is $40_8$. The last digit is $0_8$. If you take two banknotes with the value of $20$, the total value will be $40$, this is $50_8$ in the octal system. The last digit is $0_8$. No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_8$ could also be obtained in other ways. The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.
[ { "input": "2 8\n12 20", "output": "2\n0 4 " }, { "input": "3 10\n10 20 30", "output": "1\n0 " }, { "input": "5 10\n20 16 4 16 2", "output": "5\n0 2 4 6 8 " }, { "input": "10 5\n4 6 8 6 4 10 2 10 8 6", "output": "5\n0 1 2 3 4 " }, { "input": "20 25\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 20 20 20", "output": "5\n0 5 10 15 20 " }, { "input": "30 30\n11 23 7 30 13 6 25 29 1 15 20 5 28 15 19 22 21 5 27 25 29 10 1 4 12 19 1 5 8 10", "output": "30\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 " }, { "input": "40 30\n16 12 12 22 18 28 32 24 36 26 12 30 22 16 32 30 36 18 20 16 12 24 28 20 16 28 8 34 18 18 18 4 4 36 18 10 30 38 18 10", "output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 " }, { "input": "50 30\n15 9 21 39 42 39 3 42 42 39 6 48 39 30 12 39 27 45 30 48 18 33 18 36 27 3 48 12 36 27 15 12 42 39 18 21 48 39 15 42 24 36 33 48 6 48 15 12 30 18", "output": "10\n0 3 6 9 12 15 18 21 24 27 " }, { "input": "1 10\n1", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "1 2\n1", "output": "2\n0 1 " }, { "input": "60 30\n10 30 45 15 25 60 10 40 35 25 5 40 35 40 15 5 15 35 10 60 25 15 60 10 30 10 5 25 10 15 60 20 30 5 50 50 40 20 55 40 35 15 15 10 60 40 50 50 30 15 25 45 35 40 15 5 5 20 60 45", "output": "6\n0 5 10 15 20 25 " }, { "input": "70 30\n54 30 12 48 42 24 42 60 54 6 36 42 54 66 12 48 54 42 24 54 30 18 30 54 18 60 24 30 54 48 48 60 18 60 60 66 54 18 54 30 24 30 60 54 36 36 60 48 12 60 6 60 42 66 6 42 18 60 54 48 42 18 48 66 18 42 48 30 12 66", "output": "5\n0 6 12 18 24 " }, { "input": "80 30\n30 80 40 40 60 60 40 80 70 80 30 30 60 80 30 70 60 10 10 30 70 60 70 20 40 20 30 10 60 70 70 50 60 70 70 30 70 60 60 70 20 60 10 60 70 80 20 30 30 20 60 50 40 40 80 70 70 20 40 80 30 50 40 10 40 20 70 10 80 10 50 40 50 70 40 80 10 40 60 60", "output": "3\n0 10 20 " }, { "input": "90 30\n90 45 75 75 90 90 45 30 90 15 45 90 15 30 45 60 30 15 30 45 45 45 45 15 45 60 15 60 45 75 45 75 90 60 30 15 60 30 90 75 15 60 15 30 45 30 45 15 30 15 45 30 15 75 90 15 45 15 75 15 75 30 75 45 60 75 15 45 30 75 45 90 45 60 90 45 75 30 30 30 15 15 75 60 75 90 75 60 90 45", "output": "2\n0 15 " }, { "input": "100 30\n30 30 30 90 30 30 90 90 30 90 30 90 90 30 30 30 60 60 60 30 30 60 90 90 90 60 30 90 60 60 90 60 60 60 30 60 60 60 60 90 60 30 60 90 90 90 60 60 90 60 60 60 60 30 30 60 30 60 60 90 30 60 60 60 90 60 90 30 30 60 30 90 90 90 90 60 90 30 30 60 60 30 60 60 60 30 90 60 60 60 90 60 30 90 60 30 30 60 90 90", "output": "1\n0 " }, { "input": "1 10\n2", "output": "5\n0 2 4 6 8 " }, { "input": "1 10\n3", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "5 2\n1 1 1 1 1", "output": "2\n0 1 " }, { "input": "2 30\n6 10", "output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 " }, { "input": "1 10\n10", "output": "1\n0 " }, { "input": "1 10\n20", "output": "1\n0 " }, { "input": "1 2\n1000000000", "output": "1\n0 " }, { "input": "2 6\n2 3", "output": "6\n0 1 2 3 4 5 " }, { "input": "1 5\n4", "output": "5\n0 1 2 3 4 " }, { "input": "2 5\n2 4", "output": "5\n0 1 2 3 4 " }, { "input": "3 30\n6 10 15", "output": "30\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 " }, { "input": "2 7\n3 6", "output": "7\n0 1 2 3 4 5 6 " }, { "input": "2 15\n3 5", "output": "15\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 " }, { "input": "2 12\n4 6", "output": "6\n0 2 4 6 8 10 " }, { "input": "2 10\n3 6", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "2 100000\n2 4", "output": "50000\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278..." }, { "input": "1 14\n4", "output": "7\n0 2 4 6 8 10 12 " }, { "input": "1 13\n5", "output": "13\n0 1 2 3 4 5 6 7 8 9 10 11 12 " }, { "input": "2 420\n412 363", "output": "420\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 ..." }, { "input": "2 30\n10 6", "output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 " }, { "input": "1 5\n3", "output": "5\n0 1 2 3 4 " }, { "input": "1 8\n6", "output": "4\n0 2 4 6 " }, { "input": "3 10\n6 6 6", "output": "5\n0 2 4 6 8 " }, { "input": "1 7\n6", "output": "7\n0 1 2 3 4 5 6 " }, { "input": "1 9\n6", "output": "3\n0 3 6 " }, { "input": "2 10\n7 7", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "1 8\n5", "output": "8\n0 1 2 3 4 5 6 7 " }, { "input": "2 50\n3 15", "output": "50\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 " }, { "input": "1 6\n4", "output": "3\n0 2 4 " }, { "input": "1 7\n4", "output": "7\n0 1 2 3 4 5 6 " }, { "input": "1 10\n7", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "1 3\n2", "output": "3\n0 1 2 " }, { "input": "2 10\n2 5", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "2 50\n15 3", "output": "50\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 " }, { "input": "1 5\n2", "output": "5\n0 1 2 3 4 " }, { "input": "2 10\n6 5", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "2 35\n5 7", "output": "35\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 " }, { "input": "2 300\n3 10", "output": "300\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 ..." }, { "input": "1 100000\n47", "output": "100000\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 1..." }, { "input": "2 54\n6 9", "output": "18\n0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 " } ]
202
10,547,200
0
3,114
203
Photographer
[ "greedy", "sortings" ]
null
null
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes *a* megabytes of memory, one high quality photo take *b* megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the *i*-th client asks to make *x**i* low quality photos and *y**i* high quality photos. Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the *i*-th client, Valera needs to give him everything he wants, that is, to make *x**i* low quality photos and *y**i* high quality photos. To make one low quality photo, the camera must have at least *a* megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least *b* megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up. Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
The first line contains two integers *n* and *d* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*d*<=≀<=109) β€” the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≀<=*a*<=≀<=*b*<=≀<=104) β€” the size of one low quality photo and of one high quality photo, correspondingly. Next *n* lines describe the clients. The *i*-th line contains two integers *x**i* and *y**i* (0<=≀<=*x**i*,<=*y**i*<=≀<=105) β€” the number of low quality photos and high quality photos the *i*-th client wants, correspondingly. All numbers on all lines are separated by single spaces.
On the first line print the answer to the problem β€” the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
[ "3 10\n2 3\n1 4\n2 1\n1 0\n", "3 6\n6 6\n1 1\n1 0\n1 0\n" ]
[ "2\n3 2 ", "1\n2 " ]
none
[ { "input": "3 10\n2 3\n1 4\n2 1\n1 0", "output": "2\n3 2 " }, { "input": "3 6\n6 6\n1 1\n1 0\n1 0", "output": "1\n2 " }, { "input": "4 5\n6 8\n1 2\n3 0\n10 2\n0 4", "output": "0" }, { "input": "4 10\n6 6\n1 2\n2 2\n0 0\n0 0", "output": "2\n3 4 " }, { "input": "10 10\n1 1\n0 3\n6 4\n3 3\n6 3\n5 2\n6 4\n1 3\n5 5\n2 6\n6 4", "output": "2\n1 7 " }, { "input": "5 5\n1 1\n2 0\n3 2\n4 4\n10 0\n0 1", "output": "2\n5 1 " }, { "input": "4 10\n1 2\n1 0\n0 0\n2 0\n1 3", "output": "4\n2 1 3 4 " }, { "input": "1 22\n3 5\n1 3", "output": "1\n1 " }, { "input": "10 20\n3 5\n3 0\n0 3\n1 2\n1 3\n1 1\n3 0\n0 3\n0 3\n3 1\n3 1", "output": "2\n5 1 " }, { "input": "10 50\n1 1\n7 10\n6 6\n1 0\n2 5\n2 6\n9 7\n3 5\n7 6\n7 10\n7 7", "output": "6\n3 4 5 7 2 8 " }, { "input": "15 30\n13 19\n10 20\n9 0\n11 15\n10 8\n18 3\n13 15\n2 14\n9 16\n8 4\n13 10\n19 2\n13 19\n6 17\n16 4\n15 6", "output": "0" }, { "input": "30 50\n1 3\n2 2\n3 2\n3 3\n0 1\n0 2\n1 3\n1 3\n1 1\n0 1\n0 2\n1 3\n1 0\n1 0\n2 1\n0 1\n0 0\n0 3\n2 3\n2 2\n0 1\n2 3\n2 3\n0 3\n0 3\n3 3\n1 2\n2 1\n1 3\n3 1\n0 3", "output": "13\n16 12 13 4 9 15 20 8 14 27 5 10 29 " }, { "input": "50 50\n6 10\n10 0\n1 9\n8 2\n4 9\n0 7\n2 0\n7 5\n4 8\n10 7\n2 4\n5 6\n6 8\n3 2\n4 6\n7 8\n6 9\n7 7\n7 3\n9 5\n3 10\n7 2\n4 3\n2 0\n6 5\n5 3\n1 7\n1 7\n9 1\n10 4\n10 5\n4 2\n10 10\n0 7\n1 2\n10 1\n1 7\n3 7\n8 7\n5 2\n6 1\n3 1\n4 7\n7 10\n1 5\n10 8\n5 5\n5 1\n3 3\n1 6\n2 1", "output": "3\n6 23 50 " }, { "input": "1 100\n6 10\n14 19", "output": "0" }, { "input": "2 160\n6 9\n11 9\n6 6", "output": "1\n2 " }, { "input": "2 1000000000\n10000 10000\n50000 50000\n100000 100000", "output": "1\n1 " }, { "input": "2 1000000000\n10000 10000\n100000 0\n100000 100000", "output": "1\n1 " }, { "input": "1 1000000000\n1 1\n1 1", "output": "1\n1 " }, { "input": "6 1000000000\n9999 10000\n10000 9998\n10000 10000\n10000 10000\n70000 70000\n10000 10000\n10000 10000", "output": "5\n1 2 3 5 6 " }, { "input": "3 10\n1 10\n0 1\n3 0\n3 0", "output": "2\n2 3 " }, { "input": "2 1000000000\n10000 10000\n0 100000\n100000 100000", "output": "1\n1 " }, { "input": "3 3\n1 1\n3 0\n1 0\n1 0", "output": "2\n2 3 " }, { "input": "2 1000000000\n10000 10000\n100000 100000\n50000 50000", "output": "1\n2 " }, { "input": "2 1000000000\n10000 10000\n0 90000\n100000 100000", "output": "1\n1 " }, { "input": "3 1000000000\n10000 10000\n100000 0\n100000 100000\n0 0", "output": "2\n3 1 " }, { "input": "2 1000000000\n10000 10000\n10000 10000\n100000 100000", "output": "1\n1 " }, { "input": "2 1000000000\n10000 10000\n100000 100000\n100000 0", "output": "1\n2 " }, { "input": "3 1000000000\n10000 10000\n99999 0\n100000 100000\n100000 100000", "output": "1\n1 " } ]
2,000
15,462,400
0
3,120
570
Elections
[ "implementation" ]
null
null
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections.
The first line of the input contains two integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≀<=*j*<=≀<=*n*, 1<=≀<=*i*<=≀<=*m*, 0<=≀<=*a**ij*<=≀<=109) denotes the number of votes for candidate *j* in city *i*. It is guaranteed that the total number of people in all the cities does not exceed 109.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
[ "3 3\n1 2 3\n2 3 1\n1 2 1\n", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n" ]
[ "2", "1" ]
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
[ { "input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2" }, { "input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1" }, { "input": "1 3\n5\n3\n2", "output": "1" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "3 1\n100 100 100", "output": "1" }, { "input": "2 2\n1 2\n2 1", "output": "1" }, { "input": "2 2\n2 1\n2 1", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "3 3\n0 0 0\n1 1 1\n2 2 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9", "output": "5" }, { "input": "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n0 1 1 0", "output": "1" }, { "input": "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0", "output": "1" }, { "input": "4 4\n1 4 1 300\n3 1 2 1\n5 0 0 2\n0 1 10 100", "output": "1" }, { "input": "5 5\n15 45 15 300 10\n53 15 25 51 10\n5 50 50 2 10\n1000 1 10 100 10\n10 10 10 10 10", "output": "1" }, { "input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "1" }, { "input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "1 100\n859\n441\n272\n47\n355\n345\n612\n569\n545\n599\n410\n31\n720\n303\n58\n537\n561\n730\n288\n275\n446\n955\n195\n282\n153\n455\n996\n121\n267\n702\n769\n560\n353\n89\n990\n282\n801\n335\n573\n258\n722\n768\n324\n41\n249\n125\n557\n303\n664\n945\n156\n884\n985\n816\n433\n65\n976\n963\n85\n647\n46\n877\n665\n523\n714\n182\n377\n549\n994\n385\n184\n724\n447\n99\n766\n353\n494\n747\n324\n436\n915\n472\n879\n582\n928\n84\n627\n156\n972\n651\n159\n372\n70\n903\n590\n480\n184\n540\n270\n892", "output": "1" }, { "input": "100 1\n439 158 619 538 187 153 973 781 610 475 94 947 449 531 220 51 788 118 189 501 54 434 465 902 280 635 688 214 737 327 682 690 683 519 261 923 254 388 529 659 662 276 376 735 976 664 521 285 42 147 187 259 407 977 879 465 522 17 550 701 114 921 577 265 668 812 232 267 135 371 586 201 608 373 771 358 101 412 195 582 199 758 507 882 16 484 11 712 916 699 783 618 405 124 904 257 606 610 230 718", "output": "54" }, { "input": "1 99\n511\n642\n251\n30\n494\n128\n189\n324\n884\n656\n120\n616\n959\n328\n411\n933\n895\n350\n1\n838\n996\n761\n619\n131\n824\n751\n707\n688\n915\n115\n244\n476\n293\n986\n29\n787\n607\n259\n756\n864\n394\n465\n303\n387\n521\n582\n485\n355\n299\n997\n683\n472\n424\n948\n339\n383\n285\n957\n591\n203\n866\n79\n835\n980\n344\n493\n361\n159\n160\n947\n46\n362\n63\n553\n793\n754\n429\n494\n523\n227\n805\n313\n409\n243\n927\n350\n479\n971\n825\n460\n544\n235\n660\n327\n216\n729\n147\n671\n738", "output": "1" }, { "input": "99 1\n50 287 266 159 551 198 689 418 809 43 691 367 160 664 86 805 461 55 127 950 576 351 721 493 972 560 934 885 492 92 321 759 767 989 883 7 127 413 404 604 80 645 666 874 371 718 893 158 722 198 563 293 134 255 742 913 252 378 859 721 502 251 839 284 133 209 962 514 773 124 205 903 785 859 911 93 861 786 747 213 690 69 942 697 211 203 284 961 351 137 962 952 408 249 238 850 944 40 346", "output": "34" }, { "input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2", "output": "100" }, { "input": "1 1\n0", "output": "1" }, { "input": "2 1\n0 0", "output": "1" }, { "input": "2 2\n0 0\n0 0", "output": "1" }, { "input": "2 2\n1 2\n0 0", "output": "1" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "1" }, { "input": "2 3\n0 0\n0 0\n0 1", "output": "1" }, { "input": "3 2\n1 1 3\n0 0 0", "output": "1" }, { "input": "3 4\n1 10 3\n0 0 0\n0 0 0\n0 0 0", "output": "1" }, { "input": "2 4\n2 1\n1 2\n0 0\n1 2", "output": "1" }, { "input": "2 2\n0 1\n0 1", "output": "2" }, { "input": "2 3\n1 2\n0 0\n2 1", "output": "1" }, { "input": "2 2\n0 0\n4 5", "output": "1" }, { "input": "3 2\n10 15 20\n0 0 0", "output": "1" }, { "input": "3 4\n0 0 0\n0 0 0\n0 0 0\n1 2 3", "output": "1" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 1", "output": "1" }, { "input": "3 3\n0 0 0\n1 2 3\n1 3 2", "output": "1" }, { "input": "3 1\n0 0 0", "output": "1" }, { "input": "3 3\n0 0 1\n0 0 0\n0 0 0", "output": "1" } ]
31
0
0
3,122
812
Sagheer, the Hausmeister
[ "bitmasks", "brute force", "dp" ]
null
null
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=15 and 1<=≀<=*m*<=≀<=100) β€” the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.
Print a single integer β€” the minimum total time needed to turn off all the lights.
[ "2 2\n0010\n0100\n", "3 4\n001000\n000010\n000010\n", "4 3\n01110\n01110\n01110\n01110\n" ]
[ "5\n", "12\n", "18\n" ]
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
[ { "input": "2 2\n0010\n0100", "output": "5" }, { "input": "3 4\n001000\n000010\n000010", "output": "12" }, { "input": "4 3\n01110\n01110\n01110\n01110", "output": "18" }, { "input": "3 2\n0000\n0100\n0100", "output": "4" }, { "input": "1 89\n0000000000000000000000000000000100000000000000010000000000010000000000000000000000000000000", "output": "59" }, { "input": "2 73\n000000000000000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000100000010000000000000000000000000000", "output": "46" }, { "input": "3 61\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "4 53\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "5 93\n00000000000000000000000000000000000000000000000000000000100000000000000000000000000000000001010\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000010000000000000000000100000000000000000000000000000000000000000000\n00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", "output": "265" }, { "input": "6 77\n0000000000000000100000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000010000000000000\n0000000000010000000000000000000000000000000000000000000000000000000000000000010\n0000000000000000000001000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000100000000000000000000000000000", "output": "311" }, { "input": "7 65\n0000000001000000000000000010000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000001000001000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000", "output": "62" }, { "input": "8 57\n00000000100000000000000000000000000000000000000000000000000\n00000000000000010000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000010000000000000000000000000000000000000000000000\n00000000000000000000000000000000000000000000000001000000000", "output": "277" }, { "input": "12 13\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n010000000000000\n000000000000000\n000000000000000\n000000000000000\n000010000000000\n000000000000000", "output": "14" }, { "input": "13 1\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000", "output": "0" }, { "input": "1 33\n00000100101110001101000000110100010", "output": "33" }, { "input": "2 21\n00100110100010010010010\n01000001111001010000000", "output": "43" }, { "input": "3 5\n0001010\n0100000\n0100000", "output": "11" }, { "input": "4 45\n00010000101101100000101101000000100000001101100\n01110000100111010011000000100000000001000001100\n00000000001000100110100001000010011010001010010\n01111110100100000101101010011000100100001000000", "output": "184" }, { "input": "5 37\n010100000000000000000110000110010000010\n001101100010110011101000001010101101110\n010000001000100010010100000000001010000\n000000000100101000000101100001000001110\n000010000000000000100001001000011100110", "output": "193" }, { "input": "6 25\n011001000100111010000101000\n000000000010000010001000010\n011001100001100001001001010\n000000100000010000000000110\n010001100001000001000000010\n011000001001010111110000100", "output": "160" }, { "input": "7 61\n010000111100010100001000011010100001000000000011100000100010000\n000010011000001000000100110101010001000000010001100000100100100\n000010001000001000000100001000000100100011001110000111000000100\n000000000101000011010000011000000101000001011001000011101010010\n000010010011000000100000110000001000000101000000101000010000010\n000010010101101100100100100011001011101010000101000010000101010\n000100001100001001000000001000000001011000110010100000000010110", "output": "436" }, { "input": "8 49\n000100100000000111110010011100110100010010000011000\n001000000101111000000001111100010010100000010000000\n000000010000011100001000000000101000110010000100100\n000000000001000110000011101101000000100000101010000\n000000110001000101101000000001000000110001000110000\n000100000000000000100100010011000001111101010100110\n000000001000000010101111000100001100000000010111000\n001000010000110000011100000000100110000010001000000", "output": "404" }, { "input": "9 41\n0011000000000101001101001000000001110000010\n0000110000001010110010110010110010010001000\n0001100010100000000001110100100001101000100\n0001010101111010000000010010001001011111000\n0101000101000011101011000000001100110010000\n0001010000000000000001011000000100010101000\n0000010011000000001000110001000010110001000\n0000100010000110100001000000100010001111100\n0000001110100001000001000110001110000100000", "output": "385" }, { "input": "10 29\n0000000000101001100001001011000\n0001110100000000000000100010000\n0010001001000011000100010001000\n0001000010101000000010100010100\n0111000000000000100100100010100\n0001000100011111000100010100000\n0000000000000001000001001011000\n0000101110000001010001011001110\n0000001000101010011000001100100\n0100010000101011010000000000000", "output": "299" }, { "input": "1 57\n00011101100001110001111000000100101111000111101100111001000", "output": "55" }, { "input": "2 32\n0011110111011011011101111101011110\n0111000110111111011110011101011110", "output": "65" }, { "input": "3 20\n0110011111110101101100\n0111110000111010100100\n0110111110010100011110", "output": "63" }, { "input": "4 4\n011100\n001010\n010000\n011110", "output": "22" }, { "input": "5 44\n0001010010001111111001111111000010100100000010\n0001111001111001101111011111010110001001111110\n0111111010111111011101100011101010100101110110\n0011010011101011101111001001010110000111111100\n0110100111011100110101110010010011011101100100", "output": "228" }, { "input": "6 36\n01110101111111110101011000011111110010\n00011101100010110111111111110001100100\n00001111110010111111101110101110111110\n00110110011100100111011110000000000010\n01100101101001010001011111100111101100\n00011111111011001000011001011110011110", "output": "226" }, { "input": "7 24\n01111001111001011010010100\n00111011010101000111101000\n01001110110010010110011110\n00000101111011011111111000\n01111111101111001001010010\n01110000111101011111111010\n00000100011100110000110000", "output": "179" }, { "input": "8 8\n0011101110\n0110010100\n0100111110\n0111111100\n0011010100\n0001101110\n0111100000\n0110111000", "output": "77" }, { "input": "9 48\n00011010111110111011111001111111111101001111110010\n01000101000101101101111110111101011100001011010010\n00110111110110101110101110111111011011101111011000\n00110111111100010110110110111001001111011010101110\n01111111100101010011111100100111110011001101110100\n01111011110011111101010101010100001110111111111000\n01110101101101110001000010110100010110101111111100\n00111101001010110010110100000111110101010100001000\n00011011010110011111001100111100100011100110110100", "output": "448" }, { "input": "10 40\n010011001001111011011011101111010001010010\n011000000110000010001011111010100000110000\n011010101001110010110110011111010101101000\n000111111010101111000110011111011011011010\n010110101110001001001111111000110011101010\n010011010100111110010100100111100111011110\n001111101100111111111111001010111010000110\n001111110010101100110100101110001011100110\n010111010010001111110101111111111110111000\n011101101111000100111111111001111100111010", "output": "418" }, { "input": "11 28\n011100111101101001011111001110\n010001111110011101101011001000\n001010011011011010101101101100\n001100011001101011011001110100\n010111110011101110000110111100\n010010001111110000011111010100\n001011111111110011101101111010\n001101101011100100011011001110\n001111110110100110101011000010\n000101101011100001101101100100\n010011101101111011100111110100", "output": "328" }, { "input": "1 68\n0101111110111111111111111111110111111111111111111110111111101111111110", "output": "68" }, { "input": "2 56\n0011111111111110111111111111111111011111111111011111011110\n0111111111010111111111110111111111111110111111010111111110", "output": "113" }, { "input": "3 17\n0111111101111111110\n0111111111101011110\n0101111111111111110", "output": "55" }, { "input": "4 4\n011110\n010110\n010110\n011110", "output": "22" }, { "input": "5 89\n0011111111111101110110111111111101111011111011101110111111111111111111111111111111111111110\n0111111111111111111111111101111111111111111111111111111111111111111111111111111111111111110\n0111111111111011111111111111111111101111011111111111111111110110111101111111111111111011010\n0111111111111111011011111111111011111111111111111111111111111111111111111111111110111111010\n0111111101111011111110101011111111110111100100101111111011111111111111011011101111111111110", "output": "453" }, { "input": "6 77\n0111111110101011111111111111111111111111111111111111100111111111101111111111110\n0111111111111111111101111101111111111011111111011111111001011111111111101111110\n0111101111111111111111111111111111111110110011111111111011111111101111111111110\n0111110111111111111111111111111111111111111111111111011011111111111111111111110\n0101111110111111111111111111111111111111111011111111111111111111101111011011110\n0110111111101111110111111111111011111111101011111101111111111111111111110111100", "output": "472" }, { "input": "7 20\n0111111111111111111100\n0111110111111111111110\n0111111111111111111100\n0111111011111111111110\n0111111111111011101110\n0111101011110111111010\n0111111111111111111010", "output": "151" }, { "input": "8 8\n0111111110\n0111101110\n0111111110\n0111111110\n0111111110\n0110111100\n0101111110\n0110111110", "output": "78" }, { "input": "11 24\n01111111111101111111111110\n01111111111111111111111110\n01110111111111111111111110\n01111111111111111111011110\n01111111111111111110111110\n01111010111111100111101110\n01111111111111010101111100\n01111111111111110111111110\n01011101111111111101111110\n00111111011111111110111110\n01111111101111111101111110", "output": "284" }, { "input": "12 12\n01111111111000\n01101111110110\n01111110111110\n01111111111110\n01111111111010\n01011111110110\n01111111111110\n01101101011110\n01111111111110\n01111101011110\n00111111111110\n01111111011110", "output": "166" }, { "input": "15 28\n011111111101011111111101111110\n011111111111111111111111111110\n011101110111011011101111011110\n011111111011111011110111111110\n011111111110101111111111111110\n011111011111110011111111011010\n011110111111001101111111111110\n011111111110111111111011111110\n011111111111111111111111011110\n011111011111111111111011001010\n011111111101111111111101111110\n011111111110111111101111011110\n010111111111101111111111111110\n011111111111111111011111111110\n011011111111111110110111110110", "output": "448" }, { "input": "2 11\n0100000000000\n0000000010000", "output": "18" }, { "input": "1 100\n010010010011100001101101110111101010000101010001111001001101011110000011101110101000100111111001101110", "output": "100" }, { "input": "15 1\n010\n010\n010\n010\n010\n010\n000\n000\n000\n010\n000\n010\n000\n000\n000", "output": "29" }, { "input": "3 3\n00010\n00000\n00010", "output": "7" } ]
155
1,228,800
3
3,126
414
Mashmokh and Numbers
[ "constructive algorithms", "number theory" ]
null
null
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers *x* and *y* from the board, he gets *gcd*(*x*,<=*y*) points. At the beginning of the game Bimokh has zero points. Mashmokh wants to win in the game. For this reason he wants his boss to get exactly *k* points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* such that his boss will score exactly *k* points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
The first line of input contains two space-separated integers *n*,<=*k*Β (1<=≀<=*n*<=≀<=105;Β 0<=≀<=*k*<=≀<=108).
If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n*Β (1<=≀<=*a**i*<=≀<=109).
[ "5 2\n", "5 3", "7 2\n" ]
[ "1 2 3 4 5\n", "2 4 3 7 1", "-1\n" ]
*gcd*(*x*, *y*) is greatest common divisor of *x* and *y*.
[ { "input": "5 2", "output": "1 2 3 4 5" }, { "input": "5 3", "output": "2 4 5 6 7" }, { "input": "7 2", "output": "-1" }, { "input": "1 1", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input": "1 0", "output": "1" }, { "input": "7 3", "output": "1 2 3 4 5 6 7" }, { "input": "7 6", "output": "4 8 1 2 5 6 7" }, { "input": "7 7", "output": "5 10 1 2 3 4 6" }, { "input": "100000 100000000", "output": "99950001 199900002 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "3455 2792393", "output": "2790667 5581334 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151..." }, { "input": "74086 16504611", "output": "16467569 32935138 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "28515 44887064", "output": "44872808 89745616 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "21324 73830196", "output": "73819535 147639070 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "90212 5921828", "output": "5876723 11753446 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 15..." }, { "input": "25095 2372924", "output": "2360378 4720756 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151..." }, { "input": "92977 95851971", "output": "95805484 191610968 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "39095 77350428", "output": "77330882 154661764 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "785 70908164", "output": "70907773 141815546 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "28051 5506872", "output": "5492848 10985696 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 15..." }, { "input": "74077 37498088", "output": "37461051 74922102 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "58284 12998910", "output": "12969769 25939538 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "28768 33384329", "output": "33369946 66739892 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "6357 92661202", "output": "92658025 185316050 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "80996 61457012", "output": "61416515 122833030 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "60752 21494069", "output": "21463694 42927388 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "95065 81120597", "output": "81073066 162146132 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "77240 1683376", "output": "1644757 3289514 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151..." }, { "input": "35136 35044765", "output": "35027198 70054396 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "98218 71868966", "output": "71819858 143639716 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "45671 48503349", "output": "48480515 96961030 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "7081 26961063", "output": "26957524 53915048 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "69213 98333912", "output": "98299307 196598614 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "91055 20775941", "output": "20730415 41460830 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "14106 71280052", "output": "71273000 142546000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "17599 34327121", "output": "34318323 68636646 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "74244 96611492", "output": "96574371 193148742 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "77554 5672752", "output": "5633976 11267952 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 15..." }, { "input": "51040 32015531", "output": "31990012 63980024 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "95593 16086029", "output": "16038234 32076468 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "44405 95772109", "output": "95749908 191499816 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "46297 84634875", "output": "84611728 169223456 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "3842 99757561", "output": "99755641 199511282 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "90252 19406877", "output": "19361752 38723504 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "13321 67580511", "output": "67573852 135147704 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "19919 79287791", "output": "79277833 158555666 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "58499 59427255", "output": "59398007 118796014 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "34423 86770315", "output": "86753105 173506210 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "21460 11888516", "output": "11877787 23755574 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "57534 85681593", "output": "85652827 171305654 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "28652 18840000", "output": "18825675 37651350 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "18247 23541343", "output": "23532221 47064442 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "89529 95022203", "output": "94977440 189954880 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "42775 89315917", "output": "89294531 178589062 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "946 93333203", "output": "93332731 186665462 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "93595 48782905", "output": "48736109 97472218 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "87371 60145723", "output": "60102039 120204078 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "7695 94816808", "output": "94812962 189625924 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 ..." }, { "input": "21846 16967905", "output": "16956983 33913966 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 1..." }, { "input": "10 3", "output": "-1" }, { "input": "6 1000003", "output": "1000001 2000002 1 2 3 4" }, { "input": "100000 549999", "output": "500000 1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 ..." }, { "input": "10 4", "output": "-1" }, { "input": "8 10", "output": "7 14 1 2 3 4 5 6" }, { "input": "6 10000003", "output": "10000001 20000002 1 2 3 4" }, { "input": "50 50000030", "output": "50000006 100000012 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48" }, { "input": "7 11", "output": "9 18 1 2 3 4 5" }, { "input": "2 96996900", "output": "96996900 193993800" }, { "input": "3 99999997", "output": "99999997 199999994 1" }, { "input": "10000 10", "output": "-1" }, { "input": "5 100000000", "output": "99999999 199999998 1 2 3" }, { "input": "20 15", "output": "6 12 1 2 3 4 7 8 9 10 13 14 15 16 17 18 19 20 21 22" }, { "input": "10 50000006", "output": "50000002 100000004 1 2 3 4 5 6 7 8" }, { "input": "4 1257", "output": "1256 2512 1 2" }, { "input": "100 1", "output": "-1" }, { "input": "6 1", "output": "-1" }, { "input": "10 1000004", "output": "1000000 2000000 1 2 3 4 5 6 7 8" }, { "input": "100000 100000", "output": "50001 100002 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 15..." }, { "input": "10 3000004", "output": "3000000 6000000 1 2 3 4 5 6 7 8" }, { "input": "99999 149998", "output": "100000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 1..." }, { "input": "11 1434567", "output": "1434563 2869126 1 2 3 4 5 6 7 8 9" }, { "input": "205 110", "output": "9 18 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "11 14342267", "output": "14342263 28684526 1 2 3 4 5 6 7 8 9" } ]
343
102,400
3
3,141
298
Sail
[ "brute force", "greedy", "implementation" ]
null
null
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1). Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≀<=*t*<=≀<=105,<=<=-<=109<=≀<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≀<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
[ "5 0 0 1 1\nSESNW\n", "10 5 3 3 6\nNENSWESNEE\n" ]
[ "4\n", "-1\n" ]
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
[ { "input": "5 0 0 1 1\nSESNW", "output": "4" }, { "input": "10 5 3 3 6\nNENSWESNEE", "output": "-1" }, { "input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "output": "13" }, { "input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE", "output": "4" }, { "input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "output": "41" }, { "input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE", "output": "-1" }, { "input": "1 0 0 0 -1\nS", "output": "1" }, { "input": "1 5 5 5 6\nE", "output": "-1" }, { "input": "15 1 1 1 2\nNNNNNNNNNNNNNNN", "output": "1" }, { "input": "11 1 1 1 2\nNNNNNNNNNNN", "output": "1" } ]
310
22,630,400
3
3,144
108
Palindromic Times
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, { "input": "12:15", "output": "12:21" }, { "input": "07:07", "output": "10:01" }, { "input": "00:17", "output": "01:10" }, { "input": "04:55", "output": "05:50" }, { "input": "02:17", "output": "02:20" }, { "input": "07:56", "output": "10:01" }, { "input": "00:29", "output": "01:10" }, { "input": "23:31", "output": "23:32" }, { "input": "19:30", "output": "20:02" }, { "input": "12:14", "output": "12:21" }, { "input": "17:32", "output": "20:02" }, { "input": "03:44", "output": "04:40" }, { "input": "07:15", "output": "10:01" }, { "input": "18:42", "output": "20:02" }, { "input": "08:56", "output": "10:01" }, { "input": "04:50", "output": "05:50" }, { "input": "14:32", "output": "14:41" }, { "input": "23:23", "output": "23:32" }, { "input": "08:35", "output": "10:01" }, { "input": "03:32", "output": "04:40" }, { "input": "07:59", "output": "10:01" }, { "input": "14:12", "output": "14:41" }, { "input": "23:52", "output": "00:00" }, { "input": "16:36", "output": "20:02" }, { "input": "17:50", "output": "20:02" }, { "input": "06:59", "output": "10:01" }, { "input": "16:50", "output": "20:02" }, { "input": "00:00", "output": "01:10" }, { "input": "23:59", "output": "00:00" }, { "input": "23:33", "output": "00:00" } ]
124
0
0
3,146
577
Multiplication Table
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=Γ—<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
The single line contains numbers *n* and *x* (1<=≀<=*n*<=≀<=105, 1<=≀<=*x*<=≀<=109) β€” the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 1000000000", "output": "0" }, { "input": "100000 1000000000", "output": "16" }, { "input": "100000 362880", "output": "154" }, { "input": "1 4", "output": "0" }, { "input": "9 12", "output": "4" }, { "input": "10 123", "output": "0" }, { "input": "9551 975275379", "output": "0" }, { "input": "17286 948615687", "output": "0" }, { "input": "58942 936593001", "output": "0" }, { "input": "50000 989460910", "output": "4" }, { "input": "22741 989460910", "output": "0" }, { "input": "22740 989460910", "output": "0" }, { "input": "100000 989460910", "output": "4" }, { "input": "100000 98280", "output": "128" }, { "input": "100000 997920", "output": "222" }, { "input": "100000 720720", "output": "226" }, { "input": "100000 2162160", "output": "282" }, { "input": "100000 4324320", "output": "320" }, { "input": "100000 8648640", "output": "348" }, { "input": "100000 183783600", "output": "438" }, { "input": "100000 551350800", "output": "392" }, { "input": "40000 551350800", "output": "150" }, { "input": "20000 400000000", "output": "1" }, { "input": "19999 400000000", "output": "0" }, { "input": "19999 399960001", "output": "1" }, { "input": "31621 999887641", "output": "1" }, { "input": "31622 999887641", "output": "1" }, { "input": "31620 999887641", "output": "0" }, { "input": "100000 999887641", "output": "3" }, { "input": "100000 25", "output": "3" }, { "input": "100000 1", "output": "1" }, { "input": "100000 3628800", "output": "220" }, { "input": "100000 39916800", "output": "328" }, { "input": "100000 479001600", "output": "254" }, { "input": "4 9", "output": "1" }, { "input": "2 6", "output": "0" }, { "input": "20 100", "output": "3" }, { "input": "10 3", "output": "2" }, { "input": "4 4", "output": "3" }, { "input": "2 4", "output": "1" }, { "input": "89874 1", "output": "1" } ]
1,000
0
0
3,155
916
Jamie and Interesting Graph
[ "constructive algorithms", "graphs", "shortest paths" ]
null
null
Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number. - The graph contains no loops or multi-edges. If you are not familiar with some terms from the statement you can find definitions of them in notes section. Help Jamie construct any graph with given number of vertices and edges that is interesting!
First line of input contains 2 integers *n*, *m* Β β€” the required number of vertices and edges.
In the first line output 2 integers *sp*, *mstw* (1<=≀<=*sp*,<=*mstw*<=≀<=1014)Β β€” the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≀<=*u*,<=*v*<=≀<=*n*,<=1<=≀<=*w*<=≀<=109) describing the edge connecting *u* and *v* and having weight *w*.
[ "4 4\n", "5 4\n" ]
[ "7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n", "7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n" ]
The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*). Definition of terms used in the problem statement: A shortest path in an undirected graph is a sequence of vertices (*v*<sub class="lower-index">1</sub>, *v*<sub class="lower-index">2</sub>, ... , *v*<sub class="lower-index">*k*</sub>) such that *v*<sub class="lower-index">*i*</sub> is adjacent to *v*<sub class="lower-index">*i* + 1</sub> 1 ≀ *i* &lt; *k* and the sum of weight <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e7f62cfd5c2c3b81dc80aaf2f512898495354f03.png" style="max-width: 100.0%;max-height: 100.0%;"/> is minimized where *w*(*i*, *j*) is the edge weight between *i* and *j*. ([https://en.wikipedia.org/wiki/Shortest_path_problem](https://en.wikipedia.org/wiki/Shortest_path_problem)) A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ([https://en.wikipedia.org/wiki/Prime_number](https://en.wikipedia.org/wiki/Prime_number)) A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. ([https://en.wikipedia.org/wiki/Minimum_spanning_tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)) [https://en.wikipedia.org/wiki/Multiple_edges](https://en.wikipedia.org/wiki/Multiple_edges)
[ { "input": "4 4", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000" }, { "input": "5 4", "output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1" }, { "input": "2 1", "output": "100003 100003\n1 2 100003" }, { "input": "10 19", "output": "100003 100003\n1 2 99995\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n1 10 1000000000\n2 4 1000000000\n2 5 1000000000" }, { "input": "9 18", "output": "100003 100003\n1 2 99996\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n2 4 1000000000\n2 5 1000000000\n2 6 1000000000" }, { "input": "92 280", "output": "100003 100003\n1 2 99913\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "89 3439", "output": "100003 100003\n1 2 99916\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "926 31057", "output": "100003 100003\n1 2 99079\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "753 98686", "output": "100003 100003\n1 2 99252\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9724 31045", "output": "100003 100003\n1 2 90281\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "8732 93395", "output": "100003 100003\n1 2 91273\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "80297 83088", "output": "100003 100003\n1 2 19708\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "86549 98929", "output": "100003 100003\n1 2 13456\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "87 109", "output": "100003 100003\n1 2 99918\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "95 3582", "output": "100003 100003\n1 2 99910\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "96 557", "output": "100003 100003\n1 2 99909\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "85 3106", "output": "100003 100003\n1 2 99920\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "98 367", "output": "100003 100003\n1 2 99907\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "77 2344", "output": "100003 100003\n1 2 99928\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "84 286", "output": "100003 100003\n1 2 99921\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 4665", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "94 350", "output": "100003 100003\n1 2 99911\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 4309", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "88 666", "output": "100003 100003\n1 2 99917\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "93 4075", "output": "100003 100003\n1 2 99912\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 342", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "84 3482", "output": "100003 100003\n1 2 99921\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "943 51645", "output": "100003 100003\n1 2 99062\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "808 63768", "output": "100003 100003\n1 2 99197\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "898 1882", "output": "100003 100003\n1 2 99107\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "662 76813", "output": "100003 100003\n1 2 99343\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "681 13806", "output": "100003 100003\n1 2 99324\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "991 92176", "output": "100003 100003\n1 2 99014\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "745 4986", "output": "100003 100003\n1 2 99260\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "954 94880", "output": "100003 100003\n1 2 99051\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "965 5451", "output": "100003 100003\n1 2 99040\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "943 95302", "output": "100003 100003\n1 2 99062\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "879 8524", "output": "100003 100003\n1 2 99126\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "953 98192", "output": "100003 100003\n1 2 99052\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "806 1771", "output": "100003 100003\n1 2 99199\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "790 97497", "output": "100003 100003\n1 2 99215\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9492 36483", "output": "100003 100003\n1 2 90513\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "5839 48668", "output": "100003 100003\n1 2 94166\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9029 15632", "output": "100003 100003\n1 2 90976\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "5127 53185", "output": "100003 100003\n1 2 94878\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "7044 33010", "output": "100003 100003\n1 2 92961\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9637 98924", "output": "100003 100003\n1 2 90368\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "7837 45130", "output": "100003 100003\n1 2 92168\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9603 99398", "output": "100003 100003\n1 2 90402\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9204 11722", "output": "100003 100003\n1 2 90801\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "6996 90227", "output": "100003 100003\n1 2 93009\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9897 21204", "output": "100003 100003\n1 2 90108\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9051 92600", "output": "100003 100003\n1 2 90954\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9880 13424", "output": "100003 100003\n1 2 90125\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9811 89446", "output": "100003 100003\n1 2 90194\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "90498 92256", "output": "100003 100003\n1 2 9507\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99840 99968", "output": "100003 100003\n1 2 165\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "92340 92571", "output": "100003 100003\n1 2 7665\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99019 99681", "output": "100003 100003\n1 2 986\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "93750 94653", "output": "100003 100003\n1 2 6255\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99831 99956", "output": "100003 100003\n1 2 174\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "95373 95859", "output": "100003 100003\n1 2 4632\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "95519 99837", "output": "100003 100003\n1 2 4486\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "94183 94638", "output": "100003 100003\n1 2 5822\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "84935 98326", "output": "100003 100003\n1 2 15070\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "94995 95821", "output": "100003 100003\n1 2 5010\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "88804 99911", "output": "100003 100003\n1 2 11201\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "93394 94036", "output": "100003 100003\n1 2 6611\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "97796 99885", "output": "100003 100003\n1 2 2209\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "3 2", "output": "100003 100003\n1 2 100002\n2 3 1" }, { "input": "3 3", "output": "100003 100003\n1 2 100002\n2 3 1\n1 3 1000000000" }, { "input": "4 3", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1" }, { "input": "4 5", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000\n1 4 1000000000" }, { "input": "4 6", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000\n1 4 1000000000\n2 4 1000000000" }, { "input": "100000 100000", "output": "100003 100003\n1 2 5\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1\n..." }, { "input": "50000 100000", "output": "100003 100003\n1 2 50005\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "1415 100000", "output": "100003 100003\n1 2 98590\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "13 17", "output": "100003 100003\n1 2 99992\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000" }, { "input": "19 31", "output": "100003 100003\n1 2 99986\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n1 10 1000000000\n1 11 1000000000\n1 12 1000000000\n1 13 1000000000\n1 14 1000000000\n1 15 1000000000" } ]
841
7,270,400
3
3,159
621
Wet Shark and Bishops
[ "combinatorics", "implementation" ]
null
null
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.
The first line of the input contains *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of bishops. Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=1000)Β β€” the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops share the same position.
Output one integerΒ β€” the number of pairs of bishops which attack each other.
[ "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "3\n1 1\n2 3\n3 5\n" ]
[ "6\n", "0\n" ]
In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
[ { "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5", "output": "6" }, { "input": "3\n1 1\n2 3\n3 5", "output": "0" }, { "input": "3\n859 96\n634 248\n808 72", "output": "0" }, { "input": "3\n987 237\n891 429\n358 145", "output": "0" }, { "input": "3\n411 81\n149 907\n611 114", "output": "0" }, { "input": "3\n539 221\n895 89\n673 890", "output": "0" }, { "input": "3\n259 770\n448 54\n926 667", "output": "0" }, { "input": "3\n387 422\n898 532\n988 636", "output": "0" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 42\n788 639\n710 709", "output": "0" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n510 389\n729 950", "output": "0" }, { "input": "10\n518 518\n71 971\n121 862\n967 607\n138 754\n513 337\n499 873\n337 387\n647 917\n76 417", "output": "0" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n798 657", "output": "0" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n284 929\n816 602", "output": "0" }, { "input": "2\n1 1\n1 1000", "output": "0" }, { "input": "2\n1 1\n1000 1", "output": "0" }, { "input": "2\n1 1\n1000 1000", "output": "1" }, { "input": "2\n1000 1\n1 1000", "output": "1" }, { "input": "2\n1000 1\n1000 1000", "output": "0" }, { "input": "2\n1 1000\n1000 1000", "output": "0" }, { "input": "1\n6 3", "output": "0" }, { "input": "1\n1 1", "output": "0" }, { "input": "1\n1 1000", "output": "0" }, { "input": "1\n1000 1", "output": "0" }, { "input": "1\n1000 1000", "output": "0" }, { "input": "2\n1 1\n3 1", "output": "0" }, { "input": "2\n999 1\n1000 2", "output": "1" }, { "input": "5\n1 1000\n2 999\n3 998\n4 997\n5 996", "output": "10" } ]
1,560
9,728,000
3
3,160
585
Lizard Era: Beginning
[ "meet-in-the-middle" ]
null
null
In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has *n* mandatory quests. To perform each of them, you need to take exactly two companions. The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction. Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible.
The first line contains positive integer *n* (1<=≀<=*n*<=≀<=25) β€” the number of important tasks. Next *n* lines contain the descriptions of the tasks β€” the *i*-th line contains three integers *l**i*,<=*m**i*,<=*w**i* β€” the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the *i*-th task. All the numbers in the input are integers and do not exceed 107 in absolute value.
If there is no solution, print in the first line "Impossible". Otherwise, print *n* lines, two characters is each line β€” in the *i*-th line print the first letters of the companions' names that hero should take to complete the *i*-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them.
[ "3\n1 0 0\n0 1 0\n0 0 1\n", "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7\n", "2\n1 0 0\n1 1 0\n" ]
[ "LM\nMW\nMW\n", "LM\nMW\nLM\nLW\nMW\nLM\nLW\n", "Impossible\n" ]
none
[ { "input": "3\n1 0 0\n0 1 0\n0 0 1", "output": "LM\nMW\nMW" }, { "input": "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7", "output": "LM\nMW\nLM\nLW\nMW\nLM\nLW" }, { "input": "2\n1 0 0\n1 1 0", "output": "Impossible" }, { "input": "25\n26668 10412 12658\n25216 11939 10247\n28514 22515 5833\n4955 19029 22405\n12552 6903 19634\n12315 1671 505\n20848 9175 6060\n12990 5827 16433\n9184 30621 25596\n31818 7826 11221\n18090 4476 30078\n30915 11014 16950\n3119 29529 21390\n775 4290 11723\n29679 14840 3566\n4491 29480 2079\n24129 5496 6381\n20849 25772 9299\n10825 30424 11842\n18290 14728 30342\n24893 27064 11604\n26248 7490 18116\n17182 32158 12518\n23145 4288 7754\n18544 25694 18784", "output": "LW\nLM\nLW\nMW\nMW\nLW\nMW\nLW\nMW\nLW\nLW\nLW\nLM\nMW\nMW\nMW\nLW\nLM\nLM\nMW\nMW\nLW\nMW\nMW\nLW" }, { "input": "1\n0 0 0", "output": "MW" }, { "input": "1\n1 0 0", "output": "MW" }, { "input": "1\n0 1 0", "output": "LW" }, { "input": "1\n0 0 1", "output": "LM" }, { "input": "7\n-925 88 -550\n205 406 -957\n-596 259 -448\n857 635 719\n-149 -487 -85\n245 -59 78\n-870 -959 -733", "output": "LM\nMW\nMW\nLW\nMW\nLW\nLM" }, { "input": "8\n697 78 -270\n17 240 64\n615 6 967\n565 486 -862\n517 -17 -852\n958 949 505\n199 -866 711\n251 -177 549", "output": "LW\nMW\nMW\nMW\nLM\nMW\nLW\nLW" }, { "input": "9\n-477 504 222\n30 698 346\n-142 168 -322\n162 371 219\n-470 417 -102\n-104 -236 785\n131 -686 870\n420 -289 -333\n743 -611 111", "output": "LM\nLW\nMW\nLM\nMW\nLW\nLM\nMW\nLW" }, { "input": "10\n-134 5 -71\n-615 -591 -548\n626 -787 -682\n-392 -689 900\n-93 789 194\n-657 438 806\n308 219 129\n-247 -220 -358\n-720 -841 -974\n833 -845 -268", "output": "LW\nLM\nMW\nLM\nLM\nMW\nLW\nLM\nLW\nLW" }, { "input": "11\n-368 775 -959\n-281 483 -979\n685 902 211\n-336 63 458\n116 -957 -802\n-856 751 -608\n956 -636 -17\n561 186 228\n-301 -807 304\n-103 -476 18\n-579 116 850", "output": "LW\nLM\nLM\nMW\nLM\nLW\nMW\nLM\nLM\nLM\nLM" }, { "input": "12\n-749 66 -780\n293 440 891\n-404 -787 -159\n454 68 -675\n105 116 -121\n516 849 470\n603 208 -583\n333 110 17\n-591 818 252\n-313 -131 -370\n-865 61 309\n583 306 536", "output": "LM\nLM\nMW\nLM\nLW\nLW\nLM\nLW\nLM\nMW\nLW\nLW" }, { "input": "13\n-495 262 21\n148 188 374\n935 67 567\n-853 -862 -164\n-878 990 -80\n824 536 934\n254 -436 -310\n355 803 -627\n30 409 -624\n-212 -950 182\n582 96 738\n316 221 -341\n-178 691 3", "output": "LW\nLM\nMW\nMW\nMW\nLW\nMW\nMW\nLW\nLM\nMW\nMW\nLW" }, { "input": "14\n167 -30 -195\n-8 604 701\n592 -402 168\n-982 12 592\n929 999 -200\n-37 645 615\n512 -553 515\n-830 743 -574\n436 -815 180\n-787 420 906\n733 226 -650\n295 -571 7\n-879 739 369\n-124 801 -253", "output": "MW\nLM\nLM\nMW\nLW\nLM\nLM\nLM\nMW\nLW\nLM\nLM\nMW\nMW" }, { "input": "15\n74 716 -568\n-958 -441 167\n-716 -554 -403\n-364 934 395\n-673 36 945\n-102 -227 69\n979 -721 -132\n790 -494 292\n-781 -478 -545\n-591 -274 965\n-46 -983 -835\n37 -540 -375\n-417 139 -761\n772 969 -197\n-74 -975 -662", "output": "LM\nLW\nMW\nLW\nMW\nLW\nLM\nLM\nLW\nMW\nLW\nLM\nLW\nMW\nLW" }, { "input": "16\n-885 -621 -319\n500 705 -709\n-376 -884 -102\n346 176 448\n611 954 -23\n-372 -993 177\n-288 -977 -777\n-966 -644 867\n834 -561 984\n-868 545 789\n340 0 782\n754 -263 518\n112 -747 -944\n-760 -624 383\n353 -654 -341\n-451 477 -819", "output": "LW\nLM\nLW\nLM\nLM\nLM\nLW\nMW\nLW\nLM\nMW\nLW\nMW\nLM\nLW\nMW" }, { "input": "17\n881 984 -560\n-272 527 537\n944 135 782\n265 652 73\n340 995 -116\n-625 -197 -859\n-515 584 416\n709 -144 -5\n-187 -95 228\n646 -711 -647\n892 -824 -177\n442 -258 622\n-527 -715 155\n-110 -417 857\n-72 -547 531\n86 597 454\n-332 57 -731", "output": "MW\nMW\nMW\nLW\nMW\nMW\nMW\nLW\nLM\nLW\nLW\nLW\nLM\nMW\nMW\nMW\nLM" }, { "input": "18\n59 502 341\n-464 -595 655\n161 617 569\n179 284 -667\n418 430 239\n803 105 385\n770 -807 -223\n-154 47 560\n-886 -907 -533\n-723 -728 -584\n676 715 460\n779 26 -894\n26 989 -364\n-390 738 241\n246 683 220\n-716 -752 722\n913 528 926\n229 -813 485", "output": "LW\nMW\nMW\nMW\nLW\nLM\nLW\nLW\nLM\nLW\nLM\nLM\nLW\nMW\nMW\nLW\nLM\nLW" }, { "input": "16\n4642484 -2788746 9992951\n5803062 8109045 72477\n6993256 5860518 -5298508\n2983494 5924807 9075779\n9616987 -7580870 -2342882\n2620968 -2619488 2599421\n1318060 -7292211 3454517\n-7018501 -2464950 9497459\n2254377 -2500546 -1888489\n-20354 -7510645 173023\n619811 -861516 -6346093\n38813 3848272 -8558276\n6409071 4528454 -9768150\n-9344900 3107745 4779111\n5984141 2896281 2888362\n-9097994 -8937736 -419949", "output": "LW\nMW\nLM\nMW\nLW\nMW\nMW\nLM\nLW\nLM\nMW\nMW\nLM\nLW\nLM\nLW" }, { "input": "17\n3461788 -7190737 790707\n-3979181 -7527409 1464659\n3368847 -7475254 -7377314\n-2469024 9316013 6583991\n8223943 9596309 7549117\n1525938 3840013 -9805857\n2489326 7215738 -5874041\n-6183012 596945 5059562\n3412087 6788437 939017\n9690067 -2007875 -1424714\n834164 5247338 -6872328\n3860491 8096731 -2390366\n8174160 7465170 4040376\n-5138898 -2348036 -9154464\n1527659 -4375219 -2725794\n-5350381 -8411693 214736\n-5832848 -6704847 4997762", "output": "MW\nLW\nLW\nLW\nMW\nLM\nMW\nLW\nLW\nLM\nLW\nLM\nLW\nLM\nLW\nMW\nLW" }, { "input": "16\n6742718 -9848759 -3874332\n-8128485 -6617274 1575011\n-1740148 623444 9963227\n3629451 -2414107 -9704466\n7753671 7021614 7248025\n-5420494 6909667 5118838\n4090028 3512092 -6413023\n282544 8907950 5863326\n-9977956 -7405023 8905548\n-7480107 6149899 3468303\n-5494025 2101036 8801937\n-5351537 7051449 69239\n137681 -9994993 -2053076\n-4251695 8203962 -4620459\n8897087 -7891039 5515252\n916961 2371338 -6986487", "output": "MW\nLM\nLM\nMW\nLM\nLW\nLW\nLM\nMW\nLW\nLM\nMW\nMW\nLW\nLW\nLW" }, { "input": "17\n8003952 1945229 -824287\n-2548751 860618 589233\n4195712 -3840408 7878690\n-3178201 -1509129 6136806\n-1406078 3402700 -3298516\n-2639343 -7312210 -7052356\n5744330 -228480 5806356\n-7992147 -9663118 6294695\n-4197990 8982179 4355332\n-406724 -362338 -3609437\n-6459171 -4710527 6551785\n4054102 -9505148 2215175\n-2286309 728140 -2206363\n7183109 -8393962 -5369491\n-7303376 328150 5437901\n8549874 8031324 -4716139\n-5998559 -3896390 2664375", "output": "MW\nLM\nMW\nLM\nMW\nMW\nLM\nLW\nLM\nLW\nLM\nLW\nMW\nLW\nMW\nLW\nLM" }, { "input": "16\n2033906 6164819 -3535254\n-7271523 -1386302 -5832930\n7664268 -7927384 -8316758\n-5929014 6352246 8535844\n-5992054 -3159960 5973202\n8477561 5763594 7527604\n-1611804 3925028 -9320743\n-3732863 -7513881 7445368\n7044279 6186756 -87415\n6810089 -9828741 -8531792\n2105994 -4192310 -1962547\n4522049 5717418 -2009682\n-5638994 7361890 -2071446\n-6518199 -670199 3519089\n-5881880 3506792 -7813715\n3774507 -5501152 2112631", "output": "MW\nLW\nLW\nLW\nMW\nLW\nMW\nMW\nMW\nMW\nLM\nLM\nLW\nLW\nLM\nLM" }, { "input": "17\n5145283 -2753062 -2936514\n-2127587 9440797 -4470168\n4109762 -1351398 1013844\n-5272277 -916706 -402190\n-7510148 -8867866 -2714993\n2254647 7293040 7375284\n-3027010 -8436598 -585941\n9910514 4179567 -7552626\n4295472 -8584445 -5072169\n6661724 9675368 7315049\n-3327283 -7829466 -4900987\n-6243053 -2828295 -6456626\n7489319 -7983760 -3082241\n-8134992 -6899104 -2317283\n9790680 -3222471 2050981\n-8211631 2874090 544657\n-4219486 848554 -287544", "output": "LM\nLM\nMW\nLW\nLM\nLW\nLM\nLW\nLW\nLW\nLW\nLW\nLW\nLW\nMW\nLM\nLW" }, { "input": "16\n-3253484 -6513322 5617669\n-8870526 9976385 -7313669\n5682511 -1202928 -7057533\n4747064 475782 7416790\n-4387656 3965849 9530503\n-8224426 4339650 181725\n1012598 -8651198 -222828\n-1012251 -9099337 719019\n-903577 -1340167 -8701346\n-4502739 736866 -5741036\n-6125650 9410041 948124\n-8344882 3820318 3738053\n5202105 524964 2938536\n752123 2136713 -3095341\n545090 -6807501 -5000825\n5921735 5822186 4106753", "output": "LW\nMW\nLW\nMW\nMW\nMW\nLM\nMW\nLM\nMW\nLW\nLW\nLM\nLW\nMW\nLM" }, { "input": "17\n-9095076 8052666 -1032018\n2681359 -9998418 -3163796\n5865270 -1926467 -6480441\n-2780849 5921425 -7844112\n2813688 -9288645 -8474670\n8145658 -5741326 9011572\n9364418 -8442485 -8888763\n3473152 -1301704 -2502205\n4201907 8497194 9692725\n8874792 537379 8954057\n2083242 -3975356 -62337\n-3654609 2243771 8422585\n7822816 9702585 -3007717\n-6801114 -3025102 -6129158\n7033485 7157201 -6012950\n-7895796 -6052792 9119000\n-932955 4934837 -873726", "output": "LM\nLM\nLM\nMW\nLM\nLM\nMW\nLW\nMW\nMW\nLM\nLM\nMW\nLM\nLM\nLW\nMW" }, { "input": "3\n7089544 9134148 -5332724\n368810 1638695 7889905\n-3866235 -4257263 5802154", "output": "Impossible" }, { "input": "15\n-3682462 -194732 9446852\n-4405738 6933459 -9496709\n9422280 7851074 -9960800\n1002721 -4735302 -6724485\n-9025771 7592049 106547\n2508567 -9291847 8728657\n-558387 1839538 -8263150\n9066346 1788798 -111846\n3033903 -7178126 -2777630\n9282416 2652252 -8446308\n-7520805 -9819190 -9526851\n6504744 3375811 8450106\n-9694972 5307787 622433\n1364366 -7259170 5463805\n8696617 5410821 5813911", "output": "Impossible" }, { "input": "6\n1 0 1\n1 1 0\n0 1 1\n0 1 1\n1 1 0\n1 0 1", "output": "LW\nLM\nMW\nMW\nLM\nLW" } ]
2,000
261,529,600
0
3,162
819
Mister B and PR Shifts
[ "data structures", "implementation", "math" ]
null
null
Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation. Let's define the deviation of a permutation *p* as . Find a cyclic shift of permutation *p* with minimum possible deviation. If there are multiple solutions, print any of them. Let's denote id *k* (0<=≀<=*k*<=&lt;<=*n*) of a cyclic shift of permutation *p* as the number of right shifts needed to reach this shift, for example: - *k*<==<=0: shift *p*1,<=*p*2,<=... *p**n*, - *k*<==<=1: shift *p**n*,<=*p*1,<=... *p**n*<=-<=1, - ..., - *k*<==<=*n*<=-<=1: shift *p*2,<=*p*3,<=... *p**n*,<=*p*1.
First line contains single integer *n* (2<=≀<=*n*<=≀<=106) β€” the length of the permutation. The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≀<=*p**i*<=≀<=*n*)Β β€” the elements of the permutation. It is guaranteed that all elements are distinct.
Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them.
[ "3\n1 2 3\n", "3\n2 3 1\n", "3\n3 2 1\n" ]
[ "0 0\n", "0 1\n", "2 1\n" ]
In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well. In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift. In the third sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts.
[ { "input": "3\n1 2 3", "output": "0 0" }, { "input": "3\n2 3 1", "output": "0 1" }, { "input": "3\n3 2 1", "output": "2 1" }, { "input": "2\n1 2", "output": "0 0" }, { "input": "2\n2 1", "output": "0 1" }, { "input": "10\n10 1 9 2 8 3 7 4 6 5", "output": "24 7" }, { "input": "108\n1 102 33 99 6 83 4 20 61 100 76 71 44 9 24 87 57 2 81 82 90 85 12 30 66 53 47 36 43 29 31 64 96 84 77 23 93 78 58 68 42 55 13 70 62 19 92 14 10 65 63 75 91 48 11 105 37 50 32 94 18 26 52 89 104 106 86 97 80 95 17 72 40 22 79 103 25 101 35 51 15 98 67 5 34 69 54 27 45 88 56 16 46 60 74 108 21 41 73 39 107 59 3 8 28 49 7 38", "output": "3428 30" }, { "input": "4\n1 2 3 4", "output": "0 0" }, { "input": "4\n1 2 4 3", "output": "2 0" }, { "input": "4\n1 3 2 4", "output": "2 0" }, { "input": "4\n1 3 4 2", "output": "2 1" }, { "input": "4\n1 4 2 3", "output": "4 0" }, { "input": "4\n1 4 3 2", "output": "4 0" }, { "input": "4\n2 1 3 4", "output": "2 0" }, { "input": "4\n2 1 4 3", "output": "4 0" }, { "input": "4\n2 3 1 4", "output": "4 0" }, { "input": "4\n2 3 4 1", "output": "0 1" }, { "input": "4\n2 4 1 3", "output": "2 2" }, { "input": "4\n2 4 3 1", "output": "2 1" }, { "input": "4\n3 1 2 4", "output": "2 3" }, { "input": "4\n3 1 4 2", "output": "4 1" }, { "input": "4\n3 2 1 4", "output": "4 0" }, { "input": "4\n3 2 4 1", "output": "2 1" }, { "input": "4\n3 4 1 2", "output": "0 2" }, { "input": "4\n3 4 2 1", "output": "2 2" }, { "input": "4\n4 1 2 3", "output": "0 3" }, { "input": "4\n4 1 3 2", "output": "2 3" }, { "input": "4\n4 2 1 3", "output": "2 3" }, { "input": "4\n4 2 3 1", "output": "4 1" }, { "input": "4\n4 3 1 2", "output": "2 2" }, { "input": "4\n4 3 2 1", "output": "4 1" }, { "input": "10\n1 2 3 4 6 5 7 9 10 8", "output": "6 0" }, { "input": "10\n1 2 10 9 7 4 8 3 6 5", "output": "26 5" }, { "input": "10\n1 3 10 9 4 7 5 8 6 2", "output": "22 1" }, { "input": "10\n1 4 10 8 9 2 3 6 7 5", "output": "20 5" }, { "input": "10\n1 5 10 8 4 3 9 2 7 6", "output": "26 6" }, { "input": "10\n1 6 10 7 9 5 3 8 4 2", "output": "24 4" }, { "input": "10\n1 7 10 6 5 2 3 8 9 4", "output": "26 6" }, { "input": "10\n1 8 10 6 2 4 9 3 7 5", "output": "24 6" }, { "input": "10\n1 9 10 5 6 7 3 8 4 2", "output": "26 1" }, { "input": "10\n1 10 9 5 3 2 4 7 8 6", "output": "20 7" }, { "input": "10\n2 1 10 5 8 4 9 3 7 6", "output": "28 0" }, { "input": "10\n2 3 10 5 4 8 6 9 7 1", "output": "14 1" }, { "input": "10\n2 4 10 3 9 1 5 7 8 6", "output": "28 0" }, { "input": "10\n2 5 10 3 6 4 9 1 8 7", "output": "28 0" }, { "input": "10\n2 6 10 1 9 7 4 8 5 3", "output": "28 1" }, { "input": "10\n2 7 10 1 6 3 4 8 9 5", "output": "20 7" } ]
46
0
0
3,166
195
After Training
[ "data structures", "implementation", "math" ]
null
null
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*. Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number. For every ball print the number of the basket where it will go according to Valeric's scheme. Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on.
The first line contains two space-separated integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=105) β€” the number of balls and baskets, correspondingly.
Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball.
[ "4 3\n", "3 1\n" ]
[ "2\n1\n3\n2\n", "1\n1\n1\n" ]
none
[ { "input": "4 3", "output": "2\n1\n3\n2" }, { "input": "3 1", "output": "1\n1\n1" }, { "input": "10 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2" }, { "input": "6 5", "output": "3\n2\n4\n1\n5\n3" }, { "input": "2 6", "output": "3\n4" }, { "input": "5 2", "output": "1\n2\n1\n2\n1" }, { "input": "85702 100000", "output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..." }, { "input": "9 2", "output": "1\n2\n1\n2\n1\n2\n1\n2\n1" }, { "input": "45 88", "output": "44\n45\n43\n46\n42\n47\n41\n48\n40\n49\n39\n50\n38\n51\n37\n52\n36\n53\n35\n54\n34\n55\n33\n56\n32\n57\n31\n58\n30\n59\n29\n60\n28\n61\n27\n62\n26\n63\n25\n64\n24\n65\n23\n66\n22" }, { "input": "61 51", "output": "26\n25\n27\n24\n28\n23\n29\n22\n30\n21\n31\n20\n32\n19\n33\n18\n34\n17\n35\n16\n36\n15\n37\n14\n38\n13\n39\n12\n40\n11\n41\n10\n42\n9\n43\n8\n44\n7\n45\n6\n46\n5\n47\n4\n48\n3\n49\n2\n50\n1\n51\n26\n25\n27\n24\n28\n23\n29\n22\n30\n21" }, { "input": "21 57", "output": "29\n28\n30\n27\n31\n26\n32\n25\n33\n24\n34\n23\n35\n22\n36\n21\n37\n20\n38\n19\n39" }, { "input": "677 787", "output": "394\n393\n395\n392\n396\n391\n397\n390\n398\n389\n399\n388\n400\n387\n401\n386\n402\n385\n403\n384\n404\n383\n405\n382\n406\n381\n407\n380\n408\n379\n409\n378\n410\n377\n411\n376\n412\n375\n413\n374\n414\n373\n415\n372\n416\n371\n417\n370\n418\n369\n419\n368\n420\n367\n421\n366\n422\n365\n423\n364\n424\n363\n425\n362\n426\n361\n427\n360\n428\n359\n429\n358\n430\n357\n431\n356\n432\n355\n433\n354\n434\n353\n435\n352\n436\n351\n437\n350\n438\n349\n439\n348\n440\n347\n441\n346\n442\n345\n443\n344\n444\n343\n4..." }, { "input": "37 849", "output": "425\n424\n426\n423\n427\n422\n428\n421\n429\n420\n430\n419\n431\n418\n432\n417\n433\n416\n434\n415\n435\n414\n436\n413\n437\n412\n438\n411\n439\n410\n440\n409\n441\n408\n442\n407\n443" }, { "input": "453 855", "output": "428\n427\n429\n426\n430\n425\n431\n424\n432\n423\n433\n422\n434\n421\n435\n420\n436\n419\n437\n418\n438\n417\n439\n416\n440\n415\n441\n414\n442\n413\n443\n412\n444\n411\n445\n410\n446\n409\n447\n408\n448\n407\n449\n406\n450\n405\n451\n404\n452\n403\n453\n402\n454\n401\n455\n400\n456\n399\n457\n398\n458\n397\n459\n396\n460\n395\n461\n394\n462\n393\n463\n392\n464\n391\n465\n390\n466\n389\n467\n388\n468\n387\n469\n386\n470\n385\n471\n384\n472\n383\n473\n382\n474\n381\n475\n380\n476\n379\n477\n378\n478\n377\n4..." }, { "input": "165 374", "output": "187\n188\n186\n189\n185\n190\n184\n191\n183\n192\n182\n193\n181\n194\n180\n195\n179\n196\n178\n197\n177\n198\n176\n199\n175\n200\n174\n201\n173\n202\n172\n203\n171\n204\n170\n205\n169\n206\n168\n207\n167\n208\n166\n209\n165\n210\n164\n211\n163\n212\n162\n213\n161\n214\n160\n215\n159\n216\n158\n217\n157\n218\n156\n219\n155\n220\n154\n221\n153\n222\n152\n223\n151\n224\n150\n225\n149\n226\n148\n227\n147\n228\n146\n229\n145\n230\n144\n231\n143\n232\n142\n233\n141\n234\n140\n235\n139\n236\n138\n237\n137\n238\n1..." }, { "input": "328 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3..." }, { "input": "8 80", "output": "40\n41\n39\n42\n38\n43\n37\n44" }, { "input": "90 544", "output": "272\n273\n271\n274\n270\n275\n269\n276\n268\n277\n267\n278\n266\n279\n265\n280\n264\n281\n263\n282\n262\n283\n261\n284\n260\n285\n259\n286\n258\n287\n257\n288\n256\n289\n255\n290\n254\n291\n253\n292\n252\n293\n251\n294\n250\n295\n249\n296\n248\n297\n247\n298\n246\n299\n245\n300\n244\n301\n243\n302\n242\n303\n241\n304\n240\n305\n239\n306\n238\n307\n237\n308\n236\n309\n235\n310\n234\n311\n233\n312\n232\n313\n231\n314\n230\n315\n229\n316\n228\n317" }, { "input": "85 60", "output": "30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18\n43\n17\n44\n16\n45\n15\n46\n14\n47\n13\n48\n12\n49\n11\n50\n10\n51\n9\n52\n8\n53\n7\n54\n6\n55\n5\n56\n4\n57\n3\n58\n2\n59\n1\n60\n30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18" }, { "input": "392 5", "output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..." }, { "input": "8 87", "output": "44\n43\n45\n42\n46\n41\n47\n40" }, { "input": "6 358", "output": "179\n180\n178\n181\n177\n182" }, { "input": "501 70", "output": "35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n66\n4\n67\n3\n68\n2\n69\n1\n70\n35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n6..." }, { "input": "3834 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1..." }, { "input": "1 8828", "output": "4414" }, { "input": "69230 89906", "output": "44953\n44954\n44952\n44955\n44951\n44956\n44950\n44957\n44949\n44958\n44948\n44959\n44947\n44960\n44946\n44961\n44945\n44962\n44944\n44963\n44943\n44964\n44942\n44965\n44941\n44966\n44940\n44967\n44939\n44968\n44938\n44969\n44937\n44970\n44936\n44971\n44935\n44972\n44934\n44973\n44933\n44974\n44932\n44975\n44931\n44976\n44930\n44977\n44929\n44978\n44928\n44979\n44927\n44980\n44926\n44981\n44925\n44982\n44924\n44983\n44923\n44984\n44922\n44985\n44921\n44986\n44920\n44987\n44919\n44988\n44918\n44989\n44917\n..." }, { "input": "27646 59913", "output": "29957\n29956\n29958\n29955\n29959\n29954\n29960\n29953\n29961\n29952\n29962\n29951\n29963\n29950\n29964\n29949\n29965\n29948\n29966\n29947\n29967\n29946\n29968\n29945\n29969\n29944\n29970\n29943\n29971\n29942\n29972\n29941\n29973\n29940\n29974\n29939\n29975\n29938\n29976\n29937\n29977\n29936\n29978\n29935\n29979\n29934\n29980\n29933\n29981\n29932\n29982\n29931\n29983\n29930\n29984\n29929\n29985\n29928\n29986\n29927\n29987\n29926\n29988\n29925\n29989\n29924\n29990\n29923\n29991\n29922\n29992\n29921\n29993\n..." }, { "input": "37006 54783", "output": "27392\n27391\n27393\n27390\n27394\n27389\n27395\n27388\n27396\n27387\n27397\n27386\n27398\n27385\n27399\n27384\n27400\n27383\n27401\n27382\n27402\n27381\n27403\n27380\n27404\n27379\n27405\n27378\n27406\n27377\n27407\n27376\n27408\n27375\n27409\n27374\n27410\n27373\n27411\n27372\n27412\n27371\n27413\n27370\n27414\n27369\n27415\n27368\n27416\n27367\n27417\n27366\n27418\n27365\n27419\n27364\n27420\n27363\n27421\n27362\n27422\n27361\n27423\n27360\n27424\n27359\n27425\n27358\n27426\n27357\n27427\n27356\n27428\n..." }, { "input": "1 100000", "output": "50000" }, { "input": "100000 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1..." }, { "input": "100000 100000", "output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..." }, { "input": "100000 13", "output": "7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n..." }, { "input": "100000 44", "output": "22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21..." }, { "input": "100000 37820", "output": "18910\n18911\n18909\n18912\n18908\n18913\n18907\n18914\n18906\n18915\n18905\n18916\n18904\n18917\n18903\n18918\n18902\n18919\n18901\n18920\n18900\n18921\n18899\n18922\n18898\n18923\n18897\n18924\n18896\n18925\n18895\n18926\n18894\n18927\n18893\n18928\n18892\n18929\n18891\n18930\n18890\n18931\n18889\n18932\n18888\n18933\n18887\n18934\n18886\n18935\n18885\n18936\n18884\n18937\n18883\n18938\n18882\n18939\n18881\n18940\n18880\n18941\n18879\n18942\n18878\n18943\n18877\n18944\n18876\n18945\n18875\n18946\n18874\n..." }, { "input": "99999 77777", "output": "38889\n38888\n38890\n38887\n38891\n38886\n38892\n38885\n38893\n38884\n38894\n38883\n38895\n38882\n38896\n38881\n38897\n38880\n38898\n38879\n38899\n38878\n38900\n38877\n38901\n38876\n38902\n38875\n38903\n38874\n38904\n38873\n38905\n38872\n38906\n38871\n38907\n38870\n38908\n38869\n38909\n38868\n38910\n38867\n38911\n38866\n38912\n38865\n38913\n38864\n38914\n38863\n38915\n38862\n38916\n38861\n38917\n38860\n38918\n38859\n38919\n38858\n38920\n38857\n38921\n38856\n38922\n38855\n38923\n38854\n38924\n38853\n38925\n..." }, { "input": "1991 1935", "output": "968\n967\n969\n966\n970\n965\n971\n964\n972\n963\n973\n962\n974\n961\n975\n960\n976\n959\n977\n958\n978\n957\n979\n956\n980\n955\n981\n954\n982\n953\n983\n952\n984\n951\n985\n950\n986\n949\n987\n948\n988\n947\n989\n946\n990\n945\n991\n944\n992\n943\n993\n942\n994\n941\n995\n940\n996\n939\n997\n938\n998\n937\n999\n936\n1000\n935\n1001\n934\n1002\n933\n1003\n932\n1004\n931\n1005\n930\n1006\n929\n1007\n928\n1008\n927\n1009\n926\n1010\n925\n1011\n924\n1012\n923\n1013\n922\n1014\n921\n1015\n920\n1016\n919\n1017..." }, { "input": "17 812", "output": "406\n407\n405\n408\n404\n409\n403\n410\n402\n411\n401\n412\n400\n413\n399\n414\n398" }, { "input": "30078 300", "output": "150\n151\n149\n152\n148\n153\n147\n154\n146\n155\n145\n156\n144\n157\n143\n158\n142\n159\n141\n160\n140\n161\n139\n162\n138\n163\n137\n164\n136\n165\n135\n166\n134\n167\n133\n168\n132\n169\n131\n170\n130\n171\n129\n172\n128\n173\n127\n174\n126\n175\n125\n176\n124\n177\n123\n178\n122\n179\n121\n180\n120\n181\n119\n182\n118\n183\n117\n184\n116\n185\n115\n186\n114\n187\n113\n188\n112\n189\n111\n190\n110\n191\n109\n192\n108\n193\n107\n194\n106\n195\n105\n196\n104\n197\n103\n198\n102\n199\n101\n200\n100\n201\n9..." }, { "input": "10500 5", "output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..." }, { "input": "90091 322", "output": "161\n162\n160\n163\n159\n164\n158\n165\n157\n166\n156\n167\n155\n168\n154\n169\n153\n170\n152\n171\n151\n172\n150\n173\n149\n174\n148\n175\n147\n176\n146\n177\n145\n178\n144\n179\n143\n180\n142\n181\n141\n182\n140\n183\n139\n184\n138\n185\n137\n186\n136\n187\n135\n188\n134\n189\n133\n190\n132\n191\n131\n192\n130\n193\n129\n194\n128\n195\n127\n196\n126\n197\n125\n198\n124\n199\n123\n200\n122\n201\n121\n202\n120\n203\n119\n204\n118\n205\n117\n206\n116\n207\n115\n208\n114\n209\n113\n210\n112\n211\n111\n212\n1..." }, { "input": "8471 92356", "output": "46178\n46179\n46177\n46180\n46176\n46181\n46175\n46182\n46174\n46183\n46173\n46184\n46172\n46185\n46171\n46186\n46170\n46187\n46169\n46188\n46168\n46189\n46167\n46190\n46166\n46191\n46165\n46192\n46164\n46193\n46163\n46194\n46162\n46195\n46161\n46196\n46160\n46197\n46159\n46198\n46158\n46199\n46157\n46200\n46156\n46201\n46155\n46202\n46154\n46203\n46153\n46204\n46152\n46205\n46151\n46206\n46150\n46207\n46149\n46208\n46148\n46209\n46147\n46210\n46146\n46211\n46145\n46212\n46144\n46213\n46143\n46214\n46142\n..." }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1\n1" }, { "input": "52097 88310", "output": "44155\n44156\n44154\n44157\n44153\n44158\n44152\n44159\n44151\n44160\n44150\n44161\n44149\n44162\n44148\n44163\n44147\n44164\n44146\n44165\n44145\n44166\n44144\n44167\n44143\n44168\n44142\n44169\n44141\n44170\n44140\n44171\n44139\n44172\n44138\n44173\n44137\n44174\n44136\n44175\n44135\n44176\n44134\n44177\n44133\n44178\n44132\n44179\n44131\n44180\n44130\n44181\n44129\n44182\n44128\n44183\n44127\n44184\n44126\n44185\n44125\n44186\n44124\n44187\n44123\n44188\n44122\n44189\n44121\n44190\n44120\n44191\n44119\n..." } ]
530
0
3
3,170
304
Calendar
[ "brute force", "implementation" ]
null
null
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February. Look at the sample to understand what borders are included in the aswer.
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≀<=*yyyy*<=≀<=2038 and yyyy:mm:dd is a legal date).
Print a single integer β€” the answer to the problem.
[ "1900:01:01\n2038:12:31\n", "1996:03:09\n1991:11:12\n" ]
[ "50768\n", "1579\n" ]
none
[ { "input": "1900:01:01\n2038:12:31", "output": "50768" }, { "input": "1996:03:09\n1991:11:12", "output": "1579" }, { "input": "1999:12:31\n2000:02:29", "output": "60" }, { "input": "1903:09:27\n1988:06:15", "output": "30943" }, { "input": "1913:11:14\n1901:05:11", "output": "4570" }, { "input": "1915:01:01\n2007:07:01", "output": "33784" }, { "input": "1925:07:15\n2010:06:22", "output": "31023" }, { "input": "1935:10:08\n1923:01:07", "output": "4657" }, { "input": "1986:08:24\n1926:04:13", "output": "22048" }, { "input": "1932:11:18\n2028:09:25", "output": "35010" }, { "input": "1942:06:04\n1982:12:29", "output": "14818" }, { "input": "1993:08:25\n1985:02:16", "output": "3112" }, { "input": "1954:06:30\n1911:05:04", "output": "15763" }, { "input": "2005:08:01\n1963:08:23", "output": "15319" }, { "input": "2015:10:17\n1966:07:12", "output": "17994" }, { "input": "2025:08:10\n2018:09:03", "output": "2533" }, { "input": "2027:07:31\n1945:04:06", "output": "30066" }, { "input": "2037:05:16\n1996:03:11", "output": "15041" }, { "input": "1949:07:09\n1901:10:24", "output": "17425" }, { "input": "2028:04:11\n1931:09:01", "output": "35287" }, { "input": "1900:02:06\n1997:12:07", "output": "35733" }, { "input": "1902:09:06\n1951:03:31", "output": "17738" }, { "input": "1912:03:09\n1954:06:17", "output": "15440" }, { "input": "1963:05:02\n2005:08:02", "output": "15433" }, { "input": "1973:03:18\n1932:11:07", "output": "14741" }, { "input": "1934:01:09\n1935:02:22", "output": "409" }, { "input": "1985:08:24\n1987:05:01", "output": "615" }, { "input": "1995:06:03\n1990:07:22", "output": "1777" }, { "input": "1907:04:04\n1902:10:01", "output": "1646" }, { "input": "1910:01:11\n1987:02:08", "output": "28152" }, { "input": "1996:03:09\n1996:03:09", "output": "0" }, { "input": "1900:03:02\n2038:03:01", "output": "50403" }, { "input": "2000:01:02\n2000:02:02", "output": "31" }, { "input": "1999:04:08\n1999:02:04", "output": "63" }, { "input": "1999:01:01\n1999:01:10", "output": "9" }, { "input": "2012:05:29\n2012:02:29", "output": "90" }, { "input": "1900:01:01\n1900:01:01", "output": "0" }, { "input": "1996:02:01\n1996:01:27", "output": "5" }, { "input": "1901:12:31\n1901:12:31", "output": "0" }, { "input": "2000:02:28\n2000:02:28", "output": "0" } ]
404
1,126,400
3
3,171
31
Schedule
[ "implementation" ]
C. Schedule
2
256
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect. The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.
The first line contains integer *n* (1<=≀<=*n*<=≀<=5000) β€” amount of groups, which have lessons in the room 31. Then *n* lines follow, each of them contains two integers *l**i* *r**i* (1<=≀<=*l**i*<=&lt;<=*r**i*<=≀<=106) β€” starting and finishing times of lesson of the *i*-th group. It is possible that initially no two lessons intersect (see sample 1).
Output integer *k* β€” amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output *k* numbers β€” indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.
[ "3\n3 10\n20 30\n1 3\n", "4\n3 10\n20 30\n1 3\n1 39\n", "3\n1 5\n2 6\n3 7\n" ]
[ "3\n1 2 3 ", "1\n4 ", "0\n" ]
none
[ { "input": "3\n3 10\n20 30\n1 3", "output": "3\n1 2 3 " }, { "input": "4\n3 10\n20 30\n1 3\n1 39", "output": "1\n4 " }, { "input": "3\n1 5\n2 6\n3 7", "output": "0" }, { "input": "4\n1 5\n5 7\n6 9\n9 10", "output": "2\n2 3 " }, { "input": "11\n717170 795210\n866429 970764\n163324 322182\n677099 717170\n241684 393937\n50433 114594\n970764 997956\n393937 664883\n235698 241684\n795210 832346\n114594 232438", "output": "1\n3 " }, { "input": "16\n203671 381501\n58867 59732\n817520 962123\n125391 163027\n601766 617692\n381501 444610\n761937 817520\n16 10551\n21096 38291\n718073 761937\n583868 601766\n554859 731755\n678098 718073\n962123 992003\n163027 203671\n87917 96397", "output": "1\n12 " } ]
2,000
204,800
0
3,173
15
Cottage Village
[ "implementation", "sortings" ]
A. Cottage Village
2
64
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
The first line of the input data contains numbers *n* and *t* (1<=≀<=*n*,<=*t*<=≀<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* β€” *x*-coordinate of the centre of the *i*-th house, and *a**i* β€” length of its side (<=-<=1000<=≀<=*x**i*<=≀<=1000, 1<=≀<=*a**i*<=≀<=1000).
Output the amount of possible positions of the new house.
[ "2 2\n0 4\n6 2\n", "2 2\n0 4\n5 2\n", "2 3\n0 4\n5 2\n" ]
[ "4\n", "3\n", "2\n" ]
It is possible for the *x*-coordinate of the new house to have non-integer value.
[ { "input": "2 2\n0 4\n6 2", "output": "4" }, { "input": "2 2\n0 4\n5 2", "output": "3" }, { "input": "2 3\n0 4\n5 2", "output": "2" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 2\n2 1", "output": "2" }, { "input": "2 1\n2 1\n1 1", "output": "2" }, { "input": "2 2\n0 4\n7 4", "output": "4" }, { "input": "4 1\n-12 1\n-14 1\n4 1\n-11 1", "output": "5" }, { "input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1", "output": "2" }, { "input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6", "output": "6" }, { "input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9", "output": "35" }, { "input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34", "output": "16" }, { "input": "3 501\n827 327\n-85 480\n-999 343", "output": "6" }, { "input": "2 999\n-999 471\n530 588", "output": "4" }, { "input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31", "output": "30" }, { "input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3", "output": "16" }, { "input": "4 512\n-997 354\n-568 216\n-234 221\n603 403", "output": "4" }, { "input": "3 966\n988 5\n15 2\n-992 79", "output": "6" }, { "input": "2 1000\n-995 201\n206 194", "output": "4" }, { "input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2", "output": "9" }, { "input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1", "output": "43" }, { "input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7", "output": "96" }, { "input": "1 1000\n0 1000", "output": "2" } ]
154
2,355,200
3.943952
3,176
499
Watching a movie
[ "greedy", "implementation" ]
null
null
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
The first line contains two space-separated integers *n*, *x* (1<=≀<=*n*<=≀<=50, 1<=≀<=*x*<=≀<=105) β€” the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*.
Output a single number β€” the answer to the problem.
[ "2 3\n5 6\n10 12\n", "1 1\n1 100000\n" ]
[ "6\n", "100000\n" ]
In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
[ { "input": "2 3\n5 6\n10 12", "output": "6" }, { "input": "1 1\n1 100000", "output": "100000" }, { "input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53974" }, { "input": "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53983" }, { "input": "10 10\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "54038" }, { "input": "10 1000\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "58728" }, { "input": "12 14\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41870" }, { "input": "12 17\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41872" }, { "input": "18 111\n1449 2156\n3497 4784\n7775 14575\n23857 24593\n29211 30739\n31932 33447\n35902 36426\n36991 38506\n39679 47202\n48772 60016\n60522 61868\n63340 63982\n68417 78537\n79445 86568\n86918 87940\n90081 90310\n90629 94325\n95728 96263", "output": "58967" }, { "input": "1 1\n14575 60522", "output": "45948" }, { "input": "1 10\n14575 60522", "output": "45952" }, { "input": "2 10\n14575 36426\n60522 79445", "output": "40785" }, { "input": "3 1\n14575 36426\n48772 60522\n79445 90081", "output": "44240" }, { "input": "1 100000\n1 100000", "output": "100000" }, { "input": "1 2\n2 100000", "output": "100000" }, { "input": "1 3\n4 100000", "output": "99997" }, { "input": "2 100\n5 6\n7 7", "output": "7" }, { "input": "1 10000\n500 600", "output": "600" }, { "input": "2 3\n1 3\n4 8", "output": "8" }, { "input": "3 1\n1 2\n3 4\n6 7", "output": "6" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 3\n5 6", "output": "3" }, { "input": "1 5\n7 10", "output": "5" }, { "input": "1 100\n5 6", "output": "6" }, { "input": "1 2\n1 1", "output": "1" }, { "input": "1 100000\n100000 100000", "output": "100000" }, { "input": "2 3\n1 1\n5 6", "output": "3" } ]
93
204,800
-1
3,179
991
Candies
[ "binary search", "implementation" ]
null
null
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeatsΒ β€” next day Vasya eats $k$ candies again, and PetyaΒ β€” $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$)Β β€” the initial amount of candies in the box.
Output a single integerΒ β€” the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
[ "68\n" ]
[ "3\n" ]
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while PetyaΒ β€” $29$.
[ { "input": "68", "output": "3" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "1" }, { "input": "43", "output": "2" }, { "input": "756", "output": "29" }, { "input": "999999972", "output": "39259423" }, { "input": "999999973", "output": "39259424" }, { "input": "1000000000000000000", "output": "39259424579862572" }, { "input": "6", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "66", "output": "2" }, { "input": "67", "output": "3" }, { "input": "1000", "output": "39" }, { "input": "10000", "output": "392" }, { "input": "100500", "output": "3945" }, { "input": "1000000", "output": "39259" }, { "input": "10000000", "output": "392594" }, { "input": "100000000", "output": "3925942" }, { "input": "123456789", "output": "4846842" }, { "input": "543212345", "output": "21326204" }, { "input": "505050505", "output": "19827992" }, { "input": "777777777", "output": "30535108" }, { "input": "888888871", "output": "34897266" }, { "input": "1000000000", "output": "39259424" }, { "input": "999999999999999973", "output": "39259424579862572" }, { "input": "999999999999999998", "output": "39259424579862572" }, { "input": "999999999999999999", "output": "39259424579862573" }, { "input": "100000000000000000", "output": "3925942457986257" }, { "input": "540776028375043656", "output": "21230555700587649" }, { "input": "210364830044445976", "output": "8258802179385535" }, { "input": "297107279239074256", "output": "11664260821414605" }, { "input": "773524766411950187", "output": "30368137227605772" }, { "input": "228684941775227220", "output": "8978039224174797" }, { "input": "878782039723446310", "output": "34500477210660436" }, { "input": "615090701338187389", "output": "24148106998961343" }, { "input": "325990422297859188", "output": "12798196397960353" }, { "input": "255163492355051023", "output": "10017571883647466" }, { "input": "276392003308849171", "output": "10850991008380891" }, { "input": "601", "output": "23" }, { "input": "983", "output": "38" }, { "input": "729", "output": "29" }, { "input": "70", "output": "3" }, { "input": "703", "output": "28" }, { "input": "257", "output": "10" }, { "input": "526", "output": "20" }, { "input": "466", "output": "18" }, { "input": "738", "output": "29" }, { "input": "116", "output": "5" }, { "input": "888888888888888887", "output": "34897266293211176" }, { "input": "888888888888888888", "output": "34897266293211176" }, { "input": "888888888888888889", "output": "34897266293211176" }, { "input": "999999999999999969", "output": "39259424579862571" }, { "input": "999999999999999970", "output": "39259424579862571" }, { "input": "999999999999999971", "output": "39259424579862572" }, { "input": "999999999999999943", "output": "39259424579862571" }, { "input": "999999999999999944", "output": "39259424579862570" }, { "input": "999999999999999945", "output": "39259424579862571" }, { "input": "999999999999999917", "output": "39259424579862570" }, { "input": "999999999999999918", "output": "39259424579862569" }, { "input": "999999999999999919", "output": "39259424579862570" }, { "input": "99999999999999957", "output": "3925942457986255" }, { "input": "99999999999999958", "output": "3925942457986255" }, { "input": "99999999999999959", "output": "3925942457986256" }, { "input": "888888888888888853", "output": "34897266293211174" }, { "input": "888888888888888854", "output": "34897266293211174" }, { "input": "888888888888888855", "output": "34897266293211175" } ]
1,000
0
0
3,181
987
Three displays
[ "brute force", "dp", "implementation" ]
null
null
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i &lt; j &lt; k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i &lt; s_j &lt; s_k$ should be held. The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
The first line contains a single integer $n$ ($3 \le n \le 3\,000$)Β β€” the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$)Β β€” the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$)Β β€” the rent costs for each display.
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integerΒ β€” the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$.
[ "5\n2 4 5 4 10\n40 30 20 10 40\n", "3\n100 101 100\n2 4 5\n", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n" ]
[ "90\n", "-1\n", "33\n" ]
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
[ { "input": "5\n2 4 5 4 10\n40 30 20 10 40", "output": "90" }, { "input": "3\n100 101 100\n2 4 5", "output": "-1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "output": "33" }, { "input": "3\n1 2 3\n100000000 100000000 100000000", "output": "300000000" }, { "input": "3\n999999998 999999999 1000000000\n100000000 100000000 99999999", "output": "299999999" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n23219513 68171337 12183499 5549873 73542337 66661387 79397647 34495917 31413076 50918417", "output": "85904709" }, { "input": "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499\n61699500 83254572 59454419 27833657 55743179 99661234 94729965 75591136 62937826 3626886 73906880 3664913 39990362 94385934 33153747 23840219 64514676 14746017 13062847 65187713", "output": "72432912" }, { "input": "3\n1 2 3\n1 1 1", "output": "3" } ]
296
7,270,400
-1
3,182
255
Almost Arithmetical Progression
[ "brute force", "dp" ]
null
null
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: - *a*1<==<=*p*, where *p* is some integer; - *a**i*<==<=*a**i*<=-<=1<=+<=(<=-<=1)*i*<=+<=1Β·*q* (*i*<=&gt;<=1), where *q* is some integer. Right now Gena has a piece of paper with sequence *b*, consisting of *n* integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression. Sequence *s*1,<=<=*s*2,<=<=...,<=<=*s**k* is a subsequence of sequence *b*1,<=<=*b*2,<=<=...,<=<=*b**n*, if there is such increasing sequence of indexes *i*1,<=*i*2,<=...,<=*i**k* (1<=<=≀<=<=*i*1<=<=&lt;<=<=*i*2<=<=&lt;<=... <=<=&lt;<=<=*i**k*<=<=≀<=<=*n*), that *b**i**j*<=<==<=<=*s**j*. In other words, sequence *s* can be obtained from *b* by crossing out some elements.
The first line contains integer *n* (1<=≀<=*n*<=≀<=4000). The next line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≀<=*b**i*<=≀<=106).
Print a single integer β€” the length of the required longest subsequence.
[ "2\n3 5\n", "4\n10 20 10 30\n" ]
[ "2\n", "3\n" ]
In the first test the sequence actually is the suitable subsequence. In the second test the following subsequence fits: 10, 20, 10.
[ { "input": "2\n3 5", "output": "2" }, { "input": "4\n10 20 10 30", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "2" }, { "input": "6\n2 3 2 2 1 3", "output": "4" }, { "input": "8\n2 2 5 3 4 3 3 2", "output": "3" }, { "input": "2\n468 335", "output": "2" }, { "input": "1\n170", "output": "1" }, { "input": "5\n479 359 963 465 706", "output": "2" }, { "input": "6\n282 828 962 492 996 943", "output": "2" }, { "input": "8\n437 392 605 903 154 293 383 422", "output": "2" }, { "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": "4" }, { "input": "73\n531 626 701 57 708 511 54 441 297 697 411 253 397 652 21 59 851 561 539 461 629 894 275 417 127 505 433 243 963 247 5 368 969 541 408 485 319 117 441 131 265 357 1 659 267 983 643 285 913 782 813 569 99 781 297 636 645 341 6 17 601 129 509 197 226 105 241 737 86 128 762 647 849", "output": "4" }, { "input": "49\n516 161 416 850 361 861 833 233 281 798 225 771 841 111 481 617 463 305 743 945 833 141 70 617 511 522 840 505 753 544 931 213 626 567 137 687 221 942 951 881 617 129 761 225 849 915 96 801 164", "output": "4" } ]
249
5,427,200
0
3,188
999
Reachability from the Capital
[ "dfs and similar", "graphs", "greedy" ]
null
null
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way.
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) β€” the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$. The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
Print one integer β€” the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
[ "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n", "5 4 5\n1 2\n2 3\n3 4\n4 1\n" ]
[ "3\n", "1\n" ]
The first example is illustrated by the following: For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$. The second example is illustrated by the following: In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
[ { "input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "output": "3" }, { "input": "5 4 5\n1 2\n2 3\n3 4\n4 1", "output": "1" }, { "input": "5000 0 2956", "output": "4999" }, { "input": "2 0 2", "output": "1" }, { "input": "2 1 1\n1 2", "output": "0" }, { "input": "2 1 2\n1 2", "output": "1" }, { "input": "2 2 2\n1 2\n2 1", "output": "0" }, { "input": "5000 2 238\n3212 238\n238 3212", "output": "4998" }, { "input": "5000 2 3810\n3225 1137\n1137 3225", "output": "4998" }, { "input": "100 1 30\n69 81", "output": "98" }, { "input": "500 1 209\n183 107", "output": "498" }, { "input": "1000 1 712\n542 916", "output": "998" }, { "input": "39 40 38\n4 8\n24 28\n16 17\n7 25\n4 29\n34 35\n16 24\n21 10\n23 36\n36 14\n28 16\n34 19\n15 21\n22 38\n22 37\n37 27\n28 33\n3 29\n32 22\n12 30\n9 15\n5 19\n23 27\n19 17\n25 17\n24 11\n39 10\n6 20\n16 6\n3 18\n34 21\n15 38\n11 19\n11 3\n32 4\n15 13\n16 11\n11 7\n33 7\n3 33", "output": "12" }, { "input": "8 8 1\n3 2\n3 4\n4 5\n5 3\n6 4\n6 7\n7 8\n8 6", "output": "1" }, { "input": "7 7 1\n2 3\n4 2\n7 4\n5 7\n4 5\n4 6\n6 4", "output": "1" }, { "input": "2333 1 1\n1 2", "output": "2331" }, { "input": "7 4 2\n1 2\n3 4\n5 6\n7 1", "output": "3" }, { "input": "1 0 1", "output": "0" }, { "input": "9 9 1\n2 3\n3 4\n4 5\n6 2\n7 6\n8 7\n6 8\n5 9\n9 2", "output": "1" }, { "input": "30 30 29\n29 9\n1 3\n15 5\n14 24\n7 18\n17 12\n5 9\n22 7\n26 20\n7 29\n8 2\n10 12\n17 18\n17 24\n8 12\n23 28\n10 15\n18 2\n29 13\n25 29\n9 2\n7 13\n11 5\n19 26\n10 5\n25 5\n20 10\n5 26\n24 23\n22 8", "output": "13" }, { "input": "30 30 28\n16 28\n5 30\n7 17\n6 1\n12 28\n15 28\n14 30\n25 11\n25 10\n25 8\n12 30\n27 5\n30 10\n22 14\n30 13\n20 27\n15 25\n24 20\n20 15\n1 30\n3 10\n3 4\n3 18\n15 14\n18 22\n20 26\n10 3\n15 27\n23 29\n10 24", "output": "9" } ]
514
11,468,800
0
3,191
777
Alyona and Spreadsheet
[ "binary search", "data structures", "dp", "greedy", "implementation", "two pointers" ]
null
null
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≀<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1. Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≀<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive. Alyona is too small to deal with this task and asks you to help!
The first line of the input contains two positive integers *n* and *m* (1<=≀<=*n*Β·*m*<=≀<=100<=000)Β β€” the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table. Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≀<=*a**i*,<=*j*<=≀<=109). The next line of the input contains an integer *k* (1<=≀<=*k*<=≀<=100<=000)Β β€” the number of task that teacher gave to Alyona. The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=*n*).
Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
[ "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n" ]
[ "Yes\nNo\nYes\nYes\nYes\nNo\n" ]
In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3.
[ { "input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "output": "Yes\nNo\nYes\nYes\nYes\nNo" }, { "input": "1 1\n1\n1\n1 1", "output": "Yes" }, { "input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10", "output": "No\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo" }, { "input": "15 1\n556231456\n573340933\n626155933\n397229387\n10255952\n376567394\n906742013\n269437009\n31298788\n712285290\n620239975\n379221898\n229140718\n95080095\n997123854\n18\n5 15\n1 12\n4 10\n2 15\n12 15\n15 15\n2 2\n15 15\n15 15\n13 13\n10 14\n3 6\n14 15\n3 6\n4 4\n14 15\n12 14\n1 9", "output": "No\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo" }, { "input": "11 1\n501465490\n366941771\n415080944\n385243536\n445132523\n697044413\n894369800\n812743722\n23684788\n466526046\n953916313\n45\n2 4\n8 9\n7 7\n4 9\n2 9\n2 11\n4 4\n5 7\n1 2\n5 10\n4 6\n1 7\n4 4\n1 6\n4 7\n10 11\n1 8\n6 11\n8 8\n8 10\n1 1\n5 10\n9 10\n6 9\n6 11\n1 1\n9 9\n5 11\n1 2\n9 11\n2 6\n3 7\n11 11\n6 7\n11 11\n7 8\n5 8\n11 11\n5 6\n4 5\n2 6\n5 10\n9 9\n1 1\n1 1", "output": "No\nNo\nYes\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes" } ]
966
23,654,400
0
3,193
543
Writing Code
[ "dp" ]
null
null
Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that he writes. Let's call a sequence of non-negative integers *v*1,<=*v*2,<=...,<=*v**n* a plan, if *v*1<=+<=*v*2<=+<=...<=+<=*v**n*<==<=*m*. The programmers follow the plan like that: in the beginning the first programmer writes the first *v*1 lines of the given task, then the second programmer writes *v*2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most *b* bugs in total. Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer *mod*.
The first line contains four integers *n*, *m*, *b*, *mod* (1<=≀<=*n*,<=*m*<=≀<=500, 0<=≀<=*b*<=≀<=500; 1<=≀<=*mod*<=≀<=109<=+<=7)Β β€” the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer. The next line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=500)Β β€” the number of bugs per line for each programmer.
Print a single integer β€” the answer to the problem modulo *mod*.
[ "3 3 3 100\n1 1 1\n", "3 6 5 1000000007\n1 2 3\n", "3 5 6 11\n1 2 1\n" ]
[ "10\n", "0\n", "0\n" ]
none
[ { "input": "3 3 3 100\n1 1 1", "output": "10" }, { "input": "3 6 5 1000000007\n1 2 3", "output": "0" }, { "input": "3 5 6 11\n1 2 1", "output": "0" }, { "input": "2 3 3 1000\n1 2", "output": "1" }, { "input": "3 10 10 150691913\n8 7 10", "output": "0" }, { "input": "100 500 500 895583345\n20 39 5 5 41 47 36 33 34 22 21 33 7 4 15 35 16 37 39 46 27 4 12 35 43 26 23 40 16 50 27 7 49 28 17 28 16 22 18 12 25 34 28 24 10 21 38 10 40 50 35 18 23 38 10 42 22 19 24 45 33 34 50 24 29 36 39 11 37 18 10 2 9 38 17 36 49 1 32 6 20 5 37 18 31 44 1 36 24 35 13 35 8 10 26 45 43 28 38 22", "output": "501" }, { "input": "100 100 100 960694994\n1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1", "output": "527886216" }, { "input": "123 432 342 1000000007\n72 20 34 115 65 29 114 41 18 16 122 104 88 37 119 11 108 91 13 110 47 73 80 35 62 12 9 116 55 66 54 113 50 57 8 25 98 105 0 120 93 78 61 17 84 48 42 106 63 103 7 59 90 89 28 49 53 71 51 83 75 67 64 95 107 3 32 85 69 99 33 79 109 56 10 23 87 19 121 94 44 82 102 27 112 52 21 1 5 74 117 111 76 24 4 101 30 36 97 60 92 46 22 68 118 58 38 70 39 26 43 77 6 2 40 100 81 96 14 31 15 45 86", "output": "902925242" }, { "input": "100 500 499 1000000007\n72 20 34 92 65 29 40 41 18 16 86 14 88 37 31 11 39 91 13 43 47 73 80 35 62 12 9 81 55 66 54 2 50 57 8 25 98 58 0 15 93 78 61 17 84 48 42 38 63 68 7 59 90 89 28 49 53 71 51 83 75 67 64 95 70 3 32 85 69 99 33 79 26 56 10 23 87 19 45 94 44 82 22 27 6 52 21 1 5 74 96 77 76 24 4 46 30 36 97 60", "output": "416898599" }, { "input": "1 1 0 1000\n0", "output": "1" }, { "input": "1 4 25 1000\n6", "output": "1" }, { "input": "1 5 1 10\n1", "output": "0" }, { "input": "1 5 5 1000\n1", "output": "1" }, { "input": "1 5 5 1000\n500", "output": "0" }, { "input": "2 500 250 100\n100 200", "output": "0" }, { "input": "2 500 50 10000\n0 50", "output": "2" }, { "input": "100 500 500 1000000007\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "925584498" }, { "input": "10 9 20 48620\n1 1 1 1 1 1 1 1 2 2", "output": "0" }, { "input": "21 63 40 1009\n4 4 2 2 4 4 3 2 4 2 0 3 3 4 3 4 3 0 4 2 4", "output": "1002" }, { "input": "29 157 50 1\n3 0 0 3 1 1 2 0 4 4 1 2 2 1 0 0 2 0 3 2 2 3 3 1 4 1 1 4 1", "output": "0" }, { "input": "1 1 1 1\n0", "output": "0" }, { "input": "1 1 1 1\n2", "output": "0" } ]
3,000
14,745,600
0
3,197
0
none
[ "none" ]
null
null
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample). We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously. Help Vasya count to which girlfriend he will go more often.
The first line contains two integers *a* and *b* (*a*<=β‰ <=*b*,<=1<=≀<=*a*,<=*b*<=≀<=106).
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
[ "3 7\n", "5 3\n", "2 3\n" ]
[ "Dasha\n", "Masha\n", "Equal\n" ]
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often. If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute. If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute. If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute. If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction. In sum Masha and Dasha get equal time β€” three minutes for each one, thus, Vasya will go to both girlfriends equally often.
[ { "input": "3 7", "output": "Dasha" }, { "input": "5 3", "output": "Masha" }, { "input": "2 3", "output": "Equal" }, { "input": "31 88", "output": "Dasha" }, { "input": "8 75", "output": "Dasha" }, { "input": "32 99", "output": "Dasha" }, { "input": "77 4", "output": "Masha" }, { "input": "27 1", "output": "Masha" }, { "input": "84 11", "output": "Masha" }, { "input": "4 6", "output": "Equal" }, { "input": "52 53", "output": "Equal" }, { "input": "397 568", "output": "Dasha" }, { "input": "22 332", "output": "Dasha" }, { "input": "419 430", "output": "Dasha" }, { "input": "638 619", "output": "Masha" }, { "input": "393 325", "output": "Masha" }, { "input": "876 218", "output": "Masha" }, { "input": "552 551", "output": "Equal" }, { "input": "906 912", "output": "Equal" }, { "input": "999 996", "output": "Equal" }, { "input": "652 653", "output": "Equal" }, { "input": "3647 7698", "output": "Dasha" }, { "input": "2661 8975", "output": "Dasha" }, { "input": "251 9731", "output": "Dasha" }, { "input": "9886 8671", "output": "Masha" }, { "input": "8545 7312", "output": "Masha" }, { "input": "4982 2927", "output": "Masha" }, { "input": "7660 7658", "output": "Equal" }, { "input": "9846 9844", "output": "Equal" }, { "input": "9632 9640", "output": "Equal" }, { "input": "5036 5037", "output": "Equal" }, { "input": "64854 77725", "output": "Dasha" }, { "input": "4965 85708", "output": "Dasha" }, { "input": "20393 86640", "output": "Dasha" }, { "input": "99207 30728", "output": "Masha" }, { "input": "77545 13842", "output": "Masha" }, { "input": "30362 10712", "output": "Masha" }, { "input": "51291 51292", "output": "Equal" }, { "input": "55381 55382", "output": "Equal" }, { "input": "91560 91550", "output": "Equal" }, { "input": "99087 99090", "output": "Equal" }, { "input": "983794 986389", "output": "Dasha" }, { "input": "779183 786727", "output": "Dasha" }, { "input": "450766 610961", "output": "Dasha" }, { "input": "664690 630787", "output": "Masha" }, { "input": "461363 256765", "output": "Masha" }, { "input": "638067 409048", "output": "Masha" }, { "input": "929061 929052", "output": "Equal" }, { "input": "996219 996216", "output": "Equal" }, { "input": "716249 716248", "output": "Equal" }, { "input": "782250 782252", "output": "Equal" }, { "input": "1 2", "output": "Equal" }, { "input": "2 1", "output": "Equal" }, { "input": "999999 1000000", "output": "Equal" }, { "input": "999997 1000000", "output": "Dasha" }, { "input": "1000000 999993", "output": "Masha" }, { "input": "999983 999979", "output": "Masha" } ]
92
512,000
-1
3,203
287
IQ Test
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=Γ—<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=Γ—<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=Γ—<=2 square, consisting of cells of the same color.
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "output": "NO" }, { "input": ".#.#\n#.#.\n#.#.\n#.#.", "output": "NO" }, { "input": ".#.#\n#.#.\n#.#.\n.#.#", "output": "NO" }, { "input": "#.#.\n#.#.\n#.#.\n#.#.", "output": "NO" }, { "input": ".#.#\n.#.#\n.#.#\n.#.#", "output": "NO" }, { "input": "#..#\n.##.\n####\n####", "output": "YES" }, { "input": "#.#.\n.###\n#.#.\n.###", "output": "YES" }, { "input": "#..#\n.##.\n.##.\n#..#", "output": "YES" }, { "input": ".##.\n.#..\n##.#\n#..#", "output": "YES" }, { "input": ".##.\n##..\n#..#\n..##", "output": "YES" }, { "input": "##..\n##..\n..##\n..##", "output": "YES" }, { "input": ".#..\n###.\n.#.#\n..#.", "output": "YES" }, { "input": "###.\n###.\n...#\n...#", "output": "YES" }, { "input": "#.##\n##.#\n#.##\n##.#", "output": "YES" }, { "input": ".#.#\n#.#.\n.#.#\n#.##", "output": "YES" }, { "input": "##..\n..##\n##..\n...#", "output": "YES" }, { "input": ".#..\n..##\n##..\n..##", "output": "YES" }, { "input": "##..\n...#\n##..\n...#", "output": "YES" }, { "input": ".#..\n..#.\n.#..\n..#.", "output": "YES" }, { "input": "....\n....\n....\n.#.#", "output": "YES" }, { "input": "....\n....\n....\n...#", "output": "YES" } ]
77
7,065,600
3
3,206
980
Posterized
[ "games", "greedy" ]
null
null
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, therefore the color of each pixel will be an integer between 0 and 255 (inclusive). To implement the filter, students are required to divide the black and white color range [0, 255] into groups of consecutive colors, and select one color in each group to be the group’s key. In order to preserve image details, the size of a group must not be greater than $k$, and each color should belong to exactly one group. Finally, the students will replace the color of each pixel in the array with that color’s assigned group key. To better understand the effect, here is an image of a basking turtle where the Posterization Filter was applied with increasing $k$ to the right. To make the process of checking the final answer easier, Professor Ibrahim wants students to divide the groups and assign the keys in a way that produces the lexicographically smallest possible array.
The first line of input contains two integers $n$ and $k$ ($1 \leq n \leq 10^5$, $1 \leq k \leq 256$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ($0 \leq p_i \leq 255$), where $p_i$ is the color of the $i$-th pixel.
Print $n$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
[ "4 3\n2 14 3 4\n", "5 2\n0 2 1 255 254\n" ]
[ "0 12 3 3\n", "0 1 1 254 254\n" ]
One possible way to group colors and assign keys for the first sample: Color $2$ belongs to the group $[0,2]$, with group key $0$. Color $14$ belongs to the group $[12,14]$, with group key $12$. Colors $3$ and $4$ belong to group $[3, 5]$, with group key $3$. Other groups won't affect the result so they are not listed here.
[ { "input": "4 3\n2 14 3 4", "output": "0 12 3 3" }, { "input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254" }, { "input": "10 3\n112 184 161 156 118 231 191 128 91 229", "output": "110 182 159 154 116 229 189 126 89 229" }, { "input": "9 3\n174 149 118 124 166 146 219 233 107", "output": "172 147 116 122 164 144 217 231 105" }, { "input": "8 4\n180 195 13 195 61 24 132 160", "output": "177 192 10 192 58 21 129 157" }, { "input": "1 4\n51", "output": "48" }, { "input": "2 4\n218 213", "output": "215 210" }, { "input": "3 3\n212 167 3", "output": "210 165 1" }, { "input": "100 7\n39 242 238 155 95 30 129 132 72 59 22 61 133 113 99 81 253 204 160 109 92 187 11 227 145 148 100 42 78 14 113 91 140 197 123 182 4 185 208 27 182 207 63 146 102 79 159 195 26 100 72 127 157 159 152 53 0 117 111 125 19 188 179 145 240 50 205 207 113 246 42 56 181 13 188 244 159 222 119 204 87 182 212 175 199 69 81 45 30 32 238 255 81 61 177 125 149 121 35 38", "output": "33 236 236 149 89 24 123 130 66 53 16 60 130 107 96 75 247 198 156 107 89 181 5 221 139 146 96 40 75 12 107 89 139 191 123 181 0 181 205 24 181 205 60 146 96 75 156 191 24 96 66 123 156 156 149 53 0 114 107 123 16 188 173 139 236 44 205 205 107 243 40 53 181 12 188 243 156 221 114 198 82 181 209 173 198 66 75 44 24 31 236 254 75 60 173 123 149 120 33 33" }, { "input": "4 2\n122 108 224 154", "output": "121 107 223 153" } ]
218
2,048,000
-1
3,207
437
The Child and Set
[ "bitmasks", "greedy", "implementation", "sortings" ]
null
null
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set *S*: - its elements were distinct integers from 1 to *limit*; - the value of was equal to *sum*; here *lowbit*(*x*) equals 2*k* where *k* is the position of the first one in the binary representation of *x*. For example, *lowbit*(100102)<==<=102,<=*lowbit*(100012)<==<=12,<=*lowbit*(100002)<==<=100002 (binary representation). Can you help Picks and find any set *S*, that satisfies all the above conditions?
The first line contains two integers: *sum*,<=*limit* (1<=≀<=*sum*,<=*limit*<=≀<=105).
In the first line print an integer *n* (1<=≀<=*n*<=≀<=105), denoting the size of *S*. Then print the elements of set *S* in any order. If there are multiple answers, print any of them. If it's impossible to find a suitable set, print -1.
[ "5 5\n", "4 3\n", "5 1\n" ]
[ "2\n4 5\n", "3\n2 3 1\n", "-1\n" ]
In sample test 1: *lowbit*(4) = 4, *lowbit*(5) = 1, 4 + 1 = 5. In sample test 2: *lowbit*(1) = 1, *lowbit*(2) = 2, *lowbit*(3) = 1, 1 + 2 + 1 = 4.
[ { "input": "5 5", "output": "2\n4 5" }, { "input": "4 3", "output": "3\n2 3 1" }, { "input": "5 1", "output": "-1" }, { "input": "54321 12345", "output": "7008\n8958 8925 11009 10808 8221 9771 11269 7017 6416 11723 10324 5654 6569 10454 9164 10754 6069 7913 12154 11111 7361 9619 9829 6664 8468 7239 5453 11577 11423 10031 11624 11486 11984 5378 8695 8640 9957 10453 11538 11943 9558 7846 12099 9317 11626 7001 5975 8923 9528 6850 10896 5989 10638 10500 10645 7253 12066 11635 5414 8824 7375 7771 8206 10398 11255 10687 7478 6385 11536 9511 7360 6646 5653 7317 9011 8265 9961 5817 9556 9903 5421 10281 6812 9312 6289 5468 8832 7075 7268 9545 12173 6126 6750 7789 740..." }, { "input": "1997 508", "output": "429\n372 314 295 417 413 215 501 175 275 251 381 258 320 378 389 318 440 505 317 471 257 504 414 331 139 438 193 460 445 239 494 236 147 391 359 497 137 131 249 106 439 310 262 165 189 292 284 132 319 486 279 185 355 266 306 194 229 464 136 478 407 97 383 408 288 214 506 197 469 458 157 419 221 451 167 244 220 429 424 201 181 448 479 241 237 264 150 392 123 233 336 280 254 330 187 289 300 360 382 98 368 130 313 481 463 345 370 216 195 450 433 118 94 152 253 79 308 485 499 202 465 435 418 277 105 255 500 16..." }, { "input": "100000 30000", "output": "14127\n26613 18365 28664 17829 21130 27426 21717 24672 24071 19607 19925 18270 20786 18268 26819 18080 22887 17706 19483 19506 25016 20111 27484 24319 19265 19207 23108 18049 21756 19686 17917 20556 16214 23033 20478 16698 22390 22634 29193 15951 21420 25501 22429 26972 29281 17977 15947 20937 16929 24505 28551 18726 21728 28155 19143 24908 16146 20285 17685 26479 17361 25426 22492 20423 21741 22680 25133 24040 29191 27166 17529 24301 23308 24972 16663 25920 27616 23472 27211 27558 23076 27936 24467 26967 ..." }, { "input": "100000 100000", "output": "10735\n96613 91015 98664 98463 91130 97426 91717 94672 94071 89606 89924 93309 90786 92311 96819 90266 92887 95568 89482 89505 95016 90110 97484 94319 89677 91493 93108 99232 91756 89685 99279 90556 91261 93033 90478 89768 92390 92634 99193 99598 91420 95501 92429 96972 99281 91403 93630 90937 97183 94505 98551 93644 91728 98155 98300 94908 99721 90285 91440 96479 95030 95426 92492 90423 91741 92680 95133 94040 99191 97166 89517 94301 93308 94972 92077 95920 97616 93472 97211 97558 93076 97936 94467 96967 ..." }, { "input": "1 100000", "output": "1\n99999" }, { "input": "29985 15678", "output": "4368\n12291 12258 14342 14141 11554 13104 14602 15169 14887 15056 13657 12832 13865 13787 12497 14087 12934 14599 15487 14444 11956 12952 13162 15113 11801 12732 14195 14910 14756 13364 14957 14819 15317 12023 12028 11973 13290 13786 14871 15276 12891 15480 15432 12650 14959 14893 13483 12256 12861 14335 14229 11522 13971 13833 13978 12923 15399 14968 14781 12157 14840 12905 11539 13731 14588 14020 12343 15367 14869 12844 12431 15589 14489 13240 12344 11598 13294 13937 12889 13236 15351 13614 11665 12645 1..." }, { "input": "83451 17526", "output": "10644\n14139 8541 16190 15989 8656 14952 9243 12198 11597 7132 7450 10835 8312 9837 14345 7791 10413 13094 7008 7031 12542 7636 15010 11845 7203 9019 10634 16758 9282 7211 16805 8081 8787 10559 8003 7294 9916 10160 16719 17124 8946 13027 9955 14498 16807 8929 11156 8463 14709 12031 16077 11170 9254 15681 15826 12434 17247 7810 8966 14005 12556 12952 10018 7948 9267 10206 12659 11566 16717 14692 7043 11827 10834 12498 9603 13446 15142 10998 14737 15084 10602 15462 11993 14493 9323 10649 7358 12256 12449 930..." }, { "input": "96024 12472", "output": "-1" }, { "input": "21741 3575", "output": "-1" }, { "input": "40287 17817", "output": "4069\n14430 14397 16481 16280 14255 15243 16741 17308 17026 17195 15796 14971 16004 15926 14636 16226 15073 16738 17626 16583 14095 15091 15301 17252 13940 14871 16334 17049 16895 15503 17096 16958 17456 14162 14167 14112 15429 15925 17010 17415 15030 17619 17571 14789 17098 17032 15622 14395 15000 16474 16368 15258 16110 15972 16117 15062 17538 17107 16920 14296 16979 15044 15580 15870 16727 16159 14482 17506 17008 14983 14570 17728 16628 15379 14483 13847 15433 16076 15028 15375 17490 15753 13803 14784 1..." }, { "input": "58934 6404", "output": "-1" }, { "input": "62658 10881", "output": "8365\n7494 7461 9545 9344 6757 8307 2598 5553 4952 10259 8860 4190 2991 3192 7700 9290 3768 6449 10690 9647 5897 8155 8365 5200 3867 5775 3989 10113 2637 8567 10160 10022 10520 3914 7231 7176 3271 3515 10074 10479 8094 6382 3310 7853 10162 5537 4511 7459 8064 5386 9432 4525 2609 9036 9181 5789 10602 10171 3950 7360 5911 6307 3373 8934 2622 3561 6014 4921 10072 8047 5896 5182 4189 5853 2958 6801 8497 4353 8092 8439 3957 8817 5348 7848 2678 4004 3747 5611 5804 2657 10709 4662 5286 6325 5940 7248 2855 3912 62..." }, { "input": "89829 8298", "output": "-1" }, { "input": "5499 1023", "output": "-1" }, { "input": "5499 1024", "output": "871\n346 262 304 933 200 223 161 515 233 402 159 373 180 894 325 834 956 1021 833 366 488 1020 482 459 655 445 546 256 213 755 303 165 663 547 260 552 653 647 217 622 300 826 778 681 305 239 800 648 835 252 795 565 871 246 573 710 745 314 220 332 186 613 899 160 349 559 1022 713 215 587 673 935 737 324 683 290 736 945 240 258 697 964 995 383 753 780 212 908 639 591 852 174 770 172 703 805 540 876 898 293 508 646 468 364 979 861 886 567 711 401 949 516 610 263 769 421 824 1001 1015 579 188 951 934 483 621 4..." }, { "input": "53689 10552", "output": "6908\n7165 7132 9216 9015 6428 7978 9476 5224 4623 9930 8531 3861 4776 8661 7371 8961 4276 6120 10361 9318 5568 7826 8036 4871 6675 5446 3660 9784 9630 8238 9831 9693 10191 6897 6902 6847 8164 8660 9745 10150 7765 6053 10306 7524 9833 5208 4182 7130 7735 5057 9103 4196 8845 8707 8852 5460 10273 9842 9655 7031 5582 5978 6413 8605 9462 8894 5685 4592 9743 7718 5567 4853 3860 5524 7218 6472 8168 4024 7763 8110 4831 8488 5019 7519 4496 3675 7039 5282 5475 7752 10380 4333 4957 5996 5611 6919 3792 8542 5897 6811..." }, { "input": "247 3270", "output": "62\n3228 3223 3212 3243 3230 3241 3263 3227 3255 3265 3262 3239 3261 3235 3219 3236 3231 3267 3210 3233 3258 3266 3237 3232 3252 3218 3251 3222 3242 3216 3256 3238 3253 3247 3214 3259 3217 3211 3269 3215 3220 3246 3221 3225 3264 3244 3250 3257 3209 3248 3234 3268 3260 3229 3254 3270 3245 3226 3213 3240 3249 3224" }, { "input": "58413 1253", "output": "-1" }, { "input": "47283 15757", "output": "7089\n12370 12337 14421 14220 11633 13183 14681 10429 9828 15135 13736 9066 9981 13866 12576 14166 9481 11325 15566 14523 10773 13031 13241 10076 8743 10651 8865 14989 14835 13443 15036 14898 15396 8790 12107 12052 13369 13865 14950 15355 12970 11258 15511 12729 15038 10413 9387 12335 12940 10262 14308 9401 14050 13912 14057 10665 15478 15047 8826 12236 10787 11183 11618 13810 14667 14099 10890 9797 14948 12923 10772 10058 9065 10729 12423 11677 13373 9229 12968 13315 8833 13693 10224 12724 8670 8880 12244..." }, { "input": "93145 14496", "output": "12533\n11109 2861 13160 2325 5626 11922 6213 9168 8567 4103 4421 2766 5282 2764 11315 2576 7383 2202 3979 4002 9512 4607 11980 8815 3761 3703 7604 2545 6252 4182 2413 5052 5757 7529 4974 4265 6886 7130 13689 14094 5916 9997 6925 11468 13777 2473 8126 5433 11679 9001 13047 3222 6224 12651 3639 9404 14217 4781 2181 10975 9526 9922 6988 4919 6237 7176 9629 8536 13687 11662 2025 8797 7804 9468 6573 10416 12112 7968 11707 12054 7572 12432 8963 11463 6293 7619 4329 9226 9419 6272 14324 8277 8901 5655 1983 10863 ..." }, { "input": "66947 17657", "output": "7720\n14270 14237 16321 16120 13533 15083 16581 12329 11728 17035 15636 10966 11881 9968 14476 16066 10544 13225 17466 16423 12673 14931 15141 11976 10643 12551 10765 16889 16735 15343 16936 16798 17296 10690 14007 13952 10047 10291 16850 17255 14870 13158 10086 14629 16938 12313 11287 14235 14840 12162 16208 11301 15950 15812 15957 12565 17378 16947 10726 14136 12687 13083 10149 15710 16567 10337 12790 11697 16848 14823 12672 11958 10965 12629 14323 13577 15273 11129 14868 15215 10733 15593 12124 14624 10..." }, { "input": "49940 18445", "output": "5320\n15058 15025 17109 16908 14321 15871 17369 17936 17654 17823 16424 15599 16632 16554 15264 16854 15701 14013 18254 17211 13461 15719 15929 17880 14568 13339 13680 17677 17523 16131 17724 17586 18084 14790 14795 14740 16057 16553 17638 18043 15658 13946 18199 15417 17726 17660 16250 15023 15628 17102 16996 14289 16738 16600 16745 13353 18166 17735 17548 14924 13475 13871 14306 16498 17355 16787 13578 13628 17636 15611 13460 18356 13731 13417 15111 14365 16061 16704 15656 16003 18118 16381 14432 15412 1..." }, { "input": "61897 33128", "output": "4993\n29741 29708 31792 31591 29004 30554 32052 32619 32337 32506 31107 30282 31315 31237 29947 31537 30384 28696 32937 31894 28143 30402 30612 32563 29251 30182 28362 32360 32206 30814 32407 32269 32767 29473 29478 29423 30740 31236 32321 32726 30341 28628 32882 30100 32409 32343 30933 29706 30311 31785 31679 28972 31421 31283 31428 30373 32849 32418 32231 29607 28157 28553 28989 31181 32038 31470 28260 28310 32319 30294 28142 33039 28413 30690 29794 29048 30744 31387 30339 30686 32801 31064 29115 30095 3..." }, { "input": "97660 28794", "output": "13667\n25407 17159 27458 16623 19924 26220 20511 23466 22865 18401 18719 17064 19580 17062 25613 16874 21681 16500 18277 18300 23810 18905 26278 23113 18059 18001 21902 16843 20550 18480 16711 19350 20055 21827 19272 15491 21184 21428 27987 28392 20214 24295 21223 25766 28075 16771 22424 19731 15722 23299 27345 17520 20522 26949 17937 23702 28515 19079 16479 25273 16154 24220 21286 19217 20535 21474 23927 22834 27985 25960 16322 23095 22102 23766 15456 24714 26410 22266 26005 26352 21870 26730 23261 25761 ..." }, { "input": "99808 14000", "output": "14000\n10613 2365 12664 1829 5130 11426 5717 8672 8071 3607 3925 2270 4786 2268 10819 2080 6887 1706 3483 3506 9016 4111 11484 8319 3265 3207 7108 2049 5756 3686 1917 4556 215 7033 4478 698 6390 6634 13193 13598 5420 9501 6429 10972 13281 1977 7630 4937 929 8505 12551 2726 5728 12155 3143 8908 147 4285 1685 10479 1361 9426 6492 4423 5741 6680 9133 8040 13191 11166 1529 8301 7308 8972 663 9920 11616 7472 11211 11558 7076 11936 8467 10967 5797 7123 3833 8730 8923 5776 13828 7781 8405 5159 1487 10367 4313 321..." }, { "input": "100000 1", "output": "-1" }, { "input": "1 1", "output": "1\n1" }, { "input": "100000 14047", "output": "-1" }, { "input": "100000 14048", "output": "14043\n10661 2413 12712 1877 5178 11474 5765 8720 8119 3655 3973 2318 4834 2316 10867 2128 6935 1754 3531 3554 9064 4159 11532 8367 3313 3255 7156 2097 5804 3734 1965 4604 263 7081 4526 746 6438 6682 13241 13646 5468 9549 6477 11020 13329 2025 7678 4985 977 8553 12599 2774 5776 12203 3191 8956 195 4333 1733 10527 1409 9474 6540 4471 5789 6728 9181 8088 13239 11214 1577 8349 7356 9020 711 9968 11664 7520 11259 11606 7124 11984 8515 11015 5845 7171 3881 8778 8971 5824 13876 7829 8453 5207 1535 10415 4361 326..." }, { "input": "21741 3576", "output": "3573\n189 156 2240 2039 14 1002 2500 3067 2785 2954 1555 730 1763 1685 395 1985 832 2497 3385 2342 3040 850 1060 3011 1487 630 2093 2808 2654 1262 2855 2717 3215 3099 1631 1199 1188 1684 2769 3174 789 3378 3330 548 2857 2791 1381 154 759 2233 2127 1017 1869 1731 1876 821 3297 2866 2679 55 2738 803 1339 1629 2486 1918 241 3265 2767 742 329 3487 2387 1138 242 1400 1192 1835 787 1134 3249 1512 1563 543 2398 3332 63 1702 2231 776 3404 510 2668 469 2243 1016 1057 1566 943 667 1411 3198 699 499 3531 2227 576 157..." } ]
61
0
0
3,217
961
Lecture Sleep
[ "data structures", "dp", "implementation", "two pointers" ]
null
null
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during the *i*-th minute of the lecture then *t**i* will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β€” *a**i* during the *i*-th minute. Otherwise he writes nothing. You know some secret technique to keep Mishka awake for *k* minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and *n*<=-<=*k*<=+<=1. If you use it on some minute *i* then Mishka will be awake during minutes *j* such that and will write down all the theorems lecturer tells. You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
The first line of the input contains two integer numbers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=105) β€” the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≀<=*a**i*<=≀<=104) β€” the number of theorems lecturer tells during the *i*-th minute. The third line of the input contains *n* integer numbers *t*1,<=*t*2,<=... *t**n* (0<=≀<=*t**i*<=≀<=1) β€” type of Mishka's behavior at the *i*-th minute of the lecture.
Print only one integer β€” the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
[ "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n" ]
[ "16\n" ]
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
[ { "input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0", "output": "16" }, { "input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0", "output": "30000" }, { "input": "3 3\n10 10 10\n1 1 0", "output": "30" }, { "input": "1 1\n423\n0", "output": "423" }, { "input": "6 6\n1 3 5 2 5 4\n1 1 0 1 0 0", "output": "20" }, { "input": "5 2\n1 2 3 4 20\n0 0 0 1 0", "output": "24" }, { "input": "3 1\n1 2 3\n0 0 1", "output": "5" }, { "input": "4 2\n4 5 6 8\n1 0 1 0", "output": "18" }, { "input": "6 3\n1 3 5 2 1 15\n1 1 0 1 0 0", "output": "22" }, { "input": "5 5\n1 2 3 4 5\n1 1 1 0 1", "output": "15" }, { "input": "3 3\n3 3 3\n1 0 1", "output": "9" }, { "input": "5 5\n500 44 3 4 50\n1 0 0 0 0", "output": "601" }, { "input": "2 2\n3 2\n1 0", "output": "5" }, { "input": "7 6\n4 9 1 7 1 8 4\n0 0 0 1 0 1 0", "output": "30" }, { "input": "4 3\n6 5 9 6\n1 1 0 1", "output": "26" }, { "input": "2 1\n3 2\n0 0", "output": "3" }, { "input": "1 1\n10\n0", "output": "10" }, { "input": "2 1\n3 2\n1 0", "output": "5" }, { "input": "4 2\n3 6 7 2\n0 0 1 1", "output": "18" }, { "input": "10 5\n3 5 9 2 5 9 3 8 8 1\n0 1 1 1 0 1 0 0 0 0", "output": "49" }, { "input": "10 4\n9 5 6 4 3 9 5 1 10 7\n0 0 0 0 0 0 1 0 0 1", "output": "36" }, { "input": "9 8\n3 3 7 7 1 9 10 7 1\n1 1 1 1 1 1 1 1 1", "output": "48" }, { "input": "2 1\n3 4\n0 0", "output": "4" }, { "input": "2 1\n3 2\n0 1", "output": "5" }, { "input": "10 1\n6 6 8 7 6 6 3 2 5 6\n0 0 1 0 0 1 0 1 1 1", "output": "34" }, { "input": "3 2\n10 10 6\n0 0 0", "output": "20" }, { "input": "6 3\n1 3 5 2 5 4\n1 1 1 1 1 1", "output": "20" }, { "input": "10 5\n1 1 1 1 1 1 1 1 10000 1\n1 1 1 1 1 1 1 1 0 1", "output": "10009" } ]
249
12,288,000
3
3,219
95
Lucky Numbers
[ "dp", "greedy" ]
B. Lucky Numbers
2
256
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*.
The only line contains a positive integer *n* (1<=≀<=*n*<=≀<=10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to *n*.
[ "4500\n", "47\n" ]
[ "4747\n", "47\n" ]
none
[ { "input": "4500", "output": "4747" }, { "input": "47", "output": "47" }, { "input": "1", "output": "47" }, { "input": "12", "output": "47" }, { "input": "4587", "output": "4747" }, { "input": "100", "output": "4477" }, { "input": "1007", "output": "4477" }, { "input": "99999999", "output": "4444477777" }, { "input": "49102094540227023300", "output": "74444444444777777777" }, { "input": "1000000000", "output": "4444477777" }, { "input": "777777", "output": "44447777" }, { "input": "99999999", "output": "4444477777" }, { "input": "474", "output": "4477" }, { "input": "85469", "output": "444777" }, { "input": "7474747", "output": "44447777" }, { "input": "2145226", "output": "44447777" }, { "input": "5556585", "output": "44447777" }, { "input": "87584777", "output": "4444477777" }, { "input": "77777777", "output": "4444477777" }, { "input": "1000000000", "output": "4444477777" }, { "input": "999999999", "output": "4444477777" }, { "input": "74477744", "output": "74477744" }, { "input": "444444444", "output": "4444477777" }, { "input": "467549754", "output": "4444477777" }, { "input": "147474747", "output": "4444477777" }, { "input": "555", "output": "4477" }, { "input": "100000", "output": "444777" }, { "input": "74777443", "output": "74777444" }, { "input": "4700007", "output": "44447777" }, { "input": "70070077", "output": "74444777" }, { "input": "123", "output": "4477" }, { "input": "7474", "output": "7474" }, { "input": "3696", "output": "4477" }, { "input": "5594108733309806863211189515406929423407691887690557101598403485", "output": "7444444444444444444444444444444447777777777777777777777777777777" }, { "input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777" }, { "input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777" }, { "input": "300315701225398103949172355218103087569515283105400017868730132769291700939035921405014640214190659140126383204458315111136164707153628616177467538307534664174018683245377348638677858006052356516328838399769950207054982712314494543889750490268253870160095357456864075250350735474301206523459172092665900965024129501630212966373988276932458849720393142004789869863743947961634907491797090041095838600303393556660079821519800685499052949978754418782241756597476926001413610822", "output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444" }, { "input": "474777447477447774447777477444444747747747447474", "output": "474777447477447774447777477444444747747747447474" }, { "input": "4610011341130234325130111223432762111322200032405402224411031600004377332320125004161111207316702630337013246237324411010232123224431343463152610127222227432331505230001434422203415026064601462701340036346273331432110074431135223142761441433403414301432300263254301342131314327333745711213130421310313153504022700431534463141461236322033420140324202221402036761452134031253152442133141307046425107520", "output": "4744444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "35881905331681060827588553219538774024143083787975", "output": "44444444444444444444444447777777777777777777777777" }, { "input": "221020945402270233", "output": "444444444777777777" }, { "input": "241925018843248944336317949908388280315030601139576419352009710", "output": "4444444444444444444444444444444477777777777777777777777777777777" }, { "input": "888999577", "output": "4444477777" }, { "input": "10", "output": "47" }, { "input": "7", "output": "47" }, { "input": "50", "output": "74" }, { "input": "70", "output": "74" }, { "input": "74700", "output": "444777" }, { "input": "1024", "output": "4477" }, { "input": "73", "output": "74" }, { "input": "74710000", "output": "74744477" }, { "input": "444000000", "output": "4444477777" }, { "input": "4", "output": "47" }, { "input": "1", "output": "47" }, { "input": "9", "output": "47" }, { "input": "99", "output": "4477" }, { "input": "48", "output": "74" }, { "input": "4747474749", "output": "4747474774" }, { "input": "4747474774", "output": "4747474774" }, { "input": "77777777", "output": "4444477777" }, { "input": "4777", "output": "7447" }, { "input": "7748", "output": "444777" }, { "input": "7773", "output": "444777" }, { "input": "19", "output": "47" }, { "input": "447777", "output": "474477" } ]
404
2,048,000
-1
3,222
374
Inna and Pink Pony
[ "greedy", "implementation" ]
null
null
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an *n*<=Γ—<=*m* chessboard, a very tasty candy and two numbers *a* and *b*. Dima put the chessboard in front of Inna and placed the candy in position (*i*,<=*j*) on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types: - move the candy from position (*x*,<=*y*) on the board to position (*x*<=-<=*a*,<=*y*<=-<=*b*); - move the candy from position (*x*,<=*y*) on the board to position (*x*<=+<=*a*,<=*y*<=-<=*b*); - move the candy from position (*x*,<=*y*) on the board to position (*x*<=-<=*a*,<=*y*<=+<=*b*); - move the candy from position (*x*,<=*y*) on the board to position (*x*<=+<=*a*,<=*y*<=+<=*b*). Naturally, Dima doesn't allow to move the candy beyond the chessboard borders. Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position (*i*,<=*j*) to one of the chessboard corners. Help them cope with the task!
The first line of the input contains six integers *n*,<=*m*,<=*i*,<=*j*,<=*a*,<=*b* (1<=≀<=*n*,<=*m*<=≀<=106;Β 1<=≀<=*i*<=≀<=*n*;Β 1<=≀<=*j*<=≀<=*m*;Β 1<=≀<=*a*,<=*b*<=≀<=106). You can assume that the chessboard rows are numbered from 1 to *n* from top to bottom and the columns are numbered from 1 to *m* from left to right. Position (*i*,<=*j*) in the statement is a chessboard cell on the intersection of the *i*-th row and the *j*-th column. You can consider that the corners are: (1,<=*m*), (*n*,<=1), (*n*,<=*m*), (1,<=1).
In a single line print a single integer β€” the minimum number of moves needed to get the candy. If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes.
[ "5 7 1 3 2 2\n", "5 5 2 3 1 1\n" ]
[ "2\n", "Poor Inna and pony!\n" ]
Note to sample 1: Inna and the pony can move the candy to position (1 + 2, 3 + 2) = (3, 5), from there they can move it to positions (3 - 2, 5 + 2) = (1, 7) and (3 + 2, 5 + 2) = (5, 7). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two.
[ { "input": "5 7 1 3 2 2", "output": "2" }, { "input": "5 5 2 3 1 1", "output": "Poor Inna and pony!" }, { "input": "1 1 1 1 1 1", "output": "0" }, { "input": "23000 15500 100 333 9 1", "output": "15167" }, { "input": "33999 99333 33000 99000 3 9", "output": "333" }, { "input": "5 7 1 3 1 2", "output": "2" }, { "input": "1 100 1 50 1 50", "output": "Poor Inna and pony!" }, { "input": "1000 1 1 1 1 500", "output": "0" }, { "input": "304 400 12 20 4 4", "output": "95" }, { "input": "1000000 1000000 1000000 1000000 1000000 1000000", "output": "0" }, { "input": "1000000 99999 12345 23456 23 54", "output": "Poor Inna and pony!" }, { "input": "50000 100000 500 1000 500 1000", "output": "99" }, { "input": "50000 100000 500 1000 500 2000", "output": "Poor Inna and pony!" }, { "input": "50000 100000 500 1000 500 500", "output": "Poor Inna and pony!" }, { "input": "99999 99999 1 2 1 1", "output": "Poor Inna and pony!" }, { "input": "5 4 2 3 2 2", "output": "Poor Inna and pony!" }, { "input": "5 4 2 3 1 1", "output": "1" }, { "input": "5 5 1 3 1 2", "output": "Poor Inna and pony!" }, { "input": "2347 2348 234 48 238 198", "output": "Poor Inna and pony!" }, { "input": "1000000 2 2 2 2 1", "output": "499999" }, { "input": "100 100 50 50 500 500", "output": "Poor Inna and pony!" }, { "input": "1000 2000 100 200 90 90", "output": "20" }, { "input": "1000 1000 10 15 10 5", "output": "197" }, { "input": "23000 15500 100 333 9 1", "output": "15167" }, { "input": "5 5 4 3 1 2", "output": "1" }, { "input": "5 5 4 4 1 1", "output": "1" }, { "input": "5 5 4 2 1 1", "output": "1" }, { "input": "3 3 2 2 2 2", "output": "Poor Inna and pony!" }, { "input": "5 8 4 1 2 1", "output": "Poor Inna and pony!" }, { "input": "5 8 4 2 1 2", "output": "3" }, { "input": "2 8 1 2 1 3", "output": "2" }, { "input": "1000000 1000000 500000 500000 1 1", "output": "499999" }, { "input": "500000 100000 400 80000 2 2", "output": "249800" }, { "input": "1004 999004 4 4 5 5", "output": "199800" }, { "input": "11 11 3 3 4 4", "output": "2" }, { "input": "100 100 70 5 1 1", "output": "30" }, { "input": "1 5 1 3 1 1", "output": "Poor Inna and pony!" }, { "input": "1 5 1 3 10 1", "output": "Poor Inna and pony!" }, { "input": "6 1 5 1 2 2", "output": "Poor Inna and pony!" }, { "input": "2 10 1 5 2 2", "output": "Poor Inna and pony!" }, { "input": "5 1 3 1 1 1", "output": "Poor Inna and pony!" }, { "input": "1000 1000 1 3 10000 1", "output": "Poor Inna and pony!" }, { "input": "2 6 1 2 2 2", "output": "Poor Inna and pony!" }, { "input": "2 6 1 2 6 2", "output": "Poor Inna and pony!" }, { "input": "7 1 5 1 2 2", "output": "Poor Inna and pony!" }, { "input": "2 20 2 5 2 2", "output": "Poor Inna and pony!" }, { "input": "4 4 3 4 1 5", "output": "Poor Inna and pony!" } ]
77
2,048,000
-1
3,225
690
Photographs (II)
[]
null
null
Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now the questions being asked are more complicated, and even humans have trouble answering them. Can you still program the robot army to do this reliably? The new questions are of the following form: a grayscale photograph has been divided into several horizontal pieces, which have been arbitrarily rearranged. The task is to assemble the original image back from these pieces (somewhat like in a jigsaw puzzle). To further delay the zombies, significant Gaussian-distributed noise has been added to the image.
The input format is the same as in the previous version, except that the first line of every question now contains three space-separated numbers *h*, *w* and *k* (1<=≀<=*h*,<=*w*<=≀<=600, 2<=≀<=*k*<=≀<=16) – the height (number of rows) and width (number of columns) of the photograph and the number of pieces, respectively. The number of pieces evenly divides the height, and each piece is of the same height *h*<=/<=*k*. Again, there is only one input file to be processed, and the same resources are provided to you as in the previous version (except that now you are given all input images in .bmp format, rather than the first 50).
Your program should print *q* lines. The *i*-th line should contain your answer for the *i*-th question: a space-separated sequence of *k* numbers Ο€1,<=Ο€2,<=...,<=Ο€*k* such that: - Ο€ is a permutation of {1,<=2,<=...,<=*k*}, that is, each number from 1 to *k* appears exactly once in Ο€, - for each *j*<==<=1,<=...,<=*k*, Ο€*j* is the position (index), in the original image, of the piece which is at position *j* in the input image. (See the illustration below for clarity.) The second image from the test set. If the three pieces in the original image are numbered 1, 2, 3 from top to bottom, then the numbering in the image on the right should be 2, 3, 1. The correct answer for this image is thus 2 3 1. Again, your answers will be accepted if they conform to this format and if at least 75% of them are correct. Again, you may process the input locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
[]
[]
The link to download all the necessary materials is http://assets.codeforces.com/files/690/medium_contestant_package.zip
[]
46
0
3
3,227
426
Sereja and Mirroring
[ "implementation" ]
null
null
Let's assume that we are given a matrix *b* of size *x*<=Γ—<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=Γ—<=*y* matrix *c* which has the following properties: - the upper half of matrix *c* (rows with numbers from 1 to *x*) exactly matches *b*; - the lower half of matrix *c* (rows with numbers from *x*<=+<=1 to 2*x*) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows *x* and *x*<=+<=1). Sereja has an *n*<=Γ—<=*m* matrix *a*. He wants to find such matrix *b*, that it can be transformed into matrix *a*, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain?
The first line contains two integers, *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Each of the next *n* lines contains *m* integers β€” the elements of matrix *a*. The *i*-th line contains integers *a**i*1,<=*a**i*2,<=...,<=*a**im* (0<=≀<=*a**ij*<=≀<=1) β€” the *i*-th row of the matrix *a*.
In the single line, print the answer to the problem β€” the minimum number of rows of matrix *b*.
[ "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1\n", "3 3\n0 0 0\n0 0 0\n0 0 0\n", "8 1\n0\n1\n1\n0\n0\n1\n1\n0\n" ]
[ "2\n", "3\n", "2\n" ]
In the first test sample the answer is a 2 × 3 matrix *b*: If we perform a mirroring operation with this matrix, we get the matrix *a* that is given in the input:
[ { "input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3" }, { "input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2" }, { "input": "10 4\n0 0 1 0\n0 0 1 0\n1 1 0 1\n0 0 1 1\n1 0 1 0\n1 0 1 0\n0 0 1 1\n1 1 0 1\n0 0 1 0\n0 0 1 0", "output": "5" }, { "input": "10 3\n0 0 0\n1 1 1\n1 1 0\n0 0 0\n0 1 1\n0 1 1\n0 0 0\n1 1 0\n1 1 1\n0 0 0", "output": "5" }, { "input": "8 4\n1 0 0 0\n1 1 0 0\n1 0 0 1\n1 1 1 1\n0 0 1 1\n0 1 0 1\n0 1 1 1\n1 0 0 0", "output": "8" }, { "input": "2 9\n1 0 0 1 1 1 0 1 0\n1 0 0 1 0 0 0 1 1", "output": "2" }, { "input": "10 3\n0 1 0\n1 1 1\n1 0 1\n0 0 1\n1 0 1\n1 0 0\n1 1 0\n1 1 1\n1 0 1\n0 0 1", "output": "10" }, { "input": "8 4\n1 1 0 1\n0 0 0 0\n0 0 0 0\n1 1 0 1\n1 1 0 1\n0 0 0 0\n0 0 0 0\n1 1 0 1", "output": "2" }, { "input": "8 7\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0\n1 1 0 0 1 1 0", "output": "1" }, { "input": "6 5\n0 0 1 0 1\n1 0 0 1 0\n1 1 1 0 0\n1 0 1 1 0\n0 0 0 0 0\n1 0 1 0 0", "output": "6" }, { "input": "1 69\n0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 1 0 0 0 1 1 1 1 1 1 1 1 0 1 0", "output": "1" }, { "input": "8 20\n0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0\n1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1\n1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1\n0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0\n0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0\n1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1\n1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1\n0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0", "output": "2" }, { "input": "1 1\n0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 2\n1 0\n0 1", "output": "2" }, { "input": "2 2\n0 1\n0 1", "output": "1" }, { "input": "1 2\n0 1", "output": "1" }, { "input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "1 100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "1" }, { "input": "1 100\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "100 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "25" }, { "input": "100 1\n1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1", "output": "50" }, { "input": "100 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0", "output": "100" }, { "input": "8 1\n1\n0\n0\n1\n1\n0\n1\n1", "output": "8" }, { "input": "6 1\n0\n0\n0\n0\n0\n0", "output": "3" }, { "input": "10 2\n1 1\n0 0\n0 0\n1 1\n0 0\n0 0\n1 1\n0 0\n0 0\n1 1", "output": "5" }, { "input": "4 2\n1 1\n0 0\n0 0\n0 0", "output": "4" }, { "input": "6 3\n1 1 1\n0 0 0\n1 1 1\n1 1 1\n0 0 0\n1 1 1", "output": "3" }, { "input": "6 3\n1 1 1\n1 0 1\n1 1 1\n1 1 1\n1 0 1\n1 1 1", "output": "3" }, { "input": "6 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "3" }, { "input": "4 3\n1 0 1\n0 1 0\n1 0 1\n1 0 1", "output": "4" }, { "input": "6 1\n1\n1\n1\n1\n1\n1", "output": "3" }, { "input": "10 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "5" }, { "input": "3 1\n1\n1\n1", "output": "3" }, { "input": "6 3\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0", "output": "3" }, { "input": "6 1\n1\n0\n1\n1\n0\n1", "output": "3" }, { "input": "6 6\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0", "output": "3" }, { "input": "3 1\n1\n0\n1", "output": "3" }, { "input": "12 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "3" }, { "input": "12 1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0", "output": "3" }, { "input": "2 3\n0 0 0\n0 0 0", "output": "1" }, { "input": "3 3\n1 1 1\n1 1 1\n0 0 0", "output": "3" }, { "input": "10 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "5" }, { "input": "12 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "3" }, { "input": "6 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "3" }, { "input": "6 3\n1 1 0\n0 0 0\n1 1 0\n1 1 0\n0 0 0\n1 1 0", "output": "3" }, { "input": "6 2\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1", "output": "3" }, { "input": "12 1\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n1", "output": "3" }, { "input": "6 2\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0", "output": "3" } ]
62
5,222,400
0
3,230
792
New Bus Route
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates β€” integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money β€” he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.
The first line contains one integer number *n* (2<=≀<=*n*<=≀<=2Β·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≀<=*a**i*<=≀<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers β€” the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -979619603", "output": "1 4" }, { "input": "5\n-799147771 -799147773 -799147764 -799147774 -799147770", "output": "1 2" }, { "input": "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 553280636 553280635 553280632 553280634 553280622 553280633 553280621 553280630 553280619", "output": "1 19" }, { "input": "20\n105619866 106083760 106090730 105809555 106115212 105155938 105979518 106075627 106145216 105637844 105925719 105498536 105927000 106155938 106134226 106125969 106130588 105464813 106145509 106114971", "output": "241 1" }, { "input": "10\n570685866 570685854 570685858 570685850 570685856 570685864 570685860 570685852 570685862 570685868", "output": "2 9" }, { "input": "2\n1 1000000000", "output": "999999999 1" }, { "input": "6\n1 2 3 4 5 6", "output": "1 5" }, { "input": "3\n7 10 12", "output": "2 1" }, { "input": "5\n-7 -5 -4 -3 -1", "output": "1 2" }, { "input": "4\n-6 -4 -2 1", "output": "2 2" }, { "input": "4\n3 5 7 8", "output": "1 1" }, { "input": "9\n-9 -8 -7 -6 -5 -4 -3 -2 -1", "output": "1 8" }, { "input": "2\n15 13", "output": "2 1" }, { "input": "2\n14 13", "output": "1 1" }, { "input": "2\n12 13", "output": "1 1" }, { "input": "2\n-1000000000 13265920", "output": "1013265920 1" }, { "input": "2\n8 10", "output": "2 1" } ]
1,000
12,902,400
0
3,235
53
Physical Education
[ "sortings" ]
D. Physical Education
2
256
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the height of the *i*-th student in the line and *n* is the number of students in the line. The children find it hard to keep in mind this strange arrangement, and today they formed the line in the following order: *b*1,<=*b*2,<=...,<=*b**n*, which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: *a*1,<=*a*2,<=...,<=*a**n*. During each move Vasya can swap two people who stand next to each other in the line. Help Vasya, find the sequence of swaps leading to the arrangement Vasya needs. It is not required to minimize the number of moves.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=300) which is the number of students. The second line contains *n* space-separated integers *a**i* (1<=≀<=*a**i*<=≀<=109) which represent the height of the student occupying the *i*-th place must possess. The third line contains *n* space-separated integers *b**i* (1<=≀<=*b**i*<=≀<=109) which represent the height of the student occupying the *i*-th place in the initial arrangement. It is possible that some students possess similar heights. It is guaranteed that it is possible to arrange the children in the required order, i.e. *a* and *b* coincide as multisets.
In the first line print an integer *k* (0<=≀<=*k*<=≀<=106) which is the number of moves. It is not required to minimize *k* but it must not exceed 106. Then print *k* lines each containing two space-separated integers. Line *p**i*, *p**i*<=+<=1 (1<=≀<=*p**i*<=≀<=*n*<=-<=1) means that Vasya should swap students occupying places *p**i* and *p**i*<=+<=1.
[ "4\n1 2 3 2\n3 2 1 2\n", "2\n1 100500\n1 100500\n" ]
[ "4\n2 3\n1 2\n3 4\n2 3\n", "0\n" ]
none
[ { "input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3" }, { "input": "2\n1 100500\n1 100500", "output": "0" }, { "input": "3\n652586118 652586118 652586118\n652586118 652586118 652586118", "output": "3\n2 3\n1 2\n2 3" }, { "input": "4\n681106577 681106577 675077178 675077178\n675077178 681106577 681106577 675077178", "output": "4\n2 3\n1 2\n2 3\n3 4" }, { "input": "5\n470138369 747764103 729004864 491957578 874531368\n874531368 729004864 491957578 747764103 470138369", "output": "9\n4 5\n3 4\n2 3\n1 2\n4 5\n3 4\n2 3\n3 4\n4 5" }, { "input": "6\n590202194 293471749 259345095 293471749 18056518 293471749\n293471749 293471749 293471749 18056518 259345095 590202194", "output": "12\n5 6\n4 5\n3 4\n2 3\n1 2\n3 4\n2 3\n5 6\n4 5\n3 4\n4 5\n5 6" }, { "input": "1\n873725529\n873725529", "output": "0" }, { "input": "1\n800950546\n800950546", "output": "0" }, { "input": "2\n344379439 344379439\n344379439 344379439", "output": "1\n1 2" }, { "input": "2\n305292852 305292852\n305292852 305292852", "output": "1\n1 2" } ]
124
512,000
3.968046
3,249
276
Lunch Rush
[ "implementation" ]
null
null
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
The first line contains two space-separated integers β€” *n* (1<=≀<=*n*<=≀<=104) and *k* (1<=≀<=*k*<=≀<=109) β€” the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers β€” *f**i* (1<=≀<=*f**i*<=≀<=109) and *t**i* (1<=≀<=*t**i*<=≀<=109) β€” the characteristics of the *i*-th restaurant.
In a single line print a single integer β€” the maximum joy value that the Rabbits will get from the lunch.
[ "2 5\n3 3\n4 5\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "1 5\n1 7\n" ]
[ "4\n", "3\n", "-1\n" ]
none
[ { "input": "2 5\n3 3\n4 5", "output": "4" }, { "input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3" }, { "input": "1 5\n1 7", "output": "-1" }, { "input": "4 9\n10 13\n4 18\n13 3\n10 6", "output": "13" }, { "input": "1 1\n1 1000000000", "output": "-999999998" }, { "input": "1 1\n1000000000 1000000000", "output": "1" }, { "input": "1 1\n1000000000 1", "output": "1000000000" }, { "input": "2 3\n1000000000 1\n2 2", "output": "1000000000" }, { "input": "2 5\n1 7\n1 1000000000", "output": "-1" } ]
186
0
3
3,251
289
Polo the Penguin and Matrix
[ "brute force", "dp", "implementation", "sortings", "ternary search" ]
null
null
Little penguin Polo has an *n*<=Γ—<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
The first line contains three integers *n*, *m* and *d* (1<=≀<=*n*,<=*m*<=≀<=100,<=1<=≀<=*d*<=≀<=104) β€” the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≀<=*a**ij*<=≀<=104).
In a single line print a single integer β€” the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
[ "2 2 2\n2 4\n6 8\n", "1 2 7\n6 7\n" ]
[ "4\n", "-1\n" ]
none
[ { "input": "2 2 2\n2 4\n6 8", "output": "4" }, { "input": "1 2 7\n6 7", "output": "-1" }, { "input": "3 2 1\n5 7\n1 2\n5 100", "output": "104" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 2", "output": "12" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 3", "output": "-1" }, { "input": "2 2 4\n5 5\n5 5", "output": "0" }, { "input": "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7", "output": "9" }, { "input": "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91", "output": "0" }, { "input": "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47", "output": "-1" }, { "input": "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366", "output": "1508" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "1 1 8\n12", "output": "0" } ]
404
2,150,400
-1
3,258
909
Segments
[ "constructive algorithms", "math" ]
null
null
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given *N*.
The only input line contains a single integer *N* (1<=≀<=*N*<=≀<=100).
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
[ "2\n", "3\n", "4\n" ]
[ "2\n", "4\n", "6\n" ]
As an example, here are the segments and their optimal arrangement into layers for *N* = 4.
[ { "input": "2", "output": "2" }, { "input": "3", "output": "4" }, { "input": "4", "output": "6" }, { "input": "21", "output": "121" }, { "input": "100", "output": "2550" }, { "input": "1", "output": "1" }, { "input": "5", "output": "9" }, { "input": "6", "output": "12" }, { "input": "7", "output": "16" }, { "input": "8", "output": "20" }, { "input": "9", "output": "25" }, { "input": "10", "output": "30" }, { "input": "11", "output": "36" }, { "input": "12", "output": "42" }, { "input": "13", "output": "49" }, { "input": "14", "output": "56" }, { "input": "15", "output": "64" }, { "input": "16", "output": "72" }, { "input": "17", "output": "81" }, { "input": "18", "output": "90" }, { "input": "19", "output": "100" }, { "input": "20", "output": "110" }, { "input": "22", "output": "132" }, { "input": "23", "output": "144" }, { "input": "24", "output": "156" }, { "input": "25", "output": "169" }, { "input": "26", "output": "182" }, { "input": "27", "output": "196" }, { "input": "28", "output": "210" }, { "input": "29", "output": "225" }, { "input": "30", "output": "240" }, { "input": "31", "output": "256" }, { "input": "32", "output": "272" }, { "input": "33", "output": "289" }, { "input": "34", "output": "306" }, { "input": "35", "output": "324" }, { "input": "36", "output": "342" }, { "input": "37", "output": "361" }, { "input": "38", "output": "380" }, { "input": "39", "output": "400" }, { "input": "40", "output": "420" }, { "input": "41", "output": "441" }, { "input": "42", "output": "462" }, { "input": "43", "output": "484" }, { "input": "44", "output": "506" }, { "input": "45", "output": "529" }, { "input": "46", "output": "552" }, { "input": "47", "output": "576" }, { "input": "48", "output": "600" }, { "input": "49", "output": "625" }, { "input": "50", "output": "650" }, { "input": "51", "output": "676" }, { "input": "52", "output": "702" }, { "input": "53", "output": "729" }, { "input": "54", "output": "756" }, { "input": "55", "output": "784" }, { "input": "56", "output": "812" }, { "input": "57", "output": "841" }, { "input": "58", "output": "870" }, { "input": "59", "output": "900" }, { "input": "60", "output": "930" }, { "input": "61", "output": "961" }, { "input": "62", "output": "992" }, { "input": "63", "output": "1024" }, { "input": "64", "output": "1056" }, { "input": "65", "output": "1089" }, { "input": "66", "output": "1122" }, { "input": "67", "output": "1156" }, { "input": "68", "output": "1190" }, { "input": "69", "output": "1225" }, { "input": "70", "output": "1260" }, { "input": "71", "output": "1296" }, { "input": "72", "output": "1332" }, { "input": "73", "output": "1369" }, { "input": "74", "output": "1406" }, { "input": "75", "output": "1444" }, { "input": "76", "output": "1482" }, { "input": "77", "output": "1521" }, { "input": "78", "output": "1560" }, { "input": "79", "output": "1600" }, { "input": "80", "output": "1640" }, { "input": "81", "output": "1681" }, { "input": "82", "output": "1722" }, { "input": "83", "output": "1764" }, { "input": "84", "output": "1806" }, { "input": "85", "output": "1849" }, { "input": "86", "output": "1892" }, { "input": "87", "output": "1936" }, { "input": "88", "output": "1980" }, { "input": "89", "output": "2025" }, { "input": "90", "output": "2070" }, { "input": "91", "output": "2116" }, { "input": "92", "output": "2162" }, { "input": "93", "output": "2209" }, { "input": "94", "output": "2256" }, { "input": "95", "output": "2304" }, { "input": "96", "output": "2352" }, { "input": "97", "output": "2401" }, { "input": "98", "output": "2450" }, { "input": "99", "output": "2500" }, { "input": "1", "output": "1" }, { "input": "5", "output": "9" } ]
93
1,433,600
3
3,263
53
Little Frog
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
The single line contains a number *n* (1<=≀<=*n*<=≀<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≀<=*p**i*<=≀<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≀<=*i*<=≀<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "input": "9149", "output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..." }, { "input": "2877", "output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..." }, { "input": "2956", "output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..." }, { "input": "3035", "output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..." }, { "input": "3114", "output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..." }, { "input": "3193", "output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..." }, { "input": "3273", "output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..." }, { "input": "7000", "output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..." }, { "input": "7079", "output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..." }, { "input": "4653", "output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..." }, { "input": "9995", "output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..." }, { "input": "9996", "output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..." }, { "input": "9997", "output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..." }, { "input": "9998", "output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..." }, { "input": "9999", "output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..." }, { "input": "10000", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..." } ]
92
0
3.977
3,272
794
Cutting Carrot
[ "geometry", "math" ]
null
null
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area?
The first and only line of input contains two space-separated integers, *n* and *h* (2<=≀<=*n*<=≀<=1000, 1<=≀<=*h*<=≀<=105).
The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "3 2\n", "2 100000\n" ]
[ "1.154700538379 1.632993161855\n", "70710.678118654752\n" ]
Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
[ { "input": "3 2", "output": "1.154700538379 1.632993161855" }, { "input": "2 100000", "output": "70710.678118654752" }, { "input": "1000 100000", "output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8944.271909999159 9486.832980505138 10000.000000000000 10488.088481701515 10954.451150103322 11401.754250991380 11832.159566199232 12247.448713915890 12649.110640673517 13038.404810405297 13416.407864998738 13784.048752090222 14142.135623730950 14491.376746189439 14832.396974191326 15165.750888103101 15491.933384829668 15811.388300841897 16124.515496597099 16431.676725154983 16733.2..." }, { "input": "2 1", "output": "0.707106781187" }, { "input": "1000 1", "output": "0.031622776602 0.044721359550 0.054772255751 0.063245553203 0.070710678119 0.077459666924 0.083666002653 0.089442719100 0.094868329805 0.100000000000 0.104880884817 0.109544511501 0.114017542510 0.118321595662 0.122474487139 0.126491106407 0.130384048104 0.134164078650 0.137840487521 0.141421356237 0.144913767462 0.148323969742 0.151657508881 0.154919333848 0.158113883008 0.161245154966 0.164316767252 0.167332005307 0.170293863659 0.173205080757 0.176068168617 0.178885438200 0.181659021246 0.184390889146 0..." }, { "input": "20 17", "output": "3.801315561750 5.375872022286 6.584071688553 7.602631123499 8.500000000000 9.311283477588 10.057335631269 10.751744044572 11.403946685249 12.020815280171 12.607537428063 13.168143377105 13.705838172108 14.223220451079 14.722431864335 15.205262246999 15.673225577398 16.127616066859 16.569550386175" }, { "input": "999 1", "output": "0.031638599858 0.044743737014 0.054799662435 0.063277199717 0.070746059996 0.077498425829 0.083707867056 0.089487474029 0.094915799575 0.100050037531 0.104933364623 0.109599324870 0.114074594073 0.118380800867 0.122535770349 0.126554399434 0.130449289063 0.134231211043 0.137909459498 0.141492119993 0.144986278734 0.148398187395 0.151733394554 0.154996851658 0.158192999292 0.161325838061 0.164398987305 0.167415734111 0.170379074505 0.173291748303 0.176156268782 0.178974948057 0.181749918935 0.184483153795 0..." }, { "input": "998 99999", "output": "3165.413034717700 4476.570044210349 5482.656203071844 6330.826069435401 7078.078722492680 7753.646760213179 8374.895686665300 8953.140088420697 9496.239104153101 10009.914924893578 10498.487342658843 10965.312406143687 11413.059004696742 11843.891063542002 12259.591967329534 12661.652138870802 13051.332290848021 13429.710132631046 13797.715532900862 14156.157444985360 14505.744837393740 14847.103184390411 15180.787616204127 15507.293520426358 15827.065173588502 16140.502832606510 16447.968609215531 16749.7..." }, { "input": "574 29184", "output": "1218.116624752432 1722.677051277028 2109.839883615525 2436.233249504864 2723.791577469041 2983.764177844748 3222.833656968322 3445.354102554056 3654.349874257297 3852.022989934325 4040.035795197963 4219.679767231051 4391.981950040022 4557.775066957079 4717.745401404559 4872.466499009729 5022.423508175150 5168.031153831084 5309.647268742708 5447.583154938083 5582.111638212139 5713.473414041731 5841.882108059006 5967.528355689497 6090.583123762161 6211.200439444432 6329.519650846576 6445.667313936643 6559.75..." }, { "input": "2 5713", "output": "4039.701040918746" }, { "input": "937 23565", "output": "769.834993893392 1088.711089153444 1333.393322867831 1539.669987786784 1721.403377803760 1885.702921177414 2036.791944396843 2177.422178306887 2309.504981680176 2434.432003204934 2553.253825229922 2666.786645735663 2775.679544129132 2880.458791498282 2981.558110676796 3079.339975573568 3174.110994119182 3266.133267460331 3355.632941582547 3442.806755607520 3527.827132142336 3610.846187821139 3691.998931463184 3771.405842354828 3849.174969466960 3925.403656108988 4000.179968603494 4073.583888793686 4145.688..." }, { "input": "693 39706", "output": "1508.306216302128 2133.067107306117 2612.463000007259 3016.612432604256 3372.675230537060 3694.580605808168 3990.603149268227 4266.134214612233 4524.918648906384 4769.683052505315 5002.485788434792 5224.926000014517 5438.275401978402 5643.565095743912 5841.644856719264 6033.224865208513 6218.905845589392 6399.201321918350 6574.554372775177 6745.350461074120 6911.927407376938 7074.583247583148 7233.582498950279 7389.161211616337 7541.531081510641 7690.882829397851 7837.389000021776 7981.206298536455 8122.47..." }, { "input": "449 88550", "output": "4178.932872810542 5909.903544975429 7238.124057127628 8357.865745621084 9344.377977012855 10236.253207728862 11056.417127089408 11819.807089950858 12536.798618431626 13214.946067032045 13859.952363194553 14476.248114255256 15067.356749640443 15636.135052384012 16184.937421313947 16715.731491242168 17230.181636963718 17729.710634926286 18215.546084421264 18688.755954025709 19150.276213793575 19600.932605874766 20041.458005232581 20472.506415457724 20894.664364052710 21308.460264455309 21714.372171382883 221..." }, { "input": "642 37394", "output": "1475.823459881026 2087.129552632132 2556.201215516026 2951.646919762052 3300.041579082908 3615.014427137354 3904.661853880105 4174.259105264265 4427.470379643078 4666.963557534173 4894.752673229489 5112.402431032051 5321.157158133711 5522.025750238117 5715.839682061424 5903.293839524104 6084.976009853978 6261.388657896397 6432.965320127946 6600.083158165816 6763.072717296425 6922.225614943105 7077.800671741869 7230.028854274709 7379.117299405130 7525.252620551370 7668.603646548077 7809.323707760210 7947.55..." }, { "input": "961 53535", "output": "1726.935483870968 2442.255582633666 2991.139999458060 3453.870967741935 3861.545134691976 4230.110754190240 4569.041820575576 4884.511165267332 5180.806451612903 5461.049501197232 5727.597037150849 5982.279998916119 6226.554436514989 6461.600909707837 6688.392369006905 6907.741935483871 7120.337408627144 7326.766747900998 7527.537256208063 7723.090269383951 7913.812575143900 8100.045409746687 8282.091632275692 8460.221508380480 8634.677419354839 8805.677730973862 8973.419998374179 9138.083641151152 9299.83..." }, { "input": "4 31901", "output": "15950.500000000000 22557.413426632053 27627.076406127377" }, { "input": "4 23850", "output": "11925.000000000000 16864.496731299158 20654.705880258862" }, { "input": "4 72694", "output": "36347.000000000000 51402.420351574886 62954.850702705983" }, { "input": "4 21538", "output": "10769.000000000000 15229.665853195861 18652.455146709240" }, { "input": "4 70383", "output": "35191.500000000000 49768.296580252774 60953.465994560145" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "20 1", "output": "0.223606797750 0.316227766017 0.387298334621 0.447213595500 0.500000000000 0.547722557505 0.591607978310 0.632455532034 0.670820393250 0.707106781187 0.741619848710 0.774596669241 0.806225774830 0.836660026534 0.866025403784 0.894427191000 0.921954445729 0.948683298051 0.974679434481" }, { "input": "775 1", "output": "0.035921060405 0.050800050800 0.062217101684 0.071842120811 0.080321932890 0.087988269013 0.095038192662 0.101600101600 0.107763181216 0.113592366849 0.119136679436 0.124434203368 0.129515225161 0.134404301006 0.139121668728 0.143684241621 0.148106326235 0.152400152400 0.156576272252 0.160643865780 0.164610978351 0.168484707835 0.172271353843 0.175976538026 0.179605302027 0.183162187956 0.186651305051 0.190076385325 0.193440830330 0.196747750735 0.200000000000 0.203200203200 0.206350781829 0.209453975235 0..." }, { "input": "531 1", "output": "0.043396303660 0.061371641193 0.075164602800 0.086792607321 0.097037084957 0.106298800691 0.114815827305 0.122743282386 0.130188910981 0.137231161599 0.143929256529 0.150329205601 0.156467598013 0.162374100149 0.168073161363 0.173585214641 0.178927543753 0.184114923580 0.189160102178 0.194074169913 0.198866846404 0.203546706606 0.208121361089 0.212597601381 0.216981518301 0.221278599182 0.225493808401 0.229631654609 0.233696247231 0.237691344271 0.241620392998 0.245486564773 0.249292785005 0.253041759057 0..." }, { "input": "724 1", "output": "0.037164707312 0.052558833123 0.064371161313 0.074329414625 0.083102811914 0.091034569355 0.098328573097 0.105117666246 0.111494121937 0.117525123681 0.123261389598 0.128742322627 0.133999257852 0.139057601643 0.143938292487 0.148658829249 0.153234013794 0.157676499368 0.161997203441 0.166205623829 0.170310084440 0.174317928887 0.178235674883 0.182069138710 0.185823536562 0.189503567803 0.193113483940 0.196657146194 0.200138073886 0.203559485381 0.206924332929 0.210235332491 0.213494989396 0.216705620524 0..." }, { "input": "917 1", "output": "0.033022909334 0.046701446249 0.057197356781 0.066045818668 0.073841470086 0.080889277691 0.087370405666 0.093402892499 0.099068728003 0.104427608461 0.109524599747 0.114394713561 0.119065792869 0.123560412643 0.127897177895 0.132091637337 0.136156943250 0.140104338748 0.143943524609 0.147682940172 0.151329981692 0.154891174376 0.158372309576 0.161778555382 0.165114546671 0.168384459091 0.171592070342 0.174740811332 0.177833809176 0.180873923568 0.183863777748 0.186805784998 0.189702171441 0.192554995756 0..." }, { "input": "458 100", "output": "4.672693135160 6.608186004551 8.093341918275 9.345386270320 10.448459488214 11.445713905748 12.362783988552 13.216372009102 14.018079405480 14.776353114139 15.497569889795 16.186683836551 16.847634693328 17.483616785299 18.097262694412 18.690772540640 19.266007352363 19.824558013653 20.367797170339 20.896918976429 21.412969991171 21.916873521973 22.409449036367 22.891427811495 23.363465675800 23.826153477212 24.280025754826 24.725567977104 25.163222626003 25.593394344267 26.016454316384 26.432744018204 26...." } ]
30
0
-1
3,281
357
Flag Day
[ "constructive algorithms", "implementation" ]
null
null
In Berland, there is the national holiday coming β€” the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland). The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance. You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
The first line contains two space-separated integers *n* (3<=≀<=*n*<=≀<=105) and *m* (1<=≀<=*m*<=≀<=105) β€” the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers β€” the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance.
Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
[ "7 3\n1 2 3\n1 4 5\n4 6 7\n", "9 3\n3 6 9\n2 5 8\n1 4 7\n", "5 2\n4 1 5\n3 1 2\n" ]
[ "1 2 3 3 2 2 1 \n", "1 1 1 2 2 2 3 3 3 \n", "2 3 1 1 3 \n" ]
none
[ { "input": "7 3\n1 2 3\n1 4 5\n4 6 7", "output": "1 2 3 3 2 2 1 " }, { "input": "9 3\n3 6 9\n2 5 8\n1 4 7", "output": "1 1 1 2 2 2 3 3 3 " }, { "input": "5 2\n4 1 5\n3 1 2", "output": "2 3 1 1 3 " }, { "input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12", "output": "1 3 3 2 2 2 1 1 2 2 3 3 1 1 " }, { "input": "14 6\n14 3 13\n10 14 5\n6 2 10\n7 13 9\n12 11 8\n1 4 9", "output": "2 2 2 3 2 1 2 3 1 3 2 1 3 1 " }, { "input": "14 6\n11 13 10\n3 10 14\n2 7 12\n13 1 9\n5 11 4\n8 6 5", "output": "1 1 2 2 3 2 2 1 3 3 1 3 2 1 " }, { "input": "13 5\n13 6 2\n13 3 8\n11 4 7\n10 9 5\n1 12 6", "output": "3 3 3 2 3 2 3 2 2 1 1 1 1 " }, { "input": "14 6\n5 4 8\n5 7 12\n3 6 12\n7 11 14\n10 13 2\n10 1 9", "output": "3 3 3 2 1 1 3 3 2 1 2 2 2 1 " }, { "input": "14 5\n4 13 2\n7 2 11\n6 1 5\n14 12 8\n10 3 9", "output": "2 3 2 1 3 1 2 3 3 1 1 2 2 1 " }, { "input": "14 6\n2 14 5\n3 4 5\n6 13 14\n7 13 12\n8 10 11\n9 6 1", "output": "1 1 1 2 3 3 3 1 2 2 3 2 1 2 " }, { "input": "14 6\n7 14 12\n6 1 12\n13 5 2\n2 3 9\n7 4 11\n5 8 10", "output": "2 3 2 3 2 1 1 1 1 3 2 3 1 2 " }, { "input": "13 6\n8 7 6\n11 7 3\n13 9 3\n12 1 13\n8 10 4\n2 7 5", "output": "3 1 3 2 3 3 2 1 2 3 1 2 1 " }, { "input": "13 5\n8 4 3\n1 9 5\n6 2 11\n12 10 4\n7 10 13", "output": "1 2 3 2 3 1 3 1 2 1 3 3 2 " }, { "input": "20 8\n16 19 12\n13 3 5\n1 5 17\n10 19 7\n8 18 2\n3 11 14\n9 20 12\n4 15 6", "output": "2 3 2 1 3 3 3 1 1 1 1 3 1 3 2 1 1 2 2 2 " }, { "input": "19 7\n10 18 14\n5 9 11\n9 17 7\n3 15 4\n6 8 12\n1 2 18\n13 16 19", "output": "3 1 1 3 1 1 3 2 2 1 3 3 1 3 2 2 1 2 3 " }, { "input": "18 7\n17 4 13\n7 1 6\n16 9 13\n9 2 5\n11 12 17\n14 8 10\n3 15 18", "output": "2 1 1 2 3 3 1 2 2 3 2 3 3 1 2 1 1 3 " }, { "input": "20 7\n8 5 11\n3 19 20\n16 1 17\n9 6 2\n7 18 13\n14 12 18\n10 4 15", "output": "2 3 1 2 2 2 1 1 1 1 3 1 3 3 3 1 3 2 2 3 " }, { "input": "20 7\n6 11 20\n19 5 2\n15 10 12\n3 7 8\n9 1 6\n13 17 18\n14 16 4", "output": "3 3 1 3 2 1 2 3 2 2 2 3 1 1 1 2 2 3 1 3 " }, { "input": "18 7\n15 5 1\n6 11 4\n14 8 17\n11 12 13\n3 8 16\n9 4 7\n2 18 10", "output": "3 1 1 3 2 1 1 2 2 3 2 1 3 1 1 3 3 2 " }, { "input": "19 7\n3 10 8\n17 7 4\n1 19 18\n2 9 5\n12 11 15\n11 14 6\n13 9 16", "output": "1 1 1 3 3 3 2 3 2 2 2 1 1 1 3 3 1 3 2 " }, { "input": "19 7\n18 14 4\n3 11 6\n8 10 7\n10 19 16\n17 13 15\n5 1 14\n12 9 2", "output": "1 3 1 3 3 3 3 1 2 2 2 1 2 2 3 3 1 1 1 " }, { "input": "20 7\n18 7 15\n17 5 20\n9 19 12\n16 13 10\n3 6 1\n3 8 11\n4 2 14", "output": "3 2 1 1 2 2 2 3 1 3 2 3 2 3 3 1 1 1 2 3 " }, { "input": "18 7\n8 4 6\n13 17 3\n9 8 12\n12 16 5\n18 2 7\n11 1 10\n5 15 14", "output": "2 2 3 2 3 3 3 1 3 3 1 2 1 1 2 1 2 1 " }, { "input": "99 37\n40 10 7\n10 3 5\n10 31 37\n87 48 24\n33 47 38\n34 87 2\n2 35 28\n99 28 76\n66 51 97\n72 77 9\n18 17 67\n23 69 98\n58 89 99\n42 44 52\n65 41 80\n70 92 74\n62 88 45\n68 27 61\n6 83 95\n39 85 49\n57 75 77\n59 54 81\n56 20 82\n96 4 53\n90 7 11\n16 43 84\n19 25 59\n68 8 93\n73 94 78\n15 71 79\n26 12 50\n30 32 4\n14 22 29\n46 21 36\n60 55 86\n91 8 63\n13 1 64", "output": "2 2 1 2 3 1 3 3 3 2 1 2 1 1 1 1 2 1 2 2 2 2 1 3 3 1 2 3 3 3 1 1 1 3 1 3 3 3 1 1 2 1 2 2 3 1 2 2 3 3 2 3 3 2 2 1 3 3 1 1 3 1 1 3 1 1 3 1 2 1 2 1 1 3 1 1 2 3 3 3 3 3 2 3 2 3 1 2 1 2 2 2 2 2 3 1 3 3 2 " }, { "input": "99 41\n11 70 20\n57 11 76\n52 11 64\n49 70 15\n19 61 17\n71 77 21\n77 59 39\n37 64 68\n17 84 36\n46 11 90\n35 11 14\n36 25 80\n12 43 48\n18 78 42\n82 94 15\n22 10 84\n63 86 4\n98 86 50\n92 60 9\n73 42 65\n21 5 27\n30 24 23\n7 88 49\n40 97 45\n81 56 17\n79 61 33\n13 3 77\n54 6 28\n99 58 8\n29 95 24\n89 74 32\n51 89 66\n87 91 96\n22 34 38\n1 53 72\n55 97 26\n41 16 44\n2 31 47\n83 67 91\n75 85 69\n93 47 62", "output": "1 1 1 3 2 2 2 3 3 1 1 1 3 2 3 2 3 1 1 3 3 3 3 2 3 3 1 3 3 1 2 3 3 2 3 1 1 1 3 1 1 3 2 3 3 3 3 3 1 3 3 3 2 1 1 2 3 2 1 2 2 1 1 2 1 2 1 3 3 2 1 3 2 2 1 2 2 2 1 2 1 1 3 2 2 2 1 3 1 2 2 1 2 2 1 3 2 1 1 " }, { "input": "99 38\n70 56 92\n61 70 68\n18 92 91\n82 43 55\n37 5 43\n47 27 26\n64 63 40\n20 61 57\n69 80 59\n60 89 50\n33 25 86\n38 15 73\n96 85 90\n3 12 64\n95 23 48\n66 30 9\n38 99 45\n67 88 71\n74 11 81\n28 51 79\n72 92 34\n16 77 31\n65 18 94\n3 41 2\n36 42 81\n22 77 83\n44 24 52\n10 75 97\n54 21 53\n4 29 32\n58 39 98\n46 62 16\n76 5 84\n8 87 13\n6 41 14\n19 21 78\n7 49 93\n17 1 35", "output": "2 3 2 1 1 3 1 1 3 1 2 3 3 2 2 1 1 2 1 2 2 1 2 2 2 3 2 1 2 2 3 3 1 1 3 1 3 1 2 3 1 2 2 1 2 2 1 3 2 3 2 3 3 1 3 2 1 1 3 1 3 3 2 1 1 1 1 2 1 1 3 2 3 1 2 3 2 3 3 2 3 1 3 2 2 3 2 2 2 3 1 3 3 3 1 1 3 3 3 " }, { "input": "98 38\n70 23 73\n73 29 86\n93 82 30\n6 29 10\n7 22 78\n55 61 87\n98 2 12\n11 5 54\n44 56 60\n89 76 50\n37 72 43\n47 41 61\n85 40 38\n48 93 20\n90 64 29\n31 68 25\n83 57 41\n51 90 3\n91 97 66\n96 95 1\n50 84 71\n53 19 5\n45 42 28\n16 17 89\n63 58 15\n26 47 39\n21 24 19\n80 74 38\n14 46 75\n88 65 36\n77 92 33\n17 59 34\n35 69 79\n13 94 39\n8 52 4\n67 27 9\n65 62 18\n81 32 49", "output": "3 2 1 3 2 1 1 1 3 3 1 3 2 1 3 2 3 3 1 2 2 2 2 3 3 2 2 3 2 3 1 2 3 1 1 3 1 3 1 2 1 2 3 1 1 2 3 3 3 3 2 2 3 3 1 2 3 2 2 3 2 1 1 1 2 3 1 2 2 1 1 2 3 2 3 2 1 3 3 1 1 2 2 2 1 1 3 1 1 3 1 2 1 3 2 1 2 1 " }, { "input": "99 42\n61 66 47\n10 47 96\n68 86 67\n21 29 10\n55 44 47\n12 82 4\n45 71 55\n86 3 95\n16 99 93\n14 92 82\n12 59 20\n73 24 8\n79 72 48\n44 87 39\n87 84 97\n47 70 37\n49 77 95\n39 75 28\n75 25 5\n44 41 36\n76 86 78\n73 6 90\n8 22 58\n9 72 63\n81 42 14\n1 21 35\n91 54 15\n30 13 39\n56 89 79\n11 2 76\n19 65 52\n23 85 74\n7 38 24\n57 94 81\n43 34 60\n62 82 27\n69 64 53\n18 32 17\n24 31 88\n51 50 33\n40 80 98\n83 46 26", "output": "2 3 1 3 3 3 3 3 1 2 2 1 2 3 3 1 3 1 1 2 3 2 1 2 1 3 3 1 1 1 1 2 3 2 1 3 1 1 3 1 1 2 1 2 2 2 3 3 1 2 1 3 3 2 1 2 2 1 3 3 1 1 3 2 2 2 3 1 1 2 3 2 1 3 2 1 2 3 1 2 1 2 1 3 2 2 1 3 3 2 1 1 3 3 3 1 2 3 2 " } ]
31
307,200
0
3,283
724
Batch Sort
[ "brute force", "greedy", "implementation", "math" ]
null
null
You are given a table consisting of *n* rows and *m* columns. Numbers in each row form a permutation of integers from 1 to *m*. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to *n*<=+<=1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1,<=2,<=...,<=*m* in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=20)Β β€” the number of rows and the number of columns in the given table. Each of next *n* lines contains *m* integersΒ β€” elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*.
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
[ "2 4\n1 3 2 4\n1 3 4 2\n", "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n", "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is <center class="tex-equation">1Β 2Β 3Β 4</center> <center class="tex-equation">1Β 4Β 3Β 2</center> 1. In the second row, swap the second and the fourth elements. Now the table is <center class="tex-equation">1Β 2Β 3Β 4</center> <center class="tex-equation">1Β 2Β 3Β 4</center>
[ { "input": "2 4\n1 3 2 4\n1 3 4 2", "output": "YES" }, { "input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "output": "NO" }, { "input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5", "output": "YES" }, { "input": "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "5 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 8 5 6 7 10 9 4 11 12\n1 5 3 4 2 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12", "output": "YES" }, { "input": "4 10\n3 2 8 10 5 6 7 1 9 4\n1 2 9 4 5 3 7 8 10 6\n7 5 3 4 8 6 1 2 9 10\n4 2 3 9 8 6 7 5 1 10", "output": "NO" }, { "input": "5 10\n9 2 3 4 5 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 10 7 8 1 6", "output": "NO" }, { "input": "1 10\n9 10 4 2 3 5 7 1 8 6", "output": "NO" }, { "input": "5 10\n6 4 7 3 5 8 1 9 10 2\n1 5 10 6 3 4 9 7 2 8\n3 2 1 7 8 6 5 4 10 9\n7 9 1 6 8 2 4 5 3 10\n3 4 6 9 8 7 1 2 10 5", "output": "NO" }, { "input": "20 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n2 1", "output": "YES" }, { "input": "20 3\n3 2 1\n2 3 1\n2 3 1\n2 1 3\n1 3 2\n2 1 3\n1 2 3\n3 2 1\n3 1 2\n1 3 2\n3 1 2\n2 1 3\n2 3 1\n2 3 1\n3 1 2\n1 3 2\n3 1 2\n1 3 2\n3 1 2\n3 1 2", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n1 2 3 4 5 6 7 10 9 8", "output": "YES" }, { "input": "1 10\n6 9 3 4 5 1 8 7 2 10", "output": "NO" }, { "input": "5 20\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "output": "YES" }, { "input": "5 20\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20", "output": "YES" }, { "input": "5 20\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20", "output": "NO" }, { "input": "1 10\n4 2 3 8 5 6 7 1 9 10", "output": "YES" }, { "input": "1 10\n3 2 1 4 5 6 7 8 10 9", "output": "YES" }, { "input": "5 20\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20", "output": "YES" }, { "input": "5 20\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20", "output": "YES" }, { "input": "5 20\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20", "output": "NO" }, { "input": "1 10\n10 2 3 4 5 9 7 8 6 1", "output": "YES" }, { "input": "1 10\n1 9 2 4 6 5 8 3 7 10", "output": "NO" }, { "input": "5 20\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20", "output": "NO" }, { "input": "5 20\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20", "output": "NO" }, { "input": "5 20\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1", "output": "NO" }, { "input": "1 4\n2 3 4 1", "output": "NO" }, { "input": "3 3\n1 2 3\n2 1 3\n3 2 1", "output": "YES" }, { "input": "15 6\n2 1 4 3 6 5\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "2 4\n4 3 2 1\n4 3 1 2", "output": "NO" }, { "input": "2 4\n1 2 3 4\n2 1 4 3", "output": "YES" }, { "input": "10 6\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1", "output": "NO" }, { "input": "4 4\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "4 8\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7", "output": "YES" }, { "input": "4 6\n1 2 3 5 6 4\n3 2 1 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "3 3\n1 2 3\n3 1 2\n1 3 2", "output": "YES" }, { "input": "2 5\n5 2 1 4 3\n2 1 5 4 3", "output": "YES" }, { "input": "20 8\n4 3 2 1 5 6 7 8\n1 2 3 4 8 7 6 5\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8", "output": "NO" }, { "input": "6 8\n8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8", "output": "NO" }, { "input": "6 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11", "output": "YES" }, { "input": "6 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 10 11 12 9", "output": "NO" }, { "input": "2 4\n2 3 1 4\n3 2 1 4", "output": "YES" }, { "input": "2 4\n4 3 2 1\n1 2 3 4", "output": "YES" }, { "input": "2 4\n1 2 3 4\n4 3 2 1", "output": "YES" }, { "input": "2 6\n2 3 1 4 5 6\n1 2 3 5 6 4", "output": "NO" }, { "input": "3 3\n2 3 1\n2 3 1\n1 2 3", "output": "YES" }, { "input": "2 6\n6 5 4 3 2 1\n6 5 4 3 2 1", "output": "NO" }, { "input": "5 4\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "5 4\n3 1 4 2\n3 1 4 2\n3 1 4 2\n3 1 4 2\n3 1 4 2", "output": "NO" }, { "input": "6 8\n3 8 1 4 5 6 7 2\n1 8 3 6 5 4 7 2\n1 8 3 5 4 6 7 2\n1 8 3 7 5 6 4 2\n1 8 3 7 5 6 4 2\n1 8 3 7 5 6 4 2", "output": "YES" }, { "input": "2 5\n5 2 4 3 1\n2 1 5 4 3", "output": "NO" }, { "input": "4 4\n2 3 1 4\n1 2 3 4\n2 3 1 4\n2 1 3 4", "output": "YES" }, { "input": "2 4\n1 2 4 3\n2 1 4 3", "output": "YES" }, { "input": "3 5\n1 2 4 3 5\n2 1 4 3 5\n1 2 3 4 5", "output": "YES" }, { "input": "3 10\n2 1 3 4 5 6 8 7 10 9\n1 2 3 4 5 6 8 7 10 9\n1 2 3 4 6 5 8 7 10 9", "output": "NO" }, { "input": "3 4\n3 1 2 4\n3 2 4 1\n3 1 2 4", "output": "YES" }, { "input": "2 5\n1 4 2 3 5\n1 2 4 5 3", "output": "YES" }, { "input": "2 5\n2 1 5 3 4\n2 1 5 3 4", "output": "NO" }, { "input": "3 6\n2 3 1 4 5 6\n2 1 4 3 5 6\n1 2 3 4 5 6", "output": "YES" }, { "input": "6 6\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "2 4\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "6 6\n6 5 4 3 2 1\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "4 6\n6 5 4 3 2 1\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "2 4\n2 3 1 4\n1 2 3 4", "output": "YES" }, { "input": "3 5\n1 2 3 4 5\n1 3 4 2 5\n1 4 2 3 5", "output": "YES" }, { "input": "4 3\n1 2 3\n1 2 3\n1 2 3\n3 1 2", "output": "YES" }, { "input": "2 3\n3 1 2\n1 2 3", "output": "YES" }, { "input": "2 5\n2 1 5 4 3\n2 1 5 4 3", "output": "YES" }, { "input": "7 4\n1 2 3 4\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1", "output": "YES" }, { "input": "3 3\n1 2 3\n1 3 2\n3 1 2", "output": "YES" }, { "input": "10 6\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5", "output": "NO" } ]
109
4,915,200
3
3,288
977
Less or Equal
[ "sortings" ]
null
null
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$. Note that the sequence can contain equal elements. If there is no such $x$, print "-1" (without quotes).
The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β€” the sequence itself.
Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$. If there is no such $x$, print "-1" (without quotes).
[ "7 4\n3 7 5 1 10 3 20\n", "7 2\n3 7 5 1 10 3 20\n" ]
[ "6", "-1\n" ]
In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$. In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ elements of the given sequence will be also less than or equal to this number.
[ { "input": "7 4\n3 7 5 1 10 3 20", "output": "5" }, { "input": "7 2\n3 7 5 1 10 3 20", "output": "-1" }, { "input": "1 0\n1", "output": "-1" }, { "input": "1 0\n2", "output": "1" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "3 0\n3 3 3", "output": "2" }, { "input": "3 0\n2 2 3", "output": "1" }, { "input": "5 0\n3 4 5 6 7", "output": "2" }, { "input": "4 0\n2 3 4 5", "output": "1" }, { "input": "2 2\n1000000000 1000000000", "output": "1000000000" }, { "input": "7 2\n2 7 5 1 10 2 20", "output": "-1" }, { "input": "2 1\n1 1", "output": "-1" }, { "input": "5 3\n1 3 3 4 5", "output": "3" }, { "input": "4 4\n1000000000 1000000000 1000000000 1000000000", "output": "1000000000" } ]
46
0
0
3,290
526
Om Nom and Necklace
[ "hashing", "string suffix structures", "strings" ]
null
null
One day Om Nom found a thread with *n* beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly. Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads *S* is regular if it can be represented as *S*<==<=*A*<=+<=*B*<=+<=*A*<=+<=*B*<=+<=*A*<=+<=...<=+<=*A*<=+<=*B*<=+<=*A*, where *A* and *B* are some bead sequences, "<=+<=" is the concatenation of sequences, there are exactly 2*k*<=+<=1 summands in this sum, among which there are *k*<=+<=1 "*A*" summands and *k* "*B*" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if *A* or *B* is an empty sequence. Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order.
The first line contains two integers *n*, *k* (1<=≀<=*n*,<=*k*<=≀<=1<=000<=000) β€” the number of beads on the thread that Om Nom found and number *k* from the definition of the regular sequence above. The second line contains the sequence of *n* lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.
Print a string consisting of *n* zeroes and ones. Position *i* (1<=≀<=*i*<=≀<=*n*) must contain either number one if the first *i* beads on the thread form a regular sequence, or a zero otherwise.
[ "7 2\nbcabcab\n", "21 2\nababaababaababaababaa\n" ]
[ "0000011", "000110000111111000011" ]
In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take *A* = "", *B* = "bca"), and a sequence of the first 7 beads (we can take *A* = "b", *B* = "ca"). In the second sample test, for example, a sequence of the first 13 beads is regular, if we take *A* = "aba", *B* = "ba".
[ { "input": "7 2\nbcabcab", "output": "0000011" }, { "input": "21 2\nababaababaababaababaa", "output": "000110000111111000011" }, { "input": "321 2\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaaba", "output": "000001111001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "153 2\nabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaa", "output": "000000011111000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "2 1\nab", "output": "11" }, { "input": "2 2\nab", "output": "00" }, { "input": "2 3\nab", "output": "00" }, { "input": "5 6\naaaaa", "output": "00000" }, { "input": "5 5\naaaaa", "output": "00001" }, { "input": "5 4\naaaaa", "output": "00011" }, { "input": "1 1\na", "output": "1" }, { "input": "1 2\na", "output": "0" }, { "input": "1 42\na", "output": "0" } ]
140
22,528,000
3
3,291
48
Rock-paper-scissors
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up β€” who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { "input": "rock\npaper\nrock", "output": "M" }, { "input": "rock\nscissors\nrock", "output": "?" }, { "input": "paper\nscissors\nrock", "output": "?" }, { "input": "scissors\nscissors\nrock", "output": "S" }, { "input": "rock\nrock\npaper", "output": "S" }, { "input": "paper\nrock\npaper", "output": "?" }, { "input": "scissors\nrock\npaper", "output": "?" }, { "input": "rock\npaper\npaper", "output": "?" }, { "input": "paper\npaper\npaper", "output": "?" }, { "input": "scissors\npaper\npaper", "output": "F" }, { "input": "rock\nscissors\npaper", "output": "?" }, { "input": "paper\nscissors\npaper", "output": "M" }, { "input": "scissors\nscissors\npaper", "output": "?" }, { "input": "rock\nrock\nscissors", "output": "?" }, { "input": "paper\nrock\nscissors", "output": "?" }, { "input": "scissors\nrock\nscissors", "output": "M" }, { "input": "rock\npaper\nscissors", "output": "?" }, { "input": "paper\npaper\nscissors", "output": "S" }, { "input": "scissors\npaper\nscissors", "output": "?" }, { "input": "rock\nscissors\nscissors", "output": "F" }, { "input": "paper\nscissors\nscissors", "output": "?" }, { "input": "scissors\nscissors\nscissors", "output": "?" } ]
92
4,505,600
3.968608
3,321
311
The Closest Pair
[ "constructive algorithms", "implementation" ]
null
null
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given *n* points in the plane, find a pair of points between which the distance is minimized. Distance between (*x*1,<=*y*1) and (*x*2,<=*y*2) is . The pseudo code of the unexpected code is as follows: Here, *tot* can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, *tot* should not be more than *k* in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
A single line which contains two space-separated integers *n* and *k* (2<=≀<=*n*<=≀<=2000, 1<=≀<=*k*<=≀<=109).
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print *n* lines, and the *i*-th line contains two integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≀<=109) representing the coordinates of the *i*-th point. The conditions below must be held: - All the points must be distinct. - |*x**i*|,<=|*y**i*|<=≀<=109. - After running the given code, the value of *tot* should be larger than *k*.
[ "4 3\n", "2 100\n" ]
[ "0 0\n0 1\n1 0\n1 1\n", "no solution\n" ]
none
[ { "input": "4 3", "output": "0 0\n0 1\n1 0\n1 1" }, { "input": "2 100", "output": "no solution" }, { "input": "5 6", "output": "0 0\n0 1\n0 2\n0 3\n0 4" }, { "input": "8 20", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7" }, { "input": "6 15", "output": "no solution" }, { "input": "1808 505823289", "output": "no solution" }, { "input": "1850 507001807", "output": "no solution" }, { "input": "1892 948371814", "output": "no solution" }, { "input": "1788 94774524", "output": "no solution" }, { "input": "1947 944738707", "output": "no solution" }, { "input": "1989 367830", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1885 1096142", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1854 631695", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1750 215129", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1792 341122", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1834 1680860", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1657 1371995", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1699 1442450", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "1595 1271214", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "2000 1998999", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "2000 1000000000", "output": "no solution" }, { "input": "2 1", "output": "no solution" }, { "input": "3 2", "output": "0 0\n0 1\n0 2" }, { "input": "5 1", "output": "0 0\n0 1\n0 2\n0 3\n0 4" }, { "input": "1000 500", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." }, { "input": "342 340", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..." } ]
109
0
0
3,329
0
none
[ "none" ]
null
null
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 12$) β€” the number of pairs the first participant communicated to the second and vice versa. The second line contains $n$ pairs of integers, each between $1$ and $9$, β€” pairs of numbers communicated from first participant to the second. The third line contains $m$ pairs of integers, each between $1$ and $9$, β€” pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair $(1,2)$, there will be no pair $(2,1)$ within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.
If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print $0$. Otherwise print $-1$.
[ "2 2\n1 2 3 4\n1 5 3 4\n", "2 2\n1 2 3 4\n1 5 6 4\n", "2 3\n1 2 4 5\n1 2 1 3 2 3\n" ]
[ "1\n", "0\n", "-1\n" ]
In the first example the first participant communicated pairs $(1,2)$ and $(3,4)$, and the second communicated $(1,5)$, $(3,4)$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $(3,4)$. Thus, the first participant has $(1,2)$ and the second has $(1,5)$, and at this point you already know the shared number is $1$. In the second example either the first participant has $(1,2)$ and the second has $(1,5)$, or the first has $(3,4)$ and the second has $(6,4)$. In the first case both of them know the shared number is $1$, in the second case both of them know the shared number is $4$. You don't have enough information to tell $1$ and $4$ apart. In the third case if the first participant was given $(1,2)$, they don't know what the shared number is, since from their perspective the second participant might have been given either $(1,3)$, in which case the shared number is $1$, or $(2,3)$, in which case the shared number is $2$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $-1$.
[ { "input": "2 2\n1 2 3 4\n1 5 3 4", "output": "1" }, { "input": "2 2\n1 2 3 4\n1 5 6 4", "output": "0" }, { "input": "2 3\n1 2 4 5\n1 2 1 3 2 3", "output": "-1" }, { "input": "2 1\n1 2 1 3\n1 2", "output": "1" }, { "input": "4 4\n1 2 3 4 5 6 7 8\n2 3 4 5 6 7 8 1", "output": "-1" }, { "input": "3 3\n1 2 5 6 7 8\n2 3 4 5 8 9", "output": "0" }, { "input": "4 3\n1 2 4 5 6 7 8 9\n1 2 8 9 3 1", "output": "1" }, { "input": "3 4\n2 1 8 9 3 1\n1 2 4 5 6 7 8 9", "output": "1" }, { "input": "3 8\n8 9 8 5 9 2\n8 4 8 3 2 6 4 2 4 3 3 7 3 6 1 6", "output": "0" }, { "input": "9 1\n3 4 3 2 3 7 3 5 9 4 1 9 6 4 5 2 7 6\n8 3", "output": "3" }, { "input": "5 6\n4 7 7 3 4 3 9 4 3 9\n7 5 7 8 1 7 7 2 6 2 1 2", "output": "7" }, { "input": "7 3\n2 6 6 7 6 4 6 1 9 6 7 4 1 9\n6 5 3 6 6 8", "output": "6" }, { "input": "9 2\n9 6 1 6 2 5 7 3 8 1 7 2 9 1 2 8 3 8\n6 4 4 5", "output": "0" }, { "input": "5 6\n1 7 5 6 6 9 3 6 1 9\n2 7 2 5 8 5 4 8 4 2 8 2", "output": "0" }, { "input": "3 9\n9 7 9 2 7 2\n9 8 1 9 3 9 6 3 8 6 4 6 1 3 5 4 5 3", "output": "9" }, { "input": "9 4\n2 8 8 9 8 1 9 2 5 9 3 5 3 2 5 2 9 1\n8 4 8 7 6 8 4 7", "output": "8" }, { "input": "1 12\n6 8\n8 4 8 2 5 8 9 8 8 3 8 7 8 1 1 3 1 9 4 3 7 3 5 7", "output": "8" }, { "input": "12 12\n7 6 3 8 8 4 4 7 1 9 9 5 7 5 4 9 8 6 2 7 7 3 3 6\n9 1 2 4 9 8 5 3 6 7 3 8 2 7 5 9 6 4 3 1 2 6 1 4", "output": "-1" }, { "input": "12 12\n1 6 2 6 8 3 6 4 4 8 7 2 7 5 9 4 2 4 9 5 8 5 3 6\n2 8 6 9 2 6 7 4 6 5 6 3 5 8 7 8 7 1 1 9 9 7 7 3", "output": "-1" }, { "input": "12 12\n6 7 5 4 7 8 2 9 8 5 3 5 1 6 7 3 7 9 5 7 1 8 6 8\n6 4 2 1 7 8 1 6 8 5 9 8 1 5 7 2 5 9 6 3 9 2 9 4", "output": "-1" }, { "input": "1 10\n3 9\n3 2 3 4 5 3 5 7 8 6 2 5 7 8 2 4 1 7 5 1", "output": "3" }, { "input": "3 10\n6 1 4 1 4 6\n7 1 8 1 8 5 3 2 9 7 9 3 5 9 5 3 5 7 7 2", "output": "1" }, { "input": "2 7\n2 7 2 5\n7 1 9 7 8 9 4 9 8 1 3 9 3 8", "output": "7" }, { "input": "12 1\n6 2 6 4 8 6 6 9 5 6 6 1 9 1 1 3 3 9 2 4 5 2 8 1\n6 7", "output": "6" }, { "input": "2 11\n6 1 3 6\n1 7 1 2 1 5 1 4 5 3 3 2 9 8 4 2 7 5 4 9 2 9", "output": "0" }, { "input": "6 9\n8 1 8 4 2 8 2 1 4 1 4 2\n8 3 8 6 7 8 5 8 6 7 5 7 9 6 5 6 5 3", "output": "8" }, { "input": "6 4\n2 7 3 2 8 3 1 5 7 4 3 5\n2 6 9 8 8 6 6 9", "output": "0" }, { "input": "3 10\n1 5 7 1 2 1\n9 5 5 6 3 5 4 7 8 3 9 6 8 4 9 8 4 6 3 4", "output": "0" }, { "input": "1 7\n8 4\n9 8 8 2 6 8 8 1 7 8 2 1 9 5", "output": "8" }, { "input": "3 6\n3 5 7 4 7 5\n3 9 3 2 8 6 6 2 8 2 6 9", "output": "3" }, { "input": "8 5\n7 9 6 7 4 7 2 1 4 9 2 9 4 2 9 6\n8 7 1 8 8 5 3 5 3 8", "output": "0" }, { "input": "8 1\n1 6 7 6 7 3 9 2 1 2 8 6 2 3 4 1\n8 3", "output": "-1" }, { "input": "12 5\n9 2 6 7 7 8 3 4 8 4 7 1 2 1 7 3 7 2 5 6 3 8 1 5\n3 7 7 5 7 4 5 8 4 6", "output": "-1" }, { "input": "11 1\n2 6 1 4 7 9 7 6 8 1 4 8 4 7 7 2 1 7 9 6 6 5\n3 1", "output": "1" }, { "input": "10 2\n4 9 2 1 5 1 6 2 6 7 2 7 5 8 1 7 5 3 9 1\n9 7 1 4", "output": "-1" }, { "input": "9 1\n1 8 7 6 7 2 7 9 4 1 4 3 3 8 4 6 9 6\n9 4", "output": "-1" }, { "input": "4 7\n9 2 4 1 2 3 2 7\n6 1 5 4 7 5 6 3 1 5 8 1 1 4", "output": "-1" }, { "input": "3 7\n8 2 7 9 8 1\n3 1 8 1 2 7 4 7 4 2 1 4 4 6", "output": "-1" }, { "input": "12 2\n3 1 8 2 6 9 2 6 5 4 4 3 4 1 4 2 6 3 9 7 9 4 3 2\n7 1 4 1", "output": "-1" }, { "input": "7 6\n6 2 9 2 6 5 2 4 1 2 4 5 6 7\n3 9 5 1 9 8 9 5 3 4 2 3", "output": "-1" }, { "input": "4 12\n2 8 3 1 2 1 9 4\n9 5 5 3 1 6 3 7 7 1 8 5 6 5 4 6 1 9 1 4 2 5 9 8", "output": "-1" }, { "input": "2 2\n1 2 2 3\n2 3 3 4", "output": "0" }, { "input": "2 2\n1 2 1 3\n1 2 1 3", "output": "1" }, { "input": "3 3\n1 2 1 3 2 3\n1 2 1 3 2 3", "output": "-1" }, { "input": "2 3\n1 2 1 3\n1 2 1 3 2 3", "output": "-1" }, { "input": "2 2\n1 2 2 4\n1 2 1 3", "output": "0" }, { "input": "2 1\n4 5 6 7\n4 7", "output": "-1" }, { "input": "3 2\n1 2 1 3 2 3\n1 2 4 5", "output": "-1" }, { "input": "4 4\n1 2 1 3 6 7 6 8\n1 4 1 5 6 1 6 9", "output": "-1" }, { "input": "4 4\n1 2 2 3 1 3 4 5\n1 3 3 2 1 2 4 6", "output": "-1" }, { "input": "3 2\n1 2 4 5 6 7\n4 7 1 3", "output": "-1" }, { "input": "2 3\n1 2 7 8\n1 3 2 4 7 9", "output": "-1" } ]
77
0
0
3,331
919
Supermarket
[ "brute force", "greedy", "implementation" ]
null
null
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo. Now imagine you'd like to buy $m$ kilos of apples. You've asked $n$ supermarkets and got the prices. Find the minimum cost for those apples. You can assume that there are enough apples in all supermarkets.
The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples. The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b \leq 100$), denoting that in this supermarket, you are supposed to pay $a$ yuan for $b$ kilos of apples.
The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$. Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} \le 10^{-6}$.
[ "3 5\n1 2\n3 4\n1 3\n", "2 1\n99 100\n98 99\n" ]
[ "1.66666667\n", "0.98989899\n" ]
In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan. In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan.
[ { "input": "3 5\n1 2\n3 4\n1 3", "output": "1.66666667" }, { "input": "2 1\n99 100\n98 99", "output": "0.98989899" }, { "input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 82\n38 62\n11 50\n55 84\n1 97\n12 67\n51 96\n51 7\n1 100\n79 61\n66 54\n97 93\n52 75\n80 54\n98 73\n29 28\n73 96\n24 73\n3 25\n1 29\n43 50\n97 95\n54 64\n38 97\n68 16\n22 68\n25 91\n77 13", "output": "0.37000000" }, { "input": "5 1\n5 100\n55 6\n53 27\n57 53\n62 24", "output": "0.05000000" }, { "input": "10 7\n83 93\n90 2\n63 51\n51 97\n7 97\n25 78\n17 68\n30 10\n46 14\n22 28", "output": "0.50515464" }, { "input": "1 100\n100 1", "output": "10000.00000000" }, { "input": "1 1\n59 1", "output": "59.00000000" }, { "input": "1 100\n1 100", "output": "1.00000000" }, { "input": "1 100\n1 99", "output": "1.01010101" }, { "input": "1 1\n100 1", "output": "100.00000000" }, { "input": "15 100\n1 2\n3 4\n10 11\n12 13\n20 21\n28 29\n34 35\n42 43\n59 60\n61 62\n74 75\n89 90\n96 97\n98 99\n99 100", "output": "50.00000000" }, { "input": "15 100\n3 2\n5 4\n12 11\n14 13\n22 21\n30 29\n36 35\n44 43\n61 60\n63 62\n76 75\n91 90\n98 97\n99 98\n100 99", "output": "101.01010101" }, { "input": "1 1\n100 10", "output": "10.00000000" }, { "input": "1 1\n100 3", "output": "33.33333333" }, { "input": "1 100\n100 3", "output": "3333.33333333" }, { "input": "1 100\n100 1", "output": "10000.00000000" }, { "input": "7 8\n9 8\n5 1\n3 1\n6 2\n7 3\n2 1\n3 1", "output": "9.00000000" }, { "input": "5 8\n9 8\n3 1\n2 1\n4 2\n13 5", "output": "9.00000000" }, { "input": "2 1\n1 2\n2 10", "output": "0.20000000" }, { "input": "2 1\n99 100\n95 95", "output": "0.99000000" }, { "input": "1 5\n10 1", "output": "50.00000000" }, { "input": "5 10\n9 1\n10 1\n11 1\n12 1\n13 1", "output": "90.00000000" }, { "input": "1 100\n3 1", "output": "300.00000000" } ]
46
0
3
3,334
437
The Child and Homework
[ "implementation" ]
null
null
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: - If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose?
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
[ "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n", "A.ab\nB.abcde\nC.ab\nD.abc\n", "A.c\nB.cc\nC.c\nD.c\n" ]
[ "D\n", "C\n", "B\n" ]
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D. In the second sample, no choice is great, so the child will choose the luckiest choice C. In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
[ { "input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "output": "D" }, { "input": "A.ab\nB.abcde\nC.ab\nD.abc", "output": "C" }, { "input": "A.c\nB.cc\nC.c\nD.c", "output": "B" }, { "input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a", "output": "C" }, { "input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____", "output": "C" }, { "input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_", "output": "D" }, { "input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____", "output": "C" }, { "input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_", "output": "D" }, { "input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h", "output": "A" }, { "input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_", "output": "C" }, { "input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg", "output": "B" }, { "input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___", "output": "D" }, { "input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS", "output": "C" }, { "input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_", "output": "C" }, { "input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi", "output": "C" }, { "input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__", "output": "C" }, { "input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h", "output": "A" }, { "input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_", "output": "C" }, { "input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg", "output": "B" }, { "input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___", "output": "D" }, { "input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS", "output": "C" }, { "input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_", "output": "C" }, { "input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi", "output": "C" }, { "input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__", "output": "C" }, { "input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa", "output": "A" }, { "input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa", "output": "A" }, { "input": "A.a\nB.b\nC.c\nD.d", "output": "C" }, { "input": "A._\nB.__\nC.____\nD.________", "output": "C" }, { "input": "A.____\nB.________\nC.________\nD._______", "output": "C" }, { "input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg", "output": "C" }, { "input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa", "output": "C" }, { "input": "A.ccc\nB.ccccccc\nC.ccc\nD.c", "output": "C" }, { "input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc", "output": "C" }, { "input": "A.aa\nB.bb\nC.cc\nD.ddd", "output": "C" }, { "input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI", "output": "C" } ]
62
0
3
3,341
894
Marco and GCD Sequence
[ "constructive algorithms", "math" ]
null
null
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length *n*, but forgot the exact sequence. Let the elements of the sequence be *a*1,<=*a*2,<=...,<=*a**n*. He remembered that he calculated *gcd*(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*) for every 1<=≀<=*i*<=≀<=*j*<=≀<=*n* and put it into a set *S*. *gcd* here means the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). Note that even if a number is put into the set *S* twice or more, it only appears once in the set. Now Marco gives you the set *S* and asks you to help him figure out the initial sequence. If there are many solutions, print any of them. It is also possible that there are no sequences that produce the set *S*, in this case print -1.
The first line contains a single integer *m* (1<=≀<=*m*<=≀<=1000)Β β€” the size of the set *S*. The second line contains *m* integers *s*1,<=*s*2,<=...,<=*s**m* (1<=≀<=*s**i*<=≀<=106)Β β€” the elements of the set *S*. It's guaranteed that the elements of the set are given in strictly increasing order, that means *s*1<=&lt;<=*s*2<=&lt;<=...<=&lt;<=*s**m*.
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer *n* denoting the length of the sequence, *n* should not exceed 4000. In the second line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=106)Β β€” the sequence. We can show that if a solution exists, then there is a solution with *n* not exceeding 4000 and *a**i* not exceeding 106. If there are multiple solutions, print any of them.
[ "4\n2 4 6 12\n", "2\n2 3\n" ]
[ "3\n4 6 12", "-1\n" ]
In the first example 2 = *gcd*(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among *gcd*(*a*<sub class="lower-index">*i*</sub>, *a*<sub class="lower-index">*i* + 1</sub>, ..., *a*<sub class="lower-index">*j*</sub>) for every 1 ≀ *i* ≀ *j* ≀ *n*.
[ { "input": "4\n2 4 6 12", "output": "7\n2 2 4 2 6 2 12" }, { "input": "2\n2 3", "output": "-1" }, { "input": "2\n1 6", "output": "3\n1 1 6" }, { "input": "3\n1 2 7", "output": "5\n1 1 2 1 7" }, { "input": "1\n1", "output": "1\n1" }, { "input": "2\n1 10", "output": "3\n1 1 10" }, { "input": "3\n1 2 6", "output": "5\n1 1 2 1 6" }, { "input": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "29\n1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15" }, { "input": "14\n1 2 3 4 5 6 7 8 9 10 11 12 13 14", "output": "27\n1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14" }, { "input": "5\n2 5 6 7 11", "output": "-1" }, { "input": "11\n3 4 5 6 7 8 9 10 11 12 13", "output": "-1" }, { "input": "3\n4 9 11", "output": "-1" }, { "input": "6\n5 6 9 11 14 16", "output": "-1" }, { "input": "12\n8 9 10 11 12 13 14 15 16 17 18 19", "output": "-1" }, { "input": "3\n1007 397765 414884", "output": "5\n1007 1007 397765 1007 414884" }, { "input": "19\n1007 27189 32224 47329 93651 172197 175218 234631 289009 340366 407835 468255 521626 579025 601179 605207 614270 663613 720005", "output": "37\n1007 1007 27189 1007 32224 1007 47329 1007 93651 1007 172197 1007 175218 1007 234631 1007 289009 1007 340366 1007 407835 1007 468255 1007 521626 1007 579025 1007 601179 1007 605207 1007 614270 1007 663613 1007 720005" }, { "input": "36\n1007 27189 42294 81567 108756 133931 149036 161120 200393 231610 234631 270883 302100 307135 343387 344394 362520 383667 421933 463220 486381 526661 546801 571976 595137 615277 616284 629375 661599 674690 680732 714970 744173 785460 787474 823726", "output": "71\n1007 1007 27189 1007 42294 1007 81567 1007 108756 1007 133931 1007 149036 1007 161120 1007 200393 1007 231610 1007 234631 1007 270883 1007 302100 1007 307135 1007 343387 1007 344394 1007 362520 1007 383667 1007 421933 1007 463220 1007 486381 1007 526661 1007 546801 1007 571976 1007 595137 1007 615277 1007 616284 1007 629375 1007 661599 1007 674690 1007 680732 1007 714970 1007 744173 1007 785460 1007 787474 1007 823726" }, { "input": "49\n1007 24168 33231 34238 51357 68476 75525 89623 99693 128896 149036 150043 162127 178239 184281 203414 216505 224561 232617 260813 274911 300086 325261 337345 365541 367555 378632 384674 405821 407835 419919 432003 460199 466241 492423 515584 531696 549822 572983 589095 616284 624340 653543 683753 700872 704900 713963 736117 737124", "output": "97\n1007 1007 24168 1007 33231 1007 34238 1007 51357 1007 68476 1007 75525 1007 89623 1007 99693 1007 128896 1007 149036 1007 150043 1007 162127 1007 178239 1007 184281 1007 203414 1007 216505 1007 224561 1007 232617 1007 260813 1007 274911 1007 300086 1007 325261 1007 337345 1007 365541 1007 367555 1007 378632 1007 384674 1007 405821 1007 407835 1007 419919 1007 432003 1007 460199 1007 466241 1007 492423 1007 515584 1007 531696 1007 549822 1007 572983 1007 589095 1007 616284 1007 624340 1007 653543 1007 6..." }, { "input": "3\n99997 599982 999970", "output": "5\n99997 99997 599982 99997 999970" }, { "input": "2\n99997 399988", "output": "3\n99997 99997 399988" }, { "input": "4\n99997 399988 499985 599982", "output": "7\n99997 99997 399988 99997 499985 99997 599982" }, { "input": "4\n19997 339949 539919 719892", "output": "7\n19997 19997 339949 19997 539919 19997 719892" }, { "input": "2\n299997 599994", "output": "3\n299997 299997 599994" }, { "input": "1\n999997", "output": "1\n999997" }, { "input": "1\n1000000", "output": "1\n1000000" }, { "input": "2\n999999 1000000", "output": "-1" }, { "input": "2\n999996 1000000", "output": "-1" }, { "input": "3\n250000 750000 1000000", "output": "5\n250000 250000 750000 250000 1000000" }, { "input": "2\n666666 999999", "output": "-1" }, { "input": "4\n111111 666666 777777 999999", "output": "7\n111111 111111 666666 111111 777777 111111 999999" }, { "input": "5\n111111 233333 666666 777777 999999", "output": "-1" }, { "input": "6\n111111 222222 333333 666666 777777 999999", "output": "11\n111111 111111 222222 111111 333333 111111 666666 111111 777777 111111 999999" }, { "input": "2\n1 2", "output": "3\n1 1 2" }, { "input": "1\n233333", "output": "1\n233333" } ]
109
2,457,600
3
3,350
622
The Time
[ "implementation" ]
null
null
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes. Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedia.org/wiki/24-hour_clock).
The first line contains the current time in the format hh:mm (0<=≀<=*hh*<=&lt;<=24,<=0<=≀<=*mm*<=&lt;<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer *a* (0<=≀<=*a*<=≀<=104) β€” the number of the minutes passed.
The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format.
[ "23:59\n10\n", "20:20\n121\n", "10:10\n0\n" ]
[ "00:09\n", "22:21\n", "10:10\n" ]
none
[ { "input": "23:59\n10", "output": "00:09" }, { "input": "20:20\n121", "output": "22:21" }, { "input": "10:10\n0", "output": "10:10" }, { "input": "12:34\n10000", "output": "11:14" }, { "input": "00:00\n10000", "output": "22:40" }, { "input": "00:00\n1440", "output": "00:00" }, { "input": "23:59\n8640", "output": "23:59" }, { "input": "10:01\n0", "output": "10:01" }, { "input": "04:05\n0", "output": "04:05" }, { "input": "02:59\n1", "output": "03:00" }, { "input": "05:15\n10", "output": "05:25" }, { "input": "03:10\n20", "output": "03:30" }, { "input": "09:11\n0", "output": "09:11" }, { "input": "19:00\n0", "output": "19:00" }, { "input": "23:59\n1", "output": "00:00" }, { "input": "11:59\n1", "output": "12:00" }, { "input": "19:34\n566", "output": "05:00" }, { "input": "00:01\n59", "output": "01:00" }, { "input": "03:30\n0", "output": "03:30" }, { "input": "22:30\n30", "output": "23:00" }, { "input": "22:50\n70", "output": "00:00" }, { "input": "05:12\n0", "output": "05:12" }, { "input": "09:20\n40", "output": "10:00" }, { "input": "15:04\n36", "output": "15:40" }, { "input": "05:37\n23", "output": "06:00" }, { "input": "23:59\n59", "output": "00:58" }, { "input": "21:09\n9997", "output": "19:46" }, { "input": "11:00\n1", "output": "11:01" }, { "input": "20:01\n2699", "output": "17:00" }, { "input": "01:00\n59", "output": "01:59" }, { "input": "07:09\n6538", "output": "20:07" }, { "input": "00:00\n10", "output": "00:10" }, { "input": "02:09\n2074", "output": "12:43" }, { "input": "01:10\n1", "output": "01:11" }, { "input": "23:01\n59", "output": "00:00" }, { "input": "08:50\n20", "output": "09:10" }, { "input": "13:18\n5121", "output": "02:39" }, { "input": "18:31\n2677", "output": "15:08" }, { "input": "14:17\n108", "output": "16:05" }, { "input": "02:45\n5617", "output": "00:22" }, { "input": "00:00\n3600", "output": "12:00" }, { "input": "19:01\n59", "output": "20:00" }, { "input": "19:02\n59", "output": "20:01" }, { "input": "14:00\n2880", "output": "14:00" }, { "input": "01:10\n44", "output": "01:54" }, { "input": "02:01\n59", "output": "03:00" }, { "input": "07:02\n121", "output": "09:03" }, { "input": "10:00\n61", "output": "11:01" }, { "input": "23:59\n61", "output": "01:00" }, { "input": "00:00\n0", "output": "00:00" }, { "input": "23:59\n121", "output": "02:00" }, { "input": "00:00\n60", "output": "01:00" }, { "input": "15:52\n60", "output": "16:52" }, { "input": "00:39\n6525", "output": "13:24" }, { "input": "00:30\n30", "output": "01:00" }, { "input": "00:59\n1", "output": "01:00" }, { "input": "00:55\n4321", "output": "00:56" }, { "input": "10:05\n1", "output": "10:06" }, { "input": "23:00\n60", "output": "00:00" } ]
46
0
3
3,351
70
Cookies
[ "math" ]
A. Cookies
1
256
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=Γ—<=*k* in size, divided into blocks 1<=Γ—<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in size. Fangy also has a box with a square base 2*n*<=Γ—<=2*n*, divided into blocks 1<=Γ—<=1 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure: To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end.
The first line contains a single integer *n* (0<=≀<=*n*<=≀<=1000).
Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3.
[ "3\n" ]
[ "9" ]
If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner:
[ { "input": "3", "output": "9" }, { "input": "1", "output": "1" }, { "input": "2", "output": "3" }, { "input": "4", "output": "27" }, { "input": "6", "output": "243" }, { "input": "11", "output": "59049" }, { "input": "14", "output": "594320" }, { "input": "15", "output": "782957" }, { "input": "7", "output": "729" }, { "input": "0", "output": "1" }, { "input": "1000", "output": "691074" }, { "input": "657", "output": "874011" }, { "input": "561", "output": "842553" }, { "input": "823", "output": "858672" }, { "input": "850", "output": "557186" }, { "input": "298", "output": "999535" }, { "input": "262", "output": "946384" }, { "input": "910", "output": "678945" }, { "input": "617", "output": "247876" }, { "input": "857", "output": "562128" }, { "input": "69", "output": "327984" }, { "input": "589", "output": "889192" }, { "input": "928", "output": "794863" }, { "input": "696", "output": "695035" }, { "input": "226", "output": "376094" } ]
62
5,529,600
3.9587
3,356
590
Three States
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that one could any point of any country can be reached from any point of any other State. Since roads are always expensive, the governments of the states of the newly formed alliance asked you to help them assess the costs. To do this, you have been issued a map that can be represented as a rectangle table consisting of *n* rows and *m* columns. Any cell of the map either belongs to one of three states, or is an area where it is allowed to build a road, or is an area where the construction of the road is not allowed. A cell is called passable, if it belongs to one of the states, or the road was built in this cell. From any passable cells you can move up, down, right and left, if the cell that corresponds to the movement exists and is passable. Your task is to construct a road inside a minimum number of cells, so that it would be possible to get from any cell of any state to any cell of any other state using only passable cells. It is guaranteed that initially it is possible to reach any cell of any state from any cell of this state, moving only along its cells. It is also guaranteed that for any state there is at least one cell that belongs to it.
The first line of the input contains the dimensions of the map *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000)Β β€” the number of rows and columns respectively. Each of the next *n* lines contain *m* characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.' corresponds to the cell where it is allowed to build a road and the character '#' means no construction is allowed in this cell.
Print a single integerΒ β€” the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1.
[ "4 5\n11..2\n#..22\n#.323\n.#333", "1 5\n1#2#3\n" ]
[ "2", "-1\n" ]
none
[ { "input": "4 5\n11..2\n#..22\n#.323\n.#333", "output": "2" }, { "input": "1 5\n1#2#3", "output": "-1" }, { "input": "3 4\n.2..\n...3\n.1#.", "output": "2" }, { "input": "10 10\n##.#..#.#2\n...###....\n#..#....##\n.....#....\n.#........\n.....#####\n...#..#...\n....###...\n###.##...#\n.#...1#.3.", "output": "-1" }, { "input": "4 3\n..#\n.3.\n..2\n..1", "output": "1" }, { "input": "5 5\n.2...\n#2.3.\n.#..#\n.#.11\n#..#.", "output": "2" }, { "input": "1 3\n231", "output": "0" }, { "input": "3 1\n3\n1\n2", "output": "0" }, { "input": "1 4\n12#3", "output": "-1" }, { "input": "10 10\n#...33.#.#\n#.#.33.#1.\n2.....#.11\n222#.#.#..\n####...#.#\n#.........\n.#....#...\n..#..#.##.\n##.....#.#\n#..#....#.", "output": "12" }, { "input": "10 10\n..#.....#.\n.#.##...#.\n..#.......\n..111.....\n#..#.....#\n.#...2....\n.....2....\n.....222..\n..........\n#.3....#..", "output": "6" }, { "input": "10 10\n##.#.##.##\n#.#..####.\n#.###.333.\n..#..#3.2#\n...###3..#\n..#.#..#.#\n...#.#.#..\n...##.1..#\n.##.#.1#.#\n..#.#.11..", "output": "2" }, { "input": "10 10\n###..#.#.#\n#....####.\n##1###.#.#\n#.11######\n##11#####.\n..#####..#\n####...#.3\n.#.#..2223\n#####..#33\n#.########", "output": "-1" }, { "input": "3 10\n........2.\n......1...\n.........3", "output": "3" }, { "input": "10 10\n1111.22222\n1111.22222\n11......22\n11......22\n..........\n3333333333\n3333333333\n3333333333\n3333333333\n3333333333", "output": "2" }, { "input": "4 4\n3###\n.222\n.#.2\n1222", "output": "1" }, { "input": "3 3\n##3\n1..\n222", "output": "1" }, { "input": "4 4\n1...\n.222\n....\n...3", "output": "2" }, { "input": "1 9\n111222333", "output": "0" }, { "input": "1 10\n111222333.", "output": "0" }, { "input": "1 15\n111112222233333", "output": "0" }, { "input": "5 4\n2..3\n2..3\n....\n1..1\n1111", "output": "2" }, { "input": "10 1\n1\n.\n2\n2\n2\n2\n2\n.\n3\n.", "output": "2" }, { "input": "3 3\n#2#\n1.3\n1.#", "output": "1" }, { "input": "1 9\n1.22222.3", "output": "2" }, { "input": "3 3\n1.2\n1.2\n333", "output": "0" }, { "input": "4 7\n2..1..3\n2##.##3\n2##.##3\n2.....3", "output": "4" } ]
30
0
0
3,363
924
Mystical Mosaic
[ "greedy", "implementation" ]
null
null
There is a rectangular grid of *n* rows of *m* initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the intersection of row *r* and column *c* is coloured black. There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (*i*,<=*j*) (*i*<=&lt;<=*j*) exists such that or , where denotes intersection of sets, and denotes the empty set. You are to determine whether a valid sequence of operations exists that produces a given final grid.
The first line contains two space-separated integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=50)Β β€” the number of rows and columns of the grid, respectively. Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).
[ "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n", "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n" ]
[ "Yes\n", "No\n", "No\n" ]
For the first example, the desired setup can be produced by 3 operations, as is shown below. For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
[ { "input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..", "output": "Yes" }, { "input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..", "output": "No" }, { "input": "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#", "output": "No" }, { "input": "1 1\n#", "output": "Yes" }, { "input": "2 1\n.\n#", "output": "Yes" }, { "input": "2 5\n.####\n#..##", "output": "No" }, { "input": "5 2\n##\n##\n..\n##\n..", "output": "Yes" }, { "input": "5 2\n#.\n##\n##\n#.\n..", "output": "No" }, { "input": "4 10\n###..#..##\n...##..#..\n.##..#..#.\n.........#", "output": "No" }, { "input": "4 10\n..#......#\n.....##...\n#.........\n.#.......#", "output": "No" }, { "input": "10 15\n.......#.......\n.....#.........\n....#..........\n....#..........\n.....#.........\n.....#.........\n#.............#\n...#..#........\n...............\n.............#.", "output": "Yes" }, { "input": "50 1\n.\n.\n#\n.\n#\n.\n#\n.\n.\n#\n#\n#\n.\n#\n#\n#\n#\n.\n.\n.\n.\n.\n.\n.\n.\n.\n#\n#\n#\n#\n.\n.\n.\n.\n.\n#\n.\n.\n.\n#\n#\n.\n.\n#\n#\n.\n.\n#\n#\n.", "output": "Yes" }, { "input": "2 50\n...#.##.###...#.#..##....##..........#.#..#.#####.\n...#.##.###...#.#..##....##..........#.#..#.#####.", "output": "Yes" }, { "input": "50 2\n..\n..\n#.\n..\n.#\n..\n..\n..\n.#\n..\n..\n.#\n##\n..\n..\n..\n.#\n..\n..\n.#\n..\n..\n.#\n..\n..\n.#\n..\n.#\n..\n.#\n..\n.#\n.#\n.#\n..\n..\n..\n.#\n.#\n.#\n..\n..\n.#\n.#\n..\n..\n..\n..\n..\n..", "output": "No" }, { "input": "1 1\n.", "output": "Yes" }, { "input": "2 3\n#.#\n###", "output": "No" }, { "input": "2 3\n#.#\n##.", "output": "No" }, { "input": "4 4\n###.\n##.#\n#.##\n.###", "output": "No" }, { "input": "3 3\n.##\n#.#\n##.", "output": "No" }, { "input": "2 2\n##\n#.", "output": "No" } ]
31
0
0
3,368
626
Robot Sequence
[ "brute force", "implementation" ]
null
null
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β€” instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.
The first line of the input contains a single positive integer, *n* (1<=≀<=*n*<=≀<=200)Β β€” the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L'Β β€” Calvin's source code.
Print a single integerΒ β€” the number of contiguous substrings that Calvin can execute and return to his starting square.
[ "6\nURLLDR\n", "4\nDLUU\n", "7\nRLRLRLR\n" ]
[ "2\n", "0\n", "12\n" ]
In the first case, the entire source code works, as well as the "RL" substring in the second and third characters. Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
[ { "input": "6\nURLLDR", "output": "2" }, { "input": "4\nDLUU", "output": "0" }, { "input": "7\nRLRLRLR", "output": "12" }, { "input": "1\nR", "output": "0" }, { "input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL", "output": "1225" }, { "input": "200\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "100" }, { "input": "20\nLDURLDURRLRUDLRRUDLU", "output": "29" }, { "input": "140\nDLDLULULDRDDDLLUDRRDLLUULLDDLDLUURLDLDRDUDDLRRDURUUUUURLDUDDLLRRLLDRRRDDDDDUDUULLURRDLDULUDLLUUDRRLUDULUDUDULULUURURRDUURRDLULLURUDDDDRDRDRD", "output": "125" }, { "input": "194\nULLLDLLDRUUDURRULLRLUUURDRLLURDUDDUDLULRLDRUDURLDLRDLLLLUDDRRRULULULUDDULRURURLLDLDLDRUDUUDULRULDDRRLRDRULLDRULLLLRRDDLLLLULDRLUULRUUULDUUDLDLDUUUDDLDDRULDRRLUURRULLDULRRDLLRDURDLUUDUDLLUDDULDDD", "output": "282" }, { "input": "200\nDDDURLLUUULUDDURRDLLDDLLRLUULUULDDDLRRDLRRDUDURDUDRRLLDRDUDDLDDRDLURRRLLRDRRLLLRDDDRDRRLLRRLULRUULRLDLUDRRRDDUUURLLUDRLDUDRLLRLRRLUDLRULDUDDRRLLRLURDLRUDDDURLRDUDUUURLLULULRDRLDLDRURDDDLLRUDDRDUDDDLRU", "output": "408" }, { "input": "197\nDUUDUDUDUDUUDUUDUUUDDDDUUUDUUUDUUUUUDUUUDDUDDDUUDUDDDUUDDUUUUUUUDUDDDDDUUUUUDDDDDDUUUUDDUDDUDDDUDUUUDUUDUDUDUUUDUDDDDUUDDUDDDDUDDDUDUUUDUUDUUUDDDDUUUDUUDDUUUUUDDDDUUDUUDDDDUDDUUDUUUDDDDUDUUUDDDUUDU", "output": "1995" }, { "input": "200\nLLLLRLLRLLRRRRLLRRLRRLRRRLLLRRLRRRRLLRRLLRRRLRLRLRRLLRLLRRLLLRRRRLRLLRLLLRLLLRRLLLRLRLRRRRRRRLRRRLRLRLLLLRLRRRRRLRRLRLLLLRLLLRRLRRLLRLRLLLRRLLRRLRRRRRLRLRRLRLLRLLLLRLRRRLRRLRLLRLRRLRRRRRLRRLLLRRRRRLLR", "output": "1368" }, { "input": "184\nUUUDDUDDDDDUDDDDUDDUUUUUDDDUUDDUDUUDUUUDDUDDDDDDDDDDUDUDDUUDDDUUDDUDUDDDUUDUDUUUUDDUDUUUDDUDUUUUDUUDDUUDUUUDUDUDDUDUDDDUUDDDDUUUUUDDDUDUDUDUDUDUUUDUDDUUDDUDUUDUDUUUDUUDDDDUDDDDUDUUDUUD", "output": "1243" }, { "input": "187\nRLLRLRRLLRRLRRRRLLRLLRLLLLRRRLLLRLLLLRRLRLRRRRRRLLRRLRLLRRRLLRRLLLRRLRRLRLLLLRRRRLRRLLRRLRRRRLLLLRRLRLRLRRRRRLLRLRLRLRLRLRLLLRLLLLLRRRLLRLRRRLLLRRLLLLLRLLRLLLRRRLLLRRLRRRLLLRRLRLLRRLRLRLR", "output": "1501" }, { "input": "190\nUULLLUUULLLULLUULUUUUULUUULLULLULUULLUULLUUULULUULLUULLUUULULLLLLLULLLLLULUULLULLULLLUULUULLLUUUULLLLUUULLUUULLLULULUULULLUULULULUUULLUUUULLUUULULUULLLLULLLLLUULLUULULLULUUUUUULULLLULLUULUUU", "output": "0" }, { "input": "46\nULUURRRRLDRDRDDDURRRLLLDDULLRRRRRLUDDLRDRULLLL", "output": "23" }, { "input": "70\nUUDRLDRDRUDLLURURULRDULRRDULDUDDRUULLDDDDDRLLRDURRDULRDLRUUUDDLRUURRLD", "output": "86" }, { "input": "198\nURLLUDRDUUDRDLLRURULLRRLRRUULRLULUUDRRURLRUURRDRUUDRLRURLLULRDDDDDRDDRRRLRUDULLDDLLLUDRLDRUDRDLDUULLUUUULULLRLDDRDURDRURLULDRURLLDDULURULDLUUUUULDLURRLLDLULLDULRUURRLDLLUUURDLDDUDUULRLUDULLULDRDRLRL", "output": "160" }, { "input": "22\nDUDDDURURUDURRUDRDULUL", "output": "10" }, { "input": "200\nUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUD", "output": "10000" }, { "input": "4\nRRDR", "output": "0" }, { "input": "6\nUULLLL", "output": "0" }, { "input": "2\nDU", "output": "1" }, { "input": "6\nUURRRR", "output": "0" }, { "input": "101\nRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", "output": "0" } ]
140
0
3
3,372
839
Game of the Rows
[ "brute force", "greedy", "implementation" ]
null
null
Daenerys Targaryen has an army consisting of *k* groups of soldiers, the *i*-th group contains *a**i* soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has *n* rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1,<=2}, {3,<=4}, {4,<=5}, {5,<=6} or {7,<=8}. Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats. Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=10000, 1<=≀<=*k*<=≀<=100)Β β€” the number of rows and the number of groups of soldiers, respectively. The second line contains *k* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**k* (1<=≀<=*a**i*<=≀<=10000), where *a**i* denotes the number of soldiers in the *i*-th group. It is guaranteed that *a*1<=+<=*a*2<=+<=...<=+<=*a**k*<=≀<=8Β·*n*.
If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes). You can choose the case (lower or upper) for each letter arbitrary.
[ "2 2\n5 8\n", "1 2\n7 1\n", "1 2\n4 4\n", "1 4\n2 2 1 2\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample, Daenerys can place the soldiers like in the figure below: In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group. In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats. In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).
[ { "input": "2 2\n5 8", "output": "YES" }, { "input": "1 2\n7 1", "output": "NO" }, { "input": "1 2\n4 4", "output": "YES" }, { "input": "1 4\n2 2 1 2", "output": "YES" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9938", "output": "YES" }, { "input": "100 15\n165 26 83 64 235 48 36 51 3 18 5 10 9 6 5", "output": "YES" }, { "input": "1 4\n2 2 2 2", "output": "NO" }, { "input": "5691 91\n6573 1666 2158 2591 4636 886 263 4217 389 29 1513 1172 617 2012 1855 798 1588 979 152 37 890 375 1091 839 385 382 1 255 117 289 119 224 182 69 19 71 115 13 4 22 35 2 60 12 6 12 19 9 3 2 2 6 5 1 7 7 3 1 5 1 7 1 4 1 1 3 2 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5631", "output": "NO" }, { "input": "2000 50\n203 89 1359 3105 898 1381 248 365 108 766 961 630 265 819 838 125 1751 289 177 81 131 564 102 95 49 74 92 101 19 17 156 5 5 4 20 9 25 16 16 2 8 5 4 2 1 3 4 1 3 2", "output": "NO" }, { "input": "10000 100\n800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800", "output": "YES" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 2050 1074 605 979 1724 1608 672 88 1243 129 718 544 3590 37 187 600 738 34 64 316 58 6 84 252 75 68 40 68 4 29 29 8 13 11 5 1 5 1 3 2 1 1 1 2 3 4 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 3", "output": "NO" }, { "input": "8459 91\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 107 213 52 110 323 81 98 8 7 73 20 12 56 3 40 12 8 7 69 1 14 3 6 2 6 8 3 5 4 4 3 1 1 4 2 1 1 1 8 2 2 2 1 1 1 2 8421", "output": "NO" }, { "input": "1 3\n2 3 2", "output": "YES" }, { "input": "10000 91\n2351 1402 1137 2629 4718 1138 1839 1339 2184 2387 165 370 918 1476 2717 879 1152 5367 3940 608 941 766 1256 656 2768 916 4176 489 1989 1633 2725 2329 2795 1970 667 340 1275 120 870 488 225 59 64 255 207 3 37 127 19 224 34 283 144 50 132 60 57 29 18 6 7 4 4 15 3 5 1 10 5 2 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 9948", "output": "YES" }, { "input": "10000 83\n64 612 2940 2274 1481 1713 860 1264 104 5616 2574 5292 4039 292 1416 854 3854 1140 4344 3904 1720 1968 442 884 2032 875 291 677 2780 3074 3043 2997 407 727 344 511 156 321 134 51 382 336 591 52 134 39 104 10 20 15 24 2 70 39 14 16 16 25 1 6 2 2 1 1 1 2 4 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 9968", "output": "YES" }, { "input": "4000 71\n940 1807 57 715 532 212 3842 2180 2283 744 1453 800 1945 380 2903 293 633 391 2866 256 102 46 228 1099 434 210 244 14 27 4 63 53 3 9 36 25 1 12 2 14 12 28 2 28 8 5 11 8 2 3 6 4 1 1 1 3 2 1 1 1 2 2 1 1 1 1 1 2 1 1 3966", "output": "YES" }, { "input": "3403 59\n1269 1612 453 795 1216 941 19 44 1796 324 2019 1397 651 382 841 2003 3013 638 1007 1001 351 95 394 149 125 13 116 183 20 78 208 19 152 10 151 177 16 23 17 22 8 1 3 2 6 1 5 3 13 1 8 4 3 4 4 4 2 2 3378", "output": "YES" }, { "input": "2393 33\n1381 2210 492 3394 912 2927 1189 269 66 102 104 969 395 385 369 354 251 28 203 334 20 10 156 29 61 13 30 4 1 32 2 2 2436", "output": "YES" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9939", "output": "NO" }, { "input": "10000 89\n1001 1531 2489 457 1415 617 2057 2658 3030 789 2500 3420 1550 376 720 78 506 293 1978 383 3195 2036 891 1741 1817 486 2650 360 2250 2531 3250 1612 2759 603 5321 1319 791 1507 265 174 877 1861 572 172 580 536 777 165 169 11 125 31 186 113 78 27 25 37 8 21 48 24 4 33 35 13 15 1 3 2 2 8 3 5 1 1 6 1 1 2 1 1 2 2 1 1 2 1 9953", "output": "NO" }, { "input": "4 16\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "NO" }, { "input": "10000 71\n110 14 2362 260 423 881 1296 3904 1664 849 57 631 1922 917 4832 1339 3398 4578 59 2663 2223 698 4002 3013 747 699 1230 2750 239 1409 6291 2133 1172 5824 181 797 26 281 574 557 19 82 624 387 278 53 64 163 22 617 15 35 42 48 14 140 171 36 28 22 5 49 17 5 10 14 13 1 3 3 9979", "output": "NO" }, { "input": "3495 83\n2775 2523 1178 512 3171 1159 1382 2146 2192 1823 799 231 502 16 99 309 656 665 222 285 11 106 244 137 241 45 41 29 485 6 62 38 94 5 7 93 48 5 10 13 2 1 2 1 4 8 5 9 4 6 1 1 1 3 4 3 7 1 2 3 1 1 7 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3443", "output": "NO" }, { "input": "1000 40\n1701 1203 67 464 1884 761 11 559 29 115 405 133 174 63 147 93 41 19 1 15 41 8 33 4 4 1 4 1 1 2 1 2 1 1 2 1 1 2 1 4", "output": "NO" }, { "input": "347 20\n55 390 555 426 140 360 29 115 23 113 58 30 33 1 23 3 35 5 7 363", "output": "NO" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9940", "output": "NO" }, { "input": "10000 93\n1388 119 711 23 4960 4002 2707 188 813 1831 334 543 338 3402 1808 3368 1428 971 985 220 1521 457 457 140 332 1503 1539 2095 1891 269 5223 226 1528 190 428 5061 410 1587 1149 1934 2275 1337 1828 275 181 85 499 29 585 808 751 401 635 461 181 164 274 36 401 255 38 60 76 16 6 35 79 46 1 39 11 2 8 2 4 14 3 1 1 1 1 1 2 1 3 1 1 1 1 2 1 1 9948", "output": "NO" }, { "input": "4981 51\n5364 2166 223 742 350 1309 15 229 4100 3988 227 1719 9 125 787 427 141 842 171 2519 32 2554 2253 721 775 88 720 9 397 513 100 291 111 32 238 42 152 108 5 58 96 53 7 19 11 2 5 5 6 2 4966", "output": "NO" }, { "input": "541 31\n607 204 308 298 398 213 1182 58 162 46 64 12 38 91 29 2 4 12 19 3 7 9 3 6 1 1 2 1 3 1 529", "output": "YES" }, { "input": "100 100\n6 129 61 6 87 104 45 28 3 35 2 14 1 37 2 4 24 4 3 1 6 4 2 1 1 3 1 2 2 9 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22", "output": "NO" }, { "input": "1 4\n2 2 2 1", "output": "YES" }, { "input": "1 3\n2 2 2", "output": "YES" }, { "input": "2 5\n8 2 2 2 2", "output": "YES" }, { "input": "1 4\n1 1 2 2", "output": "YES" }, { "input": "1 3\n2 2 3", "output": "YES" }, { "input": "1 3\n4 2 2", "output": "YES" }, { "input": "1 4\n2 1 2 2", "output": "YES" }, { "input": "1 3\n3 2 2", "output": "YES" }, { "input": "2 8\n2 2 2 2 2 2 1 1", "output": "YES" }, { "input": "2 6\n2 2 2 2 2 2", "output": "YES" }, { "input": "1 4\n1 2 2 2", "output": "YES" }, { "input": "1 4\n1 1 1 1", "output": "YES" }, { "input": "2 7\n2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 8\n1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "3 7\n12 2 2 2 2 2 2", "output": "YES" }, { "input": "2 6\n4 1 3 1 1 3", "output": "NO" }, { "input": "1 3\n2 2 4", "output": "YES" }, { "input": "5 15\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 8\n2 2 2 2 1 1 1 1", "output": "YES" }, { "input": "1 2\n6 2", "output": "YES" }, { "input": "4 13\n2 2 2 2 2 2 2 2 2 2 2 2 4", "output": "YES" }, { "input": "2 7\n1 1 1 4 2 2 2", "output": "YES" }, { "input": "3 8\n8 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 8\n1 1 1 1 2 2 2 2", "output": "YES" }, { "input": "2 8\n2 2 2 2 1 1 2 2", "output": "YES" }, { "input": "1 4\n2 2 1 1", "output": "YES" }, { "input": "3 9\n2 2 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 6\n2 2 2 2 2 5", "output": "YES" }, { "input": "1 1\n6", "output": "YES" }, { "input": "2 1\n16", "output": "YES" }, { "input": "1 1\n2", "output": "YES" }, { "input": "2 8\n2 2 2 2 2 2 2 1", "output": "NO" }, { "input": "4 16\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 7\n4 1 1 1 1 2 2", "output": "YES" }, { "input": "2 6\n2 2 2 5 2 2", "output": "YES" }, { "input": "3 1\n22", "output": "YES" }, { "input": "2 8\n2 2 2 2 1 1 1 3", "output": "NO" }, { "input": "3 12\n2 1 2 2 2 1 2 2 2 1 2 2", "output": "YES" }, { "input": "1 4\n2 2 3 1", "output": "NO" }, { "input": "2 6\n5 2 2 2 2 2", "output": "YES" }, { "input": "20 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "1 3\n2 2 1", "output": "YES" }, { "input": "1 2\n3 3", "output": "YES" }, { "input": "2 6\n2 3 2 2 3 2", "output": "YES" }, { "input": "2 8\n2 2 1 1 2 2 2 2", "output": "YES" }, { "input": "2 6\n3 3 2 2 2 2", "output": "YES" }, { "input": "3 12\n2 2 2 2 2 2 2 2 2 1 1 1", "output": "YES" }, { "input": "3 10\n2 2 2 2 2 2 2 2 2 3", "output": "YES" } ]
156
20,172,800
0
3,373
915
Permute Digits
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≀<=*a*<=≀<=1018). The second line contains integer *b* (1<=≀<=*b*<=≀<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" }, { "input": "123456789123456789\n276193619183618162", "output": "276193618987554432" }, { "input": "1000000000000000000\n1000000000000000000", "output": "1000000000000000000" }, { "input": "1\n1000000000000000000", "output": "1" }, { "input": "999999999999999999\n1000000000000000000", "output": "999999999999999999" }, { "input": "2475345634895\n3455834583479", "output": "3455834579642" }, { "input": "15778899\n98715689", "output": "98598771" }, { "input": "4555\n5454", "output": "4555" }, { "input": "122112\n221112", "output": "221112" }, { "input": "199999999999991\n191000000000000", "output": "119999999999999" }, { "input": "13\n31", "output": "31" }, { "input": "212\n211", "output": "122" }, { "input": "222234\n322223", "output": "243222" }, { "input": "123456789\n987654311", "output": "987654231" }, { "input": "20123\n21022", "output": "20321" }, { "input": "10101\n11000", "output": "10110" }, { "input": "592\n924", "output": "592" }, { "input": "5654456\n5634565", "output": "5566544" }, { "input": "655432\n421631", "output": "365542" }, { "input": "200\n200", "output": "200" }, { "input": "123456789987654321\n121111111111111111", "output": "119988776655443322" }, { "input": "12345\n21344", "output": "15432" }, { "input": "120\n200", "output": "120" }, { "input": "123\n212", "output": "132" }, { "input": "2184645\n5213118", "output": "5186442" }, { "input": "9912346\n9912345", "output": "9694321" }, { "input": "5003\n5000", "output": "3500" }, { "input": "12345\n31234", "output": "25431" }, { "input": "5001\n5000", "output": "1500" }, { "input": "53436\n53425", "output": "53364" }, { "input": "9329\n3268", "output": "2993" }, { "input": "1234567890\n9000000001", "output": "8976543210" }, { "input": "321\n212", "output": "132" }, { "input": "109823464\n901234467", "output": "896443210" }, { "input": "6543\n6542", "output": "6534" }, { "input": "555441\n555100", "output": "554541" }, { "input": "472389479\n327489423", "output": "327487994" }, { "input": "45645643756464352\n53465475637456247", "output": "53465475636654442" }, { "input": "254\n599", "output": "542" }, { "input": "5232222345652321\n5000000000000000", "output": "4655533322222221" }, { "input": "201\n200", "output": "120" }, { "input": "14362799391220361\n45160821596433661", "output": "43999766332221110" }, { "input": "3453\n5304", "output": "4533" }, { "input": "989\n998", "output": "998" }, { "input": "5200000000234\n5200000000311", "output": "5200000000243" }, { "input": "5555132\n1325442", "output": "1255553" }, { "input": "123\n211", "output": "132" }, { "input": "65689\n66123", "output": "65986" }, { "input": "123451234567890\n123456789012345", "output": "123456789012345" }, { "input": "22115\n22015", "output": "21521" }, { "input": "123\n311", "output": "231" }, { "input": "12222\n21111", "output": "12222" }, { "input": "765\n567", "output": "567" }, { "input": "9087645\n9087640", "output": "9087564" }, { "input": "1111111122222333\n2220000000000000", "output": "2213332221111111" }, { "input": "7901\n7108", "output": "7091" }, { "input": "215489\n215488", "output": "214985" }, { "input": "102\n200", "output": "120" }, { "input": "19260817\n20011213", "output": "19876210" }, { "input": "12345\n53200", "output": "53142" }, { "input": "1040003001\n1040003000", "output": "1040001300" }, { "input": "295\n924", "output": "592" }, { "input": "20000000000000001\n20000000000000000", "output": "12000000000000000" }, { "input": "99988877\n99887766", "output": "99879887" }, { "input": "12\n12", "output": "12" }, { "input": "199999999999999999\n900000000000000000", "output": "199999999999999999" }, { "input": "1234\n4310", "output": "4231" }, { "input": "100011\n100100", "output": "100011" }, { "input": "328899\n328811", "output": "299883" }, { "input": "646722972346\n397619201220", "output": "397476664222" }, { "input": "1203\n1200", "output": "1032" }, { "input": "1\n2", "output": "1" }, { "input": "1112\n2110", "output": "1211" }, { "input": "4545\n5540", "output": "5454" }, { "input": "3053\n5004", "output": "3530" }, { "input": "3503\n5004", "output": "3530" }, { "input": "351731653766064847\n501550303749042658", "output": "501548777666643331" }, { "input": "10123456789013451\n26666666666666666", "output": "26598754433111100" }, { "input": "1110111\n1100000", "output": "1011111" }, { "input": "30478\n32265", "output": "30874" }, { "input": "456546546549874615\n441554543131214545", "output": "441554498766665554" }, { "input": "214\n213", "output": "142" }, { "input": "415335582799619283\n133117803602859310", "output": "132999887655543321" }, { "input": "787\n887", "output": "877" }, { "input": "3333222288889999\n3333222288881111", "output": "3332999988883222" }, { "input": "495779862481416791\n836241745208800994", "output": "829998777665444111" }, { "input": "139\n193", "output": "193" }, { "input": "9568\n6500", "output": "5986" }, { "input": "3208899\n3228811", "output": "3209988" }, { "input": "27778\n28710", "output": "27877" }, { "input": "62345\n46415", "output": "46352" }, { "input": "405739873179209\n596793907108871", "output": "594998777332100" }, { "input": "365\n690", "output": "653" }, { "input": "8388731334391\n4710766672578", "output": "4398887333311" }, { "input": "1230\n1200", "output": "1032" }, { "input": "1025\n5000", "output": "2510" }, { "input": "4207799\n4027711", "output": "2997740" }, { "input": "4444222277779999\n4444222277771111", "output": "4442999977774222" }, { "input": "7430\n3047", "output": "3047" }, { "input": "649675735\n540577056", "output": "539776654" }, { "input": "26\n82", "output": "62" }, { "input": "241285\n207420", "output": "185422" }, { "input": "3\n3", "output": "3" }, { "input": "12\n21", "output": "21" }, { "input": "481287\n826607", "output": "824871" }, { "input": "40572351\n59676984", "output": "57543210" }, { "input": "268135787269\n561193454469", "output": "539887766221" }, { "input": "4\n9", "output": "4" }, { "input": "5\n6", "output": "5" }, { "input": "60579839\n33370073", "output": "30998765" }, { "input": "49939\n39200", "output": "34999" }, { "input": "2224\n4220", "output": "2422" }, { "input": "427799\n427711", "output": "299774" }, { "input": "49\n90", "output": "49" }, { "input": "93875\n82210", "output": "79853" }, { "input": "78831\n7319682", "output": "88731" }, { "input": "937177\n7143444", "output": "977731" }, { "input": "499380628\n391990337", "output": "390988642" }, { "input": "2090909\n2900000", "output": "2099900" }, { "input": "112233445566778890\n987654321987654320", "output": "987654321876543210" }, { "input": "48257086\n80903384", "output": "80876542" }, { "input": "112233445566778890\n900654321987654320", "output": "898776655443322110" }, { "input": "112233445566778890\n123456789123456788", "output": "123456789123456780" }, { "input": "5207799\n5027711", "output": "2997750" }, { "input": "200000000000000001\n200000000000000000", "output": "120000000000000000" }, { "input": "597402457\n797455420", "output": "797455420" }, { "input": "90\n94", "output": "90" }, { "input": "86888\n88683", "output": "86888" }, { "input": "419155888\n588151913", "output": "588151894" }, { "input": "408919130\n191830070", "output": "191830049" }, { "input": "524975\n554924", "output": "554792" }, { "input": "53029\n30524", "output": "30295" }, { "input": "5549\n5542", "output": "5495" }, { "input": "6\n9", "output": "6" }, { "input": "87\n810", "output": "87" }, { "input": "920491855\n281495062", "output": "281495059" }, { "input": "6691\n6910", "output": "6691" }, { "input": "533\n335", "output": "335" }, { "input": "999999999999999998\n999999999999999997", "output": "999999999999999989" }, { "input": "21111111111111111\n21111111111111110", "output": "12111111111111111" }, { "input": "2\n12", "output": "2" }, { "input": "76544\n45744", "output": "45674" }, { "input": "2000000000000001\n2000000000000000", "output": "1200000000000000" }, { "input": "740867\n467701", "output": "467087" }, { "input": "2\n6", "output": "2" }, { "input": "103\n130", "output": "130" }, { "input": "2423712\n8466235", "output": "7432221" }, { "input": "84\n48", "output": "48" }, { "input": "1210\n12113", "output": "2110" }, { "input": "2430\n20786", "output": "4320" }, { "input": "100\n999", "output": "100" }, { "input": "19325\n21903", "output": "21593" }, { "input": "1969\n23251", "output": "9961" } ]
62
0
3
3,374
777
Game of Credit Cards
[ "data structures", "dp", "greedy", "sortings" ]
null
null
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick. Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks. Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of digits in the cards Sherlock and Moriarty are going to use. The second line contains *n* digitsΒ β€” Sherlock's credit card number. The third line contains *n* digitsΒ β€” Moriarty's credit card number.
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
[ "3\n123\n321\n", "2\n88\n00\n" ]
[ "0\n2\n", "2\n0\n" ]
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
[ { "input": "3\n123\n321", "output": "0\n2" }, { "input": "2\n88\n00", "output": "2\n0" }, { "input": "1\n4\n5", "output": "0\n1" }, { "input": "1\n8\n7", "output": "1\n0" }, { "input": "2\n55\n55", "output": "0\n0" }, { "input": "3\n534\n432", "output": "1\n1" }, { "input": "3\n486\n024", "output": "2\n0" }, { "input": "5\n22222\n22222", "output": "0\n0" }, { "input": "5\n72471\n05604", "output": "2\n3" }, { "input": "5\n72471\n72471", "output": "0\n3" }, { "input": "5\n72471\n41772", "output": "0\n3" }, { "input": "8\n99999999\n99999999", "output": "0\n0" }, { "input": "8\n01234567\n01234567", "output": "0\n7" }, { "input": "8\n07070707\n76543210", "output": "3\n4" }, { "input": "8\n88888888\n98769876", "output": "4\n2" }, { "input": "8\n23456789\n01234567", "output": "2\n5" }, { "input": "5\n11222\n22111", "output": "1\n2" }, { "input": "9\n777777777\n777777777", "output": "0\n0" }, { "input": "9\n353589343\n280419388", "output": "3\n5" }, { "input": "10\n8104381743\n8104381743", "output": "0\n8" }, { "input": "10\n8104381743\n8418134730", "output": "0\n8" }, { "input": "10\n1111122222\n2222211111", "output": "0\n5" }, { "input": "100\n6317494220822818719411404030346382869796138932712461187067886456209071515048745855973784223939110171\n6017563370120161528504797580620647099370814387367549926215651181421345104088127581963662589996747937", "output": "2\n86" }, { "input": "200\n89017372169770060638462517044634884577600285180365791227828841983192945639410766634962149214165390392679430585962408483864914959904870801002680423351144765728677610509881245693518626747873607530273392\n34804385048475325130258121398275821439066233953856051421626677848150660724595847484466293487857039579239864150199164135152374201294909986469345076423004279983866383035554588630496127880705497919788390", "output": "6\n175" }, { "input": "3\n112\n111", "output": "1\n0" }, { "input": "5\n66666\n11119", "output": "4\n1" }, { "input": "3\n232\n123", "output": "1\n1" } ]
156
0
3
3,379
439
Devu, the Dumb Guy
[ "implementation", "sortings" ]
null
null
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other words he can learn a chapter of a particular subject in *x* hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the *n* subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type.
The first line will contain two space separated integers *n*, *x* (1<=≀<=*n*,<=*x*<=≀<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≀<=*c**i*<=≀<=105).
Output a single integer representing the answer to the problem.
[ "2 3\n4 1\n", "4 2\n5 1 2 1\n", "3 3\n1 1 1\n" ]
[ "11\n", "10\n", "6\n" ]
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.
[ { "input": "2 3\n4 1", "output": "11" }, { "input": "4 2\n5 1 2 1", "output": "10" }, { "input": "3 3\n1 1 1", "output": "6" }, { "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "output": "65" }, { "input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3", "output": "196" }, { "input": "1 1\n9273", "output": "9273" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 2\n1", "output": "2" }, { "input": "1 2\n2", "output": "4" }, { "input": "2 1\n1 2", "output": "3" } ]
186
7,577,600
3
3,383
86
Reflection
[ "math" ]
A. Reflection
2
256
For each positive integer *n* consider the integer ψ(*n*) which is obtained from *n* by replacing every digit *a* in the decimal notation of *n* with the digit (9<=<=-<=<=*a*). We say that ψ(*n*) is the reflection of *n*. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89<==<=890. Your task is to find the maximum weight of the numbers in the given range [*l*,<=*r*] (boundaries are included).
Input contains two space-separated integers *l* and *r* (1<=≀<=*l*<=≀<=*r*<=≀<=109) β€” bounds of the range.
Output should contain single integer number: maximum value of the product *n*·ψ(*n*), where *l*<=≀<=*n*<=≀<=*r*. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).
[ "3 7\n", "1 1\n", "8 10\n" ]
[ "20", "8", "890" ]
In the third sample weight of 8 equals 8Β·1 = 8, weight of 9 equals 9Β·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890.
[ { "input": "3 7", "output": "20" }, { "input": "1 1", "output": "8" }, { "input": "8 10", "output": "890" }, { "input": "4 6", "output": "20" }, { "input": "10 100", "output": "89900" }, { "input": "1 999", "output": "249500" }, { "input": "40 60", "output": "2450" }, { "input": "66 74", "output": "2178" }, { "input": "27 71", "output": "2450" }, { "input": "66 95", "output": "2178" }, { "input": "48 51", "output": "2450" }, { "input": "9999999 9999999", "output": "0" }, { "input": "555555 555555", "output": "246913086420" }, { "input": "942 572335596", "output": "249999999500000000" }, { "input": "2331 77424372", "output": "2499999950000000" }, { "input": "314 592188442", "output": "249999999500000000" }, { "input": "6277 181089912", "output": "148296355590742344" }, { "input": "163 306093048", "output": "212400093659976648" }, { "input": "9265 978077465", "output": "249999999500000000" }, { "input": "934 300539101", "output": "210215349469572698" }, { "input": "850 629417171", "output": "249999999500000000" }, { "input": "9015 34697316", "output": "2265827827698828" }, { "input": "595 416293084", "output": "242993151797475860" }, { "input": "3722 867350896", "output": "249999999500000000" }, { "input": "3019 712663676", "output": "249999999500000000" }, { "input": "74 25339", "output": "1891809740" }, { "input": "99 59212", "output": "2499950000" }, { "input": "90 19714", "output": "1582738490" }, { "input": "13 43460", "output": "2457184940" }, { "input": "79 12776", "output": "1114361048" }, { "input": "93 31801", "output": "2168764598" }, { "input": "2 36352", "output": "2313695744" }, { "input": "71990 79486", "output": "2016367910" }, { "input": "58067 66986", "output": "2434865444" }, { "input": "29426 33865", "output": "2239627910" }, { "input": "86189 88384", "output": "1190270090" }, { "input": "46811 52308", "output": "2499950000" }, { "input": "960440942 978948770", "output": "37994137969711694" }, { "input": "366632331 444054372", "output": "246870086263631244" }, { "input": "291070314 465398755", "output": "248802753379051220" }, { "input": "880006277 941096188", "output": "105595228560592994" }, { "input": "191970163 690033048", "output": "249999999500000000" }, { "input": "916069265 970899369", "output": "76886365806290510" }, { "input": "609160934 909699101", "output": "238083889879086710" }, { "input": "21640850 672697171", "output": "249999999500000000" }, { "input": "645009015 679697316", "output": "228972384923720760" }, { "input": "862630595 866814866", "output": "118499050707315380" }, { "input": "51473722 970290896", "output": "249999999500000000" }, { "input": "578453019 869566694", "output": "243845123231332620" }, { "input": "484380637 865372184", "output": "249999999500000000" }, { "input": "541659852 795298538", "output": "248264456189678244" }, { "input": "491257592 512099550", "output": "249999999500000000" }, { "input": "796685541 970363166", "output": "161977688964851778" }, { "input": "733403773 763985558", "output": "195522678015960698" }, { "input": "19971607 162619978", "output": "136174720592659538" }, { "input": "446235722 812546691", "output": "249999999500000000" }, { "input": "885351316 940613198", "output": "101504362371716828" }, { "input": "578176478 671720904", "output": "243888437709339038" }, { "input": "380300819 475584338", "output": "249403874973517418" }, { "input": "419917095 599395901", "output": "249999999500000000" }, { "input": "1 1000000000", "output": "8999999999000000000" }, { "input": "9999 100000001", "output": "90000000699999998" }, { "input": "999999998 999999999", "output": "999999998" }, { "input": "1000000000 1000000000", "output": "8999999999000000000" }, { "input": "999999999 1000000000", "output": "8999999999000000000" }, { "input": "1 2", "output": "14" }, { "input": "91516955 100003356", "output": "90002684688733908" }, { "input": "91769999 100006528", "output": "90005222257378688" }, { "input": "91713375 100004340", "output": "90003471881160060" }, { "input": "91933994 100016179", "output": "90012942838223780" }, { "input": "91504334 100015113", "output": "90012090071582118" }, { "input": "91921683 100018777", "output": "90015021147405494" }, { "input": "91274316 100009110", "output": "90007287816998790" }, { "input": "91135741 100003483", "output": "90002786287865228" }, { "input": "2 2", "output": "14" }, { "input": "4999 4999", "output": "24995000" }, { "input": "4999 5000", "output": "24995000" }, { "input": "5000 5000", "output": "24995000" }, { "input": "6680315 7297787", "output": "22176534820460" }, { "input": "400000001 999999998", "output": "249999999500000000" }, { "input": "100000000 999999999", "output": "249999999500000000" }, { "input": "1 4", "output": "20" }, { "input": "999999999 999999999", "output": "0" }, { "input": "6 7", "output": "18" } ]
92
0
0
3,403
712
Memory and De-Evolution
[ "greedy", "math" ]
null
null
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y*?
The first and only line contains two integers *x* and *y* (3<=≀<=*y*<=&lt;<=*x*<=≀<=100<=000)Β β€” the starting and ending equilateral triangle side lengths respectively.
Print a single integerΒ β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*.
[ "6 3\n", "8 5\n", "22 4\n" ]
[ "4\n", "3\n", "6\n" ]
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*, *b*, *c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21c6.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcfd51d1b2d764a1cf5fbc255cc02e6f5aaed3b1.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample test, Memory can do: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0969b7d413854c1e7528991d926bef1f7ffba008.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/63e9e66b882c03e4c73e93ad92204dc255329309.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "6 3", "output": "4" }, { "input": "8 5", "output": "3" }, { "input": "22 4", "output": "6" }, { "input": "4 3", "output": "3" }, { "input": "57 27", "output": "4" }, { "input": "61 3", "output": "9" }, { "input": "5 4", "output": "3" }, { "input": "10 6", "output": "3" }, { "input": "20 10", "output": "4" }, { "input": "30 5", "output": "6" }, { "input": "25 24", "output": "3" }, { "input": "25 3", "output": "7" }, { "input": "12 7", "output": "3" }, { "input": "18 6", "output": "5" }, { "input": "100000 3", "output": "25" }, { "input": "100000 9999", "output": "7" }, { "input": "9999 3", "output": "20" }, { "input": "5323 32", "output": "13" }, { "input": "6666 66", "output": "12" }, { "input": "38578 32201", "output": "3" }, { "input": "49449 5291", "output": "7" }, { "input": "65310 32879", "output": "3" }, { "input": "41183 4453", "output": "7" }, { "input": "49127 9714", "output": "6" }, { "input": "19684 12784", "output": "3" }, { "input": "15332 5489", "output": "4" }, { "input": "33904 32701", "output": "3" }, { "input": "9258 2966", "output": "5" }, { "input": "21648 11231", "output": "3" }, { "input": "90952 47239", "output": "3" }, { "input": "49298 23199", "output": "4" }, { "input": "33643 24915", "output": "3" }, { "input": "40651 5137", "output": "6" }, { "input": "52991 15644", "output": "5" }, { "input": "97075 62157", "output": "3" }, { "input": "82767 53725", "output": "3" }, { "input": "58915 26212", "output": "4" }, { "input": "86516 16353", "output": "6" }, { "input": "14746 7504", "output": "3" }, { "input": "20404 7529", "output": "4" }, { "input": "52614 8572", "output": "6" }, { "input": "50561 50123", "output": "3" }, { "input": "37509 7908", "output": "5" }, { "input": "36575 23933", "output": "3" }, { "input": "75842 8002", "output": "7" }, { "input": "47357 2692", "output": "8" }, { "input": "23214 4255", "output": "6" }, { "input": "9474 46", "output": "13" }, { "input": "79874 76143", "output": "3" }, { "input": "63784 31333", "output": "4" }, { "input": "70689 29493", "output": "4" }, { "input": "43575 4086", "output": "7" }, { "input": "87099 7410", "output": "7" }, { "input": "75749 55910", "output": "3" }, { "input": "87827 20996", "output": "5" }, { "input": "31162 4580", "output": "6" }, { "input": "63175 33696", "output": "3" }, { "input": "15108 10033", "output": "3" }, { "input": "82991 29195", "output": "4" }, { "input": "48258 12837", "output": "5" }, { "input": "59859 33779", "output": "3" }, { "input": "93698 23890", "output": "5" }, { "input": "42724 379", "output": "12" }, { "input": "70434 39286", "output": "3" }, { "input": "69826 18300", "output": "5" }, { "input": "57825 17636", "output": "5" }, { "input": "64898 2076", "output": "9" }, { "input": "76375 67152", "output": "3" }, { "input": "30698 3778", "output": "7" }, { "input": "100 3", "output": "10" }, { "input": "41 3", "output": "8" }, { "input": "28 4", "output": "7" }, { "input": "2487 19", "output": "12" }, { "input": "100000 25000", "output": "5" }, { "input": "10000 3", "output": "20" }, { "input": "16 3", "output": "6" } ]
77
0
3
3,406
580
Kefa and Park
[ "dfs and similar", "graphs", "trees" ]
null
null
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them. The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than *m* consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go.
The first line contains two integers, *n* and *m* (2<=≀<=*n*<=≀<=105, 1<=≀<=*m*<=≀<=*n*) β€” the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then vertex *i* has no cat), or equals to 1 (then vertex *i* has a cat). Next *n*<=-<=1 lines contains the edges of the tree in the format "*x**i* *y**i*" (without the quotes) (1<=≀<=*x**i*,<=*y**i*<=≀<=*n*, *x**i*<=β‰ <=*y**i*), where *x**i* and *y**i* are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree.
A single integer β€” the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats.
[ "4 1\n1 1 0 0\n1 2\n1 3\n1 4\n", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n" ]
[ "2\n", "2\n" ]
Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children. Note to the first sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/785114b4b3f5336f02078c25750f87c5a1d0b4be.png" style="max-width: 100.0%;max-height: 100.0%;"/> The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2. Note to the second sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/e5c07640680c837aec99126d94287872e69aa09a.png" style="max-width: 100.0%;max-height: 100.0%;"/> The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7.
[ { "input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4", "output": "2" }, { "input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "output": "2" }, { "input": "3 2\n1 1 1\n1 2\n2 3", "output": "0" }, { "input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5", "output": "1" }, { "input": "6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6", "output": "3" }, { "input": "7 3\n1 1 1 1 1 0 1\n1 2\n1 3\n2 4\n3 5\n5 6\n6 7", "output": "2" }, { "input": "15 2\n1 0 1 0 1 0 0 0 0 0 0 0 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15", "output": "8" }, { "input": "2 1\n1 1\n2 1", "output": "0" }, { "input": "12 3\n1 0 1 0 1 1 1 1 0 0 0 0\n6 7\n12 1\n9 7\n1 4\n10 7\n7 1\n11 8\n5 1\n3 7\n5 8\n4 2", "output": "7" } ]
31
307,200
0
3,414
33
String Problem
[ "shortest paths" ]
B. String Problem
2
256
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary character *A**i* in one of the strings into arbitrary character *B**i*, but he has to pay for every move a particular sum of money, equal to *W**i*. He is allowed to make as many moves as he needs. Since Valera is a very economical boy and never wastes his money, he asked you, an experienced programmer, to help him answer the question: what minimum amount of money should Valera have to get identical strings.
The first input line contains two initial non-empty strings *s* and *t*, consisting of lower case Latin letters. The length of each string doesn't exceed 105. The following line contains integer *n* (0<=≀<=*n*<=≀<=500)Β β€” amount of possible changings. Then follow *n* lines, each containing characters *A**i* and *B**i* (lower case Latin letters) and integer *W**i* (0<=≀<=*W**i*<=≀<=100), saying that it's allowed to change character *A**i* into character *B**i* in any of the strings and spend sum of money *W**i*.
If the answer exists, output the answer to the problem, and the resulting string. Otherwise output -1 in the only line. If the answer is not unique, output any.
[ "uayd\nuxxd\n3\na x 8\nx y 13\nd c 3\n", "a\nb\n3\na b 2\na b 3\nb a 5\n", "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0\n" ]
[ "21\nuxyd\n", "2\nb\n", "-1\n" ]
none
[ { "input": "uayd\nuxxd\n3\na x 8\nx y 13\nd c 3", "output": "21\nuxyd" }, { "input": "a\nb\n3\na b 2\na b 3\nb a 5", "output": "2\nb" }, { "input": "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0", "output": "-1" }, { "input": "xhtuopq\nrtutbz\n10\nh x 10\nx d 3\nr u 4\nu d 1\nt o 100\no t 7\np e 1\ne f 1\nb f 2\nz q 19", "output": "-1" }, { "input": "abad\nabad\n6\na c 3\nb x 100\nd e 7\nr r 10\no t 17\na a 4", "output": "0\nabad" }, { "input": "bbad\nabxd\n4\nb a 7\na b 10\nx a 0\nd t 19", "output": "7\nabad" }, { "input": "abcd\nacer\n6\nb c 100\nc b 10\nc x 1\ne x 3\nc e 7\nr d 11", "output": "25\nabxd" }, { "input": "abac\ncbad\n7\na c 100\nx y 21\nb i 90\nd e 89\nc z 12\nt r 66\na g 78", "output": "-1" }, { "input": "wye\nupt\n13\nz z 5\ne t 8\nt f 2\nf e 3\np l 16\nl s 6\ns q 13\ny o 4\no q 0\nu w 5\nk m 14\nm i 10\nw u 12", "output": "49\nwqe" }, { "input": "xyz\nopr\n10\nx y 0\ny x 0\ny u 4\nu i 3\ni r 2\nr t 1\no w 6\nw t 9\nz r 3\np y 3", "output": "31\ntxr" }, { "input": "aaaaaaaaaa\naaaaaaaaaa\n50\na a 47\na a 40\na a 22\na a 48\na a 37\na a 26\na a 40\na a 28\na a 8\na a 46\na a 42\na a 37\na a 1\na a 0\na a 16\na a 34\na a 12\na a 50\na a 45\na a 49\na a 12\na a 8\na a 32\na a 17\na a 13\na a 1\na a 1\na a 33\na a 1\na a 15\na a 9\na a 11\na a 31\na a 5\na a 18\na a 13\na a 11\na a 20\na a 14\na a 19\na a 15\na a 50\na a 44\na a 23\na a 25\na a 49\na a 7\na a 8\na a 28\na a 38", "output": "0\naaaaaaaaaa" }, { "input": "srumlvfvdnvbwycrtkwnnmsbotsoaf\nuwizokwweugnbegnhjrfdhsfioufvs\n10\nw o 40\nn d 36\nu w 34\nm o 27\nr a 7\ni o 63\ng g 52\ng k 4\ns d 20\ny c 26", "output": "-1" }, { "input": "habege\necjecg\n0", "output": "-1" }, { "input": "babaafbfde\neccefffbee\n10\nm c 15\ng b 5\nh n 6\nm j 12\nl h 7\nd b 15\nm n 0\na f 11\nk d 1\nb a 10", "output": "-1" }, { "input": "bbabcbcbbbccacaaabbb\nccbbbacbbbbcbbcacbba\n5\ne b 72\na a 92\nc b 57\ne a 94\ne d 62", "output": "-1" }, { "input": "bc\nad\n8\nt y 11\nb c 12\nc x 6\nx y 4\nd x 2\na z 4\nz y 2\ne w 1", "output": "36\nyx" } ]
1,964
22,732,800
3.466657
3,416
237
Young Table
[ "implementation", "sortings" ]
null
null
You've got table *a*, consisting of *n* rows, numbered from 1 to *n*. The *i*-th line of table *a* contains *c**i* cells, at that for all *i* (1<=&lt;<=*i*<=≀<=*n*) holds *c**i*<=≀<=*c**i*<=-<=1. Let's denote *s* as the total number of cells of table *a*, that is, . We know that each cell of the table contains a single integer from 1 to *s*, at that all written integers are distinct. Let's assume that the cells of the *i*-th row of table *a* are numbered from 1 to *c**i*, then let's denote the number written in the *j*-th cell of the *i*-th row as *a**i*,<=*j*. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all *i*,<=*j* (1<=&lt;<=*i*<=≀<=*n*;Β 1<=≀<=*j*<=≀<=*c**i*) holds *a**i*,<=*j*<=&gt;<=*a**i*<=-<=1,<=*j*; 1. for all *i*,<=*j* (1<=≀<=*i*<=≀<=*n*;Β 1<=&lt;<=*j*<=≀<=*c**i*) holds *a**i*,<=*j*<=&gt;<=*a**i*,<=*j*<=-<=1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than *s*. You do not have to minimize the number of operations.
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=50) that shows the number of rows in the table. The second line contains *n* space-separated integers *c**i* (1<=≀<=*c**i*<=≀<=50;Β *c**i*<=≀<=*c**i*<=-<=1) β€” the numbers of cells on the corresponding rows. Next *n* lines contain table *Π°*. The *i*-th of them contains *c**i* space-separated integers: the *j*-th integer in this line represents *a**i*,<=*j*. It is guaranteed that all the given numbers *a**i*,<=*j* are positive and do not exceed *s*. It is guaranteed that all *a**i*,<=*j* are distinct.
In the first line print a single integer *m* (0<=≀<=*m*<=≀<=*s*), representing the number of performed swaps. In the next *m* lines print the description of these swap operations. In the *i*-th line print four space-separated integers *x**i*,<=*y**i*,<=*p**i*,<=*q**i* (1<=≀<=*x**i*,<=*p**i*<=≀<=*n*;Β 1<=≀<=*y**i*<=≀<=*c**x**i*;Β 1<=≀<=*q**i*<=≀<=*c**p**i*). The printed numbers denote swapping the contents of cells *a**x**i*,<=*y**i* and *a**p**i*,<=*q**i*. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed.
[ "3\n3 2 1\n4 3 5\n6 1\n2\n", "1\n4\n4 3 2 1\n" ]
[ "2\n1 1 2 2\n2 1 3 1\n", "2\n1 1 1 4\n1 2 1 3\n" ]
none
[ { "input": "3\n3 2 1\n4 3 5\n6 1\n2", "output": "2\n1 1 2 2\n2 1 3 1" }, { "input": "1\n4\n4 3 2 1", "output": "2\n1 1 1 4\n1 2 1 3" }, { "input": "5\n4 4 3 3 1\n14 13 4 15\n11 1 2 5\n7 6 10\n8 9 3\n12", "output": "13\n1 1 2 2\n1 2 2 3\n1 3 4 3\n1 4 4 3\n2 1 2 4\n2 2 3 2\n2 3 3 1\n2 4 4 1\n3 1 4 2\n3 2 3 3\n3 3 4 1\n4 1 5 1\n4 3 5 1" }, { "input": "2\n8 6\n1 2 3 13 10 4 11 7\n9 12 8 5 14 6", "output": "7\n1 4 1 6\n1 5 2 4\n1 6 2 6\n1 7 1 8\n1 8 2 3\n2 2 2 4\n2 5 2 6" }, { "input": "6\n10 9 7 6 4 3\n18 20 29 19 5 28 31 30 32 15\n38 33 11 8 39 2 6 9 3\n13 37 27 24 26 1 17\n36 10 35 21 7 16\n22 23 4 12\n34 25 14", "output": "33\n1 1 3 6\n1 2 2 6\n1 3 2 9\n1 4 5 3\n1 6 2 7\n1 7 4 5\n1 8 2 4\n1 9 2 8\n1 10 4 2\n2 1 2 3\n2 2 5 4\n2 3 3 1\n2 4 6 3\n2 5 4 2\n2 6 4 6\n2 7 3 7\n2 8 3 6\n2 9 5 3\n3 1 4 6\n3 2 4 4\n3 3 5 1\n3 4 5 2\n3 5 5 2\n3 6 6 2\n3 7 5 2\n4 1 5 1\n4 2 5 2\n4 3 5 3\n4 4 6 3\n4 6 6 2\n5 1 5 4\n5 2 6 1\n6 1 6 3" }, { "input": "8\n2 2 2 2 1 1 1 1\n10 9\n11 5\n7 3\n2 6\n12\n1\n8\n4", "output": "9\n1 1 6 1\n1 2 4 1\n2 1 3 2\n2 2 8 1\n3 1 8 1\n3 2 4 2\n4 1 8 1\n4 2 7 1\n5 1 8 1" }, { "input": "4\n3 3 3 2\n6 3 11\n10 7 1\n9 4 5\n2 8", "output": "8\n1 1 2 3\n1 2 4 1\n1 3 4 1\n2 1 3 2\n2 2 3 3\n3 1 3 3\n3 2 4 2\n4 1 4 2" }, { "input": "1\n1\n1", "output": "0" }, { "input": "2\n35 7\n6 8 35 9 28 25 10 41 33 39 19 24 5 12 30 40 18 2 4 11 32 13 31 21 14 27 3 34 37 16 17 29 1 42 36\n20 23 38 15 26 7 22", "output": "39\n1 1 1 33\n1 2 1 18\n1 3 1 27\n1 4 1 19\n1 5 1 13\n1 6 1 33\n1 7 2 6\n1 8 1 18\n1 9 1 19\n1 10 2 6\n1 11 1 20\n1 12 1 14\n1 13 1 22\n1 14 1 25\n1 15 2 4\n1 16 1 30\n1 17 1 31\n1 18 1 31\n1 19 1 20\n1 20 2 1\n1 21 1 24\n1 22 2 7\n1 23 2 2\n1 24 1 25\n1 25 1 33\n1 26 2 5\n1 27 2 5\n1 28 2 7\n1 29 1 32\n1 30 2 4\n1 31 2 2\n1 32 1 33\n1 33 2 1\n1 34 2 7\n1 35 2 5\n2 1 2 5\n2 2 2 5\n2 4 2 6\n2 5 2 6" }, { "input": "3\n36 28 14\n46 15 35 60 41 65 73 33 18 20 68 22 28 23 67 44 2 24 21 51 37 3 48 69 12 50 32 72 45 53 17 47 56 52 29 57\n8 62 10 19 26 64 7 49 6 25 34 63 74 31 14 43 30 4 11 76 16 55 36 5 70 61 77 27\n38 40 1 78 58 42 66 71 75 59 54 9 39 13", "output": "73\n1 1 3 3\n1 2 1 17\n1 3 1 22\n1 4 2 18\n1 5 2 24\n1 6 2 9\n1 7 2 7\n1 8 2 1\n1 9 3 12\n1 10 2 3\n1 11 2 19\n1 12 1 25\n1 13 3 14\n1 14 2 15\n1 15 1 17\n1 16 2 21\n1 17 1 31\n1 18 3 12\n1 19 2 4\n1 20 2 3\n1 21 2 4\n1 22 1 25\n1 23 2 15\n1 24 3 12\n1 25 2 10\n1 26 2 5\n1 27 2 28\n1 28 3 14\n1 29 1 35\n1 30 2 17\n1 31 2 14\n1 32 2 28\n1 33 2 1\n1 34 2 11\n1 35 2 10\n1 36 2 23\n2 1 2 4\n2 2 3 1\n2 3 3 13\n2 4 3 2\n2 5 2 24\n2 6 3 6\n2 7 2 16\n2 8 2 21\n2 9 2 10\n2 10 3 3\n2 11 2 28\n2 12 2 15\n2 13 2 21\n2..." }, { "input": "4\n40 40 24 5\n56 14 59 76 92 34 43 96 33 44 72 37 81 27 42 5 7 95 22 4 60 18 61 103 74 84 93 55 3 62 70 82 77 51 86 102 29 67 91 9\n71 53 21 64 17 45 46 101 97 30 109 100 57 16 80 87 28 12 94 23 39 98 32 52 54 10 19 41 90 11 66 65 99 89 40 36 58 20 78 108\n35 88 73 75 104 63 79 31 1 26 2 50 24 83 15 49 106 48 105 47 8 68 107 38\n69 85 13 25 6", "output": "106\n1 1 3 9\n1 2 3 11\n1 3 1 29\n1 4 1 20\n1 5 1 16\n1 6 4 5\n1 7 1 17\n1 8 3 21\n1 9 1 40\n1 10 2 26\n1 11 2 30\n1 12 2 18\n1 13 4 3\n1 14 3 11\n1 15 3 15\n1 16 2 14\n1 17 2 5\n1 18 1 22\n1 19 2 27\n1 20 2 38\n1 21 2 3\n1 22 2 27\n1 23 2 20\n1 24 3 13\n1 25 4 4\n1 26 3 10\n1 27 3 11\n1 28 2 17\n1 29 1 37\n1 30 2 10\n1 31 3 8\n1 32 2 23\n1 33 1 40\n1 34 4 5\n1 35 3 1\n1 36 2 36\n1 37 2 18\n1 38 3 24\n1 39 2 21\n1 40 2 35\n2 1 2 28\n2 2 3 15\n2 3 2 5\n2 4 2 26\n2 5 2 6\n2 6 2 7\n2 7 3 20\n2 8 3 18\n2 9 3 1..." }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n6\n42\n43\n50\n36\n39\n13\n44\n16\n25\n11\n23\n15\n46\n10\n45\n1\n37\n20\n5\n8\n48\n35\n12\n38\n40\n2\n4\n21\n31\n22\n18\n27\n26\n41\n34\n9\n14\n24\n17\n30\n28\n32\n47\n33\n49\n19\n3\n29\n7", "output": "48\n1 1 17 1\n2 1 27 1\n3 1 48 1\n4 1 28 1\n5 1 20 1\n6 1 17 1\n7 1 50 1\n8 1 21 1\n9 1 37 1\n10 1 15 1\n12 1 24 1\n13 1 50 1\n14 1 38 1\n15 1 50 1\n16 1 37 1\n17 1 40 1\n18 1 32 1\n19 1 47 1\n20 1 47 1\n21 1 29 1\n22 1 31 1\n23 1 24 1\n24 1 39 1\n25 1 50 1\n26 1 34 1\n27 1 33 1\n28 1 42 1\n29 1 49 1\n30 1 41 1\n31 1 41 1\n32 1 43 1\n33 1 45 1\n34 1 36 1\n35 1 39 1\n36 1 47 1\n37 1 43 1\n38 1 50 1\n39 1 40 1\n40 1 47 1\n41 1 47 1\n42 1 45 1\n43 1 48 1\n44 1 49 1\n45 1 48 1\n46 1 50 1\n47 1 49 1\n48 1 49 1\n..." }, { "input": "49\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n71 11\n56 27\n72 51\n65 46\n36 55\n34 60\n31 18\n22 52\n63 59\n37 17\n3 48\n35 69\n8 29\n4 19\n10 1\n33 32\n62 26\n9 64\n12 57\n30 25\n7 38\n15 14\n61 68\n50 28\n21\n58\n47\n2\n13\n44\n20\n23\n73\n49\n43\n54\n70\n16\n39\n41\n42\n66\n5\n6\n53\n24\n67\n45\n40", "output": "67\n1 1 15 2\n1 2 28 1\n2 1 11 1\n2 2 14 1\n3 1 43 1\n3 2 44 1\n4 1 21 1\n4 2 13 1\n5 1 18 1\n5 2 15 1\n6 1 28 1\n6 2 19 1\n7 1 29 1\n7 2 22 2\n8 1 22 1\n8 2 38 1\n9 1 10 2\n9 2 22 2\n10 1 14 2\n10 2 31 1\n11 1 25 1\n11 2 22 1\n12 1 32 1\n12 2 46 1\n13 1 20 2\n13 2 17 2\n14 2 24 2\n15 1 17 2\n15 2 20 1\n16 1 29 1\n17 1 29 1\n17 2 28 1\n18 1 32 1\n18 2 32 1\n19 1 24 2\n19 2 21 2\n20 1 39 1\n20 2 49 1\n21 1 40 1\n21 2 41 1\n22 1 35 1\n22 2 30 1\n23 1 48 1\n23 2 49 1\n24 1 27 1\n24 2 35 1\n25 1 34 1\n26 1 27 ..." }, { "input": "48\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n90 26 28\n70 20 1\n11 10 9\n69 84 30\n73 63 61\n17 58 41\n54 57 51\n88 4 32\n85 33 34\n40 80 77\n93 7 3\n38 75 53\n79 74 81\n91 76 87\n22 2 59\n86 82 60\n24 52\n92 72\n49 6\n8 65\n50 25\n46 16\n42 48\n78 37\n39 71\n31 5\n19 43\n64 67\n36 45\n18\n89\n55\n15\n56\n13\n27\n47\n23\n14\n68\n62\n83\n66\n29\n35\n44\n21\n12", "output": "88\n1 1 2 3\n1 2 15 2\n1 3 11 3\n2 1 8 2\n2 2 26 2\n2 3 19 2\n3 1 11 2\n3 2 20 1\n4 1 20 1\n4 2 11 2\n4 3 48 1\n5 1 35 1\n5 2 39 1\n5 3 33 1\n6 1 22 2\n6 2 22 2\n6 3 30 1\n7 1 27 1\n7 2 26 2\n7 3 47 1\n8 1 15 1\n8 2 38 1\n8 3 17 1\n9 1 21 2\n9 2 15 2\n9 3 36 1\n10 1 11 3\n10 2 44 1\n10 3 48 1\n11 1 26 1\n11 2 17 1\n11 3 15 2\n12 1 36 1\n12 2 45 1\n12 3 29 1\n13 1 24 2\n13 2 36 1\n13 3 25 1\n14 1 15 2\n14 2 30 1\n14 3 23 1\n15 1 27 2\n15 2 46 1\n15 3 29 2\n16 1 22 1\n16 2 37 1\n16 3 23 2\n17 1 19 1\n17 2 21..." }, { "input": "5\n5 2 2 2 1\n1 3 4 5 12\n2 6\n8 9\n7 10\n11", "output": "8\n1 2 2 1\n1 3 2 1\n1 4 2 1\n1 5 2 1\n2 1 2 2\n2 2 4 1\n4 1 4 2\n4 2 5 1" }, { "input": "5\n5 4 3 2 1\n1 2 3 4 5\n6 7 8 9\n10 11 12\n13 14\n15", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "4\n4 4 2 2\n1 2 3 4\n5 6 7 8\n9 10\n11 12", "output": "0" }, { "input": "1\n50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50", "output": "0" } ]
62
0
0
3,417
475
CGCDSSQ
[ "brute force", "data structures", "math" ]
null
null
Given a sequence of integers *a*1,<=...,<=*a**n* and *q* queries *x*1,<=...,<=*x**q* on it. For each query *x**i* you have to count the number of pairs (*l*,<=*r*) such that 1<=≀<=*l*<=≀<=*r*<=≀<=*n* and *gcd*(*a**l*,<=*a**l*<=+<=1,<=...,<=*a**r*)<==<=*x**i*. is a greatest common divisor of *v*1,<=*v*2,<=...,<=*v**n*, that is equal to a largest positive integer that divides all *v**i*.
The first line of the input contains integer *n*, (1<=≀<=*n*<=≀<=105), denoting the length of the sequence. The next line contains *n* space separated integers *a*1,<=...,<=*a**n*, (1<=≀<=*a**i*<=≀<=109). The third line of the input contains integer *q*, (1<=≀<=*q*<=≀<=3<=Γ—<=105), denoting the number of queries. Then follows *q* lines, each contain an integer *x**i*, (1<=≀<=*x**i*<=≀<=109).
For each query print the result in a separate line.
[ "3\n2 6 3\n5\n1\n2\n3\n4\n6\n", "7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000\n" ]
[ "1\n2\n2\n0\n1\n", "14\n0\n2\n2\n2\n0\n2\n2\n1\n1\n" ]
none
[ { "input": "3\n2 6 3\n5\n1\n2\n3\n4\n6", "output": "1\n2\n2\n0\n1" }, { "input": "7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000", "output": "14\n0\n2\n2\n2\n0\n2\n2\n1\n1" }, { "input": "10\n2 2 4 3 2 4 4 2 4 2\n104\n3\n3\n1\n4\n1\n1\n4\n1\n1\n3\n1\n1\n4\n1\n1\n1\n4\n3\n1\n1\n4\n1\n1\n1\n1\n1\n4\n1\n1\n1\n4\n1\n1\n4\n1\n1\n1\n1\n1\n4\n4\n1\n3\n1\n4\n1\n1\n1\n4\n1\n2\n4\n1\n4\n1\n4\n1\n4\n3\n1\n2\n2\n4\n2\n1\n1\n2\n4\n4\n1\n2\n3\n1\n1\n4\n4\n4\n4\n4\n2\n2\n4\n1\n1\n1\n1\n4\n2\n1\n1\n4\n1\n4\n3\n4\n4\n1\n2\n3\n1\n2\n1\n3\n1", "output": "1\n1\n27\n5\n27\n27\n5\n27\n27\n1\n27\n27\n5\n27\n27\n27\n5\n1\n27\n27\n5\n27\n27\n27\n27\n27\n5\n27\n27\n27\n5\n27\n27\n5\n27\n27\n27\n27\n27\n5\n5\n27\n1\n27\n5\n27\n27\n27\n5\n27\n22\n5\n27\n5\n27\n5\n27\n5\n1\n27\n22\n22\n5\n22\n27\n27\n22\n5\n5\n27\n22\n1\n27\n27\n5\n5\n5\n5\n5\n22\n22\n5\n27\n27\n27\n27\n5\n22\n27\n27\n5\n27\n5\n1\n5\n5\n27\n22\n1\n27\n22\n27\n1\n27" } ]
108
5,836,800
0
3,420
491
Up the hill
[ "constructive algorithms", "implementation" ]
null
null
Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through. It is known that there were *N* stops, all on different integer heights between 1 and *N* kilometers (inclusive) above the sea level. On the first day they've traveled from the first stop to the second stop, on the second day they've traveled from the second to the third and so on, and on the last day they've traveled from the stop *N*<=-<=1 to the stop *N* and successfully finished their expedition. They are trying to find out which heights were their stops located at. They have an entry in a travel journal specifying how many days did they travel up the hill, and how many days did they walk down the hill. Help them by suggesting some possible stop heights satisfying numbers from the travel journal.
In the first line there is an integer non-negative number *A* denoting the number of days of climbing up the hill. Second line contains an integer non-negative number *B*Β β€” the number of days of walking down the hill (*A*<=+<=*B*<=+<=1<==<=*N*, 1<=≀<=*N*<=≀<=100<=000).
Output *N* space-separated distinct integers from 1 to *N* inclusive, denoting possible heights of the stops in order of visiting.
[ "0\n1\n", "2\n1" ]
[ "2 1 \n", "1 3 4 2" ]
none
[ { "input": "0\n1", "output": "2 1 " }, { "input": "2\n1", "output": "2 3 4 1 " }, { "input": "0\n3", "output": "4 3 2 1 " }, { "input": "1\n1", "output": "2 3 1 " }, { "input": "3\n7", "output": "8 9 10 11 7 6 5 4 3 2 1 " }, { "input": "700\n300", "output": "301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428..." }, { "input": "37\n29", "output": "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 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "177\n191", "output": "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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319..." }, { "input": "50000\n3", "output": "4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 1..." }, { "input": "99999\n0", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "0\n99999", "output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..." }, { "input": "24999\n74997", "output": "74998 74999 75000 75001 75002 75003 75004 75005 75006 75007 75008 75009 75010 75011 75012 75013 75014 75015 75016 75017 75018 75019 75020 75021 75022 75023 75024 75025 75026 75027 75028 75029 75030 75031 75032 75033 75034 75035 75036 75037 75038 75039 75040 75041 75042 75043 75044 75045 75046 75047 75048 75049 75050 75051 75052 75053 75054 75055 75056 75057 75058 75059 75060 75061 75062 75063 75064 75065 75066 75067 75068 75069 75070 75071 75072 75073 75074 75075 75076 75077 75078 75079 75080 75081 75082 7..." }, { "input": "17\n61111", "output": "61112 61113 61114 61115 61116 61117 61118 61119 61120 61121 61122 61123 61124 61125 61126 61127 61128 61129 61111 61110 61109 61108 61107 61106 61105 61104 61103 61102 61101 61100 61099 61098 61097 61096 61095 61094 61093 61092 61091 61090 61089 61088 61087 61086 61085 61084 61083 61082 61081 61080 61079 61078 61077 61076 61075 61074 61073 61072 61071 61070 61069 61068 61067 61066 61065 61064 61063 61062 61061 61060 61059 61058 61057 61056 61055 61054 61053 61052 61051 61050 61049 61048 61047 61046 61045 6..." }, { "input": "50021\n40009", "output": "40010 40011 40012 40013 40014 40015 40016 40017 40018 40019 40020 40021 40022 40023 40024 40025 40026 40027 40028 40029 40030 40031 40032 40033 40034 40035 40036 40037 40038 40039 40040 40041 40042 40043 40044 40045 40046 40047 40048 40049 40050 40051 40052 40053 40054 40055 40056 40057 40058 40059 40060 40061 40062 40063 40064 40065 40066 40067 40068 40069 40070 40071 40072 40073 40074 40075 40076 40077 40078 40079 40080 40081 40082 40083 40084 40085 40086 40087 40088 40089 40090 40091 40092 40093 40094 4..." }, { "input": "49999\n49997", "output": "49998 49999 50000 50001 50002 50003 50004 50005 50006 50007 50008 50009 50010 50011 50012 50013 50014 50015 50016 50017 50018 50019 50020 50021 50022 50023 50024 50025 50026 50027 50028 50029 50030 50031 50032 50033 50034 50035 50036 50037 50038 50039 50040 50041 50042 50043 50044 50045 50046 50047 50048 50049 50050 50051 50052 50053 50054 50055 50056 50057 50058 50059 50060 50061 50062 50063 50064 50065 50066 50067 50068 50069 50070 50071 50072 50073 50074 50075 50076 50077 50078 50079 50080 50081 50082 5..." }, { "input": "6777\n57897", "output": "57898 57899 57900 57901 57902 57903 57904 57905 57906 57907 57908 57909 57910 57911 57912 57913 57914 57915 57916 57917 57918 57919 57920 57921 57922 57923 57924 57925 57926 57927 57928 57929 57930 57931 57932 57933 57934 57935 57936 57937 57938 57939 57940 57941 57942 57943 57944 57945 57946 57947 57948 57949 57950 57951 57952 57953 57954 57955 57956 57957 57958 57959 57960 57961 57962 57963 57964 57965 57966 57967 57968 57969 57970 57971 57972 57973 57974 57975 57976 57977 57978 57979 57980 57981 57982 5..." }, { "input": "49999\n49999", "output": "50000 50001 50002 50003 50004 50005 50006 50007 50008 50009 50010 50011 50012 50013 50014 50015 50016 50017 50018 50019 50020 50021 50022 50023 50024 50025 50026 50027 50028 50029 50030 50031 50032 50033 50034 50035 50036 50037 50038 50039 50040 50041 50042 50043 50044 50045 50046 50047 50048 50049 50050 50051 50052 50053 50054 50055 50056 50057 50058 50059 50060 50061 50062 50063 50064 50065 50066 50067 50068 50069 50070 50071 50072 50073 50074 50075 50076 50077 50078 50079 50080 50081 50082 50083 50084 5..." }, { "input": "1\n0", "output": "1 2 " }, { "input": "0\n1", "output": "2 1 " }, { "input": "0\n0", "output": "1 " }, { "input": "2\n0", "output": "1 2 3 " }, { "input": "5\n0", "output": "1 2 3 4 5 6 " }, { "input": "90000\n1", "output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1..." }, { "input": "100\n4", "output": "5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 4 3 2 1 " } ]
124
20,172,800
0
3,439
166
Median
[ "greedy", "math", "sortings" ]
null
null
A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) β€” the number 17. We define an expression as the integer part of dividing number *a* by number *b*. One day Vasya showed Petya an array consisting of *n* integers and suggested finding the array's median. Petya didn't even look at the array and said that it equals *x*. Petya is a very honest boy, so he decided to add several numbers to the given array so that the median of the resulting array would be equal to *x*. Petya can add any integers from 1 to 105 to the array, including the same numbers. Of course, he can add nothing to the array. If a number is added multiple times, then we should consider it the number of times it occurs. It is not allowed to delete of change initial numbers of the array. While Petya is busy distracting Vasya, your task is to find the minimum number of elements he will need.
The first input line contains two space-separated integers *n* and *x* (1<=≀<=*n*<=≀<=500, 1<=≀<=*x*<=≀<=105) β€” the initial array's length and the required median's value. The second line contains *n* space-separated numbers β€” the initial array. The elements of the array are integers from 1 to 105. The array elements are not necessarily different.
Print the only integer β€” the minimum number of elements Petya needs to add to the array so that its median equals *x*.
[ "3 10\n10 20 30\n", "3 4\n1 2 3\n" ]
[ "1\n", "4\n" ]
In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7dd92241318a531b780c7783dfa446a3e413115e.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 10. In the second sample you should add numbers 4, 5, 5, 5. The resulting array has median equal to 4.
[ { "input": "3 10\n10 20 30", "output": "1" }, { "input": "3 4\n1 2 3", "output": "4" }, { "input": "2 2\n3 2", "output": "0" }, { "input": "5 1\n1 1 2 1 2", "output": "0" }, { "input": "5 4\n5 5 4 3 5", "output": "1" }, { "input": "10 2\n2 2 1 3 2 1 2 1 1 3", "output": "0" }, { "input": "10 55749\n46380 58202 54935 26290 18295 83040 6933 89652 75187 93963", "output": "1" }, { "input": "10 809\n949 31 175 118 640 588 809 398 792 743", "output": "7" }, { "input": "50 1\n1 2 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 2 1 2 1 1 2 1 1 1 2 2 2 2 2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2", "output": "12" }, { "input": "100 6\n7 5 2 8 4 9 4 8 6 1 7 8 7 8 1 5 4 10 9 10 7 5 6 2 1 6 9 10 6 5 10 9 9 5 1 4 4 5 4 4 1 1 6 7 4 9 3 5 6 5 6 3 7 6 9 4 4 8 7 10 6 10 4 6 6 5 1 9 6 7 10 1 9 4 5 3 7 7 4 4 7 4 7 3 3 7 2 5 5 3 8 9 6 9 4 5 5 9 1 7", "output": "0" }, { "input": "100 813\n285 143 378 188 972 950 222 557 170 755 470 164 800 553 146 820 842 62 496 980 746 944 677 828 465 577 791 277 303 515 561 653 925 692 871 424 626 795 813 343 418 280 123 364 496 447 435 404 645 141 169 315 830 289 450 675 81 212 509 661 7 217 468 877 172 141 475 409 178 71 936 843 761 889 417 282 530 612 328 572 310 632 498 271 19 753 3 787 31 266 251 897 450 206 731 678 64 417 664 224", "output": "69" }, { "input": "100 37\n20 20 3 35 36 14 30 9 33 36 32 46 43 22 43 50 34 6 13 25 1 34 10 6 21 30 19 17 1 23 9 23 38 21 7 43 49 28 33 42 4 19 39 23 12 42 31 13 26 23 1 26 24 48 10 6 12 48 40 18 10 26 9 5 22 45 46 23 46 34 34 45 3 7 16 39 14 29 48 1 12 37 4 20 29 26 35 38 20 47 39 29 12 35 4 32 26 1 50 33", "output": "53" }, { "input": "100 20\n40 44 41 81 59 96 91 49 57 41 44 42 65 31 74 70 54 47 51 7 71 7 75 79 13 20 2 78 66 34 81 84 18 37 85 42 5 40 17 15 66 10 95 93 20 43 63 83 60 61 9 33 68 81 97 25 39 37 22 90 63 45 33 89 1 68 37 66 89 86 6 29 40 33 44 11 83 21 11 32 92 41 45 79 29 86 89 87 14 1 32 22 25 90 56 6 1 49 15 89", "output": "58" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 2\n1", "output": "2" }, { "input": "1 1\n2", "output": "1" }, { "input": "4 1\n2 3 4 5", "output": "4" }, { "input": "9 228\n1 1 1 1 1 1 228 228 228", "output": "4" } ]
124
0
3
3,442
478
Initial Bet
[ "implementation" ]
null
null
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size *b* of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins *b* in the initial bet.
The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 β€” the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=≀<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=≀<=100).
Print the only line containing a single positive integer *b* β€” the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity).
[ "2 5 4 0 4\n", "4 5 9 2 1\n" ]
[ "3\n", "-1\n" ]
In the first sample the following sequence of operations is possible: 1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to the second player.
[ { "input": "2 5 4 0 4", "output": "3" }, { "input": "4 5 9 2 1", "output": "-1" }, { "input": "0 0 0 0 0", "output": "-1" }, { "input": "1 2 1 2 3", "output": "-1" }, { "input": "100 0 0 0 0", "output": "20" }, { "input": "2 3 4 5 6", "output": "4" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "0 1 2 3 4", "output": "2" }, { "input": "100 100 100 100 100", "output": "100" }, { "input": "93 100 99 90 98", "output": "96" }, { "input": "99 99 99 99 99", "output": "99" }, { "input": "99 98 98 99 100", "output": "-1" }, { "input": "43 83 1 0 23", "output": "30" }, { "input": "43 83 1 100 23", "output": "50" }, { "input": "57 83 11 4 93", "output": "-1" }, { "input": "87 38 19 33 100", "output": "-1" }, { "input": "56 0 0 0 4", "output": "12" }, { "input": "0 0 0 0 1", "output": "-1" }, { "input": "99 100 100 100 100", "output": "-1" } ]
46
0
0
3,446
277
Learning Languages
[ "dfs and similar", "dsu" ]
null
null
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
The first line contains two integers *n* and *m* (2<=≀<=*n*,<=*m*<=≀<=100) β€” the number of employees and the number of languages. Then *n* lines follow β€” each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≀<=*k**i*<=≀<=*m*) β€” the number of languages the *i*-th employee knows. Next, the *i*-th line contains *k**i* integers β€” *a**ij* (1<=≀<=*a**ij*<=≀<=*m*) β€” the identifiers of languages the *i*-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces.
Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
[ "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "2 2\n1 2\n0\n" ]
[ "0\n", "2\n", "1\n" ]
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2.
[ { "input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "output": "0" }, { "input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "output": "2" }, { "input": "2 2\n1 2\n0", "output": "1" }, { "input": "2 2\n0\n0", "output": "2" }, { "input": "5 5\n1 3\n0\n0\n2 4 1\n0", "output": "4" }, { "input": "6 2\n0\n0\n2 1 2\n1 1\n1 1\n0", "output": "3" }, { "input": "7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1", "output": "0" }, { "input": "8 4\n0\n0\n4 2 3 1 4\n4 2 1 4 3\n3 4 3 1\n1 2\n2 4 1\n2 4 2", "output": "2" }, { "input": "10 10\n5 7 5 2 8 1\n7 10 6 9 5 8 2 4\n2 2 7\n5 8 6 9 10 1\n2 9 5\n3 6 5 2\n6 5 8 7 9 10 4\n0\n1 1\n2 8 6", "output": "1" }, { "input": "11 42\n4 20 26 9 24\n14 34 7 28 32 12 15 26 4 10 38 21 20 8 11\n4 21 8 36 6\n11 32 1 39 11 21 10 25 17 26 15 4\n2 8 12\n2 21 31\n8 17 10 3 39 32 30 5 15\n20 24 20 38 17 4 7 21 19 32 28 31 22 30 37 10 5 33 2 13 9\n7 38 34 42 27 20 11 6\n3 40 3 39\n14 39 40 4 30 33 8 36 28 14 23 16 7 25 9", "output": "0" }, { "input": "100 100\n1 33\n0\n2 35 4\n2 40 78\n1 69\n0\n1 2\n0\n0\n2 81 34\n1 45\n0\n1 87\n1 50\n1 97\n0\n2 100 59\n0\n0\n0\n1 45\n0\n0\n0\n1 6\n1 54\n0\n0\n0\n4 79 96 52 84\n1 86\n0\n0\n0\n0\n0\n0\n0\n0\n3 90 2 80\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 2\n0\n1 64\n0\n1 78\n1 82\n0\n0\n0\n0\n0\n1 6\n0\n0\n2 47 57\n1 95\n0\n2 91 79\n0\n1 27\n0\n1 74\n0\n0\n1 14\n0\n0\n2 90 19\n0\n1 10\n0\n0\n0\n0\n0\n1 57\n0\n2 28 50\n0\n0\n0\n1 47\n0\n0\n1 14\n0\n1 84\n1 1\n0\n0", "output": "87" }, { "input": "2 2\n2 1 2\n2 1 2", "output": "0" }, { "input": "2 2\n2 1 2\n1 1", "output": "0" }, { "input": "2 2\n1 2\n1 1", "output": "1" }, { "input": "3 100\n0\n0\n0", "output": "3" }, { "input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "100" }, { "input": "3 3\n0\n0\n0", "output": "3" } ]
218
307,200
0
3,448
0
none
[ "none" ]
null
null
One day, Hongcow goes to the store and sees a brand new deck of *n* special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store. This game takes some number of turns to complete. On a turn, Hongcow may do one of two things: - Collect tokens. Hongcow collects 1 red token and 1 blue token by choosing this option (thus, 2 tokens in total per one operation). - Buy a card. Hongcow chooses some card and spends tokens to purchase it as specified below. The *i*-th card requires *r**i* red resources and *b**i* blue resources. Suppose Hongcow currently has *A* red cards and *B* blue cards. Then, the *i*-th card will require Hongcow to spend *max*(*r**i*<=-<=*A*,<=0) red tokens, and *max*(*b**i*<=-<=*B*,<=0) blue tokens. Note, only tokens disappear, but the cards stay with Hongcow forever. Each card can be bought only once. Given a description of the cards and their costs determine the minimum number of turns Hongcow needs to purchase all cards.
The first line of input will contain a single integer *n* (1<=≀<=*n*<=≀<=16). The next *n* lines of input will contain three tokens *c**i*, *r**i* and *b**i*. *c**i* will be 'R' or 'B', denoting the color of the card as red or blue. *r**i* will be an integer denoting the amount of red resources required to obtain the card, and *b**i* will be an integer denoting the amount of blue resources required to obtain the card (0<=≀<=*r**i*,<=*b**i*<=≀<=107).
Output a single integer, denoting the minimum number of turns needed to acquire all the cards.
[ "3\nR 0 1\nB 1 0\nR 1 1\n", "3\nR 3 0\nR 2 0\nR 1 0\n" ]
[ "4\n", "6\n" ]
For the first sample, Hongcow's four moves are as follows: 1. Collect tokens 1. Buy card 1 1. Buy card 2 1. Buy card 3 For the second sample, one optimal strategy is as follows: 1. Collect tokens 1. Collect tokens 1. Buy card 2 1. Collect tokens 1. Buy card 3 1. Buy card 1
[]
61
204,800
0
3,457
920
Tea Queue
[ "implementation" ]
null
null
Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea. *i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
The first line contains one integer *t* β€” the number of test cases to solve (1<=≀<=*t*<=≀<=1000). Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of students. Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=5000) β€” the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition *l**i*<=-<=1<=≀<=*l**i* holds. The sum of *n* over all test cases doesn't exceed 1000. Note that in hacks you have to set *t*<==<=1.
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
[ "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n" ]
[ "1 2 \n1 0 2 \n" ]
The example contains 2 tests: 1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
[ { "input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3", "output": "1 2 \n1 0 2 " }, { "input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000", "output": "1 \n1 \n1 \n1 \n2 \n2 \n2 \n2 \n1999 \n1999 \n2000 \n1 0 \n1 2 \n1 0 \n1 0 \n1 2 \n1 2 \n2 0 \n2 3 " }, { "input": "1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1 0 0 0 0 0 0 0 0 0 0 " }, { "input": "1\n5\n1 1\n1 2\n1 5\n1 1\n1 1", "output": "1 2 3 0 0 " } ]
77
5,734,400
3
3,459
526
King of Thieves
[ "brute force", "implementation" ]
null
null
In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level. A dungeon consists of *n* segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'. One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number *i*1, he can make a sequence of jumps through the platforms *i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**k*, if *i*2<=-<=*i*1<==<=*i*3<=-<=*i*2<==<=...<==<=*i**k*<=-<=*i**k*<=-<=1. Of course, all segments *i*1,<=*i*2,<=... *i**k* should be exactly the platforms, not pits. Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence *i*1,<=*i*2,<=...,<=*i*5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of segments on the level. Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'.
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
[ "16\n.**.*..*.***.**.\n", "11\n.*.*...*.*.\n" ]
[ "yes", "no" ]
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
[ { "input": "16\n.**.*..*.***.**.", "output": "yes" }, { "input": "11\n.*.*...*.*.", "output": "no" }, { "input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.", "output": "yes" }, { "input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**", "output": "yes" }, { "input": "56\n**.*..*...***.*.**.**..**.*.*.*.**...*.**.**....*...**..", "output": "yes" }, { "input": "64\n***.*...*...*.***.....*.....**.*****.*.*...*..*.*..***..*...***.", "output": "yes" }, { "input": "99\n.*..**..*..*..**...***.****.*...*....*****.....**..****.*..*....****..**..*****..*....**.*.**..**..", "output": "yes" }, { "input": "89\n..**..**..*.********....*.*****.**.****...*......*******..*.**.*****..*..****....*...**..", "output": "yes" }, { "input": "99\n..*.*..**.*.*.******.*.*.**.**.**.*..**.*.*****..*.*.****.*....**....*****.....***..**....***.*.*.*", "output": "yes" }, { "input": "5\n*****", "output": "yes" }, { "input": "10\n.*.*.*.*.*", "output": "yes" }, { "input": "51\n....****....*........*.*..**........*....****....*.", "output": "no" }, { "input": "98\n.**..**.*****..***...*.**..*..*....*******..**....*.****.**.*.....*.**..***.**..***.*******..****.", "output": "yes" }, { "input": "45\n.***..******....***..**..*.*.*.**..**..*.**..", "output": "yes" }, { "input": "67\n..**.*...*.....****.***.**.*....***..***.*..***.....*******.....*.*", "output": "yes" }, { "input": "97\n...*..*...*******.*.**..**..******.*.*..*****.*...***.*.**.**.**..**.******.****.*.***.**..*...**", "output": "yes" }, { "input": "87\n*..*..***.**.*...****...*....***....***......*..*.*.*****.**..*.***...*.****..**.*..***", "output": "yes" }, { "input": "99\n***....*.....****.*.**.*.*.**.*.*.*..*...*..*...***..*.*...*.*...***.*.*...**.**.*******....**....*", "output": "yes" }, { "input": "90\n**....****.***..***.*.*****...*.*.***..***.******.**...***..*...*****..*.**.**...*..**...*", "output": "yes" }, { "input": "58\n**.*.*.**..******.**.*..*.**.*.*******.**.*.**.*..*****.*.", "output": "yes" }, { "input": "75\n..*.**..*.*****.......*....*.*.*..**.*.***.*.***....******.****.*.....****.", "output": "yes" }, { "input": "72\n.***.**.*.*...*****.*.*.*.*.**....**.*.**..*.*...**..***.**.**..*.**..**", "output": "yes" }, { "input": "69\n.***...*.***.**...*....*.***.*..*....**.*...**....*.*..**....**..*.**", "output": "yes" }, { "input": "42\n..*...*.*..**..*.*.*..**...**.***.*.******", "output": "yes" }, { "input": "54\n...***.*...****.*..****....*..**..**..***.*..**...**..", "output": "yes" }, { "input": "55\n...*..*.*.**..*.*....*.****..****....*..***.*****..*..*", "output": "yes" }, { "input": "57\n**...*....**.**.*.******.**..**.*.....**.***..***...**..*", "output": "yes" }, { "input": "97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.", "output": "yes" }, { "input": "42\n***.*..*.*.***...**..*..**....**..*..*...*", "output": "yes" }, { "input": "99\n**...*.*.*..*....**.***..*...***..***.**.*.....*.*....*...*.**.**.****..**..*.*..*.***....**...**.*", "output": "yes" }, { "input": "1\n.", "output": "no" }, { "input": "1\n*", "output": "no" }, { "input": "99\n.*.......................*.......................*.......................*.......................*.", "output": "yes" }, { "input": "99\n.*.......................*...............................................*.......................*.", "output": "no" }, { "input": "100\n****************************************************************************************************", "output": "yes" }, { "input": "99\n***************************************************************************************************", "output": "yes" }, { "input": "5\n.****", "output": "no" }, { "input": "5\n*.***", "output": "no" }, { "input": "5\n**.**", "output": "no" }, { "input": "5\n***.*", "output": "no" }, { "input": "5\n****.", "output": "no" }, { "input": "100\n*...............................................................................................****", "output": "no" }, { "input": "11\n.**.*..*.**", "output": "no" }, { "input": "21\n*.*...*.*...*.*...*.*", "output": "no" }, { "input": "6\n***.**", "output": "no" }, { "input": "13\n*..*..*..*..*", "output": "yes" }, { "input": "4\n****", "output": "no" }, { "input": "17\n.*..*..*.....*..*", "output": "no" }, { "input": "7\n***.***", "output": "no" }, { "input": "20\n.*..*...*....*.....*", "output": "no" }, { "input": "11\n*...**..*.*", "output": "no" }, { "input": "10\n*****....*", "output": "yes" }, { "input": "16\n*.**.**.**.*..*.", "output": "yes" }, { "input": "10\n.*.*.*.*..", "output": "no" }, { "input": "17\n*...*...*...*...*", "output": "yes" }, { "input": "15\n..........*****", "output": "yes" } ]
61
0
0
3,460