contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
0
11
title
stringclasses
522 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
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
217
A
Ice Skating
PROGRAMMING
1,200
[ "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
500
[ { "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" } ]
1,669,392,988
2,147,483,647
PyPy 3
OK
TESTS
76
186
1,740,800
n = int(input()) points = [] for _ in range(n): x, y = list(map(int, input().split(' '))) points.append((x, y)) seen = set() def dfs(x, y, tmp): seen.add((x, y)) tmp.append((x, y)) for nx, ny in points: if (nx, ny) not in seen and (nx == x or ny == y): dfs(nx, ny, tmp) cc = [] for x, y in points: if (x, y) not in seen: tmp = [] dfs(x, y, tmp) cc.append(tmp) ans = len(cc) - 1 print(ans)
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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. Input Specification: 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 Specification: 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. Demo Input: ['2\n2 1\n1 2\n', '2\n2 1\n4 1\n'] Demo Output: ['1\n', '0\n'] Note: none
```python n = int(input()) points = [] for _ in range(n): x, y = list(map(int, input().split(' '))) points.append((x, y)) seen = set() def dfs(x, y, tmp): seen.add((x, y)) tmp.append((x, y)) for nx, ny in points: if (nx, ny) not in seen and (nx == x or ny == y): dfs(nx, ny, tmp) cc = [] for x, y in points: if (x, y) not in seen: tmp = [] dfs(x, y, tmp) cc.append(tmp) ans = len(cc) - 1 print(ans) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,590,789,056
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
80
248
307,200
import math n = int(input()) arraylist = [] for i in range(0,n): current = list(map(int,input().strip().split(" "))) arraylist.append(current) def sum (array): sum = 0 for i in range(0, len(array)): sum += array[i] return sum n = len(arraylist) sumarr = [] for i in range(0, len(arraylist)): sumarr.append(sum(arraylist[i])) totalsum = sum(sumarr) if totalsum == 0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python import math n = int(input()) arraylist = [] for i in range(0,n): current = list(map(int,input().strip().split(" "))) arraylist.append(current) def sum (array): sum = 0 for i in range(0, len(array)): sum += array[i] return sum n = len(arraylist) sumarr = [] for i in range(0, len(arraylist)): sumarr.append(sum(arraylist[i])) totalsum = sum(sumarr) if totalsum == 0: print('YES') else: print('NO') ```
0
631
A
Interview
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109).
Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
[ "5\n1 2 4 3 2\n2 3 3 12 1\n", "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n" ]
[ "22", "46" ]
Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5. In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9.
500
[ { "input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22" }, { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46" }, { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116", "output": "254" }, { "input": "20\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64", "output": "128" }, { "input": "1\n1000000000\n1000000000", "output": "2000000000" }, { "input": "1\n0\n0", "output": "0" }, { "input": "2\n7 16\n16 7", "output": "46" }, { "input": "4\n6 0 0 0\n0 0 0 1", "output": "7" }, { "input": "8\n1 2 4 8 16 32 64 128\n1 2 4 8 16 32 64 128", "output": "510" }, { "input": "1\n2\n3", "output": "5" }, { "input": "1\n4\n3", "output": "7" }, { "input": "1\n1\n1", "output": "2" } ]
1,551,131,984
284
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
614,400
n=int(input()) maxf = -9999; p=input().rstrip().split(' ') q=input().rstrip().split(' ') for i in range(0,len(p)): for j in range(i,len(p)): y=p[i:j+1] Y=q[i:j+1] S=0; D=0; F=0; for k in range(0,len(y)): S=S|int(y[k]) D=D|int(Y[k]) F=S+D; if F>maxf: maxf = F; print(maxf)
Title: Interview Time Limit: None seconds Memory Limit: None megabytes Problem Description: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). Output Specification: Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Demo Input: ['5\n1 2 4 3 2\n2 3 3 12 1\n', '10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n'] Demo Output: ['22', '46'] Note: Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5. In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9.
```python n=int(input()) maxf = -9999; p=input().rstrip().split(' ') q=input().rstrip().split(' ') for i in range(0,len(p)): for j in range(i,len(p)): y=p[i:j+1] Y=q[i:j+1] S=0; D=0; F=0; for k in range(0,len(y)): S=S|int(y[k]) D=D|int(Y[k]) F=S+D; if F>maxf: maxf = F; print(maxf) ```
0
946
C
String Transformation
PROGRAMMING
1,300
[ "greedy", "strings" ]
null
null
You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.
The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters.
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
[ "aacceeggiikkmmooqqssuuwwyy\n", "thereisnoanswer\n" ]
[ "abcdefghijklmnopqrstuvwxyz\n", "-1\n" ]
none
0
[ { "input": "aacceeggiikkmmooqqssuuwwyy", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "thereisnoanswer", "output": "-1" }, { "input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs", "output": "-1" }, { "input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaa" }, { "input": "abcdefghijklmnopqrstuvwxxx", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvwxya", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "cdaaaaaaaaabcdjklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "cdabcdefghijklmnopqrstuvwxyzxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "zazaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zazbcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abbbefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaa" }, { "input": "abcdefghijklmaopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvwxyx", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaz" }, { "input": "zaaaazaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zabcdzefghijklmnopqrstuvwxyzaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaa" }, { "input": "aaaaaafghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyzz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "abcdefghijklmnopqrstuvwxyzaaaaaz" }, { "input": "abcdefghijklmnopqrstuvwaxy", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaa" }, { "input": "abcdefghijklmnapqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvnxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaa" }, { "input": "abcdefghijklmnopqrstuvwxyzzzz", "output": "abcdefghijklmnopqrstuvwxyzzzz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aacceeggiikkmmooqqssuuwwya", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aacdefghijklmnopqrstuvwxyyy", "output": "abcdefghijklmnopqrstuvwxyzy" }, { "input": "abcaefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "zaaacaaaaaaaaaaaaaaaaaaaayy", "output": "zabcdefghijklmnopqrstuvwxyz" }, { "input": "abcdedccdcdccdcdcdcdcdcddccdcdcdc", "output": "abcdefghijklmnopqrstuvwxyzcdcdcdc" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "abcdecdcdcddcdcdcdcdcdcdcd", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "a", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaa" }, { "input": "aaadefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaa" }, { "input": "abbbbbbbbbbbbbbbbbbbbbbbbz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aacceeggiikkmmaacceeggiikkmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy", "output": "abcdefghijklmnopqrstuvwxyzmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "phqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxf", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaap", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "zabcdefghijklmnopqrstuvwxyz", "output": "zabcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "rveviaomdienfygifatviahordebxazoxflfgzslhyzowhxbhqzpsgellkoimnwkvhpbijorhpggwfjexivpqbcbmqjyghkbq", "output": "rveviaomdienfygifbtvichordefxgzoxhlijzslkyzowlxmnqzpsopqrstuvwxyzhpbijorhpggwfjexivpqbcbmqjyghkbq" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "xtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknly", "output": "xtlsgypsfadpooefxzbcoejuvpvdeoygpofylgphnpljvrvipyjmyklwqnqrqpmxunopqrvstwuxwvwxyzbxcoksfzkvatxdknly" }, { "input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxsa", "output": "jqcfvsavebixhiocdefphgmsmhijkylwsmpynoypqrxstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqh", "output": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldcefsdrefynghiyjkxxplmornopqrstuvwxyzopkmcoqh" }, { "input": "abadefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "zazsazcbbbbbbbbbbbbbbbbbbbbbbb", "output": "zazsbzcdefghijklmnopqrstuvwxyz" }, { "input": "zazsazcbbbbbbbbbbbbbbbbbbbbbyb", "output": "zazsbzcdefghijklmnopqrstuvwxyz" }, { "input": "bbcdefghijklmnopqrstuvwxyzzz", "output": "-1" }, { "input": "zaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zabcdefghijklmnopqrstuvwxyz" }, { "input": "zzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zzzzzabcdefghijklmnopqrstuvwxyza" }, { "input": "kkimnfjbbgggicykcciwtoazomcvisigagkjwhyrmojmoebnqoadpmockfjxibdtvrbedrsdoundbcpkfdqdidqdmxdltink", "output": "kkimnfjbbgggicykcciwtoazomcvisigbgkjwhyrmojmoecnqodepmofkgjxihitvrjklrsmounopqrstuvwxyzdmxdltink" }, { "input": "cawgathqceccscakbazmhwbefvygjbcfyihcbgga", "output": "-1" }, { "input": "acrsbyszsbfslzbqzzamcmrypictkcheddehvxdipaxaannjodzyfxgtfnwababzjraapqbqbfzhbiewlzz", "output": "acrsbyszscfslzdqzzemfmrypigtkhijklmnvxopqrxstuvwxyzyfxgtfnwababzjraapqbqbfzhbiewlzz" }, { "input": "ggcebbheeblbioxdvtlrtkxeuilonazpebcbqpzz", "output": "-1" }, { "input": "zzzzabcdefghijklmnopqrstuvwxy", "output": "-1" }, { "input": "zabcdefghijklmnopqrstuvwxy", "output": "-1" }, { "input": "babcdefghijklmnopqrstuvwxyz", "output": "babcdefghijklmnopqrstuvwxyz" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } ]
1,678,873,602
2,147,483,647
PyPy 3
OK
TESTS
102
93
4,198,400
s=list(input()) i,j=97,0 for c in s: if c<=chr(i): s[j]=chr(i);i+=1 if i>122: print(''.join(s));break j+=1 else:print(-1)
Title: String Transformation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible. Input Specification: The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. Output Specification: If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). Demo Input: ['aacceeggiikkmmooqqssuuwwyy\n', 'thereisnoanswer\n'] Demo Output: ['abcdefghijklmnopqrstuvwxyz\n', '-1\n'] Note: none
```python s=list(input()) i,j=97,0 for c in s: if c<=chr(i): s[j]=chr(i);i+=1 if i>122: print(''.join(s));break j+=1 else:print(-1) ```
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,596,622,938
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
13
218
6,963,200
import sys def parse_line(line): line = line.strip().split() name = line[0] score = int(line[1]) return name, score def update_scores(name, score, scores, winner): if name not in scores: scores[name] = score else: scores[name] += score if winner == '': winner = name else: if scores[name] > scores[winner]: winner = name return winner lines = sys.stdin.readlines() rounds = int(lines[0].strip()) scores = {} winner = '' for round in range(1, rounds+1): name, score = parse_line(lines[round]) winner = update_scores(name, score, scores, winner) print(winner)
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python import sys def parse_line(line): line = line.strip().split() name = line[0] score = int(line[1]) return name, score def update_scores(name, score, scores, winner): if name not in scores: scores[name] = score else: scores[name] += score if winner == '': winner = name else: if scores[name] > scores[winner]: winner = name return winner lines = sys.stdin.readlines() rounds = int(lines[0].strip()) scores = {} winner = '' for round in range(1, rounds+1): name, score = parse_line(lines[round]) winner = update_scores(name, score, scores, winner) print(winner) ```
0
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,695,402,575
2,147,483,647
Python 3
OK
TESTS
15
46
0
L = [int(i) for i in input().split()] s = 0 for i in range(1,L[2]+1): s+= i * L[0] if L[1] - s >= 0: print(0) else: print(s-L[1])
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python L = [int(i) for i in input().split()] s = 0 for i in range(1,L[2]+1): s+= i * L[0] if L[1] - s >= 0: print(0) else: print(s-L[1]) ```
3
821
C
Okabe and Boxes
PROGRAMMING
1,500
[ "data structures", "greedy", "trees" ]
null
null
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack. That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it. Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack. It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
[ "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n" ]
[ "1\n", "2\n" ]
In the first sample, Daru should reorder the boxes after adding box 3 to the stack. In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
1,500
[ { "input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "output": "1" }, { "input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove", "output": "2" }, { "input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremove", "output": "2" }, { "input": "2\nadd 1\nremove\nadd 2\nremove", "output": "0" }, { "input": "1\nadd 1\nremove", "output": "0" }, { "input": "15\nadd 12\nadd 7\nadd 10\nadd 11\nadd 5\nadd 2\nadd 1\nadd 6\nadd 8\nremove\nremove\nadd 15\nadd 4\nadd 13\nadd 9\nadd 3\nadd 14\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "2" }, { "input": "14\nadd 7\nadd 2\nadd 13\nadd 5\nadd 12\nadd 6\nadd 4\nadd 1\nadd 14\nremove\nadd 10\nremove\nadd 9\nadd 8\nadd 11\nadd 3\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "3" }, { "input": "11\nadd 10\nadd 9\nadd 11\nadd 1\nadd 5\nadd 6\nremove\nadd 3\nadd 8\nadd 2\nadd 4\nremove\nremove\nremove\nremove\nremove\nadd 7\nremove\nremove\nremove\nremove\nremove", "output": "2" }, { "input": "3\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove", "output": "0" }, { "input": "4\nadd 1\nadd 3\nadd 4\nremove\nadd 2\nremove\nremove\nremove", "output": "1" }, { "input": "6\nadd 3\nadd 4\nadd 5\nadd 1\nadd 6\nremove\nadd 2\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "16\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "2\nadd 2\nadd 1\nremove\nremove", "output": "0" }, { "input": "17\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "18\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "4\nadd 1\nadd 2\nremove\nremove\nadd 4\nadd 3\nremove\nremove", "output": "1" }, { "input": "19\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nadd 19\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "5\nadd 4\nadd 3\nadd 1\nremove\nadd 2\nremove\nremove\nadd 5\nremove\nremove", "output": "1" }, { "input": "7\nadd 4\nadd 6\nadd 1\nadd 5\nadd 7\nremove\nadd 2\nremove\nadd 3\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "8\nadd 1\nadd 2\nadd 3\nadd 7\nadd 8\nremove\nremove\nremove\nadd 6\nadd 5\nadd 4\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "4\nadd 1\nadd 4\nremove\nadd 3\nadd 2\nremove\nremove\nremove", "output": "1" }, { "input": "7\nadd 1\nadd 2\nadd 3\nadd 5\nadd 7\nremove\nremove\nremove\nadd 4\nremove\nremove\nadd 6\nremove\nremove", "output": "1" }, { "input": "4\nadd 4\nadd 1\nadd 2\nremove\nremove\nadd 3\nremove\nremove", "output": "1" }, { "input": "5\nadd 1\nadd 3\nadd 4\nadd 5\nremove\nadd 2\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "5\nadd 2\nadd 1\nremove\nremove\nadd 5\nadd 3\nremove\nadd 4\nremove\nremove", "output": "0" }, { "input": "9\nadd 3\nadd 2\nadd 1\nadd 4\nadd 6\nadd 9\nremove\nremove\nremove\nremove\nadd 5\nremove\nremove\nadd 8\nadd 7\nremove\nremove\nremove", "output": "1" }, { "input": "10\nadd 9\nadd 10\nadd 4\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove\nremove\nadd 8\nadd 7\nadd 5\nadd 6\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" } ]
1,498,461,013
2,147,483,647
Python 3
OK
TESTS
89
1,544
12,800,000
# Time : 2017-6-26 14:30 # Auther : Anjone # URL : http://codeforces.com/contest/821/problem/C ans = 0 num = 1 stack = [] n = int(input()) for i in range(2*n): s = input() if s.find("add") != -1: stack.append(int(s.split()[1]) ) else: if len(stack) != 0 and stack[-1] != num: stack = [] ans+=1 if len(stack): stack.pop() num += 1 print(ans)
Title: Okabe and Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack. That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it. Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. Input Specification: The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack. It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. Output Specification: Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. Demo Input: ['3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n', '7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n'] Demo Output: ['1\n', '2\n'] Note: In the first sample, Daru should reorder the boxes after adding box 3 to the stack. In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
```python # Time : 2017-6-26 14:30 # Auther : Anjone # URL : http://codeforces.com/contest/821/problem/C ans = 0 num = 1 stack = [] n = int(input()) for i in range(2*n): s = input() if s.find("add") != -1: stack.append(int(s.split()[1]) ) else: if len(stack) != 0 and stack[-1] != num: stack = [] ans+=1 if len(stack): stack.pop() num += 1 print(ans) ```
3
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,611,767,799
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
122
0
s = input() n = input() if s == 'front' and n == '1': print('L') elif s == 'back' and n == '2': print('L') else: print('R')
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. Input Specification: The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. Output Specification: Print character "R" if the VIP is right-handed or "L" if he is left-handed. Demo Input: ['front\n1\n'] Demo Output: ['L\n'] Note: none
```python s = input() n = input() if s == 'front' and n == '1': print('L') elif s == 'back' and n == '2': print('L') else: print('R') ```
-1
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,649,795,006
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
0
a, b = list(map(int, input().split())) while b % a != 0: a, b = b, a % b print(a)
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python a, b = list(map(int, input().split())) while b % a != 0: a, b = b, a % b print(a) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,684,761,551
2,147,483,647
Python 3
OK
TESTS
20
31
0
import math m, n, a = [int(x) for x in input().split()] g = math.ceil(n/a) j = math.ceil(m/a) print(g*j)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python import math m, n, a = [int(x) for x in input().split()] g = math.ceil(n/a) j = math.ceil(m/a) print(g*j) ```
3.9845
0
none
none
none
0
[ "none" ]
null
null
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
[ "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n" ]
[ "2\n4\n7\n" ]
none
0
[ { "input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "output": "2\n4\n7" }, { "input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "output": "7\n1\n4\n7\n8\n9\n11\n13" }, { "input": "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13 2\n14 12\n15 14\n16 8\n17 9\n18 13\n19 2\n20 17\n1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0\n1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1", "output": "8\n11\n15\n17\n20\n10\n18\n19\n7" }, { "input": "30\n2 1\n3 2\n4 3\n5 3\n6 5\n7 3\n8 3\n9 2\n10 3\n11 2\n12 11\n13 6\n14 4\n15 5\n16 11\n17 9\n18 14\n19 6\n20 2\n21 19\n22 9\n23 19\n24 20\n25 14\n26 22\n27 1\n28 6\n29 13\n30 27\n1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0\n0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0", "output": "15\n1\n2\n4\n5\n6\n13\n29\n19\n21\n23\n28\n7\n22\n26\n30" }, { "input": "15\n2 1\n3 1\n4 1\n5 1\n6 3\n7 1\n8 1\n9 1\n10 5\n11 9\n12 3\n13 5\n14 5\n15 4\n1 1 0 0 0 0 1 1 1 0 1 1 1 0 0\n1 0 1 1 0 1 1 1 1 1 1 1 1 1 0", "output": "6\n2\n3\n6\n4\n10\n14" }, { "input": "20\n2 1\n3 1\n4 2\n5 2\n6 3\n7 1\n8 6\n9 2\n10 3\n11 6\n12 2\n13 3\n14 2\n15 1\n16 8\n17 15\n18 2\n19 14\n20 14\n0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1\n0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0", "output": "10\n2\n4\n19\n18\n8\n16\n11\n10\n13\n7" }, { "input": "23\n2 1\n3 2\n4 1\n5 1\n6 5\n7 3\n8 2\n9 8\n10 5\n11 6\n12 9\n13 3\n14 11\n15 5\n16 2\n17 3\n18 10\n19 16\n20 14\n21 19\n22 17\n23 7\n0 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1", "output": "8\n2\n23\n13\n17\n9\n4\n11\n20" }, { "input": "1\n0\n0", "output": "0" }, { "input": "10\n1 10\n1 9\n10 2\n10 3\n3 7\n3 8\n9 4\n9 5\n5 6\n1 0 1 1 0 1 0 1 0 1\n0 0 0 0 0 0 0 0 0 0", "output": "6\n1\n10\n2\n7\n5\n6" } ]
1,399,826,317
3,517
Python 3
WRONG_ANSWER
PRETESTS
1
61
0
from collections import deque n = int(input()) edges = {} for i in range(n - 1): v, u = tuple(map(int, input().split())) if u not in edges: edges[u] = [v] else: edges[u].append(v) def children(u): if u not in edges: return [] return edges[u] def grandchildren(u): gc = [] for c in children(u): gc += children(c) return gc gcs = {} for i in range(1, n + 1): gcs[i] = grandchildren(i) start = list(map(int, input().split())) goal = list(map(int, input().split())) queue = deque() queue.append(1) fixes = [] def fix(cur): fixes.append(cur) start[cur - 1] = 0 if start[cur - 1] == 1 else 0 gc = deque(gcs[cur]) while len(gc) > 0: cur = gc.popleft() start[cur - 1] = 0 if start[cur - 1] == 1 else 0 gc.extend(gcs[cur]) while len(queue) > 0: cur = queue.popleft() if start[cur - 1] != goal[cur - 1]: fix(cur) queue.extend(children(cur)) print(len(fixes)) for f in fixes: print(f)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). Output Specification: In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. Demo Input: ['10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n'] Demo Output: ['2\n4\n7\n'] Note: none
```python from collections import deque n = int(input()) edges = {} for i in range(n - 1): v, u = tuple(map(int, input().split())) if u not in edges: edges[u] = [v] else: edges[u].append(v) def children(u): if u not in edges: return [] return edges[u] def grandchildren(u): gc = [] for c in children(u): gc += children(c) return gc gcs = {} for i in range(1, n + 1): gcs[i] = grandchildren(i) start = list(map(int, input().split())) goal = list(map(int, input().split())) queue = deque() queue.append(1) fixes = [] def fix(cur): fixes.append(cur) start[cur - 1] = 0 if start[cur - 1] == 1 else 0 gc = deque(gcs[cur]) while len(gc) > 0: cur = gc.popleft() start[cur - 1] = 0 if start[cur - 1] == 1 else 0 gc.extend(gcs[cur]) while len(queue) > 0: cur = queue.popleft() if start[cur - 1] != goal[cur - 1]: fix(cur) queue.extend(children(cur)) print(len(fixes)) for f in fixes: print(f) ```
0
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on... For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner.
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output": "I hate that I love that I hate that I love that I hate it" }, { "input": "10", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it" }, { "input": "18", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it" }, { "input": "19", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it" }, { "input": "76", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "77", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "81", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "82", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "85", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "86", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "100", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "99", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "98", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "33", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it" }, { "input": "34", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it" }, { "input": "57", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." }, { "input": "100", "output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..." } ]
1,699,701,121
2,147,483,647
PyPy 3-64
OK
TESTS
21
62
0
n = int(input()) string1 = 'I hate' string2 = 'I love' output = '' flag = True for i in range(n): if i == n - 1: flag = False if i % 2 == 0 and flag: output += string1 + ' that ' elif i % 2 == 1 and flag: output += string2 + ' that ' elif i % 2 == 0: output += string1 else: output += string2 print(output + ' it')
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on... For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner. Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. Output Specification: Print Dr.Banner's feeling in one line. Demo Input: ['1\n', '2\n', '3\n'] Demo Output: ['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n'] Note: none
```python n = int(input()) string1 = 'I hate' string2 = 'I love' output = '' flag = True for i in range(n): if i == n - 1: flag = False if i % 2 == 0 and flag: output += string1 + ' that ' elif i % 2 == 1 and flag: output += string2 + ' that ' elif i % 2 == 0: output += string1 else: output += string2 print(output + ' it') ```
3
712
B
Memory and Trident
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given.
If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
[ "RRU\n", "UDUR\n", "RUUR\n" ]
[ "-1\n", "1\n", "2\n" ]
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
1,000
[ { "input": "RRU", "output": "-1" }, { "input": "UDUR", "output": "1" }, { "input": "RUUR", "output": "2" }, { "input": "DDDD", "output": "2" }, { "input": "RRRR", "output": "2" }, { "input": "RRRUUD", "output": "2" }, { "input": "UDURLRDURLRD", "output": "1" }, { "input": "RLRU", "output": "1" }, { "input": "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDULRURRDDDLLUDRLUDDLDDDRRDDDULLLLDLDRLRRLRRDDRLULURRUDRDUUUULDURUDRDLDDUDUDRRURDULRRUDRLRRDLUURURDLDRLRDUDDDLDDDURURLUULRDUUULRURUDUDRRUDULLLUUUDRLLDRRDDLRUDRDRDLLRURURRRULURURRRLUUULRRRUURUUDURUDDLLDLDRLRDLDRLLDLDRDRRLRRRURUUUDRDLRLRUDRLULUUULUDDLULDLRLLRDUULLRLRURLRURULLLUDUDDLRULRDUURURLDLUURRRDURRLLDRUUDRDLLDUUDLURUDDUUUULRLLURLUDDRLRRDRURLRUDRLDDRLLL", "output": "-1" }, { "input": "LDLDLDLDLDRULD", "output": "5" }, { "input": "LULULURULLLU", "output": "5" }, { "input": "DRDRDDRR", "output": "4" }, { "input": "LR", "output": "0" }, { "input": "UL", "output": "1" }, { "input": "UD", "output": "0" }, { "input": "R", "output": "-1" }, { "input": "LU", "output": "1" }, { "input": "RR", "output": "1" }, { "input": "UDLR", "output": "0" }, { "input": "RRRRRLLUUUUDD", "output": "-1" }, { "input": "UUUUDLLLLR", "output": "3" }, { "input": "LLRUD", "output": "-1" }, { "input": "LLRDDU", "output": "1" } ]
1,609,682,431
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
108
0
s=input() if len(s)%2==1: print(-1) else: x=0 y=0 for i in s: if i=="R": x+=1 elif i=="l": x-=1 elif i=="U": y+=1 else: y-=1 print((abs(x)+abs(y))//2)
Title: Memory and Trident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. Input Specification: The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. Output Specification: If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. Demo Input: ['RRU\n', 'UDUR\n', 'RUUR\n'] Demo Output: ['-1\n', '1\n', '2\n'] Note: In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
```python s=input() if len(s)%2==1: print(-1) else: x=0 y=0 for i in s: if i=="R": x+=1 elif i=="l": x-=1 elif i=="U": y+=1 else: y-=1 print((abs(x)+abs(y))//2) ```
0
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,657,142,476
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
156
9,830,400
#n,t=map from cmath import sqrt from math import ceil n=int(input()) a = list(map(int,input().strip().split()))[:n] b=a b=sorted(b) s,c=0,0 last=n-1 for i in range(0,n): if a==b and c==0: s=1 break a[0],a[last]=a[last],a[0] last-=1 if a==b: s=1 c+=1 break if last<0: break if s==1: print(c) else: print(-1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python #n,t=map from cmath import sqrt from math import ceil n=int(input()) a = list(map(int,input().strip().split()))[:n] b=a b=sorted(b) s,c=0,0 last=n-1 for i in range(0,n): if a==b and c==0: s=1 break a[0],a[last]=a[last],a[0] last-=1 if a==b: s=1 c+=1 break if last<0: break if s==1: print(c) else: print(-1) ```
0
515
A
Drazil and Date
PROGRAMMING
1,000
[ "math" ]
null
null
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes".
[ "5 5 11\n", "10 15 25\n", "0 5 1\n", "0 0 2\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "5 5 11", "output": "No" }, { "input": "10 15 25", "output": "Yes" }, { "input": "0 5 1", "output": "No" }, { "input": "0 0 2", "output": "Yes" }, { "input": "999999999 999999999 2000000000", "output": "Yes" }, { "input": "-606037695 998320124 820674098", "output": "No" }, { "input": "948253616 -83299062 1031552680", "output": "Yes" }, { "input": "711980199 216568284 928548487", "output": "Yes" }, { "input": "-453961301 271150176 725111473", "output": "No" }, { "input": "0 0 2000000000", "output": "Yes" }, { "input": "0 0 1999999999", "output": "No" }, { "input": "1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 1000000000", "output": "No" }, { "input": "-1 -1 3", "output": "No" }, { "input": "919785634 216774719 129321944", "output": "No" }, { "input": "-467780354 -721273539 1369030008", "output": "No" }, { "input": "-232833910 -880680184 1774549792", "output": "Yes" }, { "input": "45535578 402686155 1011249824", "output": "No" }, { "input": "-203250176 -30379840 233630015", "output": "No" }, { "input": "-814516648 -75830576 890347222", "output": "No" }, { "input": "869184175 -511854751 1381038923", "output": "No" }, { "input": "552884998 -262338193 815223187", "output": "No" }, { "input": "-133874494 857573117 991447611", "output": "Yes" }, { "input": "169406792 786701289 956108082", "output": "No" }, { "input": "30237137 -989203246 1019440385", "output": "Yes" }, { "input": "576608216 -617624133 1194232352", "output": "No" }, { "input": "-662360368 97618995 759979367", "output": "Yes" }, { "input": "-115989290 321714461 437703756", "output": "No" }, { "input": "-1 -3 2", "output": "No" }, { "input": "-2 -2 2", "output": "No" }, { "input": "0 0 1", "output": "No" }, { "input": "0 -1 7", "output": "Yes" }, { "input": "1 2 7", "output": "Yes" }, { "input": "0 5 6", "output": "No" }, { "input": "0 -4 2", "output": "No" }, { "input": "-5 5 2", "output": "No" }, { "input": "-5 -2 7", "output": "Yes" }, { "input": "5 -5 2", "output": "No" } ]
1,687,312,973
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
a, b, s = (int(i) for i in input().split()) res = "YES" if s >= a + b and (a + b) & 1 == s & 1 else "NO" print(res)
Title: Drazil and Date Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? Input Specification: You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. Output Specification: If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes". Demo Input: ['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n'] Demo Output: ['No\n', 'Yes\n', 'No\n', 'Yes\n'] Note: In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a, b, s = (int(i) for i in input().split()) res = "YES" if s >= a + b and (a + b) & 1 == s & 1 else "NO" print(res) ```
0
691
A
Fashion in Berland
PROGRAMMING
1,000
[ "implementation" ]
null
null
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
[ "3\n1 0 1\n", "3\n1 0 0\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 1 0", "output": "YES" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "3\n0 0 0", "output": "NO" }, { "input": "3\n0 1 1", "output": "YES" }, { "input": "3\n0 1 0", "output": "NO" }, { "input": "2\n0 1", "output": "YES" }, { "input": "2\n1 0", "output": "YES" }, { "input": "2\n0 0", "output": "NO" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1", "output": "YES" }, { "input": "1\n0", "output": "NO" }, { "input": "10\n1 0 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "5\n1 1 1 1 0", "output": "YES" }, { "input": "4\n1 0 1 0", "output": "NO" }, { "input": "4\n1 1 0 0", "output": "NO" }, { "input": "10\n0 0 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "94\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", "output": "NO" }, { "input": "64\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", "output": "NO" }, { "input": "34\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", "output": "NO" }, { "input": "35\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", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "NO" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "NO" }, { "input": "10\n1 1 0 1 1 1 0 1 1 1", "output": "NO" } ]
1,471,303,706
2,147,483,647
Python 3
OK
TESTS
83
77
4,608,000
n=int(input()) bs=input() def f(n,bs): if (n == 1): if (bs == "0"): print("NO") else: print("YES") else: s = 0 for a in bs[::2]: if (a == "0"): s += 1 if (s > 1): print("NO") return if (s == 1): print("YES") else: print("NO") f(n,bs)
Title: Fashion in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. Output Specification: In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". Demo Input: ['3\n1 0 1\n', '3\n1 0 0\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n=int(input()) bs=input() def f(n,bs): if (n == 1): if (bs == "0"): print("NO") else: print("YES") else: s = 0 for a in bs[::2]: if (a == "0"): s += 1 if (s > 1): print("NO") return if (s == 1): print("YES") else: print("NO") f(n,bs) ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0.
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output": "1\n1 2 3" }, { "input": "12\n3 3 3 3 3 3 3 3 1 3 3 2", "output": "1\n9 12 2" }, { "input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2", "output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47" }, { "input": "12\n3 1 1 1 1 1 1 2 1 1 1 1", "output": "1\n3 8 1" }, { "input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2", "output": "1\n18 2 11" }, { "input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3", "output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36" }, { "input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1", "output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200" }, { "input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3", "output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64" }, { "input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1", "output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44" }, { "input": "5\n1 2 2 3 3", "output": "1\n1 3 4" } ]
1,671,822,594
2,147,483,647
PyPy 3-64
OK
TESTS
41
92
4,403,200
_ = int(input()) students = input() rec = {'1':[],'2':[],'3':[]} for c in range(len(students)): if students[c] == ' ': continue rec[students[c]].append(c//2+1) teams = len(min(rec.values(),key=lambda x : len(x))) print(teams) for i in range(teams): print(rec['1'][i],rec['2'][i],rec['3'][i])
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. Output Specification: In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0. Demo Input: ['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n'] Demo Output: ['2\n3 5 2\n6 7 4\n', '0\n'] Note: none
```python _ = int(input()) students = input() rec = {'1':[],'2':[],'3':[]} for c in range(len(students)): if students[c] == ' ': continue rec[students[c]].append(c//2+1) teams = len(min(rec.values(),key=lambda x : len(x))) print(teams) for i in range(teams): print(rec['1'][i],rec['2'][i],rec['3'][i]) ```
3
960
B
Minimize the error
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed.
The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*.
Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*.
[ "2 0 0\n1 2\n2 3\n", "2 1 0\n1 2\n2 2\n", "2 5 7\n3 4\n14 4\n" ]
[ "2", "0", "1" ]
In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
1,000
[ { "input": "2 0 0\n1 2\n2 3", "output": "2" }, { "input": "2 1 0\n1 2\n2 2", "output": "0" }, { "input": "2 5 7\n3 4\n14 4", "output": "1" }, { "input": "2 0 1\n1 2\n2 2", "output": "0" }, { "input": "2 1 1\n0 0\n1 1", "output": "0" }, { "input": "5 5 5\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "3 4 5\n1 2 3\n3 2 1", "output": "1" }, { "input": "3 1000 0\n1 2 3\n-1000 -1000 -1000", "output": "1341346" }, { "input": "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3", "output": "1" }, { "input": "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 21 25 2 -3 45 -7 -98 -56", "output": "0" }, { "input": "10 10 580\n302 -553 -281 -299 -270 -890 -989 -749 -418 486\n735 330 6 725 -984 209 -855 -786 -502 967", "output": "2983082" }, { "input": "10 403 187\n9691 -3200 3016 3540 -9475 8840 -4705 7940 6293 -2631\n-2288 9129 4067 696 -6754 9869 -5747 701 3344 -3426", "output": "361744892" }, { "input": "10 561 439\n76639 67839 10670 -23 -18393 65114 46538 67596 86615 90480\n50690 620 -33631 -75857 75634 91321 -81662 -93668 -98557 -43621", "output": "116776723778" }, { "input": "10 765 62\n-929885 -995154 254071 -370672 -435272 584846 -301610 -234118 -82557 743536\n-36327 439149 -977780 -821019 -585558 953598 -151943 140715 -311253 -383103", "output": "6216649853365" }, { "input": "22 334 246\n-462653 -618002 4973 -348485 366658 192390 274752 200590 138367 779540 -661269 642587 113645 -110388 -604418 -491231 -933401 -219332 -603140 836439 167007 210226\n357638 -646669 -558432 -434313 -285851 -119233 323088 -512237 -729293 215256 39316 -984201 -209814 715016 -271932 796550 988227 -89577 67202 462973 -942079 -823339", "output": "15389604923763" }, { "input": "1 1000 0\n1000000\n-1000000", "output": "3996001000000" }, { "input": "1 1000 0\n1000000\n1000000", "output": "0" }, { "input": "1 0 1000\n-1000000\n1000000", "output": "3996001000000" }, { "input": "1 0 1000\n1000000\n1000000", "output": "0" }, { "input": "1 5 7\n1\n2", "output": "1" }, { "input": "2 1 3\n2 2\n2 2", "output": "0" }, { "input": "3 3 0\n1 1 1\n1 1 1", "output": "1" }, { "input": "1 0 6\n0\n0", "output": "0" }, { "input": "2 1 1\n2 2\n0 0", "output": "2" }, { "input": "3 1 4\n0 0 0\n1 5 6", "output": "19" }, { "input": "1 1 2\n0\n8", "output": "25" }, { "input": "2 2 0\n3 3\n3 3", "output": "0" } ]
1,696,179,134
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n, k1, k2=map(int, input(). split()) a=[int(x) for x in map(int, input().split())] b=[int(x) for x in map(int, input().split())] k=k1+k2 s=0 while k>0: for i in range(n): if a[i]<b[i]: a[i]+=1 k-=1 elif a[i]>b[i]: a[i]-=1 k-=1 else: if a==b: s+=k k=0 for i in range(n): s+=(a[i]-b[i])**2 print(s)
Title: Minimize the error Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed. Input Specification: The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*. Output Specification: Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. Demo Input: ['2 0 0\n1 2\n2 3\n', '2 1 0\n1 2\n2 2\n', '2 5 7\n3 4\n14 4\n'] Demo Output: ['2', '0', '1'] Note: In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
```python n, k1, k2=map(int, input(). split()) a=[int(x) for x in map(int, input().split())] b=[int(x) for x in map(int, input().split())] k=k1+k2 s=0 while k>0: for i in range(n): if a[i]<b[i]: a[i]+=1 k-=1 elif a[i]>b[i]: a[i]-=1 k-=1 else: if a==b: s+=k k=0 for i in range(n): s+=(a[i]-b[i])**2 print(s) ```
0
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,693,981,012
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
k,n,w = map(int, input().split()) print( ((w*(w+1)) // 2) * k - n)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python k,n,w = map(int, input().split()) print( ((w*(w+1)) // 2) * k - n) ```
0
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808", "output": "7" }, { "input": "1\n487 550", "output": "0" }, { "input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676", "output": "0" }, { "input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136", "output": "8" }, { "input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188", "output": "9" }, { "input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191", "output": "5" }, { "input": "4\n1 0\n2 0\n1 1\n1 -1", "output": "0" } ]
1,609,669,652
2,147,483,647
Python 3
OK
TESTS
26
280
307,200
def right_count(a, arr): c = 0 for items in arr: if items[0] > a[0] and items[1] == a[1]: c += 1 return c def left_count(a, arr): c = 0 for items in arr: if items[0] < a[0] and items[1] == a[1]: c += 1 return c def lower_count(a, arr): c = 0 for items in arr: if items[0] == a[0] and items[1] < a[1]: c += 1 return c def upper_count(a, arr): c = 0 for items in arr: if items[0] == a[0] and items[1] > a[1]: c += 1 return c def supercentral(a, arr): if right_count(a, arr) >= 1: if left_count(a, arr) >= 1: if lower_count(a, arr) >= 1: if upper_count(a, arr) >= 1: return 1 else: return 0 else: return 0 else: return 0 else: return 0 p = int(input()) myarr = list(input().split() for _ in range(p)) for x in range(len(myarr)): for y in range(2): myarr[x][y] = int(myarr[x][y]) c = 0 for z in range(len(myarr)): if supercentral(myarr[z], myarr) != 0: c += 1 print(c)
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. Input Specification: The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. Output Specification: Print the only number — the number of supercentral points of the given set. Demo Input: ['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
```python def right_count(a, arr): c = 0 for items in arr: if items[0] > a[0] and items[1] == a[1]: c += 1 return c def left_count(a, arr): c = 0 for items in arr: if items[0] < a[0] and items[1] == a[1]: c += 1 return c def lower_count(a, arr): c = 0 for items in arr: if items[0] == a[0] and items[1] < a[1]: c += 1 return c def upper_count(a, arr): c = 0 for items in arr: if items[0] == a[0] and items[1] > a[1]: c += 1 return c def supercentral(a, arr): if right_count(a, arr) >= 1: if left_count(a, arr) >= 1: if lower_count(a, arr) >= 1: if upper_count(a, arr) >= 1: return 1 else: return 0 else: return 0 else: return 0 else: return 0 p = int(input()) myarr = list(input().split() for _ in range(p)) for x in range(len(myarr)): for y in range(2): myarr[x][y] = int(myarr[x][y]) c = 0 for z in range(len(myarr)): if supercentral(myarr[z], myarr) != 0: c += 1 print(c) ```
3
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "output": "8" }, { "input": "774", "output": "13" }, { "input": "4", "output": "1" }, { "input": "4447747", "output": "140" }, { "input": "7747474", "output": "233" }, { "input": "4444", "output": "15" }, { "input": "4447", "output": "16" }, { "input": "7", "output": "2" }, { "input": "4", "output": "1" }, { "input": "4447744", "output": "139" }, { "input": "77474", "output": "57" }, { "input": "7747", "output": "28" }, { "input": "444", "output": "7" }, { "input": "7", "output": "2" }, { "input": "7774477", "output": "242" }, { "input": "4477774", "output": "157" }, { "input": "7444", "output": "23" }, { "input": "7474747", "output": "212" }, { "input": "77", "output": "6" }, { "input": "774477", "output": "114" }, { "input": "7", "output": "2" }, { "input": "47", "output": "4" }, { "input": "747777", "output": "110" }, { "input": "444444444", "output": "511" }, { "input": "777777777", "output": "1022" }, { "input": "477477447", "output": "728" }, { "input": "777744747", "output": "996" } ]
1,656,843,041
2,147,483,647
PyPy 3-64
OK
TESTS
33
109
512,000
a = [] for i in range(1,10): a.append(int('4' * i)) for i in range(2**9):b=bin(i)[2:];b=b.replace('1','4');b=b.replace('0','7');a.append(int(b)) for i in range(2**9):b=bin(i)[2:];b=b.replace('0','4');b=b.replace('1','7');a.append(int(b)) a=sorted(list(set(a)));print(a.index(int(input()))+1)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. Input Specification: The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the index of *n* among all lucky numbers. Demo Input: ['4\n', '7\n', '77\n'] Demo Output: ['1\n', '2\n', '6\n'] Note: none
```python a = [] for i in range(1,10): a.append(int('4' * i)) for i in range(2**9):b=bin(i)[2:];b=b.replace('1','4');b=b.replace('0','7');a.append(int(b)) for i in range(2**9):b=bin(i)[2:];b=b.replace('0','4');b=b.replace('1','7');a.append(int(b)) a=sorted(list(set(a)));print(a.index(int(input()))+1) ```
3
863
B
Kayaking
PROGRAMMING
1,500
[ "brute force", "greedy", "sortings" ]
null
null
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability!
The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Print minimum possible total instability.
[ "2\n1 2 3 4\n", "4\n1 3 4 6 3 4 100 200\n" ]
[ "1\n", "5\n" ]
none
0
[ { "input": "2\n1 2 3 4", "output": "1" }, { "input": "4\n1 3 4 6 3 4 100 200", "output": "5" }, { "input": "3\n305 139 205 406 530 206", "output": "102" }, { "input": "3\n610 750 778 6 361 407", "output": "74" }, { "input": "5\n97 166 126 164 154 98 221 7 51 47", "output": "35" }, { "input": "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3 2 1 3 3 2 2 1 3 1 3 1 2 2 1 2 3 2", "output": "0" }, { "input": "50\n5 5 5 5 4 2 2 3 2 2 4 1 5 5 1 2 4 2 4 2 5 2 2 2 2 3 2 4 2 5 5 4 3 1 2 3 3 5 4 2 2 5 2 4 5 5 4 4 1 5 5 3 2 2 5 1 3 3 2 4 4 5 1 2 3 4 4 1 3 3 3 5 1 2 4 4 4 4 2 5 2 5 3 2 4 5 5 2 1 1 2 4 5 3 2 1 2 4 4 4", "output": "1" }, { "input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319 382 651 594 411 845 746 18 232 6 289 889 81 174 175 805 1000 799 950 475 713 951 685 729 925 262 447 139 217 788 514 658 572 784 185 112 636 10 251 621 218 210 89 597 553 430 532 264 11 160 476", "output": "368" }, { "input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393 955 540 896 241 362 146 74 680 734 767 851 337 751 860 542 735 444 793 340 259 495 903 743 961 964 966 87 275 22 776 368 701 835 732 810 735 267 988 352 647 924 183 1 924 217 944 322 252 758 597", "output": "393" }, { "input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52 69 591 181 573 258 381 665 301 589 379 362 146 790 842 765 100 229 916 938 97 340 793 758 177 736 396 247 562 571 92 923 861 165 748 345 703 431 930 101 761 862 595 505 393 126 846 431 103 596 21", "output": "387" }, { "input": "50\n721 631 587 746 692 406 583 90 388 16 161 948 921 70 387 426 39 398 517 724 879 377 906 502 359 950 798 408 846 718 911 845 57 886 9 668 537 632 344 762 19 193 658 447 870 173 98 156 592 519 183 539 274 393 962 615 551 626 148 183 769 763 829 120 796 761 14 744 537 231 696 284 581 688 611 826 703 145 224 600 965 613 791 275 984 375 402 281 851 580 992 8 816 454 35 532 347 250 242 637", "output": "376" }, { "input": "50\n849 475 37 120 754 183 758 374 543 198 896 691 11 607 198 343 761 660 239 669 628 259 223 182 216 158 20 565 454 884 137 923 156 22 310 77 267 707 582 169 120 308 439 309 59 152 206 696 210 177 296 887 559 22 154 553 142 247 491 692 473 572 461 206 532 319 503 164 328 365 541 366 300 392 486 257 863 432 877 404 520 69 418 99 519 239 374 927 601 103 226 316 423 219 240 26 455 101 184 61", "output": "351" }, { "input": "3\n1 2 10 11 100 100", "output": "1" }, { "input": "17\n814 744 145 886 751 1000 272 914 270 529 467 164 410 369 123 424 991 12 702 582 561 858 746 950 598 393 606 498 648 686 455 873 728 858", "output": "318" }, { "input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 990 714 662 572 467 949 799 648 581 545 828 508 636", "output": "355" }, { "input": "2\n55 5 25 51", "output": "4" }, { "input": "25\n89 50 640 463 858 301 522 241 923 378 892 822 550 17 42 66 706 779 657 840 273 222 444 459 94 925 437 159 182 727 92 851 742 215 653 891 782 533 29 128 133 883 317 475 165 994 802 434 744 973", "output": "348" }, { "input": "4\n35 48 71 44 78 79 57 48", "output": "10" }, { "input": "3\n58 89 73 15 5 47", "output": "21" }, { "input": "2\n1 20 99 100", "output": "1" } ]
1,664,826,655
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,867,200
from sympy import N def solve(n, nums): nums.sort() for _ in range(2): if nums[-1]-nums[-2] > nums[1] - nums[0]: nums.pop() else: nums.pop(0) return sum(y-x for x,y in zip(nums,nums[1:])) n = int(input()) nums = list(map(int,input().split())) print(solve(n,nums))
Title: Kayaking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability! Input Specification: The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). Output Specification: Print minimum possible total instability. Demo Input: ['2\n1 2 3 4\n', '4\n1 3 4 6 3 4 100 200\n'] Demo Output: ['1\n', '5\n'] Note: none
```python from sympy import N def solve(n, nums): nums.sort() for _ in range(2): if nums[-1]-nums[-2] > nums[1] - nums[0]: nums.pop() else: nums.pop(0) return sum(y-x for x,y in zip(nums,nums[1:])) n = int(input()) nums = list(map(int,input().split())) print(solve(n,nums)) ```
-1
330
B
Road Construction
PROGRAMMING
1,300
[ "constructive algorithms", "graphs" ]
null
null
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given *m* pairs of cities — roads cannot be constructed between these pairs of cities. Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
The first line consists of two integers *n* and *m* . Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*. It is guaranteed that every pair of cities will appear at most once in the input.
You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*. If there are several solutions, you may print any of them.
[ "4 1\n1 3\n" ]
[ "3\n1 2\n4 2\n2 3\n" ]
This is one possible solution of the example: These are examples of wrong solutions:
1,000
[ { "input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3" }, { "input": "1000 0", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "484 11\n414 97\n414 224\n444 414\n414 483\n414 399\n414 484\n414 189\n414 246\n414 115\n89 414\n14 414", "output": "483\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "150 3\n112 30\n61 45\n37 135", "output": "149\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26", "output": "33\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34" }, { "input": "1000 48\n816 885\n576 357\n878 659\n610 647\n37 670\n192 184\n393 407\n598 160\n547 995\n177 276\n788 44\n14 184\n604 281\n176 97\n176 293\n10 57\n852 579\n223 669\n313 260\n476 691\n667 22\n851 792\n411 489\n526 66\n233 566\n35 396\n964 815\n672 123\n148 210\n163 339\n379 598\n382 675\n132 955\n221 441\n253 490\n856 532\n135 119\n276 319\n525 835\n996 270\n92 778\n434 369\n351 927\n758 983\n798 267\n272 830\n539 728\n166 26", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "534 0", "output": "533\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "226 54\n80 165\n2 53\n191 141\n107 207\n95 196\n61 82\n42 168\n118 94\n205 182\n172 160\n84 224\n113 143\n122 93\n37 209\n176 32\n56 83\n151 81\n70 190\n99 171\n68 204\n212 48\n4 67\n116 7\n206 199\n105 62\n158 51\n178 147\n17 129\n22 47\n72 162\n188 77\n24 111\n184 26\n175 128\n110 89\n139 120\n127 92\n121 39\n217 75\n145 69\n20 161\n30 220\n222 154\n54 46\n21 87\n144 185\n164 115\n73 202\n173 35\n9 132\n74 180\n137 5\n157 117\n31 177", "output": "225\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "84 3\n39 19\n55 73\n42 43", "output": "83\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84" }, { "input": "207 35\n34 116\n184 5\n90 203\n12 195\n138 101\n40 150\n189 109\n115 91\n93 201\n106 18\n51 187\n139 197\n168 130\n182 64\n31 42\n86 107\n158 111\n159 132\n119 191\n53 127\n81 13\n153 112\n38 2\n87 84\n121 82\n120 22\n21 177\n151 202\n23 58\n68 192\n29 46\n105 70\n8 167\n56 54\n149 15", "output": "206\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "91 37\n50 90\n26 82\n61 1\n50 17\n51 73\n45 9\n39 53\n78 35\n12 45\n43 47\n83 20\n9 59\n18 48\n68 31\n47 33\n10 25\n15 78\n5 3\n73 65\n77 4\n62 31\n73 3\n53 7\n29 58\n52 14\n56 20\n6 87\n71 16\n17 19\n77 86\n1 50\n74 79\n15 54\n55 80\n13 77\n4 69\n24 69", "output": "90\n2 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "226 54\n197 107\n181 146\n218 115\n36 169\n199 196\n116 93\n152 75\n213 164\n156 95\n165 58\n90 42\n141 58\n203 221\n179 204\n186 69\n27 127\n76 189\n40 195\n111 29\n85 189\n45 88\n84 135\n82 186\n185 17\n156 217\n8 123\n179 112\n92 137\n114 89\n10 152\n132 24\n135 36\n61 218\n10 120\n155 102\n222 79\n150 92\n184 34\n102 180\n154 196\n171 9\n217 105\n84 207\n56 189\n152 179\n43 165\n115 209\n208 167\n52 14\n92 47\n197 95\n13 78\n222 138\n75 36", "output": "225\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "207 35\n154 79\n174 101\n189 86\n137 56\n66 23\n199 69\n18 28\n32 53\n13 179\n182 170\n199 12\n24 158\n105 133\n25 10\n40 162\n64 72\n108 9\n172 125\n43 190\n15 39\n128 150\n102 129\n90 97\n64 196\n70 123\n163 41\n12 126\n127 186\n107 23\n182 51\n29 46\n46 123\n89 35\n59 80\n206 171", "output": "206\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "84 0", "output": "83\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84" }, { "input": "226 54\n5 29\n130 29\n55 29\n19 29\n29 92\n29 38\n185 29\n29 150\n29 202\n29 25\n29 66\n184 29\n29 189\n177 29\n50 29\n87 29\n138 29\n29 48\n151 29\n125 29\n16 29\n42 29\n29 157\n90 29\n21 29\n29 45\n29 80\n29 67\n29 26\n29 173\n74 29\n29 193\n29 40\n172 29\n29 85\n29 102\n88 29\n29 182\n116 29\n180 29\n161 29\n10 29\n171 29\n144 29\n29 218\n190 29\n213 29\n29 71\n29 191\n29 160\n29 137\n29 58\n29 135\n127 29", "output": "225\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "207 35\n25 61\n188 61\n170 61\n113 61\n35 61\n61 177\n77 61\n61 39\n61 141\n116 61\n61 163\n30 61\n192 61\n19 61\n61 162\n61 133\n185 61\n8 61\n118 61\n61 115\n7 61\n61 105\n107 61\n61 11\n161 61\n61 149\n136 61\n82 61\n20 61\n151 61\n156 61\n12 61\n87 61\n61 205\n61 108", "output": "206\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "34 7\n11 32\n33 29\n17 16\n15 5\n13 25\n8 19\n20 4", "output": "33\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34" }, { "input": "43 21\n38 19\n43 8\n40 31\n3 14\n24 21\n12 17\n1 9\n5 27\n25 37\n11 6\n13 26\n16 22\n10 32\n36 7\n30 29\n42 35\n20 33\n4 23\n18 15\n41 34\n2 28", "output": "42\n39 1\n39 2\n39 3\n39 4\n39 5\n39 6\n39 7\n39 8\n39 9\n39 10\n39 11\n39 12\n39 13\n39 14\n39 15\n39 16\n39 17\n39 18\n39 19\n39 20\n39 21\n39 22\n39 23\n39 24\n39 25\n39 26\n39 27\n39 28\n39 29\n39 30\n39 31\n39 32\n39 33\n39 34\n39 35\n39 36\n39 37\n39 38\n39 40\n39 41\n39 42\n39 43" }, { "input": "34 7\n22 4\n5 25\n15 7\n5 9\n27 7\n34 21\n3 13", "output": "33\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34" }, { "input": "50 7\n19 37\n30 32\n43 20\n48 14\n30 29\n18 36\n9 46", "output": "49\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50" }, { "input": "41 12\n41 12\n29 13\n3 37\n2 20\n4 24\n27 6\n39 20\n28 41\n30 1\n35 9\n5 39\n12 31", "output": "40\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 8\n7 9\n7 10\n7 11\n7 12\n7 13\n7 14\n7 15\n7 16\n7 17\n7 18\n7 19\n7 20\n7 21\n7 22\n7 23\n7 24\n7 25\n7 26\n7 27\n7 28\n7 29\n7 30\n7 31\n7 32\n7 33\n7 34\n7 35\n7 36\n7 37\n7 38\n7 39\n7 40\n7 41" }, { "input": "26 2\n22 1\n14 10", "output": "25\n2 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26" }, { "input": "7 3\n4 7\n4 6\n6 5", "output": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7" }, { "input": "484 11\n459 166\n12 217\n14 231\n477 111\n365 225\n62 412\n221 223\n258 184\n266 404\n425 236\n83 269", "output": "483\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87..." }, { "input": "50 24\n18 36\n11 18\n22 18\n18 47\n18 10\n45 18\n18 29\n13 18\n8 18\n18 30\n26 18\n18 6\n5 18\n18 7\n46 18\n50 18\n18 3\n18 32\n4 18\n18 24\n18 19\n23 18\n35 18\n31 18", "output": "49\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50" }, { "input": "7 3\n3 4\n7 3\n3 2", "output": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7" }, { "input": "1 0", "output": "0" }, { "input": "2 0", "output": "1\n1 2" }, { "input": "4 1\n1 2", "output": "3\n3 1\n3 2\n3 4" }, { "input": "3 1\n1 2", "output": "2\n3 1\n3 2" }, { "input": "5 1\n1 5", "output": "4\n2 1\n2 3\n2 4\n2 5" } ]
1,592,040,331
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
248
204,800
f=lambda: map(int, input().split(' ')) n, m =f() print(n-1) if(m==0): for j in range(1,n): print(j,' ', j+1) else: s=set() for j in range(m): s=set(f()).union(s) #print(s) ss = set([i for i in range(1, n+1)]).difference(s) #print(ss) kp = list(ss)[0] for j in range(1, n+1): if(j!=kp): print(j, ' ', kp)
Title: Road Construction Time Limit: None seconds Memory Limit: None megabytes Problem Description: A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given *m* pairs of cities — roads cannot be constructed between these pairs of cities. Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible. Input Specification: The first line consists of two integers *n* and *m* . Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*. It is guaranteed that every pair of cities will appear at most once in the input. Output Specification: You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*. If there are several solutions, you may print any of them. Demo Input: ['4 1\n1 3\n'] Demo Output: ['3\n1 2\n4 2\n2 3\n'] Note: This is one possible solution of the example: These are examples of wrong solutions:
```python f=lambda: map(int, input().split(' ')) n, m =f() print(n-1) if(m==0): for j in range(1,n): print(j,' ', j+1) else: s=set() for j in range(m): s=set(f()).union(s) #print(s) ss = set([i for i in range(1, n+1)]).difference(s) #print(ss) kp = list(ss)[0] for j in range(1, n+1): if(j!=kp): print(j, ' ', kp) ```
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,698,678,719
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n = list(map(int, input().split(' '))) total = 0 for i in n: total+=i print(total//3)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python n = list(map(int, input().split(' '))) total = 0 for i in n: total+=i print(total//3) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,579,527,278
2,147,483,647
Python 3
OK
TESTS
30
310
0
import math a=input("") count=0 for i in a: if(i.isupper()): count+=1 if(count>(len(a)-count)): print(a.upper()) else: print(a.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python import math a=input("") count=0 for i in a: if(i.isupper()): count+=1 if(count>(len(a)-count)): print(a.upper()) else: print(a.lower()) ```
3.9225
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { "input": "2 6 4 5 6 5 1 3", "output": "0" }, { "input": "1 7 3 5 3 6 2 1", "output": "6" }, { "input": "2 4 5 4 5 7 3 2", "output": "1" }, { "input": "2 3 6 5 7 8 2 1", "output": "4" }, { "input": "1 4 5 5 3 10 3 1", "output": "6" }, { "input": "1 4 6 7 3 5 1 3", "output": "1" }, { "input": "1 6 5 5 5 8 3 1", "output": "8" }, { "input": "1 7 5 3 3 9 2 1", "output": "9" }, { "input": "3 5 3 7 6 10 3 1", "output": "1" }, { "input": "3 6 3 5 3 6 3 1", "output": "2" }, { "input": "1 7 5 5 5 5 2 2", "output": "2" }, { "input": "2 5 3 5 6 9 2 1", "output": "3" }, { "input": "3 4 3 5 3 6 2 1", "output": "2" }, { "input": "1 5 5 4 7 6 3 1", "output": "6" }, { "input": "2 3 7 6 5 9 3 1", "output": "3" }, { "input": "2 6 5 3 3 8 1 1", "output": "4" }, { "input": "2 4 7 3 4 10 2 1", "output": "5" }, { "input": "1 1000 1000 1000 1000 1000 1 1", "output": "1000" }, { "input": "17 1000 1000 1000 1000 1000 3 7", "output": "8" }, { "input": "115 1000 1000 1000 1000 1000 17 15", "output": "0" }, { "input": "1 587 981 1 2 1 1 1", "output": "1" }, { "input": "1 1 2 1 2 2 1 1", "output": "2" } ]
1,694,079,145
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
92
0
n, k, l, c, d, p, nl, np = list(map(int, input().split())) milk=k*l toast=milk//n lime=c*d salt=p//np min_value=min(toast,lime,salt) value=min_value//n print(value)
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? Input Specification: The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. Output Specification: Print a single integer — the number of toasts each friend can make. Demo Input: ['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
```python n, k, l, c, d, p, nl, np = list(map(int, input().split())) milk=k*l toast=milk//n lime=c*d salt=p//np min_value=min(toast,lime,salt) value=min_value//n print(value) ```
0
0
none
none
none
0
[ "none" ]
null
null
This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right. This game will go on for *m* rounds. In each round, Ithea will give Chtholly an integer between 1 and *c*, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one). Chtholly wins if, at any time, all the sheets are filled with a number and the *n* numbers are in non-decreasing order looking from left to right from sheet 1 to sheet *n*, and if after *m* rounds she still doesn't win, she loses the game. Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.
The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.
none
[ "2 4 4\n2\n1\n3\n" ]
[ "1\n2\n2\n" ]
In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets were filled with a number and they were non-decreasing, so she won the game. Note that it is required that your program terminate immediately after Chtholly wins and do not read numbers from the input for the remaining rounds. If not, undefined behaviour may arise and it won't be sure whether your program will be accepted or rejected. Also because of this, please be careful when hacking others' codes. In the sample, Chtholly won the game after the 3rd round, so it is required that your program doesn't read the number of the remaining 4th round. The input format for hacking: - The first line contains 3 integers *n*, *m* and *c*; - The following *m* lines each contains an integer between 1 and *c*, indicating the number given to Chtholly in each round.
0
[ { "input": "2 4 4\n2\n1\n3\n4", "output": "3" }, { "input": "2 2 2\n1\n2", "output": "2" }, { "input": "3 6 3\n1\n2\n1\n3\n1\n3", "output": "3" }, { "input": "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4", "output": "4" }, { "input": "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8\n3\n11\n13\n5\n12\n11\n9\n3\n10\n9\n9\n13\n13\n5\n6\n11\n3\n15\n8\n8\n10\n13\n7\n6\n4\n14\n9\n10\n5\n13\n4\n1\n8\n6\n13\n1\n3\n4\n9\n12\n2\n7\n3\n3\n7\n2\n2\n9\n2\n4\n2\n2\n11\n12\n15\n13\n6\n2\n11\n1\n8\n3\n13\n6\n15\n6\n4\n3\n4\n15\n15\n9\n5\n8\n3\n6\n14\n14\n5\n9\n4\n4\n14\n1\n12\n4\n12\n9\n11\n7\n4\n2\n5\n4\n4\n13\n13\n4\n5\n8\n3\n4\n2\n15\n3\n10\n9\n8\n12\n8", "output": "20" }, { "input": "2 2 2\n2\n1", "output": "2" }, { "input": "2 2 1\n1\n1", "output": "2" }, { "input": "2 2 2\n2\n2", "output": "2" }, { "input": "3 3 2\n2\n2\n1", "output": "3" }, { "input": "3 3 2\n1\n2\n1", "output": "3" }, { "input": "3 3 2\n2\n1\n2", "output": "3" }, { "input": "3 3 2\n2\n1\n1", "output": "3" }, { "input": "3 3 1\n1\n1\n1", "output": "3" }, { "input": "3 6 3\n2\n2\n3\n3\n1\n1", "output": "5" }, { "input": "3 6 3\n2\n2\n1\n1\n3\n3", "output": "3" }, { "input": "3 6 3\n3\n3\n2\n2\n1\n1", "output": "3" }, { "input": "4 4 2\n1\n2\n2\n1", "output": "4" }, { "input": "4 4 2\n1\n2\n1\n2", "output": "4" }, { "input": "4 4 2\n2\n2\n2\n1", "output": "4" }, { "input": "4 8 3\n2\n1\n2\n1\n2\n1\n1\n1", "output": "4" }, { "input": "4 8 3\n3\n2\n3\n2\n3\n2\n3\n1", "output": "6" }, { "input": "4 8 3\n2\n3\n2\n3\n3\n3\n3\n1", "output": "6" }, { "input": "4 8 4\n2\n3\n2\n3\n2\n3\n2\n3", "output": "4" }, { "input": "4 8 4\n3\n4\n3\n3\n4\n4\n1\n2", "output": "7" }, { "input": "10 100 20\n4\n1\n15\n2\n11\n1\n18\n9\n17\n5\n17\n12\n20\n6\n14\n19\n20\n3\n6\n14\n12\n17\n17\n10\n11\n8\n6\n6\n19\n16\n20\n6\n14\n5\n6\n19\n16\n11\n12\n1\n18\n10\n20\n8\n6\n12\n18\n16\n9\n10\n13\n17\n19\n7\n15\n7\n11\n1\n9\n10\n12\n5\n4\n16\n5\n7\n9\n15\n14\n20\n6\n3\n12\n10\n3\n6\n1\n16\n15\n18\n6\n19\n4\n17\n15\n15\n2\n6\n18\n12\n20\n10\n5\n13\n9\n11\n20\n20\n4\n16", "output": "20" }, { "input": "10 100 20\n11\n11\n11\n11\n11\n11\n11\n11\n11\n10\n10\n10\n10\n10\n10\n10\n10\n10\n9\n9\n9\n9\n9\n9\n9\n9\n9\n8\n8\n8\n8\n8\n8\n8\n8\n8\n7\n7\n7\n7\n7\n7\n7\n7\n7\n6\n6\n6\n6\n6\n6\n6\n6\n6\n5\n5\n5\n5\n5\n5\n5\n5\n5\n4\n4\n4\n4\n4\n4\n4\n4\n4\n3\n3\n3\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n12", "output": "10" } ]
1,589,371,206
5,106
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
import sys n, m, c = map(int, input().split()) l = [0 for _ in range(n)] for j in range(m): p = int(input()) if p>int(c/2): i = n-1 while (i>=0 and p<=l[i]): i-=1 l[i] = p else: i = 0 while (i<n and p>=l[i]): i+=1 l[i] = p print(i+1) # print(l) sys.stdout.flush() if (0 not in l) and (sorted(l)==l): break
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right. This game will go on for *m* rounds. In each round, Ithea will give Chtholly an integer between 1 and *c*, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one). Chtholly wins if, at any time, all the sheets are filled with a number and the *n* numbers are in non-decreasing order looking from left to right from sheet 1 to sheet *n*, and if after *m* rounds she still doesn't win, she loses the game. Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number. Input Specification: The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process. Output Specification: none Demo Input: ['2 4 4\n2\n1\n3\n'] Demo Output: ['1\n2\n2\n'] Note: In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets were filled with a number and they were non-decreasing, so she won the game. Note that it is required that your program terminate immediately after Chtholly wins and do not read numbers from the input for the remaining rounds. If not, undefined behaviour may arise and it won't be sure whether your program will be accepted or rejected. Also because of this, please be careful when hacking others' codes. In the sample, Chtholly won the game after the 3rd round, so it is required that your program doesn't read the number of the remaining 4th round. The input format for hacking: - The first line contains 3 integers *n*, *m* and *c*; - The following *m* lines each contains an integer between 1 and *c*, indicating the number given to Chtholly in each round.
```python import sys n, m, c = map(int, input().split()) l = [0 for _ in range(n)] for j in range(m): p = int(input()) if p>int(c/2): i = n-1 while (i>=0 and p<=l[i]): i-=1 l[i] = p else: i = 0 while (i<n and p>=l[i]): i+=1 l[i] = p print(i+1) # print(l) sys.stdout.flush() if (0 not in l) and (sorted(l)==l): break ```
-1
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,694,606,722
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
m = '' for i in range(int(input()): m = input() if len(m) > 10: print(m[0] + str(len(m)) + m[-1] continue print(m)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python m = '' for i in range(int(input()): m = input() if len(m) > 10: print(m[0] + str(len(m)) + m[-1] continue print(m) ```
-1
870
A
Search for Pretty Integers
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Print the smallest pretty integer.
[ "2 3\n4 2\n5 7 6\n", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n" ]
[ "25\n", "1\n" ]
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
500
[ { "input": "2 3\n4 2\n5 7 6", "output": "25" }, { "input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n9\n1", "output": "19" }, { "input": "9 1\n5 4 2 3 6 1 7 9 8\n9", "output": "9" }, { "input": "5 3\n7 2 5 8 6\n3 1 9", "output": "12" }, { "input": "4 5\n5 2 6 4\n8 9 1 3 7", "output": "12" }, { "input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "output": "1" }, { "input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "output": "1" }, { "input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n8\n9", "output": "89" }, { "input": "1 1\n9\n8", "output": "89" }, { "input": "1 1\n1\n2", "output": "12" }, { "input": "1 1\n2\n1", "output": "12" }, { "input": "1 1\n9\n9", "output": "9" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "4 5\n3 2 4 5\n1 6 5 9 8", "output": "5" }, { "input": "3 2\n4 5 6\n1 5", "output": "5" }, { "input": "5 4\n1 3 5 6 7\n2 4 3 9", "output": "3" }, { "input": "5 5\n1 3 5 7 9\n2 4 6 8 9", "output": "9" }, { "input": "2 2\n1 8\n2 8", "output": "8" }, { "input": "5 5\n5 6 7 8 9\n1 2 3 4 5", "output": "5" }, { "input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6", "output": "2" }, { "input": "2 2\n1 5\n2 5", "output": "5" }, { "input": "4 4\n1 3 5 8\n2 4 6 8", "output": "8" }, { "input": "3 3\n1 5 3\n2 5 7", "output": "5" }, { "input": "3 3\n3 6 8\n2 6 9", "output": "6" }, { "input": "2 2\n1 4\n2 4", "output": "4" }, { "input": "5 3\n3 4 5 6 7\n1 5 9", "output": "5" }, { "input": "4 4\n1 2 3 4\n2 5 6 7", "output": "2" }, { "input": "5 5\n1 2 3 4 5\n9 2 1 7 5", "output": "1" }, { "input": "2 2\n1 3\n2 3", "output": "3" }, { "input": "3 3\n3 2 1\n3 2 1", "output": "1" }, { "input": "3 3\n1 3 5\n2 3 6", "output": "3" }, { "input": "3 3\n5 6 7\n5 6 7", "output": "5" }, { "input": "1 2\n5\n2 5", "output": "5" }, { "input": "3 3\n2 4 9\n7 8 9", "output": "9" }, { "input": "3 3\n1 2 4\n3 4 5", "output": "4" }, { "input": "3 2\n1 4 9\n2 4", "output": "4" }, { "input": "3 3\n3 5 6\n1 5 9", "output": "5" }, { "input": "3 2\n1 2 4\n3 4", "output": "4" }, { "input": "2 4\n8 9\n1 2 3 9", "output": "9" }, { "input": "1 2\n9\n8 9", "output": "9" }, { "input": "3 2\n1 2 4\n4 2", "output": "2" }, { "input": "2 3\n4 5\n1 3 5", "output": "5" }, { "input": "3 2\n1 2 3\n2 3", "output": "2" }, { "input": "4 3\n1 3 5 9\n2 8 9", "output": "9" }, { "input": "2 2\n1 9\n9 2", "output": "9" } ]
1,617,212,475
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
// Problem: A. Search for Pretty Integers // Contest: Codeforces - Technocup 2018 - Elimination Round 2 // URL: https://codeforces.com/problemset/problem/870/A // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define lli long long int int main() { cin.tie(0); ios::sync_with_stdio(false); int t =1; // cin>>t; while(t--) { lli n,m;cin>>n>>m; // vector<lli> a(n); // vector<lli> b(m); lli a = 10; lli b = 11; for(lli i=0;i<n;++i){ lli temp;cin>>temp; a = min(a,temp); } cin.ignore(); for(lli i=0;i<m;++i){ lli temp2; cin>>temp2; b = min(b,temp2); } if(a==b)cout << a; else cout << min(a,b) << max(a,b); } }
Title: Search for Pretty Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. Output Specification: Print the smallest pretty integer. Demo Input: ['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n'] Demo Output: ['25\n', '1\n'] Note: In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
```python // Problem: A. Search for Pretty Integers // Contest: Codeforces - Technocup 2018 - Elimination Round 2 // URL: https://codeforces.com/problemset/problem/870/A // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define lli long long int int main() { cin.tie(0); ios::sync_with_stdio(false); int t =1; // cin>>t; while(t--) { lli n,m;cin>>n>>m; // vector<lli> a(n); // vector<lli> b(m); lli a = 10; lli b = 11; for(lli i=0;i<n;++i){ lli temp;cin>>temp; a = min(a,temp); } cin.ignore(); for(lli i=0;i<m;++i){ lli temp2; cin>>temp2; b = min(b,temp2); } if(a==b)cout << a; else cout << min(a,b) << max(a,b); } } ```
-1
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "4\n82 46 8 44", "output": "3 1\n4 2" }, { "input": "2\n35 50", "output": "1 2" }, { "input": "8\n24 39 49 38 44 64 44 50", "output": "1 6\n4 8\n2 3\n5 7" }, { "input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14", "output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15" }, { "input": "12\n22 83 2 67 55 12 40 93 83 73 12 28", "output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5" }, { "input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43", "output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7" }, { "input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58", "output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16" }, { "input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62", "output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12" }, { "input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76", "output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3" }, { "input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8", "output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5" }, { "input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41", "output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36" }, { "input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55", "output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12" }, { "input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25", "output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27" }, { "input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30", "output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10" }, { "input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39", "output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32" }, { "input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26", "output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54" }, { "input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30", "output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10" }, { "input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18", "output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34" }, { "input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65", "output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53" }, { "input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50", "output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14" }, { "input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57", "output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7" }, { "input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49", "output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24" }, { "input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69", "output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9" }, { "input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57", "output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20" }, { "input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34", "output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11" }, { "input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43", "output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3" }, { "input": "4\n100 100 1 1", "output": "3 2\n4 1" }, { "input": "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": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "4\n3 4 4 5", "output": "1 4\n2 3" }, { "input": "4\n1 1 2 2", "output": "1 4\n2 3" }, { "input": "4\n1 2 3 4", "output": "1 4\n2 3" } ]
1,564,368,981
2,147,483,647
Python 3
OK
TESTS
35
280
1,638,400
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n=I() l=LI() l2=[] for i,x in enumerate(l): l2.append([i,x]) l2=sorted(l2,key=lambda x:x[1]) for i in range(n//2): print(l2[i][0]+1,l2[n-i-1][0]+1) main() # print(main())
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. Output Specification: Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. Demo Input: ['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n'] Demo Output: ['1 3\n6 2\n4 5\n', '1 2\n3 4\n'] Note: In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n=I() l=LI() l2=[] for i,x in enumerate(l): l2.append([i,x]) l2=sorted(l2,key=lambda x:x[1]) for i in range(n//2): print(l2[i][0]+1,l2[n-i-1][0]+1) main() # print(main()) ```
3
549
G
Happy Line
PROGRAMMING
2,200
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of *n* Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people, so each person agrees to swap places with the person right behind him for just 1 dollar. More formally, if person *a* stands just behind person *b*, then person *a* can pay person *b* 1 dollar, then *a* and *b* get swapped. Of course, if person *a* has zero dollars, he can not swap places with person *b*. Residents of Berland are strange people. In particular, they get upset when there is someone with a strictly smaller sum of money in the line in front of them. Can you help the residents of Berland form such order in the line so that they were all happy? A happy resident is the one who stands first in the line or the one in front of who another resident stands with not less number of dollars. Note that the people of Berland are people of honor and they agree to swap places only in the manner described above.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of residents who stand in the line. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=109), where *a**i* is the number of Berland dollars of a man standing on the *i*-th position in the line. The positions are numbered starting from the end of the line.
If it is impossible to make all the residents happy, print ":(" without the quotes. Otherwise, print in the single line *n* space-separated integers, the *i*-th of them must be equal to the number of money of the person on position *i* in the new line. If there are multiple answers, print any of them.
[ "2\n11 8\n", "5\n10 9 7 10 6\n", "3\n12 3 3\n" ]
[ "9 10 ", ":(\n", "4 4 10 " ]
In the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line. In the second sample it is impossible to achieve the desired result. In the third sample the first person can swap with the second one, then they will have the following numbers of dollars: 4 11 3, then the second person (in the new line) swaps with the third one, and the resulting numbers of dollars will equal to: 4 4 10. In this line everybody will be happy.
1,500
[ { "input": "2\n11 8", "output": "9 10 " }, { "input": "5\n10 9 7 10 6", "output": ":(" }, { "input": "3\n12 3 3", "output": "4 4 10 " }, { "input": "4\n7 3 9 10", "output": "4 6 9 10 " }, { "input": "1\n1", "output": "1 " }, { "input": "5\n15 5 8 6 3", "output": "6 6 7 7 11 " }, { "input": "1\n1000000000", "output": "1000000000 " }, { "input": "2\n2 1", "output": ":(" }, { "input": "3\n11 1 9", "output": ":(" }, { "input": "1\n0", "output": "0 " }, { "input": "20\n38 32 21 44 26 24 15 32 34 40 31 33 33 13 26 28 12 10 14 18", "output": "21 22 24 24 24 24 24 25 25 28 28 28 28 28 28 28 28 28 29 30 " }, { "input": "20\n43 38 20 41 16 37 27 29 19 17 24 19 28 8 14 32 13 21 32 16", "output": "20 20 20 23 23 23 23 23 25 25 25 25 26 26 26 27 27 27 29 31 " }, { "input": "20\n44 50 41 18 28 31 21 38 12 20 28 15 12 29 16 31 34 24 19 15", "output": "20 20 22 23 23 24 24 25 26 27 27 27 29 29 29 29 29 29 32 32 " }, { "input": "10\n920480900 920480899 920480898 920480897 920480896 920480895 920480894 920480893 920480892 920480891", "output": ":(" }, { "input": "10\n536259132 536259132 536259132 536259132 536259132 536259132 536259132 536259132 536259132 536259132", "output": "536259132 536259132 536259132 536259132 536259132 536259132 536259132 536259132 536259132 536259132 " }, { "input": "10\n876584065 876584063 876584061 876584059 876584057 876584055 876584053 876584051 876584049 876584047", "output": "876584056 876584056 876584056 876584056 876584056 876584056 876584056 876584056 876584056 876584056 " }, { "input": "10\n528402489 528402486 528402483 528402480 528402477 528402474 528402471 528402468 528402465 528402462", "output": "528402471 528402472 528402473 528402474 528402475 528402476 528402477 528402478 528402479 528402480 " }, { "input": "10\n383593860 383593860 383593860 383593860 383593860 383593858 383593856 383593854 383593852 383593850", "output": ":(" }, { "input": "10\n198447418 198447416 198447414 198447412 198447410 198447410 198447410 198447410 198447410 198447410", "output": ":(" }, { "input": "10\n520230360 520230361 520230362 520230363 520230364 520230365 520230366 520230367 520230368 520230369", "output": "520230360 520230361 520230362 520230363 520230364 520230365 520230366 520230367 520230368 520230369 " } ]
1,689,429,450
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689429450.4168031")# 1689429450.4168234
Title: Happy Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of *n* Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people, so each person agrees to swap places with the person right behind him for just 1 dollar. More formally, if person *a* stands just behind person *b*, then person *a* can pay person *b* 1 dollar, then *a* and *b* get swapped. Of course, if person *a* has zero dollars, he can not swap places with person *b*. Residents of Berland are strange people. In particular, they get upset when there is someone with a strictly smaller sum of money in the line in front of them. Can you help the residents of Berland form such order in the line so that they were all happy? A happy resident is the one who stands first in the line or the one in front of who another resident stands with not less number of dollars. Note that the people of Berland are people of honor and they agree to swap places only in the manner described above. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of residents who stand in the line. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=109), where *a**i* is the number of Berland dollars of a man standing on the *i*-th position in the line. The positions are numbered starting from the end of the line. Output Specification: If it is impossible to make all the residents happy, print ":(" without the quotes. Otherwise, print in the single line *n* space-separated integers, the *i*-th of them must be equal to the number of money of the person on position *i* in the new line. If there are multiple answers, print any of them. Demo Input: ['2\n11 8\n', '5\n10 9 7 10 6\n', '3\n12 3 3\n'] Demo Output: ['9 10 ', ':(\n', '4 4 10 '] Note: In the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line. In the second sample it is impossible to achieve the desired result. In the third sample the first person can swap with the second one, then they will have the following numbers of dollars: 4 11 3, then the second person (in the new line) swaps with the third one, and the resulting numbers of dollars will equal to: 4 4 10. In this line everybody will be happy.
```python print("_RANDOM_GUESS_1689429450.4168031")# 1689429450.4168234 ```
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,636,028,937
2,147,483,647
Python 3
OK
TESTS
3
92
4,198,400
def main() -> None: n = int(input()) for _ in range(n): t = int(input()) n = 360 / (180 - t) print("YES" if n.is_integer() else "NO") if __name__ == '__main__': main()
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? Input Specification: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. Output Specification: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Demo Input: ['3\n30\n60\n90\n'] Demo Output: ['NO\nYES\nYES\n'] Note: In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
```python def main() -> None: n = int(input()) for _ in range(n): t = int(input()) n = 360 / (180 - t) print("YES" if n.is_integer() else "NO") if __name__ == '__main__': main() ```
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "output": "8" }, { "input": "31", "output": "3" }, { "input": "59", "output": "8" }, { "input": "79", "output": "9" }, { "input": "7", "output": "3" }, { "input": "55", "output": "4" }, { "input": "40", "output": "2" }, { "input": "719", "output": "13" }, { "input": "847", "output": "13" }, { "input": "225", "output": "4" }, { "input": "4704", "output": "51" }, { "input": "1132", "output": "15" }, { "input": "7811", "output": "80" }, { "input": "7981", "output": "84" }, { "input": "82655", "output": "830" }, { "input": "6364", "output": "70" }, { "input": "74611", "output": "748" }, { "input": "45391", "output": "459" }, { "input": "620448", "output": "6210" }, { "input": "265145", "output": "2654" }, { "input": "671704", "output": "6721" }, { "input": "365173", "output": "3658" }, { "input": "7130872", "output": "71314" }, { "input": "9628747", "output": "96292" }, { "input": "8898399", "output": "88993" }, { "input": "9497953", "output": "94985" }, { "input": "19070947", "output": "190714" }, { "input": "20185520", "output": "201856" }, { "input": "91402248", "output": "914028" }, { "input": "27035533", "output": "270360" }, { "input": "22717528", "output": "227180" }, { "input": "24403439", "output": "244041" }, { "input": "163565555", "output": "1635659" }, { "input": "152541908", "output": "1525423" }, { "input": "668439837", "output": "6684403" }, { "input": "20", "output": "1" }, { "input": "999999999", "output": "10000009" }, { "input": "10", "output": "1" }, { "input": "7", "output": "3" }, { "input": "6", "output": "2" }, { "input": "99999999", "output": "1000009" }, { "input": "1000001", "output": "10001" }, { "input": "2521", "output": "27" } ]
1,690,113,974
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=int(input()) l=[1,5,10,20,100] b=0 for i in l: b += n // i n %= i print(b)
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input Specification: The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). Output Specification: Output the minimum number of bills that Allen could receive. Demo Input: ['125\n', '43\n', '1000000000\n'] Demo Output: ['3\n', '5\n', '10000000\n'] Note: In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
```python n=int(input()) l=[1,5,10,20,100] b=0 for i in l: b += n // i n %= i print(b) ```
0
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter.
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. 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.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "output": "25" }, { "input": "10 90\n24 27 40 41 61 69 73 87 95 97", "output": "120" }, { "input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99", "output": "79351" }, { "input": "1 14751211\n847188590", "output": "0" }, { "input": "2 1000000000\n-907894512 -289906312", "output": "0" }, { "input": "2 1000000000\n-14348867 1760823", "output": "0" }, { "input": "3 1000000000\n-5 -1 1", "output": "1" } ]
1,459,344,248
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
1,126,400
from collections import deque n,d=[int(i) for i in input().split()] Deq=[int(j) for j in input().split()] cnt=0 for i in range(0,n-2): for j in range(n-1,i+1,-1): if Deq[j]-Deq[i]<=d : cnt+=int((j-i)*(j-i-1)/2) break print(cnt)
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter. Input Specification: The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase. Output Specification: Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. 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. Demo Input: ['4 3\n1 2 3 4\n', '4 2\n-3 -2 -1 0\n', '5 19\n1 10 20 30 50\n'] Demo Output: ['4\n', '2\n', '1\n'] Note: In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
```python from collections import deque n,d=[int(i) for i in input().split()] Deq=[int(j) for j in input().split()] cnt=0 for i in range(0,n-2): for j in range(n-1,i+1,-1): if Deq[j]-Deq[i]<=d : cnt+=int((j-i)*(j-i-1)/2) break print(cnt) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,684,385,774
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
n,m,k = map(int,input().split()) print(1 if n==m==k else ((n + k-(n%k)) * (m +k-(m%k)))//(k**2))
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,k = map(int,input().split()) print(1 if n==m==k else ((n + k-(n%k)) * (m +k-(m%k)))//(k**2)) ```
0
863
A
Quasi-palindrome
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number *x*. Check if it's a quasi-palindromic number.
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
[ "131\n", "320\n", "2010200\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
0
[ { "input": "131", "output": "YES" }, { "input": "320", "output": "NO" }, { "input": "2010200", "output": "YES" }, { "input": "1", "output": "YES" }, { "input": "1000000000", "output": "YES" }, { "input": "999999999", "output": "YES" }, { "input": "999999998", "output": "NO" }, { "input": "102000", "output": "NO" }, { "input": "210000000", "output": "NO" }, { "input": "213443120", "output": "YES" }, { "input": "99", "output": "YES" }, { "input": "22002", "output": "NO" }, { "input": "1010", "output": "YES" }, { "input": "1201", "output": "NO" }, { "input": "6460046", "output": "NO" }, { "input": "503435", "output": "NO" }, { "input": "21002", "output": "NO" }, { "input": "101001", "output": "NO" }, { "input": "200102", "output": "NO" }, { "input": "20010002", "output": "NO" }, { "input": "33003", "output": "NO" }, { "input": "100101", "output": "NO" }, { "input": "1021", "output": "NO" }, { "input": "1101", "output": "NO" }, { "input": "10101100", "output": "NO" }, { "input": "101", "output": "YES" }, { "input": "1011", "output": "NO" }, { "input": "11010", "output": "NO" }, { "input": "10110", "output": "NO" }, { "input": "110000", "output": "YES" }, { "input": "2011", "output": "NO" }, { "input": "10020001", "output": "NO" }, { "input": "12505021", "output": "NO" }, { "input": "12310", "output": "NO" }, { "input": "100501", "output": "NO" }, { "input": "11001", "output": "NO" }, { "input": "20020002", "output": "NO" }, { "input": "202002", "output": "NO" }, { "input": "1001", "output": "YES" }, { "input": "1020021", "output": "NO" }, { "input": "60660", "output": "NO" }, { "input": "98809", "output": "NO" }, { "input": "11000000", "output": "YES" }, { "input": "807008", "output": "NO" } ]
1,697,909,894
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
#O(n) x = input() #O(1) if x == x[::-1]: #O(1) #O(n) print("Yes") else: print("No")
Title: Quasi-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number *x*. Check if it's a quasi-palindromic number. Input Specification: The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. Output Specification: Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). Demo Input: ['131\n', '320\n', '2010200\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python #O(n) x = input() #O(1) if x == x[::-1]: #O(1) #O(n) print("Yes") else: print("No") ```
0
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 2 5 3 4", "output": "chest" }, { "input": "8\n7 2 9 10 3 8 10 6", "output": "chest" }, { "input": "9\n5 4 2 3 4 4 5 2 2", "output": "chest" }, { "input": "10\n4 9 8 5 3 8 8 10 4 2", "output": "biceps" }, { "input": "11\n10 9 7 6 1 3 9 7 1 3 5", "output": "chest" }, { "input": "12\n24 22 6 16 5 21 1 7 2 19 24 5", "output": "chest" }, { "input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "output": "chest" }, { "input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7", "output": "back" }, { "input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12", "output": "chest" }, { "input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8", "output": "biceps" }, { "input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19", "output": "chest" }, { "input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21", "output": "back" }, { "input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24", "output": "chest" }, { "input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20", "output": "chest" }, { "input": "1\n10", "output": "chest" }, { "input": "2\n15 3", "output": "chest" }, { "input": "3\n21 11 19", "output": "chest" }, { "input": "4\n19 24 13 15", "output": "chest" }, { "input": "5\n4 24 1 9 19", "output": "biceps" }, { "input": "6\n6 22 24 7 15 24", "output": "back" }, { "input": "7\n10 8 23 23 14 18 14", "output": "chest" }, { "input": "8\n5 16 8 9 17 16 14 7", "output": "biceps" }, { "input": "9\n12 3 10 23 6 4 22 13 12", "output": "chest" }, { "input": "10\n1 9 20 18 20 17 7 24 23 2", "output": "back" }, { "input": "11\n22 25 8 2 18 15 1 13 1 11 4", "output": "biceps" }, { "input": "12\n20 12 14 2 15 6 24 3 11 8 11 14", "output": "chest" }, { "input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18", "output": "back" }, { "input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22", "output": "biceps" }, { "input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6", "output": "back" }, { "input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14", "output": "chest" }, { "input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10", "output": "biceps" }, { "input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17", "output": "chest" }, { "input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14", "output": "back" }, { "input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6", "output": "back" }, { "input": "1\n19", "output": "chest" }, { "input": "2\n1 7", "output": "biceps" }, { "input": "3\n18 18 23", "output": "back" }, { "input": "4\n12 15 1 13", "output": "chest" }, { "input": "5\n11 14 25 21 21", "output": "biceps" }, { "input": "6\n11 9 12 11 22 18", "output": "biceps" }, { "input": "7\n11 1 16 20 21 25 20", "output": "chest" }, { "input": "8\n1 2 20 9 3 22 17 4", "output": "back" }, { "input": "9\n19 2 10 19 15 20 3 1 13", "output": "back" }, { "input": "10\n11 2 11 8 21 16 2 3 19 9", "output": "back" }, { "input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24", "output": "chest" }, { "input": "12\n4 24 21 3 13 24 22 13 12 21 1 15", "output": "back" }, { "input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3", "output": "biceps" }, { "input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11", "output": "biceps" }, { "input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17", "output": "back" }, { "input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17", "output": "chest" }, { "input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8", "output": "chest" }, { "input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22", "output": "chest" }, { "input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24", "output": "chest" }, { "input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23", "output": "biceps" }, { "input": "1\n19", "output": "chest" }, { "input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22", "output": "biceps" } ]
1,610,274,078
2,147,483,647
Python 3
OK
TESTS
61
154
307,200
n = int(input()) x,y,z = 0,0,0 l = list(map(int, input().split())) x = sum(l[0:len(l):3]) y = sum(l[1:len(l):3]) z = sum(l[2:len(l):3]) if x == max(x,y,z): print("chest") elif y == max(x,y,z): print("biceps") elif z == max(x,y,z): print("back")
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. Output Specification: Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. Demo Input: ['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n'] Demo Output: ['biceps\n', 'back\n', 'chest\n'] Note: In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
```python n = int(input()) x,y,z = 0,0,0 l = list(map(int, input().split())) x = sum(l[0:len(l):3]) y = sum(l[1:len(l):3]) z = sum(l[2:len(l):3]) if x == max(x,y,z): print("chest") elif y == max(x,y,z): print("biceps") elif z == max(x,y,z): print("back") ```
3
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
1,606,751,236
2,147,483,647
PyPy 3
OK
TESTS
95
1,715
28,979,200
t=[] f={} n=int(input()) for i in range(n): a = input() t.append(a) for j in range(n-1,-1,-1): if t[j] not in f: print(t[j]) f[t[j]]=1
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. Output Specification: Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. Demo Input: ['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n'] Demo Output: ['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n'] Note: In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
```python t=[] f={} n=int(input()) for i in range(n): a = input() t.append(a) for j in range(n-1,-1,-1): if t[j] not in f: print(t[j]) f[t[j]]=1 ```
3
616
B
Dinner with Emma
PROGRAMMING
1,000
[ "games", "greedy" ]
null
null
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Print the only integer *a* — the cost of the dinner for Jack and Emma.
[ "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n", "3 3\n1 2 3\n2 3 1\n3 1 2\n" ]
[ "2\n", "1\n" ]
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
0
[ { "input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2" }, { "input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n74 35 82 39 1 84 29 41 70 12", "output": "1" }, { "input": "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85", "output": "91" }, { "input": "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 825 540 435 54\n777 682 984 20 337 480 264 137 249 502\n51 467 479 228 923 752 714 436 199 973\n3 91 612 571 631 212 751 84 886 948\n252 130 583 23 194 985 234 978 709 16\n636 991 203 469 719 540 184 902 503 652\n826 680 150 284 37 987 360 183 447 51", "output": "184" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "2 1\n999999999\n1000000000", "output": "1000000000" } ]
1,646,054,890
2,147,483,647
Python 3
OK
TESTS
16
31
0
n,m = map(int,input().split()) max = 0 for i in range(n): a = list(map(int,input().split())) if min(a)>max: max = min(a) print(max)
Title: Dinner with Emma Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. Output Specification: Print the only integer *a* — the cost of the dinner for Jack and Emma. Demo Input: ['3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n', '3 3\n1 2 3\n2 3 1\n3 1 2\n'] Demo Output: ['2\n', '1\n'] Note: In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
```python n,m = map(int,input().split()) max = 0 for i in range(n): a = list(map(int,input().split())) if min(a)>max: max = min(a) print(max) ```
3
91
B
Queue
PROGRAMMING
1,500
[ "binary search", "data structures" ]
B. Queue
2
256
There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*. The *i*-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such *j* (*i*<=&lt;<=*j*), that *a**i*<=&gt;<=*a**j*. The displeasure of the *i*-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the *i*-th one. That is, the further that young walrus stands from him, the stronger the displeasure is. The airport manager asked you to count for each of *n* walruses in the queue his displeasure.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of walruses in the queue. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one.
Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus.
[ "6\n10 8 5 3 50 45\n", "7\n10 4 6 3 2 8 15\n", "5\n10 3 1 10 11\n" ]
[ "2 1 0 -1 0 -1 ", "4 2 1 0 -1 -1 -1 ", "1 0 -1 -1 -1 " ]
none
1,000
[ { "input": "6\n10 8 5 3 50 45", "output": "2 1 0 -1 0 -1 " }, { "input": "7\n10 4 6 3 2 8 15", "output": "4 2 1 0 -1 -1 -1 " }, { "input": "5\n10 3 1 10 11", "output": "1 0 -1 -1 -1 " }, { "input": "13\n18 9 8 9 23 20 18 18 33 25 31 37 36", "output": "2 0 -1 -1 2 1 -1 -1 1 -1 -1 0 -1 " }, { "input": "10\n15 21 17 22 27 21 31 26 32 30", "output": "-1 0 -1 1 2 -1 2 -1 0 -1 " }, { "input": "10\n18 20 18 17 17 13 22 20 34 29", "output": "4 3 2 1 0 -1 0 -1 0 -1 " }, { "input": "13\n16 14 12 9 11 28 30 21 35 30 32 31 43", "output": "3 2 1 -1 -1 1 0 -1 2 -1 0 -1 -1 " }, { "input": "15\n18 6 18 21 14 20 13 9 18 20 28 13 19 25 21", "output": "10 -1 8 8 6 6 0 -1 2 2 3 -1 -1 0 -1 " }, { "input": "11\n15 17 18 18 26 22 23 33 33 21 29", "output": "-1 -1 -1 -1 4 3 2 2 1 -1 -1 " }, { "input": "15\n14 4 5 12 6 19 14 19 12 22 23 17 14 21 27", "output": "7 -1 -1 0 -1 6 1 4 -1 3 2 0 -1 -1 -1 " }, { "input": "2\n1 1000000000", "output": "-1 -1 " }, { "input": "2\n1000000000 1", "output": "0 -1 " }, { "input": "5\n15 1 8 15 3", "output": "3 -1 1 0 -1 " }, { "input": "12\n5 1 2 5 100 1 1000 100 10000 20000 10000 20000", "output": "4 -1 2 1 0 -1 0 -1 -1 0 -1 -1 " } ]
1,598,550,755
2,147,483,647
PyPy 3
OK
TESTS
61
624
13,312,000
n=int(input()) a=list(map(int,input().split())) m=[0]*n for i in range(n-1,-1,-1): if(i==n-1): m[i]=a[i] else: m[i]=min(a[i],m[i+1]) res=[0 for i in range(n)] for i in range(n): left=i+1 right=n-1 ans=-1 while(left<=right): mid=left+(right-left)//2 if(m[mid]<a[i]): ans=mid left=mid+1 else: right=mid-1 if(ans!=-1): res[i]=abs(ans-i-1) else: res[i]=-1 print(*res)
Title: Queue Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*. The *i*-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such *j* (*i*<=&lt;<=*j*), that *a**i*<=&gt;<=*a**j*. The displeasure of the *i*-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the *i*-th one. That is, the further that young walrus stands from him, the stronger the displeasure is. The airport manager asked you to count for each of *n* walruses in the queue his displeasure. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of walruses in the queue. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. Output Specification: Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. Demo Input: ['6\n10 8 5 3 50 45\n', '7\n10 4 6 3 2 8 15\n', '5\n10 3 1 10 11\n'] Demo Output: ['2 1 0 -1 0 -1 ', '4 2 1 0 -1 -1 -1 ', '1 0 -1 -1 -1 '] Note: none
```python n=int(input()) a=list(map(int,input().split())) m=[0]*n for i in range(n-1,-1,-1): if(i==n-1): m[i]=a[i] else: m[i]=min(a[i],m[i+1]) res=[0 for i in range(n)] for i in range(n): left=i+1 right=n-1 ans=-1 while(left<=right): mid=left+(right-left)//2 if(m[mid]<a[i]): ans=mid left=mid+1 else: right=mid-1 if(ans!=-1): res[i]=abs(ans-i-1) else: res[i]=-1 print(*res) ```
3.819204
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10", "output": "3" }, { "input": "1\n01", "output": "1" }, { "input": "2\n01\n01", "output": "1" }, { "input": "2\n10\n01", "output": "2" }, { "input": "3\n01\n01\n01", "output": "1" }, { "input": "3\n10\n10\n01", "output": "2" }, { "input": "3\n01\n10\n10", "output": "2" }, { "input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10", "output": "55" } ]
1,691,765,236
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
n = int(input().strip() prev = "" output = 0 for x in range(n): current = input().strip() if current != prev: output+=1 prev=current print(output)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. Output Specification: On the single line of the output print the number of groups of magnets. Demo Input: ['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n'] Demo Output: ['3\n', '2\n'] Note: The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
```python n = int(input().strip() prev = "" output = 0 for x in range(n): current = input().strip() if current != prev: output+=1 prev=current print(output) ```
-1
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", "output": "1\n1 " }, { "input": "2\nBB", "output": "1\n2 " }, { "input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "output": "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 " }, { "input": "1\nW", "output": "0" }, { "input": "2\nWW", "output": "0" }, { "input": "2\nWB", "output": "1\n1 " }, { "input": "2\nBW", "output": "1\n1 " }, { "input": "3\nBBB", "output": "1\n3 " }, { "input": "3\nBWB", "output": "2\n1 1 " }, { "input": "3\nWBB", "output": "1\n2 " }, { "input": "3\nWWB", "output": "1\n1 " }, { "input": "3\nWBW", "output": "1\n1 " }, { "input": "3\nBWW", "output": "1\n1 " }, { "input": "3\nWWW", "output": "0" }, { "input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB", "output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 " }, { "input": "5\nBBBWB", "output": "2\n3 1 " }, { "input": "5\nBWWWB", "output": "2\n1 1 " }, { "input": "5\nWWWWB", "output": "1\n1 " }, { "input": "5\nBWWWW", "output": "1\n1 " }, { "input": "5\nBBBWW", "output": "1\n3 " }, { "input": "5\nWWBBB", "output": "1\n3 " }, { "input": "10\nBBBBBWWBBB", "output": "2\n5 3 " }, { "input": "10\nBBBBWBBWBB", "output": "3\n4 2 2 " }, { "input": "20\nBBBBBWWBWBBWBWWBWBBB", "output": "6\n5 1 2 1 1 3 " }, { "input": "20\nBBBWWWWBBWWWBWBWWBBB", "output": "5\n3 2 1 1 3 " }, { "input": "20\nBBBBBBBBWBBBWBWBWBBB", "output": "5\n8 3 1 1 3 " }, { "input": "20\nBBBWBWBWWWBBWWWWBWBB", "output": "6\n3 1 1 2 1 2 " }, { "input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB", "output": "5\n6 1 1 1 12 " }, { "input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB", "output": "9\n5 1 2 1 1 4 1 1 8 " }, { "input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB", "output": "7\n11 1 1 8 1 1 6 " }, { "input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW", "output": "9\n5 1 1 1 1 2 2 1 1 " }, { "input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB", "output": "6\n1 1 1 1 1 5 " }, { "input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB", "output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB", "output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n100 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB", "output": "11\n20 1 1 1 2 1 1 1 1 1 20 " }, { "input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB", "output": "11\n4 1 1 1 1 2 1 1 1 1 6 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "10\nWWBWWWBWBB", "output": "3\n1 1 2 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n17 31 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n24 42 " }, { "input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB", "output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 " }, { "input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB", "output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 " }, { "input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB", "output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 " }, { "input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB", "output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 " }, { "input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB", "output": "11\n1 5 3 4 3 1 1 2 1 2 4 " } ]
1,618,886,055
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
s = input() l = input() c = 0 for i in l: if i == "B": c+=1 else: print(c) c=0
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). Output Specification: The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. Demo Input: ['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n'] Demo Output: ['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 '] Note: The last sample case correspond to the picture in the statement.
```python s = input() l = input() c = 0 for i in l: if i == "B": c+=1 else: print(c) c=0 ```
0
660
C
Hard Process
PROGRAMMING
1,600
[ "binary search", "dp", "two pointers" ]
null
null
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*).
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*.
On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them.
[ "7 1\n1 0 0 1 1 0 1\n", "10 2\n1 0 0 1 0 1 0 1 0 1\n" ]
[ "4\n1 0 0 1 1 1 1\n", "5\n1 0 0 1 1 1 1 1 0 1\n" ]
none
0
[ { "input": "7 1\n1 0 0 1 1 0 1", "output": "4\n1 0 0 1 1 1 1" }, { "input": "10 2\n1 0 0 1 0 1 0 1 0 1", "output": "5\n1 0 0 1 1 1 1 1 0 1" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "7 0\n0 1 0 0 0 1 0", "output": "1\n0 1 0 0 0 1 0" }, { "input": "7 2\n1 0 1 1 0 0 0", "output": "5\n1 1 1 1 1 0 0" }, { "input": "7 3\n1 0 0 0 0 1 0", "output": "4\n1 1 1 1 0 1 0" }, { "input": "3 0\n1 1 1", "output": "3\n1 1 1" }, { "input": "1 0\n1", "output": "1\n1" }, { "input": "2 0\n0 1", "output": "1\n0 1" }, { "input": "1 1\n0", "output": "1\n1" }, { "input": "3 1\n0 0 1", "output": "2\n0 1 1" }, { "input": "2 0\n0 0", "output": "0\n0 0" }, { "input": "3 1\n0 0 0", "output": "1\n1 0 0" }, { "input": "7 7\n1 0 1 0 0 0 0", "output": "7\n1 1 1 1 1 1 1" }, { "input": "1 1\n1", "output": "1\n1" }, { "input": "3 0\n0 0 0", "output": "0\n0 0 0" }, { "input": "7 3\n1 1 1 1 1 1 1", "output": "7\n1 1 1 1 1 1 1" }, { "input": "10 3\n0 0 1 0 0 1 0 0 1 1", "output": "6\n0 0 1 0 1 1 1 1 1 1" }, { "input": "2 1\n0 0", "output": "1\n1 0" }, { "input": "2 2\n1 0", "output": "2\n1 1" } ]
1,599,823,139
1,439
PyPy 3
OK
TESTS
38
249
26,419,200
import sys n, k = map(int, sys.stdin.buffer.readline().split()) a = [0] + list(map(int, sys.stdin.buffer.readline().split())) zero = [0]*(n+1) for i in range(1, n+1): zero[i] = zero[i-1] + (1 if a[i] == 0 else 0) def solve(x): for i in range(x, n+1): if zero[i] - zero[i-x] <= k: return i return -1 ok, ng = 0, n+1 while abs(ok - ng) > 1: mid = (ok + ng) >> 1 if solve(mid) != -1: ok = mid else: ng = mid r = solve(ok) a[r-ok+1:r+1] = [1]*ok sys.stdout.buffer.write( (str(ok) + '\n' + ' '.join(map(str, a[1:]))).encode('utf-8'))
Title: Hard Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. Output Specification: On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them. Demo Input: ['7 1\n1 0 0 1 1 0 1\n', '10 2\n1 0 0 1 0 1 0 1 0 1\n'] Demo Output: ['4\n1 0 0 1 1 1 1\n', '5\n1 0 0 1 1 1 1 1 0 1\n'] Note: none
```python import sys n, k = map(int, sys.stdin.buffer.readline().split()) a = [0] + list(map(int, sys.stdin.buffer.readline().split())) zero = [0]*(n+1) for i in range(1, n+1): zero[i] = zero[i-1] + (1 if a[i] == 0 else 0) def solve(x): for i in range(x, n+1): if zero[i] - zero[i-x] <= k: return i return -1 ok, ng = 0, n+1 while abs(ok - ng) > 1: mid = (ok + ng) >> 1 if solve(mid) != -1: ok = mid else: ng = mid r = solve(ok) a[r-ok+1:r+1] = [1]*ok sys.stdout.buffer.write( (str(ok) + '\n' + ' '.join(map(str, a[1:]))).encode('utf-8')) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,635,206,722
2,147,483,647
Python 3
OK
TESTS
81
122
4,505,600
n=int(input()) a,b,c=0,0,0 for i in range(n): l=list(map(int,input().split())) a+=l[0] b+=l[1] c+=l[2] if a==0 and b==0 and c==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input()) a,b,c=0,0,0 for i in range(n): l=list(map(int,input().split())) a+=l[0] b+=l[1] c+=l[2] if a==0 and b==0 and c==0: print('YES') else: print('NO') ```
3.961108
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,521,117,744
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
124
5,632,000
m,n=map(int,input().split()) A=input() a=A.split() B=input() b=B.split() c=[] d=0 for i in range(0,m): for j in range(0,n): d=int(a[i])*int(b[j]) c.append(d) c.sort() print(c[-2])
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python m,n=map(int,input().split()) A=input() a=A.split() B=input() b=B.split() c=[] d=0 for i in range(0,m): for j in range(0,n): d=int(a[i])*int(b[j]) c.append(d) c.sort() print(c[-2]) ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,697,779,846
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
n=int(input()) lst=list(map(int,input().split())) m=int(input()) lstm=list(map(int,input().split())) dictv={} dictp={} for i in lstm: if(i not in dictv): for j in range(n): if(lst[j]==i): dictv[i]=j+1 dictp[i]=n-j else: dictv[i]=2*dictv[i] dictp[i]=2*dictp[i] print(sum(dictv.values()),sum(dictp.values()))
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n=int(input()) lst=list(map(int,input().split())) m=int(input()) lstm=list(map(int,input().split())) dictv={} dictp={} for i in lstm: if(i not in dictv): for j in range(n): if(lst[j]==i): dictv[i]=j+1 dictp[i]=n-j else: dictv[i]=2*dictv[i] dictp[i]=2*dictp[i] print(sum(dictv.values()),sum(dictp.values())) ```
0
814
A
An abandoned sentiment from past
PROGRAMMING
900
[ "constructive algorithms", "greedy", "implementation", "sortings" ]
null
null
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements. The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total.
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
[ "4 2\n11 0 0 14\n5 4\n", "6 1\n2 3 0 8 9 10\n5\n", "4 1\n8 94 0 4\n89\n", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
500
[ { "input": "4 2\n11 0 0 14\n5 4", "output": "Yes" }, { "input": "6 1\n2 3 0 8 9 10\n5", "output": "No" }, { "input": "4 1\n8 94 0 4\n89", "output": "Yes" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes" }, { "input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80", "output": "No" }, { "input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58", "output": "Yes" }, { "input": "4 1\n2 1 0 4\n3", "output": "Yes" }, { "input": "2 1\n199 0\n200", "output": "No" }, { "input": "3 2\n115 0 0\n145 191", "output": "Yes" }, { "input": "5 1\n196 197 198 0 200\n199", "output": "No" }, { "input": "5 1\n92 0 97 99 100\n93", "output": "No" }, { "input": "3 1\n3 87 0\n81", "output": "Yes" }, { "input": "3 1\n0 92 192\n118", "output": "Yes" }, { "input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22", "output": "Yes" }, { "input": "100 1\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\n67", "output": "No" }, { "input": "100 5\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\n98 64 55 52 29", "output": "Yes" }, { "input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27", "output": "Yes" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n11", "output": "Yes" }, { "input": "100 1\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n1", "output": "No" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\n100", "output": "No" }, { "input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65", "output": "Yes" }, { "input": "100 2\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n48 1", "output": "Yes" }, { "input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69", "output": "Yes" }, { "input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129", "output": "No" }, { "input": "5 2\n0 2 7 0 10\n1 8", "output": "Yes" }, { "input": "3 1\n5 4 0\n1", "output": "Yes" }, { "input": "3 1\n1 0 3\n4", "output": "Yes" }, { "input": "2 1\n0 2\n1", "output": "No" }, { "input": "2 1\n0 5\n7", "output": "Yes" }, { "input": "5 1\n10 11 0 12 13\n1", "output": "Yes" }, { "input": "5 1\n0 2 3 4 5\n6", "output": "Yes" }, { "input": "6 2\n1 0 3 4 0 6\n2 5", "output": "Yes" }, { "input": "7 2\n1 2 3 0 0 6 7\n4 5", "output": "Yes" }, { "input": "4 1\n1 2 3 0\n4", "output": "No" }, { "input": "2 2\n0 0\n1 2", "output": "Yes" }, { "input": "3 2\n1 0 0\n2 3", "output": "Yes" }, { "input": "4 2\n1 0 4 0\n5 2", "output": "Yes" }, { "input": "2 1\n0 1\n2", "output": "Yes" }, { "input": "5 2\n1 0 4 0 6\n2 5", "output": "Yes" }, { "input": "5 1\n2 3 0 4 5\n1", "output": "Yes" }, { "input": "3 1\n0 2 3\n5", "output": "Yes" }, { "input": "6 1\n1 2 3 4 5 0\n6", "output": "No" }, { "input": "5 1\n1 2 0 4 5\n6", "output": "Yes" }, { "input": "3 1\n5 0 2\n7", "output": "Yes" }, { "input": "4 1\n4 5 0 8\n3", "output": "Yes" }, { "input": "5 1\n10 11 12 0 14\n13", "output": "No" }, { "input": "4 1\n1 2 0 4\n5", "output": "Yes" }, { "input": "3 1\n0 11 14\n12", "output": "Yes" }, { "input": "4 1\n1 3 0 4\n2", "output": "Yes" }, { "input": "2 1\n0 5\n1", "output": "No" }, { "input": "5 1\n1 2 0 4 7\n5", "output": "Yes" }, { "input": "3 1\n2 3 0\n1", "output": "Yes" }, { "input": "6 1\n1 2 3 0 5 4\n6", "output": "Yes" }, { "input": "4 2\n11 0 0 14\n13 12", "output": "Yes" }, { "input": "2 1\n1 0\n2", "output": "No" }, { "input": "3 1\n1 2 0\n3", "output": "No" }, { "input": "4 1\n1 0 3 2\n4", "output": "Yes" }, { "input": "3 1\n0 1 2\n5", "output": "Yes" }, { "input": "3 1\n0 1 2\n3", "output": "Yes" }, { "input": "4 1\n0 2 3 4\n5", "output": "Yes" }, { "input": "6 1\n1 2 3 0 4 5\n6", "output": "Yes" }, { "input": "3 1\n1 2 0\n5", "output": "No" }, { "input": "4 2\n1 0 0 4\n3 2", "output": "Yes" }, { "input": "5 1\n2 3 0 5 7\n6", "output": "Yes" }, { "input": "3 1\n2 3 0\n4", "output": "No" }, { "input": "3 1\n1 0 11\n5", "output": "No" }, { "input": "4 1\n7 9 5 0\n8", "output": "Yes" }, { "input": "6 2\n1 2 3 0 5 0\n6 4", "output": "Yes" }, { "input": "3 2\n0 1 0\n3 2", "output": "Yes" }, { "input": "4 1\n6 9 5 0\n8", "output": "Yes" }, { "input": "2 1\n0 3\n6", "output": "Yes" }, { "input": "5 2\n1 2 0 0 5\n4 3", "output": "Yes" }, { "input": "4 2\n2 0 0 8\n3 4", "output": "Yes" }, { "input": "2 1\n0 2\n3", "output": "Yes" }, { "input": "3 1\n0 4 5\n6", "output": "Yes" }, { "input": "6 1\n1 2 3 4 0 5\n6", "output": "Yes" }, { "input": "2 1\n2 0\n3", "output": "No" }, { "input": "4 2\n11 0 0 200\n100 199", "output": "Yes" }, { "input": "2 1\n5 0\n4", "output": "Yes" }, { "input": "3 1\n1 0 5\n10", "output": "Yes" }, { "input": "6 2\n1 2 0 0 5 6\n3 4", "output": "Yes" }, { "input": "5 2\n1 0 3 0 5\n2 4", "output": "Yes" }, { "input": "4 1\n1 4 0 8\n3", "output": "Yes" }, { "input": "4 1\n5 9 4 0\n8", "output": "Yes" }, { "input": "4 2\n1 0 0 7\n3 2", "output": "Yes" }, { "input": "3 3\n0 0 0\n1 4 3", "output": "Yes" }, { "input": "5 5\n0 0 0 0 0\n5 4 3 2 1", "output": "Yes" }, { "input": "4 1\n3 9 4 0\n8", "output": "Yes" }, { "input": "4 2\n1 0 0 4\n2 3", "output": "Yes" }, { "input": "6 1\n2 4 0 8 9 10\n3", "output": "Yes" }, { "input": "4 1\n0 3 5 6\n9", "output": "Yes" }, { "input": "4 2\n1 2 0 0\n3 4", "output": "Yes" }, { "input": "5 1\n2 3 4 5 0\n1", "output": "Yes" }, { "input": "3 1\n2 0 4\n5", "output": "Yes" } ]
1,499,892,387
2,147,483,647
Python 3
OK
TESTS
96
77
5,529,600
n, k = list(map(int, input().split())) a = input() b = input().split() if len(set(b))>1: print("YES") else: b = list(map(int, b)) new_a = list(map(int, a.split())) c = 0 for i in range(len(new_a)): if new_a[i] == 0: new_a[i] = b[c] c += 1 old_a = list(new_a) new_a.sort() if new_a == old_a: print("NO") else: print("YES")
Title: An abandoned sentiment from past Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. Input Specification: The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements. The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. Output Specification: Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. Demo Input: ['4 2\n11 0 0 14\n5 4\n', '6 1\n2 3 0 8 9 10\n5\n', '4 1\n8 94 0 4\n89\n', '7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'Yes\n'] Note: In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
```python n, k = list(map(int, input().split())) a = input() b = input().split() if len(set(b))>1: print("YES") else: b = list(map(int, b)) new_a = list(map(int, a.split())) c = 0 for i in range(len(new_a)): if new_a[i] == 0: new_a[i] = b[c] c += 1 old_a = list(new_a) new_a.sort() if new_a == old_a: print("NO") else: print("YES") ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,624,197,408
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
77
0
n1 = int(input(), 2) n2 = int(input(), 2) print(bin(n1^n2).split("b")[1])
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python n1 = int(input(), 2) n2 = int(input(), 2) print(bin(n1^n2).split("b")[1]) ```
0
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..." }, { "input": "84817 1 33457", "output": "-1" }, { "input": "21 37 99", "output": "16 53 " }, { "input": "78 7 15", "output": "-1" }, { "input": "74 17 27", "output": "-1" }, { "input": "79 23 43", "output": "-1" }, { "input": "32 33 3", "output": "-1" }, { "input": "55 49 44", "output": "-1" }, { "input": "64 59 404", "output": "54 113 172 231 290 " }, { "input": "61 69 820", "output": "8 77 146 215 284 353 422 491 560 629 698 " }, { "input": "17 28 532", "output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 " }, { "input": "46592 52 232", "output": "-1" }, { "input": "1541 58 648", "output": "-1" }, { "input": "15946 76 360", "output": "-1" }, { "input": "30351 86 424", "output": "-1" }, { "input": "1 2 37493", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "1 3 27764", "output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..." }, { "input": "10 4 9174", "output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..." }, { "input": "33 7 4971", "output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..." }, { "input": "981 1 3387", "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": "386 1 2747", "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": "123 2 50000", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "3123 100 10000000", "output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..." }, { "input": "2 10000 1000000000", "output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..." }, { "input": "3 10000 1000000000", "output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..." }, { "input": "12312223 10000 1000000000", "output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..." }, { "input": "500000000 1000000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 1000000000", "output": "999999999 " }, { "input": "10 6 11", "output": "-1" }, { "input": "2 100 10", "output": "-1" }, { "input": "1 100000007 1000000000", "output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 " }, { "input": "1 999999999 1000000000", "output": "999999998 " }, { "input": "100000000 1000000000 1000000000", "output": "900000000 " }, { "input": "11 2 12", "output": "1 " }, { "input": "31 10 39", "output": "-1" }, { "input": "48 6 50", "output": "-1" }, { "input": "500000000 500000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 999999999", "output": "-1" }, { "input": "4 2 10", "output": "2 4 6 " }, { "input": "1000000000 1 1", "output": "-1" }, { "input": "1000000000 1 100000", "output": "-1" }, { "input": "1000000000 1 10", "output": "-1" }, { "input": "10 5 14", "output": "-1" }, { "input": "500000000 499999999 1000000000", "output": "499999998 " }, { "input": "1 999999997 1000000000", "output": "999999996 " } ]
1,652,101,300
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
y, k, n = map(int,input().split()) l = range((k - y) % k or k, n - y + 1, k) or -1 print(*l)
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. Input Specification: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). Output Specification: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Demo Input: ['10 1 10\n', '10 6 40\n'] Demo Output: ['-1\n', '2 8 14 20 26 \n'] Note: none
```python y, k, n = map(int,input().split()) l = range((k - y) % k or k, n - y + 1, k) or -1 print(*l) ```
-1
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,690,782,369
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
x=input() y=['H','Q','9'] for i in y: if i in x: print("Yes") else: print("no")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python x=input() y=['H','Q','9'] for i in y: if i in x: print("Yes") else: print("no") ```
0
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 13 4 3 2", "output": "36" }, { "input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "output": "55" }, { "input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "output": "36" }, { "input": "6\n1000 1 2000 1 3000 1", "output": "11995" }, { "input": "1\n0", "output": "0" }, { "input": "5\n1000000000 1 1000000000 1 1000000000", "output": "4999999996" }, { "input": "5\n1000000000 0 1000000000 0 1000000000", "output": "5000000000" }, { "input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0", "output": "10000000000" }, { "input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "19000000000" }, { "input": "7\n0 1000000000 0 1000000000 0 1000000000 0", "output": "6000000000" }, { "input": "4\n1000000000 -1000000000 1000000000 -1000000000", "output": "7000000000" }, { "input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "39000000000" }, { "input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000", "output": "11000000000" }, { "input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "9000000000" }, { "input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "43000000000" } ]
1,558,699,774
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
n = int(input()) x = list(map(int, input().split())) total = 0 for i in range(len(x)): total += abs(x[i] - total) print(total)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). Output Specification: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Demo Input: ['5\n1 2 3 4 5\n', '4\n1 2 2 1\n'] Demo Output: ['5', '3'] Note: In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
```python n = int(input()) x = list(map(int, input().split())) total = 0 for i in range(len(x)): total += abs(x[i] - total) print(total) ```
0
75
B
Facetook Priority Wall
PROGRAMMING
1,500
[ "expression parsing", "implementation", "strings" ]
B. Facetook Priority Wall
2
256
Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described). This priority factor will be affected by three types of actions: - 1. "*X* posted on *Y*'s wall" (15 points), - 2. "*X* commented on *Y*'s post" (10 points), - 3. "*X* likes *Y*'s post" (5 points). *X* and *Y* will be two distinct names. And each action will increase the priority factor between *X* and *Y* (and vice versa) by the above value of points (the priority factor between *X* and *Y* is the same as the priority factor between *Y* and *X*). You will be given *n* actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.
The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.
Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order. Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor. The lexicographical comparison is performed by the standard "&lt;" operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if either *a* is the prefix of *b*, or if exists such an *i* (1<=≤<=*i*<=≤<=*min*(|*a*|,<=|*b*|)), that *a**i*<=&lt;<=*b**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *a**j*<==<=*b**j*, where |*a*| and |*b*| stand for the lengths of strings *a* and *b* correspondently.
[ "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n", "aba\n1\nlikes likes posted's post\n" ]
[ "fatma\nmona\n", "likes\nposted\n" ]
none
1,000
[ { "input": "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post", "output": "fatma\nmona" }, { "input": "aba\n1\nlikes likes posted's post", "output": "likes\nposted" }, { "input": "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\ng likes nu's post\ng posted on nu's wall\nqv commented on pwyndmh's post", "output": "g\npwyndmh\nqv" }, { "input": "szfwtzfp\n5\nzqx posted on szfwtzfp's wall\nr commented on scguem's post\nr posted on civ's wall\nr likes scguem's post\nr likes scguem's post", "output": "zqx\nciv\nr\nscguem" }, { "input": "oaquudhavr\n3\ni posted on cwfwujpc's wall\ni likes oaquudhavr's post\noaquudhavr commented on cwfwujpc's post", "output": "cwfwujpc\ni" }, { "input": "eo\n4\neo commented on xkgjgwxtrx's post\neo posted on iqquh's wall\nn commented on xkgjgwxtrx's post\niqquh commented on n's post", "output": "iqquh\nxkgjgwxtrx\nn" }, { "input": "plwun\n3\neusjuq commented on plwun's post\nagktgdar likes eusjuq's post\nagppcoil likes agktgdar's post", "output": "eusjuq\nagktgdar\nagppcoil" }, { "input": "fgzrn\n3\nzhl likes fgzrn's post\nxryet likes fgzrn's post\nzhl commented on fgzrn's post", "output": "zhl\nxryet" }, { "input": "qatugmdjwg\n3\nb posted on cf's wall\nyjxkat posted on b's wall\nko commented on qatugmdjwg's post", "output": "ko\nb\ncf\nyjxkat" }, { "input": "dagwdwxsuf\n5\nesrvncb commented on dagwdwxsuf's post\nzcepigpbz posted on dagwdwxsuf's wall\nesrvncb commented on zcepigpbz's post\nesrvncb commented on dagwdwxsuf's post\ndagwdwxsuf commented on esrvncb's post", "output": "esrvncb\nzcepigpbz" }, { "input": "a\n1\nb likes c's post", "output": "b\nc" }, { "input": "a\n1\nc likes b's post", "output": "b\nc" }, { "input": "wuaiz\n10\nmnbggnud posted on xttaqvel's wall\ns posted on xopffmspf's wall\nkysxb likes qnrtpzkh's post\ngptks likes quebtsup's post\nkgmd commented on kmtnhsiue's post\newqjtxtiyn commented on a's post\nol posted on iglplaj's wall\nif posted on yuo's wall\nfs posted on dwjtuhgrq's wall\nygmdprun likes tzfneuly's post", "output": "a\ndwjtuhgrq\newqjtxtiyn\nfs\ngptks\nif\niglplaj\nkgmd\nkmtnhsiue\nkysxb\nmnbggnud\nol\nqnrtpzkh\nquebtsup\ns\ntzfneuly\nxopffmspf\nxttaqvel\nygmdprun\nyuo" }, { "input": "fzhzg\n11\nv likes xyf's post\nktqtpzhlh commented on ffsxarrn's post\nktqtpzhlh commented on lbt's post\njcdwpcycj commented on qbuigcgflm's post\nl likes pmg's post\nracszbmsk posted on ojr's wall\nojr commented on n's post\nnzqx commented on lkj's post\nv posted on lzoca's wall\nnwqnoham commented on gyivezpu's post\nfzhzg likes uqvzgzrpac's post", "output": "uqvzgzrpac\nffsxarrn\ngyivezpu\njcdwpcycj\nktqtpzhlh\nl\nlbt\nlkj\nlzoca\nn\nnwqnoham\nnzqx\nojr\npmg\nqbuigcgflm\nracszbmsk\nv\nxyf" }, { "input": "qdrnpb\n12\nymklhj commented on dkcbo's post\nhcucrenckl posted on mut's wall\nnvkyta commented on eo's post\npvgow likes mut's post\nob likes wlwcxtf's post\npvgow commented on advpu's post\nkfflyfbr commented on igozjnrxw's post\nsq commented on qdrnpb's post\nmrvn posted on lahduc's wall\ngsnlicy likes u's post\ndltqujf commented on qgzk's post\nr posted on bey's wall", "output": "sq\nadvpu\nbey\ndkcbo\ndltqujf\neo\ngsnlicy\nhcucrenckl\nigozjnrxw\nkfflyfbr\nlahduc\nmrvn\nmut\nnvkyta\nob\npvgow\nqgzk\nr\nu\nwlwcxtf\nymklhj" }, { "input": "biycvwb\n13\nhp likes cigobksf's post\nmcoqt commented on gaswzwat's post\nnz posted on xyvetbokl's wall\nqbnwy commented on ylkfbwjy's post\nqdwktrro likes rxgujnzecs's post\nbbsw commented on hwtatkfnps's post\ngspx posted on ugjxfnahuc's wall\nxlmut likes plle's post\numbwlleag commented on xfwlhen's post\nrlwxqksbwi commented on rypqtrgf's post\nbj posted on vovq's wall\nozpdpb commented on zti's post\nhqj posted on rxgujnzecs's wall", "output": "bbsw\nbj\ncigobksf\ngaswzwat\ngspx\nhp\nhqj\nhwtatkfnps\nmcoqt\nnz\nozpdpb\nplle\nqbnwy\nqdwktrro\nrlwxqksbwi\nrxgujnzecs\nrypqtrgf\nugjxfnahuc\numbwlleag\nvovq\nxfwlhen\nxlmut\nxyvetbokl\nylkfbwjy\nzti" }, { "input": "kmircqsffq\n14\nfrnf likes xgmmp's post\nfnfdpupayp commented on syz's post\nxefshpn commented on xgmmp's post\nm posted on gdwydzktok's wall\neskm likes pqmbnuc's post\npnqiapduhz likes zzqvjdz's post\nx likes nouuurc's post\nvnyxhoukuo posted on uhblapjab's wall\nblpjpxn likes zvwbger's post\nj posted on vuknetvl's wall\nscsw commented on xaggwxlxe's post\npqmbnuc commented on ojwaibie's post\niaazdlqdew commented on kmircqsffq's post\nqznqshxdi commented on umdqztoqun's post", "output": "iaazdlqdew\nblpjpxn\neskm\nfnfdpupayp\nfrnf\ngdwydzktok\nj\nm\nnouuurc\nojwaibie\npnqiapduhz\npqmbnuc\nqznqshxdi\nscsw\nsyz\nuhblapjab\numdqztoqun\nvnyxhoukuo\nvuknetvl\nx\nxaggwxlxe\nxefshpn\nxgmmp\nzvwbger\nzzqvjdz" }, { "input": "posted\n3\nposted posted on fatma's wall\nfatma commented on posted's post\nmona likes posted's post", "output": "fatma\nmona" }, { "input": "posted\n3\nposted posted on wall's wall\nwall commented on posted's post\nmona likes posted's post", "output": "wall\nmona" }, { "input": "posted\n3\nposted posted on wall's wall\nwall commented on posted's post\npost likes posted's post", "output": "wall\npost" }, { "input": "wall\n5\nwall posted on posted's wall\nwall posted on on's wall\nwall posted on commented's wall\nwall posted on likes's wall\nwall posted on post's wall", "output": "commented\nlikes\non\npost\nposted" }, { "input": "commented\n5\non commented on commented's post\npos commented on commented's post\nlikes commented on commented's post\nposted commented on commented's post\nwall commented on commented's post", "output": "likes\non\npos\nposted\nwall" }, { "input": "likes\n3\nlikes posted on post's wall\nlikes commented on on's post\nlikes likes commented's post", "output": "post\non\ncommented" }, { "input": "on\n4\non posted on posted's wall\non commented on commented's post\non posted on wall's wall\non commented on post's post", "output": "posted\nwall\ncommented\npost" }, { "input": "wall\n9\nwall posted on posted's wall\non commented on wall's post\nwall likes post's post\nposted posted on wall's wall\nwall commented on post's post\nlikes likes wall's post\nwall posted on on's wall\npost commented on wall's post\nwall likes likes's post", "output": "posted\non\npost\nlikes" }, { "input": "post\n9\npost posted on wall's wall\non commented on post's post\npost likes likes's post\ncommented posted on post's wall\npost commented on likes's post\nlikes likes post's post\npost posted on posted's wall\non commented on post's post\npost likes commented's post", "output": "commented\nlikes\non\nposted\nwall" }, { "input": "ahmed\n9\npost posted on ahmeds's wall\nahmeds commented on post's post\npost likes ahmeds's post\nahmeds posted on post's wall\npost commented on ahmeds's post\nahmeds likes post's post\npost posted on ahmeds's wall\nahmeds commented on post's post\npost likes ahmeds's post", "output": "ahmeds\npost" } ]
1,651,139,202
42
Python 3
WRONG_ANSWER
TESTS
1
60
0
def input_string(name: str) -> (str, int): s = input().split(" ") if s[1] == 'posted': score = 15 elif s[1] == 'commented': score = 10 else: score = 5 if s[0] != name: return s[0], score else: if score > 5: return s[3].replace("'s", ""), score else: return s[2].replace("'s", ""), score name = input() n = int(input()) dic = {} for i in range(n): a = input_string(name) if a[0] in dic: dic[a[0]] += a[1] else: dic[a[0]] = a[1] b = sorted(dic, key=dic.get, reverse=True) print('\n'.join(b))
Title: Facetook Priority Wall Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described). This priority factor will be affected by three types of actions: - 1. "*X* posted on *Y*'s wall" (15 points), - 2. "*X* commented on *Y*'s post" (10 points), - 3. "*X* likes *Y*'s post" (5 points). *X* and *Y* will be two distinct names. And each action will increase the priority factor between *X* and *Y* (and vice versa) by the above value of points (the priority factor between *X* and *Y* is the same as the priority factor between *Y* and *X*). You will be given *n* actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you. Input Specification: The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters. Output Specification: Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order. Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor. The lexicographical comparison is performed by the standard "&lt;" operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if either *a* is the prefix of *b*, or if exists such an *i* (1<=≤<=*i*<=≤<=*min*(|*a*|,<=|*b*|)), that *a**i*<=&lt;<=*b**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *a**j*<==<=*b**j*, where |*a*| and |*b*| stand for the lengths of strings *a* and *b* correspondently. Demo Input: ["ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n", "aba\n1\nlikes likes posted's post\n"] Demo Output: ['fatma\nmona\n', 'likes\nposted\n'] Note: none
```python def input_string(name: str) -> (str, int): s = input().split(" ") if s[1] == 'posted': score = 15 elif s[1] == 'commented': score = 10 else: score = 5 if s[0] != name: return s[0], score else: if score > 5: return s[3].replace("'s", ""), score else: return s[2].replace("'s", ""), score name = input() n = int(input()) dic = {} for i in range(n): a = input_string(name) if a[0] in dic: dic[a[0]] += a[1] else: dic[a[0]] = a[1] b = sorted(dic, key=dic.get, reverse=True) print('\n'.join(b)) ```
0
476
A
Dreamoon and Stairs
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10).
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
[ "10 2\n", "3 5\n" ]
[ "6\n", "-1\n" ]
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
500
[ { "input": "10 2", "output": "6" }, { "input": "3 5", "output": "-1" }, { "input": "29 7", "output": "21" }, { "input": "2 2", "output": "2" }, { "input": "1 2", "output": "-1" }, { "input": "10000 2", "output": "5000" }, { "input": "10000 3", "output": "5001" }, { "input": "10000 10", "output": "5000" }, { "input": "9999 3", "output": "5001" }, { "input": "9999 2", "output": "5000" }, { "input": "9999 10", "output": "5000" }, { "input": "9999 9", "output": "5004" }, { "input": "18 10", "output": "10" }, { "input": "19 10", "output": "10" }, { "input": "20 10", "output": "10" }, { "input": "21 10", "output": "20" }, { "input": "7688 5", "output": "3845" }, { "input": "4608 5", "output": "2305" }, { "input": "3979 2", "output": "1990" }, { "input": "9985 6", "output": "4998" }, { "input": "3230 8", "output": "1616" }, { "input": "24 9", "output": "18" }, { "input": "3275 8", "output": "1640" }, { "input": "6240 7", "output": "3122" }, { "input": "5227 4", "output": "2616" }, { "input": "3832 6", "output": "1920" }, { "input": "4 2", "output": "2" }, { "input": "6 3", "output": "3" }, { "input": "10 5", "output": "5" }, { "input": "3 2", "output": "2" }, { "input": "6 4", "output": "4" }, { "input": "5 2", "output": "4" }, { "input": "8 2", "output": "4" }, { "input": "9 9", "output": "9" }, { "input": "4 5", "output": "-1" } ]
1,671,709,667
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
9
46
1,331,200
n, m = [int(i) for i in input().split()] mn = n / 2 + n % 2 mx = n k = 0 if n < m: print(-1) else: while mn > k: k += m if k <= mx and k >= mn: print(k) else: print(-1)
Title: Dreamoon and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? Input Specification: The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10). Output Specification: Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. Demo Input: ['10 2\n', '3 5\n'] Demo Output: ['6\n', '-1\n'] Note: For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
```python n, m = [int(i) for i in input().split()] mn = n / 2 + n % 2 mx = n k = 0 if n < m: print(-1) else: while mn > k: k += m if k <= mx and k >= mn: print(k) else: print(-1) ```
0
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,661,357,692
2,147,483,647
Python 3
OK
TESTS
44
92
0
c = (input()) g="0000000" d="1111111" if c.__contains__(g) or c.__contains__(d): print ("YES") else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python c = (input()) g="0000000" d="1111111" if c.__contains__(g) or c.__contains__(d): print ("YES") else: print("NO") ```
3.977
793
A
Oleg and shares
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
[ "3 3\n12 9 15\n", "2 2\n10 9\n", "4 1\n1 1000000000 1000000000 1000000000\n" ]
[ "3", "-1", "2999999997" ]
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
500
[ { "input": "3 3\n12 9 15", "output": "3" }, { "input": "2 2\n10 9", "output": "-1" }, { "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997" }, { "input": "1 11\n123", "output": "0" }, { "input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14", "output": "151" }, { "input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54", "output": "-1" }, { "input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260", "output": "2157" }, { "input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354", "output": "-1" }, { "input": "4 2\n1 2 3 4", "output": "-1" }, { "input": "3 4\n3 5 5", "output": "-1" }, { "input": "3 2\n88888884 88888886 88888888", "output": "3" }, { "input": "2 1\n1000000000 1000000000", "output": "0" }, { "input": "4 2\n1000000000 100000000 100000000 100000000", "output": "450000000" }, { "input": "2 2\n1000000000 1000000000", "output": "0" }, { "input": "3 3\n3 2 1", "output": "-1" }, { "input": "3 4\n3 5 3", "output": "-1" }, { "input": "3 2\n1 2 2", "output": "-1" }, { "input": "4 2\n2 3 3 2", "output": "-1" }, { "input": "3 2\n1 2 4", "output": "-1" }, { "input": "3 2\n3 4 4", "output": "-1" }, { "input": "3 3\n4 7 10", "output": "3" }, { "input": "4 3\n2 2 5 1", "output": "-1" }, { "input": "3 3\n1 3 5", "output": "-1" }, { "input": "2 5\n5 9", "output": "-1" }, { "input": "2 3\n5 7", "output": "-1" }, { "input": "3 137\n1000000000 1000000000 1000000000", "output": "0" }, { "input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 5\n1 2 5", "output": "-1" }, { "input": "3 3\n1000000000 1000000000 999999997", "output": "2" }, { "input": "2 4\n5 6", "output": "-1" }, { "input": "4 1\n1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "2 3\n5 8", "output": "1" }, { "input": "2 6\n8 16", "output": "-1" }, { "input": "5 3\n15 14 9 12 18", "output": "-1" }, { "input": "3 3\n1 2 3", "output": "-1" }, { "input": "3 3\n3 4 5", "output": "-1" }, { "input": "2 5\n8 17", "output": "-1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "0" }, { "input": "3 3\n5 3 4", "output": "-1" }, { "input": "3 6\n10 14 12", "output": "-1" }, { "input": "2 2\n3 5", "output": "1" }, { "input": "3 5\n1 3 4", "output": "-1" }, { "input": "4 3\n1 6 6 6", "output": "-1" }, { "input": "2 3\n1 8", "output": "-1" }, { "input": "3 5\n6 11 17", "output": "-1" }, { "input": "2 2\n1 4", "output": "-1" }, { "input": "2 4\n6 8", "output": "-1" }, { "input": "2 1\n2 3", "output": "1" }, { "input": "4 4\n1 5 8 14", "output": "-1" }, { "input": "3 3\n1 5 3", "output": "-1" }, { "input": "4 3\n1 2 2 5", "output": "-1" }, { "input": "3 2\n1 4 6", "output": "-1" }, { "input": "2 3\n6 9", "output": "1" }, { "input": "3 3\n2 3 4", "output": "-1" }, { "input": "3 2\n9 10 10", "output": "-1" }, { "input": "2 2\n9 12", "output": "-1" }, { "input": "2 2\n100000003 100000005", "output": "1" }, { "input": "2 3\n2 4", "output": "-1" }, { "input": "3 2\n2 3 5", "output": "-1" }, { "input": "3 3\n1 3 4", "output": "-1" }, { "input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "4499999991" }, { "input": "3 5\n2 4 5", "output": "-1" }, { "input": "2 3\n7 10", "output": "1" }, { "input": "3 10\n10 13 17", "output": "-1" }, { "input": "2 3\n1 6", "output": "-1" }, { "input": "1 7\n1000000000", "output": "0" }, { "input": "2 4\n3 7", "output": "1" }, { "input": "2 3\n2 5", "output": "1" }, { "input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 3\n7 8 8", "output": "-1" }, { "input": "4 10\n1 11 100 11", "output": "-1" } ]
1,492,967,363
1,463
PyPy 3
WRONG_ANSWER
PRETESTS
1
93
23,040,000
a, b = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) mi = arr[0] flag = True c = 0 for i in arr: if abs(i - mi) % b != 0: fl = False break else: c += abs(i - mi) // b if flag: print(c) else: print(-1)
Title: Oleg and shares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. Output Specification: Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. Demo Input: ['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n'] Demo Output: ['3', '-1', '2999999997'] Note: Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
```python a, b = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) mi = arr[0] flag = True c = 0 for i in arr: if abs(i - mi) % b != 0: fl = False break else: c += abs(i - mi) // b if flag: print(c) else: print(-1) ```
0
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2", "output": "5\n7\n5\n5\n2\n7\n7\n13\n4" }, { "input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7", "output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326" }, { "input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29", "output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772" }, { "input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12", "output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195" }, { "input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1", "output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2" }, { "input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2", "output": "6\n1\n6\n1\n5\n6\n1\n5" }, { "input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4", "output": "22\n10\n10\n6\n12\n36\n6\n14\n16" }, { "input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4", "output": "11\n11\n2\n10\n1\n3\n10\n12\n12" }, { "input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5", "output": "8\n27\n1\n8\n26" }, { "input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8", "output": "10\n2\n13\n10" }, { "input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5", "output": "9\n24\n28" }, { "input": "1\n1\n2\n1 1 1\n2 1 1", "output": "1\n1" } ]
1,646,321,707
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
''' class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: seen = {} for i, value in enumerate(nums): remaining = target - nums[i] if remaining in seen: return [i, seen[remaining]] seen[value] = i ''' """ sock= int(input()) list = [int(item) for item in input().split()] frqlist =[] maxn = 0 cnt = 0 for i in range(0, sock+1): frqlist.append(0) for frq in list: frqlist[frq] +=1 if frqlist[frq] == 2: cnt -= 1 frqlist[frq] = 0 else: cnt +=1 if cnt > maxn: maxn = cnt print(maxn) """ """ test = int(input()) while( not test == 0): bad = 0 days = int(input()) list = [int(item) for item in input().split()] list.reverse() min = list[0] for i in list: if i > min: bad += 1 else: min=i print(bad) test -=1 """ ''' cnt =0 mx=0 ll = [int(item) for item in input().split()] n= ll[0] free = ll[1] list = [int(item) for item in input().split()] sum = 0 p1 = 0 p2 = 0 while(p1 < len(list) and p2 < len(list)): if sum > free: sum -= list[p1] p1+=1 cnt -= 1 else: sum += list[p2] p2 +=1 cnt +=1 if cnt > mx and sum <=free: mx = cnt print(mx) ''' """ cnt = 0 mx=0 num =int(input()) list = [int(item) for item in input().split()] diff = 0 p1 = 0 p2 = 0 list.sort() while(p1 < len(list) and p2 < len(list)): diff = list[p2] - list[p1] if diff >5: p1 += 1 cnt -= 1 else: p2 += 1 cnt += 1 if cnt > mx : mx = cnt print(mx) """ """ num = int(input()) list = [int(item) for item in input().split()] ptr1 = 0 ptr2 = len(list)-1 Bob_cnt = 0 Alice_cnt = 0 while not (ptr1 == ptr2 ): print("loop") list[ptr1] -= 1 list[ptr2] -= 1 if list[ptr1] == 0: Alice_cnt += 1 ptr1 += 1 print("A", Alice_cnt) if list[ptr2] == 0: Bob_cnt += 1 ptr2 -= 1 print("B", Bob_cnt) print(Alice_cnt, Bob_cnt) """ """ # Python program for implementation of Selection # Sort A = [64, 25, 12, 22, 11] # Traverse through all array elements for i in range(len(A)): print("i",i) # Find the minimum element in remaining # unsorted array min_idx = i for j in range(i + 1, len(A)): print(j) if A[min_idx] > A[j]: min_idx = j # Swap the found minimum element with # the first element A[i], A[min_idx] = A[min_idx], A[i] print("Sorted array") for i in range(len(A)): print("%d" % A[i], end=" ") """ """ num = int(input()) list = [int(item) for item in input().split()] ptr1 = 0 ptr2 = num-1 Bob_spent = 0 Alice_spent = 0 Bob_cnt = 0 Alice_cnt = 0 while (ptr1 <= ptr2 ): if Alice_spent <= Bob_spent : Alice_spent += list[ptr1] Alice_cnt +=1 ptr1 +=1 else: Bob_spent += list[ptr2] Bob_cnt +=1 ptr2 -=1 print(Alice_cnt,Bob_cnt) """ """ inputs = [int(item) for item in input().split()] list = [int(item) for item in input().split()] n = inputs[0] d = inputs[1] p1 = 0 p2 = 2 cnt = 0 diff = 0 if n < 3: print("0") exit() else: while p1 < n-2: if p2 == n: k = p2 - p1 - 2 cnt += (k * (k + 1) / 2) p1 += 1 continue diff = list[p2] - list[p1] if diff > d : k = p2 - p1 - 2 cnt += (k * (k + 1) / 2) p1 += 1 elif diff <= d: p2 += 1 print (int(cnt)) """ """ sum1 = 0 sum2 = 0 maxnum = 0 num = int(input()) list = [int(item) for item in input().split()] p1 = 0 p2 = num - 1 while p1 <= p2: # print(f"{sum1} {sum2}") if sum1 <= sum2: sum1 += list[p1] p1 += 1 else: sum2 += list[p2] p2 -= 1 if sum1 == sum2: maxnum = sum1 print(maxnum) """ """ import sys from os import path import math file = open("tst.txt",'r') n = 0 test = int(file.readline()) while test > 0: x = int(file.readline()) c = x * -2 n = (-1 + math.sqrt(1 - 4 * c)) / 2 print(x - int(n)) test -= 1 """ n = int(input()) list = [int(item) for item in input().split()] cum =[] for i in range(0, n): cum.append(0) for i in range(0, n): if i ==0: cum[i] = list[i] else: cum[i] = cum[i-1] + list[i] list.sort() for i in range(1,n): list[i] += list[i-1] n_qu = int(input()) while n_qu > 0: qu_list =[int(item) for item in input().split()] qu = qu_list[0] l = qu_list[1]-1 r = qu_list[2]-1 if qu == 1: if(l!=0): print(cum[r] - cum[l - 1]) else: print(cum[r] - 0) else: if (l != 0): print(list[r] - list[l - 1]) else: print(list[r] - 0)
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. Output Specification: Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. Demo Input: ['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n'] Demo Output: ['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n'] Note: Please note that the answers to the questions may overflow 32-bit integer type.
```python ''' class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: seen = {} for i, value in enumerate(nums): remaining = target - nums[i] if remaining in seen: return [i, seen[remaining]] seen[value] = i ''' """ sock= int(input()) list = [int(item) for item in input().split()] frqlist =[] maxn = 0 cnt = 0 for i in range(0, sock+1): frqlist.append(0) for frq in list: frqlist[frq] +=1 if frqlist[frq] == 2: cnt -= 1 frqlist[frq] = 0 else: cnt +=1 if cnt > maxn: maxn = cnt print(maxn) """ """ test = int(input()) while( not test == 0): bad = 0 days = int(input()) list = [int(item) for item in input().split()] list.reverse() min = list[0] for i in list: if i > min: bad += 1 else: min=i print(bad) test -=1 """ ''' cnt =0 mx=0 ll = [int(item) for item in input().split()] n= ll[0] free = ll[1] list = [int(item) for item in input().split()] sum = 0 p1 = 0 p2 = 0 while(p1 < len(list) and p2 < len(list)): if sum > free: sum -= list[p1] p1+=1 cnt -= 1 else: sum += list[p2] p2 +=1 cnt +=1 if cnt > mx and sum <=free: mx = cnt print(mx) ''' """ cnt = 0 mx=0 num =int(input()) list = [int(item) for item in input().split()] diff = 0 p1 = 0 p2 = 0 list.sort() while(p1 < len(list) and p2 < len(list)): diff = list[p2] - list[p1] if diff >5: p1 += 1 cnt -= 1 else: p2 += 1 cnt += 1 if cnt > mx : mx = cnt print(mx) """ """ num = int(input()) list = [int(item) for item in input().split()] ptr1 = 0 ptr2 = len(list)-1 Bob_cnt = 0 Alice_cnt = 0 while not (ptr1 == ptr2 ): print("loop") list[ptr1] -= 1 list[ptr2] -= 1 if list[ptr1] == 0: Alice_cnt += 1 ptr1 += 1 print("A", Alice_cnt) if list[ptr2] == 0: Bob_cnt += 1 ptr2 -= 1 print("B", Bob_cnt) print(Alice_cnt, Bob_cnt) """ """ # Python program for implementation of Selection # Sort A = [64, 25, 12, 22, 11] # Traverse through all array elements for i in range(len(A)): print("i",i) # Find the minimum element in remaining # unsorted array min_idx = i for j in range(i + 1, len(A)): print(j) if A[min_idx] > A[j]: min_idx = j # Swap the found minimum element with # the first element A[i], A[min_idx] = A[min_idx], A[i] print("Sorted array") for i in range(len(A)): print("%d" % A[i], end=" ") """ """ num = int(input()) list = [int(item) for item in input().split()] ptr1 = 0 ptr2 = num-1 Bob_spent = 0 Alice_spent = 0 Bob_cnt = 0 Alice_cnt = 0 while (ptr1 <= ptr2 ): if Alice_spent <= Bob_spent : Alice_spent += list[ptr1] Alice_cnt +=1 ptr1 +=1 else: Bob_spent += list[ptr2] Bob_cnt +=1 ptr2 -=1 print(Alice_cnt,Bob_cnt) """ """ inputs = [int(item) for item in input().split()] list = [int(item) for item in input().split()] n = inputs[0] d = inputs[1] p1 = 0 p2 = 2 cnt = 0 diff = 0 if n < 3: print("0") exit() else: while p1 < n-2: if p2 == n: k = p2 - p1 - 2 cnt += (k * (k + 1) / 2) p1 += 1 continue diff = list[p2] - list[p1] if diff > d : k = p2 - p1 - 2 cnt += (k * (k + 1) / 2) p1 += 1 elif diff <= d: p2 += 1 print (int(cnt)) """ """ sum1 = 0 sum2 = 0 maxnum = 0 num = int(input()) list = [int(item) for item in input().split()] p1 = 0 p2 = num - 1 while p1 <= p2: # print(f"{sum1} {sum2}") if sum1 <= sum2: sum1 += list[p1] p1 += 1 else: sum2 += list[p2] p2 -= 1 if sum1 == sum2: maxnum = sum1 print(maxnum) """ """ import sys from os import path import math file = open("tst.txt",'r') n = 0 test = int(file.readline()) while test > 0: x = int(file.readline()) c = x * -2 n = (-1 + math.sqrt(1 - 4 * c)) / 2 print(x - int(n)) test -= 1 """ n = int(input()) list = [int(item) for item in input().split()] cum =[] for i in range(0, n): cum.append(0) for i in range(0, n): if i ==0: cum[i] = list[i] else: cum[i] = cum[i-1] + list[i] list.sort() for i in range(1,n): list[i] += list[i-1] n_qu = int(input()) while n_qu > 0: qu_list =[int(item) for item in input().split()] qu = qu_list[0] l = qu_list[1]-1 r = qu_list[2]-1 if qu == 1: if(l!=0): print(cum[r] - cum[l - 1]) else: print(cum[r] - 0) else: if (l != 0): print(list[r] - list[l - 1]) else: print(list[r] - 0) ```
-1
681
B
Economy Game
PROGRAMMING
1,300
[ "brute force" ]
null
null
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each). Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*? Please help Kolya answer this question.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score.
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
[ "1359257\n", "17851817\n" ]
[ "YES", "NO" ]
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
1,000
[ { "input": "1359257", "output": "YES" }, { "input": "17851817", "output": "NO" }, { "input": "1000000000", "output": "YES" }, { "input": "17851818", "output": "YES" }, { "input": "438734347", "output": "YES" }, { "input": "43873430", "output": "YES" }, { "input": "999999987", "output": "YES" }, { "input": "27406117", "output": "NO" }, { "input": "27404883", "output": "NO" }, { "input": "27403649", "output": "NO" }, { "input": "27402415", "output": "NO" }, { "input": "27401181", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "999999244", "output": "YES" }, { "input": "999129999", "output": "YES" }, { "input": "17159199", "output": "NO" }, { "input": "13606913", "output": "NO" }, { "input": "14841529", "output": "NO" }, { "input": "915968473", "output": "YES" }, { "input": "980698615", "output": "YES" }, { "input": "912331505", "output": "YES" }, { "input": "917261049", "output": "YES" }, { "input": "999999997", "output": "YES" }, { "input": "12345", "output": "NO" }, { "input": "1234", "output": "YES" }, { "input": "124690", "output": "YES" }, { "input": "1359257", "output": "YES" }, { "input": "1358023", "output": "YES" }, { "input": "1234", "output": "YES" }, { "input": "1234567", "output": "YES" }, { "input": "124690", "output": "YES" }, { "input": "1358023", "output": "YES" }, { "input": "123456", "output": "YES" }, { "input": "2592590", "output": "YES" }, { "input": "999999998", "output": "YES" }, { "input": "1356789", "output": "NO" }, { "input": "12345670", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "1480800", "output": "YES" }, { "input": "908000000", "output": "YES" }, { "input": "3000", "output": "NO" }, { "input": "1235801", "output": "YES" }, { "input": "991919191", "output": "YES" }, { "input": "25613715", "output": "YES" }, { "input": "13580237", "output": "YES" }, { "input": "14814804", "output": "YES" }, { "input": "11403961", "output": "YES" }, { "input": "999999989", "output": "YES" }, { "input": "1237035", "output": "YES" }, { "input": "81134231", "output": "YES" }, { "input": "1236", "output": "NO" }, { "input": "1359250", "output": "YES" }, { "input": "100", "output": "NO" }, { "input": "987654321", "output": "YES" }, { "input": "122222", "output": "NO" }, { "input": "123458", "output": "NO" }, { "input": "20987639", "output": "YES" }, { "input": "999973333", "output": "YES" }, { "input": "253082", "output": "YES" }, { "input": "1235", "output": "NO" }, { "input": "803219200", "output": "YES" }, { "input": "100000000", "output": "YES" }, { "input": "1485181", "output": "YES" } ]
1,574,857,387
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
109
0
m = int(input()) house = 1234567 car = 123456 comp = 1234 q = 0 w = m a = 0 b = 0 c = 0 for c in range(0,m//comp + 1): if q == 0 and m >= comp: for b in range(0,m//car + 1): if q == 0 and m >= car: for a in range(0,m//house+1): if q == 0 and m >= house: m = w - a*house - b*car - c*comp if m == 0: q += 1 m = w - a*house - b*car - c*comp if m == 0: q += 1 m = w - a*house - b*car - c*comp if m == 0: q += 1 print(a,b,c,m,w,q) if q != 0: print("YES") else: print("NO")
Title: Economy Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each). Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*? Please help Kolya answer this question. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. Output Specification: Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). Demo Input: ['1359257\n', '17851817\n'] Demo Output: ['YES', 'NO'] Note: In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
```python m = int(input()) house = 1234567 car = 123456 comp = 1234 q = 0 w = m a = 0 b = 0 c = 0 for c in range(0,m//comp + 1): if q == 0 and m >= comp: for b in range(0,m//car + 1): if q == 0 and m >= car: for a in range(0,m//house+1): if q == 0 and m >= house: m = w - a*house - b*car - c*comp if m == 0: q += 1 m = w - a*house - b*car - c*comp if m == 0: q += 1 m = w - a*house - b*car - c*comp if m == 0: q += 1 print(a,b,c,m,w,q) if q != 0: print("YES") else: print("NO") ```
0
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party?
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "10 240", "output": "0" }, { "input": "9 240", "output": "0" }, { "input": "9 1", "output": "9" }, { "input": "9 235", "output": "1" }, { "input": "9 236", "output": "0" }, { "input": "5 225", "output": "2" }, { "input": "5 226", "output": "1" }, { "input": "4 210", "output": "3" }, { "input": "4 211", "output": "2" }, { "input": "4 191", "output": "3" }, { "input": "10 165", "output": "5" }, { "input": "10 166", "output": "4" }, { "input": "8 100", "output": "7" }, { "input": "8 101", "output": "6" }, { "input": "8 60", "output": "8" }, { "input": "8 61", "output": "7" }, { "input": "10 15", "output": "9" }, { "input": "10 16", "output": "8" }, { "input": "4 100", "output": "4" }, { "input": "4 101", "output": "4" }, { "input": "7 167", "output": "4" }, { "input": "10 164", "output": "5" }, { "input": "9 170", "output": "4" }, { "input": "8 160", "output": "5" }, { "input": "1 100", "output": "1" }, { "input": "8 123", "output": "6" }, { "input": "2 99", "output": "2" }, { "input": "10 88", "output": "7" }, { "input": "1 235", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "4 240", "output": "0" }, { "input": "1 55", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "3 240", "output": "0" }, { "input": "10 240", "output": "0" }, { "input": "2 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "9 1", "output": "9" }, { "input": "2 236", "output": "0" }, { "input": "10 2", "output": "9" }, { "input": "3 239", "output": "0" }, { "input": "1 237", "output": "0" }, { "input": "7 8", "output": "7" }, { "input": "10 235", "output": "1" } ]
1,677,609,349
2,147,483,647
Python 3
OK
TESTS
52
46
0
n, k = input().split() n = int(n) k = int(k) time = 60 * 4 - k count = 0 math = 0 for i in range(1,n+1): math += 5*i if math <= time: count += 1 print(count)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party? Input Specification: The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. Output Specification: Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. Demo Input: ['3 222\n', '4 190\n', '7 1\n'] Demo Output: ['2\n', '4\n', '7\n'] Note: In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
```python n, k = input().split() n = int(n) k = int(k) time = 60 * 4 - k count = 0 math = 0 for i in range(1,n+1): math += 5*i if math <= time: count += 1 print(count) ```
3
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50", "output": "49" }, { "input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2", "output": "-1" }, { "input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90", "output": "46" }, { "input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66", "output": "14" }, { "input": "1 1\n4\n9", "output": "8" }, { "input": "1 1\n2\n4", "output": "-1" }, { "input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58", "output": "-1" }, { "input": "1 1\n50\n100", "output": "-1" }, { "input": "1 1\n49\n100", "output": "98" }, { "input": "1 1\n100\n100", "output": "-1" }, { "input": "1 1\n99\n100", "output": "-1" }, { "input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100", "output": "99" }, { "input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2", "output": "-1" }, { "input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75", "output": "2" }, { "input": "3 3\n2 3 4\n8 9 10", "output": "4" }, { "input": "2 1\n2 3\n15", "output": "4" }, { "input": "2 1\n2 4\n4", "output": "-1" }, { "input": "2 3\n4 5\n10 11 12", "output": "8" }, { "input": "3 1\n2 3 3\n5", "output": "4" }, { "input": "2 1\n9 10\n100", "output": "18" }, { "input": "3 3\n3 12 15\n7 8 9", "output": "-1" }, { "input": "2 2\n3 5\n7 8", "output": "6" }, { "input": "3 3\n4 5 6\n10 11 12", "output": "8" }, { "input": "3 5\n2 3 3\n6 6 6 6 2", "output": "-1" }, { "input": "3 6\n4 5 3\n8 9 7 10 7 11", "output": "6" }, { "input": "3 6\n4 5 2\n8 9 6 10 7 4", "output": "-1" }, { "input": "2 1\n4 6\n10", "output": "8" }, { "input": "1 2\n1\n3 1", "output": "-1" }, { "input": "2 1\n5 6\n20", "output": "10" }, { "input": "2 1\n1 5\n5", "output": "-1" }, { "input": "3 2\n10 20 30\n30 40", "output": "-1" }, { "input": "2 2\n5 6\n7 100", "output": "-1" }, { "input": "2 1\n2 5\n7", "output": "5" }, { "input": "1 1\n5\n20", "output": "10" }, { "input": "2 1\n10 11\n100", "output": "20" }, { "input": "1 1\n1\n10", "output": "2" }, { "input": "1 1\n10\n100", "output": "20" } ]
1,623,938,111
2,147,483,647
Python 3
OK
TESTS
45
154
0
n,m=map(int,input().split()) n1=list(map(int,input().split())) m1=list(map(int,input().split())) if max(2*(min(n1)),max(n1))<min(m1): print(max(2*(min(n1)),max(n1))) else: print(-1)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python n,m=map(int,input().split()) n1=list(map(int,input().split())) m1=list(map(int,input().split())) if max(2*(min(n1)),max(n1))<min(m1): print(max(2*(min(n1)),max(n1))) else: print(-1) ```
3
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992", "output": "42" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "6\n5 4 3 2 1 2", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "9" }, { "input": "7\n99 100 1 2 3 4 5", "output": "5" }, { "input": "5\n3 3 1 2 3", "output": "3" }, { "input": "1\n100", "output": "1" }, { "input": "1\n5", "output": "1" } ]
1,690,962,575
2,147,483,647
Python 3
OK
TESTS
28
78
13,516,800
n = int(input()) a = [int(x) for x in input().split()] ml = 0 cl = 1 for i in range(1, len(a)): if a[i] >= a[i-1]: cl += 1 else: ml = max(ml, cl) cl = 1 ml = max(ml, cl) print(ml)
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task! Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. Demo Input: ['6\n2 2 1 3 4 1\n', '3\n2 2 9\n'] Demo Output: ['3', '3'] Note: In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
```python n = int(input()) a = [int(x) for x in input().split()] ml = 0 cl = 1 for i in range(1, len(a)): if a[i] >= a[i-1]: cl += 1 else: ml = max(ml, cl) cl = 1 ml = max(ml, cl) print(ml) ```
3
0
none
none
none
0
[ "none" ]
null
null
It's Piegirl's birthday soon, and Pieguy has decided to buy her a bouquet of flowers and a basket of chocolates. The flower shop has *F* different types of flowers available. The *i*-th type of flower always has exactly *p**i* petals. Pieguy has decided to buy a bouquet consisting of exactly *N* flowers. He may buy the same type of flower multiple times. The *N* flowers are then arranged into a bouquet. The position of the flowers within a bouquet matters. You can think of a bouquet as an ordered list of flower types. The chocolate shop sells chocolates in boxes. There are *B* different types of boxes available. The *i*-th type of box contains *c**i* pieces of chocolate. Pieguy can buy any number of boxes, and can buy the same type of box multiple times. He will then place these boxes into a basket. The position of the boxes within the basket matters. You can think of the basket as an ordered list of box types. Pieguy knows that Piegirl likes to pluck a petal from a flower before eating each piece of chocolate. He would like to ensure that she eats the last piece of chocolate from the last box just after plucking the last petal from the last flower. That is, the total number of petals on all the flowers in the bouquet should equal the total number of pieces of chocolate in all the boxes in the basket. How many different bouquet+basket combinations can Pieguy buy? The answer may be very large, so compute it modulo 1000000007<==<=109<=+<=7.
The first line of input will contain integers *F*, *B*, and *N* (1<=≤<=*F*<=≤<=10,<=1<=≤<=*B*<=≤<=100,<=1<=≤<=*N*<=≤<=1018), the number of types of flowers, the number of types of boxes, and the number of flowers that must go into the bouquet, respectively. The second line of input will contain *F* integers *p*1,<=*p*2,<=...,<=*p**F* (1<=≤<=*p**i*<=≤<=109), the numbers of petals on each of the flower types. The third line of input will contain *B* integers *c*1,<=*c*2,<=...,<=*c**B* (1<=≤<=*c**i*<=≤<=250), the number of pieces of chocolate in each of the box types.
Print the number of bouquet+basket combinations Pieguy can buy, modulo 1000000007<==<=109<=+<=7.
[ "2 3 3\n3 5\n10 3 7\n", "6 5 10\n9 3 3 4 9 9\n9 9 1 6 4\n" ]
[ "17\n", "31415926\n" ]
In the first example, there is 1 way to make a bouquet with 9 petals (3 + 3 + 3), and 1 way to make a basket with 9 pieces of chocolate (3 + 3 + 3), for 1 possible combination. There are 3 ways to make a bouquet with 13 petals (3 + 5 + 5, 5 + 3 + 5, 5 + 5 + 3), and 5 ways to make a basket with 13 pieces of chocolate (3 + 10, 10 + 3, 3 + 3 + 7, 3 + 7 + 3, 7 + 3 + 3), for 15 more combinations. Finally there is 1 way to make a bouquet with 15 petals (5 + 5 + 5) and 1 way to make a basket with 15 pieces of chocolate (3 + 3 + 3 + 3 + 3), for 1 more combination. Note that it is possible for multiple types of flowers to have the same number of petals. Such types are still considered different. Similarly different types of boxes may contain the same number of pieces of chocolate, but are still considered different.
0
[]
1,692,517,323
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1692517323.3094378")# 1692517323.3094554
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's Piegirl's birthday soon, and Pieguy has decided to buy her a bouquet of flowers and a basket of chocolates. The flower shop has *F* different types of flowers available. The *i*-th type of flower always has exactly *p**i* petals. Pieguy has decided to buy a bouquet consisting of exactly *N* flowers. He may buy the same type of flower multiple times. The *N* flowers are then arranged into a bouquet. The position of the flowers within a bouquet matters. You can think of a bouquet as an ordered list of flower types. The chocolate shop sells chocolates in boxes. There are *B* different types of boxes available. The *i*-th type of box contains *c**i* pieces of chocolate. Pieguy can buy any number of boxes, and can buy the same type of box multiple times. He will then place these boxes into a basket. The position of the boxes within the basket matters. You can think of the basket as an ordered list of box types. Pieguy knows that Piegirl likes to pluck a petal from a flower before eating each piece of chocolate. He would like to ensure that she eats the last piece of chocolate from the last box just after plucking the last petal from the last flower. That is, the total number of petals on all the flowers in the bouquet should equal the total number of pieces of chocolate in all the boxes in the basket. How many different bouquet+basket combinations can Pieguy buy? The answer may be very large, so compute it modulo 1000000007<==<=109<=+<=7. Input Specification: The first line of input will contain integers *F*, *B*, and *N* (1<=≤<=*F*<=≤<=10,<=1<=≤<=*B*<=≤<=100,<=1<=≤<=*N*<=≤<=1018), the number of types of flowers, the number of types of boxes, and the number of flowers that must go into the bouquet, respectively. The second line of input will contain *F* integers *p*1,<=*p*2,<=...,<=*p**F* (1<=≤<=*p**i*<=≤<=109), the numbers of petals on each of the flower types. The third line of input will contain *B* integers *c*1,<=*c*2,<=...,<=*c**B* (1<=≤<=*c**i*<=≤<=250), the number of pieces of chocolate in each of the box types. Output Specification: Print the number of bouquet+basket combinations Pieguy can buy, modulo 1000000007<==<=109<=+<=7. Demo Input: ['2 3 3\n3 5\n10 3 7\n', '6 5 10\n9 3 3 4 9 9\n9 9 1 6 4\n'] Demo Output: ['17\n', '31415926\n'] Note: In the first example, there is 1 way to make a bouquet with 9 petals (3 + 3 + 3), and 1 way to make a basket with 9 pieces of chocolate (3 + 3 + 3), for 1 possible combination. There are 3 ways to make a bouquet with 13 petals (3 + 5 + 5, 5 + 3 + 5, 5 + 5 + 3), and 5 ways to make a basket with 13 pieces of chocolate (3 + 10, 10 + 3, 3 + 3 + 7, 3 + 7 + 3, 7 + 3 + 3), for 15 more combinations. Finally there is 1 way to make a bouquet with 15 petals (5 + 5 + 5) and 1 way to make a basket with 15 pieces of chocolate (3 + 3 + 3 + 3 + 3), for 1 more combination. Note that it is possible for multiple types of flowers to have the same number of petals. Such types are still considered different. Similarly different types of boxes may contain the same number of pieces of chocolate, but are still considered different.
```python print("_RANDOM_GUESS_1692517323.3094378")# 1692517323.3094554 ```
0
747
B
Mammoth's Genome Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
1,000
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????", "output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT" }, { "input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "===" }, { "input": "4\n??A?", "output": "CGAT" }, { "input": "4\n?C??", "output": "ACGT" }, { "input": "4\nT???", "output": "TACG" }, { "input": "4\n???G", "output": "ACTG" }, { "input": "4\n??AC", "output": "GTAC" }, { "input": "8\n?C?AA???", "output": "CCGAAGTT" }, { "input": "12\n???A?G???A?T", "output": "ACCACGGGTATT" }, { "input": "16\n?????C??CAG??T??", "output": "AAACCCGGCAGGTTTT" }, { "input": "20\n???A?G??C?GC???????G", "output": "AAAAAGCCCCGCGGTTTTTG" }, { "input": "24\n?TG???AT?A?CTTG??T?GCT??", "output": "ATGAAAATCACCTTGCCTGGCTGG" }, { "input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?", "output": "AACTGAAGAGGTCCCGAGTTTTCCACGT" }, { "input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?", "output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT" }, { "input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?", "output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT" }, { "input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??", "output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT" }, { "input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??", "output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT" }, { "input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?", "output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT" }, { "input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG", "output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG" }, { "input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??", "output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT" }, { "input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?", "output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT" }, { "input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C", "output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC" }, { "input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??", "output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT" }, { "input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG", "output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG" }, { "input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG", "output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG" }, { "input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?", "output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG" }, { "input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C", "output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC" }, { "input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?", "output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT" }, { "input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???", "output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT" }, { "input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????", "output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT" }, { "input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT", "output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT" }, { "input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG", "output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG" }, { "input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA", "output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA" }, { "input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??", "output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT" }, { "input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C", "output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC" }, { "input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C", "output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC" }, { "input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G", "output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG" }, { "input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?", "output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT" }, { "input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT", "output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT" }, { "input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?", "output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT" }, { "input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??", "output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT" }, { "input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA", "output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA" }, { "input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?", "output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT" }, { "input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G", "output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG" }, { "input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA", "output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA" }, { "input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?", "output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT" }, { "input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?", "output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG" }, { "input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT", "output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT" }, { "input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA", "output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA" }, { "input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G", "output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG" }, { "input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?", "output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT" }, { "input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T", "output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT" }, { "input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T", "output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT" }, { "input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????", "output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT" }, { "input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??", "output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT" }, { "input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??", "output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT" }, { "input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?", "output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT" }, { "input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT", "output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT" }, { "input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?", "output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT" }, { "input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??", "output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT" }, { "input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?", "output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT" }, { "input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?", "output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT" }, { "input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C", "output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC" }, { "input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC", "output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC" }, { "input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG", "output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG" }, { "input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?", "output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT" }, { "input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC", "output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC" }, { "input": "8\n???AAA??", "output": "===" }, { "input": "12\nC??CC??????C", "output": "===" }, { "input": "4\nG??G", "output": "===" }, { "input": "4\nTT??", "output": "===" }, { "input": "4\nACAC", "output": "===" }, { "input": "8\nACGT???T", "output": "ACGTACGT" }, { "input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG" }, { "input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "4\nAA?T", "output": "===" }, { "input": "4\nAAAA", "output": "===" }, { "input": "8\nAAA?????", "output": "===" }, { "input": "10\nACGT??????", "output": "===" }, { "input": "6\nACGACG", "output": "===" }, { "input": "5\nAAAAA", "output": "===" }, { "input": "8\nGGGGAA??", "output": "===" }, { "input": "5\nATGCA", "output": "===" }, { "input": "4\nTTTT", "output": "===" }, { "input": "4\nACCG", "output": "===" }, { "input": "8\nACGTA?GT", "output": "ACGTACGT" } ]
1,657,953,170
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
length_of_genome = int(input()) s = input() number_per_characters = length_of_genome // 4 a_characters = s.count('A') c_characters = s.count('C') g_characters = s.count('G') t_characters = s.count('T') special_characters = s.count('?') deficient_characters = [] if a_characters < number_per_characters: deficient_characters.append((number_per_characters - a_characters) * 'A') if c_characters < number_per_characters: deficient_characters.append((number_per_characters - c_characters) * 'C') if g_characters < number_per_characters: deficient_characters.append((number_per_characters - g_characters) * 'G') if t_characters < number_per_characters: deficient_characters.append((number_per_characters - t_characters) * 'T') if special_characters == 0: print(s) else: if a_characters > 0 and c_characters > 0 and g_characters > 0 and t_characters > 0: for i in range(len(deficient_characters)): s = s.replace('?', deficient_characters[i]) print(s) elif (a_characters > 0 and c_characters > 0 and g_characters > 0 and t_characters == 0) or (a_characters == 0 and c_characters > 0 and g_characters > 0 and t_characters > 0) or (a_characters > 0 and c_characters == 0 and g_characters > 0 and t_characters > 0) or (a_characters > 0 and c_characters > 0 and g_characters == 0 and t_characters > 0): for i in range(len(deficient_characters)): s = s.replace('?', deficient_characters[i]) print(s) else: print('===')
Title: Mammoth's Genome Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input Specification: The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output Specification: If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Demo Input: ['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n'] Demo Output: ['AGACGTCT\n', 'AGCT\n', '===\n', '===\n'] Note: In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
```python length_of_genome = int(input()) s = input() number_per_characters = length_of_genome // 4 a_characters = s.count('A') c_characters = s.count('C') g_characters = s.count('G') t_characters = s.count('T') special_characters = s.count('?') deficient_characters = [] if a_characters < number_per_characters: deficient_characters.append((number_per_characters - a_characters) * 'A') if c_characters < number_per_characters: deficient_characters.append((number_per_characters - c_characters) * 'C') if g_characters < number_per_characters: deficient_characters.append((number_per_characters - g_characters) * 'G') if t_characters < number_per_characters: deficient_characters.append((number_per_characters - t_characters) * 'T') if special_characters == 0: print(s) else: if a_characters > 0 and c_characters > 0 and g_characters > 0 and t_characters > 0: for i in range(len(deficient_characters)): s = s.replace('?', deficient_characters[i]) print(s) elif (a_characters > 0 and c_characters > 0 and g_characters > 0 and t_characters == 0) or (a_characters == 0 and c_characters > 0 and g_characters > 0 and t_characters > 0) or (a_characters > 0 and c_characters == 0 and g_characters > 0 and t_characters > 0) or (a_characters > 0 and c_characters > 0 and g_characters == 0 and t_characters > 0): for i in range(len(deficient_characters)): s = s.replace('?', deficient_characters[i]) print(s) else: print('===') ```
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input": "2\n100 100", "output": "2" }, { "input": "3\n100 100 100", "output": "3" }, { "input": "11\n1 2 3 4 5 6 5 4 3 2 1", "output": "11" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 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", "output": "61" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1", "output": "81" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1", "output": "85" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 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 100 7 6 5 4 3 2 1", "output": "61" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 100 8 7 6 1 4 3 2 1", "output": "96" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 100 10 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 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 100 11 10 9 8 7 6 5 4 3 2 1", "output": "55" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1", "output": "59" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "86" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 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", "output": "83" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 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", "output": "74" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 100 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 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", "output": "52" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 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 1 2 1", "output": "98" }, { "input": "10\n1 4 4 4 4 4 1 2 4 3", "output": "7" } ]
1,646,370,772
2,147,483,647
Python 3
OK
TESTS
80
778
0
def solve(): arr.append(1001) arr.insert(0,10001) mx=-1 for i in range(1,n+1) : c=1 start=i end=i while True : if start>=0 and arr[start]>=arr[start-1] : c+=1 start-=1 elif end <= n+1 and arr[end]>=arr[end+1] : c+=1 end+=1 else: break mx=max(mx,c) return mx from sys import stdin input = stdin.readline ''' m,n= [int(x) for x in input().split()] arr=[] for i in range(m): arr.append([int(x) for x in input().split()]) ''' n=int(input()) arr=[int(x) for x in input().split()] print(solve())
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. Output Specification: Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. Demo Input: ['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n'] Demo Output: ['1\n', '3\n', '6\n'] Note: none
```python def solve(): arr.append(1001) arr.insert(0,10001) mx=-1 for i in range(1,n+1) : c=1 start=i end=i while True : if start>=0 and arr[start]>=arr[start-1] : c+=1 start-=1 elif end <= n+1 and arr[end]>=arr[end+1] : c+=1 end+=1 else: break mx=max(mx,c) return mx from sys import stdin input = stdin.readline ''' m,n= [int(x) for x in input().split()] arr=[] for i in range(m): arr.append([int(x) for x in input().split()]) ''' n=int(input()) arr=[int(x) for x in input().split()] print(solve()) ```
3.8055
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,657,815,174
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
61
2,764,800
n=int(input()) a=list(map(int,input().rstrip().split())) for i in range(1,n): if a[i-1]>a[i]:print[-1,n-i][sorted(a)==a[i:]+a[:i]];exit() print(0)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python n=int(input()) a=list(map(int,input().rstrip().split())) for i in range(1,n): if a[i-1]>a[i]:print[-1,n-i][sorted(a)==a[i:]+a[:i]];exit() print(0) ```
-1
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "input": "1 1 20", "output": "Yes" }, { "input": "12 14 19", "output": "No" }, { "input": "15 12 26", "output": "No" }, { "input": "2 4 8", "output": "Yes" }, { "input": "4 5 30", "output": "Yes" }, { "input": "4 5 48", "output": "Yes" }, { "input": "2 17 105", "output": "Yes" }, { "input": "10 25 282", "output": "No" }, { "input": "6 34 323", "output": "No" }, { "input": "2 47 464", "output": "Yes" }, { "input": "4 53 113", "output": "Yes" }, { "input": "6 64 546", "output": "Yes" }, { "input": "1 78 725", "output": "Yes" }, { "input": "1 84 811", "output": "Yes" }, { "input": "3 100 441", "output": "Yes" }, { "input": "20 5 57", "output": "No" }, { "input": "14 19 143", "output": "No" }, { "input": "17 23 248", "output": "No" }, { "input": "11 34 383", "output": "Yes" }, { "input": "20 47 568", "output": "Yes" }, { "input": "16 58 410", "output": "Yes" }, { "input": "11 70 1199", "output": "Yes" }, { "input": "16 78 712", "output": "Yes" }, { "input": "20 84 562", "output": "No" }, { "input": "19 100 836", "output": "Yes" }, { "input": "23 10 58", "output": "No" }, { "input": "25 17 448", "output": "Yes" }, { "input": "22 24 866", "output": "Yes" }, { "input": "24 35 67", "output": "No" }, { "input": "29 47 264", "output": "Yes" }, { "input": "23 56 45", "output": "No" }, { "input": "25 66 1183", "output": "Yes" }, { "input": "21 71 657", "output": "Yes" }, { "input": "29 81 629", "output": "No" }, { "input": "23 95 2226", "output": "Yes" }, { "input": "32 4 62", "output": "No" }, { "input": "37 15 789", "output": "Yes" }, { "input": "39 24 999", "output": "Yes" }, { "input": "38 32 865", "output": "No" }, { "input": "32 50 205", "output": "No" }, { "input": "31 57 1362", "output": "Yes" }, { "input": "38 68 1870", "output": "Yes" }, { "input": "36 76 549", "output": "No" }, { "input": "35 84 1257", "output": "No" }, { "input": "39 92 2753", "output": "Yes" }, { "input": "44 1 287", "output": "Yes" }, { "input": "42 12 830", "output": "No" }, { "input": "42 27 9", "output": "No" }, { "input": "49 40 1422", "output": "No" }, { "input": "44 42 2005", "output": "No" }, { "input": "50 55 2479", "output": "No" }, { "input": "48 65 917", "output": "No" }, { "input": "45 78 152", "output": "No" }, { "input": "43 90 4096", "output": "Yes" }, { "input": "43 94 4316", "output": "Yes" }, { "input": "60 7 526", "output": "Yes" }, { "input": "53 11 735", "output": "Yes" }, { "input": "52 27 609", "output": "Yes" }, { "input": "57 32 992", "output": "Yes" }, { "input": "52 49 421", "output": "No" }, { "input": "57 52 2634", "output": "Yes" }, { "input": "54 67 3181", "output": "Yes" }, { "input": "52 73 638", "output": "No" }, { "input": "57 84 3470", "output": "No" }, { "input": "52 100 5582", "output": "No" }, { "input": "62 1 501", "output": "Yes" }, { "input": "63 17 858", "output": "Yes" }, { "input": "70 24 1784", "output": "Yes" }, { "input": "65 32 1391", "output": "Yes" }, { "input": "62 50 2775", "output": "No" }, { "input": "62 58 88", "output": "No" }, { "input": "66 68 3112", "output": "Yes" }, { "input": "61 71 1643", "output": "No" }, { "input": "69 81 3880", "output": "No" }, { "input": "63 100 1960", "output": "Yes" }, { "input": "73 6 431", "output": "Yes" }, { "input": "75 19 736", "output": "Yes" }, { "input": "78 25 247", "output": "No" }, { "input": "79 36 2854", "output": "Yes" }, { "input": "80 43 1864", "output": "Yes" }, { "input": "76 55 2196", "output": "Yes" }, { "input": "76 69 4122", "output": "Yes" }, { "input": "76 76 4905", "output": "No" }, { "input": "75 89 3056", "output": "Yes" }, { "input": "73 100 3111", "output": "Yes" }, { "input": "84 9 530", "output": "No" }, { "input": "82 18 633", "output": "No" }, { "input": "85 29 2533", "output": "Yes" }, { "input": "89 38 2879", "output": "Yes" }, { "input": "89 49 2200", "output": "Yes" }, { "input": "88 60 4140", "output": "Yes" }, { "input": "82 68 1299", "output": "No" }, { "input": "90 76 2207", "output": "No" }, { "input": "83 84 4923", "output": "Yes" }, { "input": "89 99 7969", "output": "Yes" }, { "input": "94 9 168", "output": "No" }, { "input": "91 20 1009", "output": "No" }, { "input": "93 23 2872", "output": "Yes" }, { "input": "97 31 3761", "output": "Yes" }, { "input": "99 46 1341", "output": "Yes" }, { "input": "98 51 2845", "output": "No" }, { "input": "93 66 3412", "output": "No" }, { "input": "95 76 3724", "output": "Yes" }, { "input": "91 87 6237", "output": "Yes" }, { "input": "98 97 7886", "output": "Yes" }, { "input": "12 17 15", "output": "No" }, { "input": "93 94 95", "output": "No" }, { "input": "27 43 27", "output": "Yes" }, { "input": "17 43 68", "output": "Yes" }, { "input": "44 12 12", "output": "Yes" }, { "input": "44 50 150", "output": "Yes" }, { "input": "1 1 10000", "output": "Yes" }, { "input": "2 3 10000", "output": "Yes" }, { "input": "100 1 10", "output": "Yes" }, { "input": "3 2 1", "output": "No" }, { "input": "1 1 1", "output": "Yes" }, { "input": "9 9 10000", "output": "No" }, { "input": "2 3 9995", "output": "Yes" }, { "input": "3 5 4", "output": "No" }, { "input": "99 98 100", "output": "No" }, { "input": "6 10 2", "output": "No" }, { "input": "1 6 5", "output": "Yes" }, { "input": "1 4 3", "output": "Yes" }, { "input": "3 2 3", "output": "Yes" }, { "input": "1 7 6", "output": "Yes" }, { "input": "2 3 9871", "output": "Yes" }, { "input": "10 5 5", "output": "Yes" }, { "input": "10 8 2", "output": "No" } ]
1,530,782,532
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
109
307,200
a,b,c=input().split() a=int(a) b=int(b) c=int(c) if c%a==0 or c%b==0: print('Yes') else: v=min(a,b) b=max(a,b) a=v inc=2 flag=0 while a<=c: a=a*inc if (c-a)%b==0: flag=1 #print(check) break inc+=1 print('Yes' if flag==1 else 'No')
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. Input Specification: The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Output Specification: Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Demo Input: ['4 6 15\n', '3 2 7\n', '6 11 6\n'] Demo Output: ['No\n', 'Yes\n', 'Yes\n'] Note: In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
```python a,b,c=input().split() a=int(a) b=int(b) c=int(c) if c%a==0 or c%b==0: print('Yes') else: v=min(a,b) b=max(a,b) a=v inc=2 flag=0 while a<=c: a=a*inc if (c-a)%b==0: flag=1 #print(check) break inc+=1 print('Yes' if flag==1 else 'No') ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,662,888,477
2,147,483,647
PyPy 3-64
OK
TESTS
37
109
8,806,400
import math import copy import itertools import bisect import sys input = sys.stdin.readline def ilst(): return list(map(int,input().split())) def islst(): return list(map(str,input().split())) def inum(): return map(int,input().split()) n,m = inum() d = {} for i in range(m): tl = islst() if len(tl[0]) <= len(tl[1]): d[tl[1]] = tl[0] else: d[tl[0]] = tl[1] #print(d) tl = islst() ans = '' for i in range(n): if tl[i] not in d: ans += ' ' + tl[i] continue ans += ' '+d[tl[i]] print(ans[1:])
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python import math import copy import itertools import bisect import sys input = sys.stdin.readline def ilst(): return list(map(int,input().split())) def islst(): return list(map(str,input().split())) def inum(): return map(int,input().split()) n,m = inum() d = {} for i in range(m): tl = islst() if len(tl[0]) <= len(tl[1]): d[tl[1]] = tl[0] else: d[tl[0]] = tl[1] #print(d) tl = islst() ans = '' for i in range(n): if tl[i] not in d: ans += ' ' + tl[i] continue ans += ' '+d[tl[i]] print(ans[1:]) ```
3
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob?
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "4" }, { "input": "1 6", "output": "5" }, { "input": "1 7", "output": "5" }, { "input": "1 8", "output": "6" }, { "input": "1 9", "output": "6" }, { "input": "1 10", "output": "6" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "2 4", "output": "2" }, { "input": "2 5", "output": "3" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "4" }, { "input": "2 8", "output": "4" }, { "input": "2 9", "output": "4" }, { "input": "2 10", "output": "4" }, { "input": "3 3", "output": "1" }, { "input": "3 4", "output": "1" }, { "input": "3 5", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "3" }, { "input": "3 8", "output": "3" }, { "input": "3 9", "output": "3" }, { "input": "3 10", "output": "3" }, { "input": "4 4", "output": "1" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "4 8", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "4 10", "output": "3" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "1" }, { "input": "5 7", "output": "1" }, { "input": "5 8", "output": "2" }, { "input": "5 9", "output": "2" }, { "input": "5 10", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "6 8", "output": "1" }, { "input": "6 9", "output": "2" }, { "input": "6 10", "output": "2" }, { "input": "7 7", "output": "1" }, { "input": "7 8", "output": "1" }, { "input": "7 9", "output": "1" }, { "input": "7 10", "output": "1" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "1" }, { "input": "8 10", "output": "1" }, { "input": "9 9", "output": "1" }, { "input": "9 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "1 2", "output": "2" } ]
1,696,427,898
2,147,483,647
PyPy 3-64
OK
TESTS
62
62
0
a,b = map(int,input().split()) cnt = 0 while a<=b: cnt+=1 a = a*3 b = b*2 print(cnt)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. Output Specification: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Demo Input: ['4 7\n', '4 9\n', '1 1\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
```python a,b = map(int,input().split()) cnt = 0 while a<=b: cnt+=1 a = a*3 b = b*2 print(cnt) ```
3
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,694,878,628
2,147,483,647
PyPy 3-64
OK
TESTS
34
124
0
# Read input s1, s2, s3, s4 = map(int, input().split()) # Create a set to store unique colors colors_set = set([s1, s2, s3, s4]) # Calculate the number of additional horseshoes needed additional_horseshoes = 4 - len(colors_set) # Print the result print(additional_horseshoes)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python # Read input s1, s2, s3, s4 = map(int, input().split()) # Create a set to store unique colors colors_set = set([s1, s2, s3, s4]) # Calculate the number of additional horseshoes needed additional_horseshoes = 4 - len(colors_set) # Print the result print(additional_horseshoes) ```
3
928
A
Login Verification
PROGRAMMING
1,200
[ "*special", "strings" ]
null
null
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types: - transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other. For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not. You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins. The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes).
[ "1_wat\n2\n2_wat\nwat_1\n", "000\n3\n00\nooA\noOo\n", "_i_\n3\n__i_\n_1_\nI\n", "La0\n3\n2a0\nLa1\n1a0\n", "abc\n1\naBc\n", "0Lil\n2\nLIL0\n0Ril\n" ]
[ "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n" ]
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
500
[ { "input": "1_wat\n2\n2_wat\nwat_1", "output": "Yes" }, { "input": "000\n3\n00\nooA\noOo", "output": "No" }, { "input": "_i_\n3\n__i_\n_1_\nI", "output": "No" }, { "input": "La0\n3\n2a0\nLa1\n1a0", "output": "No" }, { "input": "abc\n1\naBc", "output": "No" }, { "input": "0Lil\n2\nLIL0\n0Ril", "output": "Yes" }, { "input": "iloO\n3\niIl0\noIl0\nIooO", "output": "Yes" }, { "input": "L1il0o1L1\n5\niLLoLL\noOI1Io10il\nIoLLoO\nO01ilOoI\nI10l0o", "output": "Yes" }, { "input": "ELioO1lOoOIOiLoooi1iolul1O\n7\nOoEIuOIl1ui1010uiooOoi0Oio001L0EoEolO0\nOLIoOEuoE11u1u1iLOI0oO\nuEOuO0uIOOlO01OlEI0E1Oo0IO1LI0uE0LILO0\nEOo0Il11iIOOOIiuOiIiiLOLEOOII001EE\niOoO0LOulioE0OLIIIulli01OoiuOOOoOlEiI0EiiElIIu0\nlE1LOE1Oil\n1u0EOliIiIOl1u110il0l1O0u", "output": "Yes" }, { "input": "0blo7X\n20\n1oobb6\nXIXIO2X\n2iYI2\n607XXol\n2I6io22\nOl10I\nbXX0Lo\nolOOb7X\n07LlXL\nlXY17\n12iIX2\n7lL70\nbOo11\n17Y6b62\n0O6L7\n1lX2L\n2iYl6lI\n7bXIi1o\niLIY2\n0OIo1X", "output": "Yes" }, { "input": "lkUL\n25\nIIfL\nokl\nfoo\ni0U\noko\niIoU\nUUv\nvli\nv0Uk\n0Of\niill\n1vkl\nUIf\nUfOO\nlvLO\nUUo0\nIOf1\nlovL\nIkk\noIv\nLvfU\n0UI\nkol\n1OO0\n1OOi", "output": "Yes" }, { "input": "L1lo\n3\nOOo1\nL1lo\n0lOl", "output": "No" }, { "input": "LIoooiLO\n5\nLIoooiLO\nl0o01I00\n0OOl0lLO01\nil10i0\noiloi", "output": "No" }, { "input": "1i1lQI\n7\nuLg1uLLigIiOLoggu\nLLLgIuQIQIIloiQuIIoIO0l0o000\n0u1LQu11oIuooIl0OooLg0i0IQu1O1lloI1\nQuQgIQi0LOIliLOuuuioLQou1l\nlLIO00QLi01LogOliOIggII1\no0Ll1uIOQl10IL0IILQ\n1i1lQI", "output": "No" }, { "input": "oIzz1\n20\n1TTl0O\nloF0LT\n1lLzo\noi0Ov\nFlIF1zT\nzoITzx\n0TIFlT\nl1vllil\nOviix1F\nLFvI1lL\nLIl0loz\nixz1v\n1i1vFi\nTIFTol\noIzz1\nIvTl0o\nxv1U0O\niiiioF\n1oiLUlO\nxToxv1", "output": "No" }, { "input": "00L0\n25\n0il\nIlkZ\nL0I\n00L0\nBd0\nZLd\n0d1k\nddk\nIdl\nkBd\nkBOL\nZ1lI\nkBL\nLOko\noZ0i\nZ1lO\nLiOk\niBld\nLO0d\ndIo\nZ10\n1k1i\n0o0L\nIoBd\ni0B0", "output": "No" }, { "input": "Z\n1\nz", "output": "No" }, { "input": "0\n1\no", "output": "No" }, { "input": "0\n1\nO", "output": "No" }, { "input": "o\n1\n0", "output": "No" }, { "input": "o\n1\nO", "output": "No" }, { "input": "o\n1\no", "output": "No" }, { "input": "O\n1\no", "output": "No" }, { "input": "O\n1\n0", "output": "No" }, { "input": "1\n1\nl", "output": "No" }, { "input": "1\n1\nL", "output": "No" }, { "input": "1\n1\ni", "output": "No" }, { "input": "1\n1\nI", "output": "No" }, { "input": "1\n1\no", "output": "Yes" }, { "input": "i\n1\n1", "output": "No" }, { "input": "i\n1\nL", "output": "No" }, { "input": "i\n1\nl", "output": "No" }, { "input": "I\n1\nL", "output": "No" }, { "input": "I\n1\nl", "output": "No" }, { "input": "I\n1\n1", "output": "No" }, { "input": "l\n1\n1", "output": "No" }, { "input": "l\n1\nL", "output": "No" }, { "input": "l\n1\ni", "output": "No" }, { "input": "l\n1\nI", "output": "No" }, { "input": "L\n1\nl", "output": "No" }, { "input": "L\n1\n1", "output": "No" }, { "input": "L\n1\ni", "output": "No" }, { "input": "L\n1\nI", "output": "No" } ]
1,519,505,073
18,573
Python 3
OK
TESTS
73
93
5,632,000
def liker(data): data = data.upper() data = data.replace('O', "0") data = data.replace("L", "I") data = data.replace("I", "1") return data login = liker(input()) numOfLogins = int(input()) loginsArray = [liker(input()) for x in range(numOfLogins)] if login in loginsArray: print("No") else: print("Yes")
Title: Login Verification Time Limit: None seconds Memory Limit: None megabytes Problem Description: When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types: - transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other. For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not. You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones. Input Specification: The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins. The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar. Output Specification: Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes). Demo Input: ['1_wat\n2\n2_wat\nwat_1\n', '000\n3\n00\nooA\noOo\n', '_i_\n3\n__i_\n_1_\nI\n', 'La0\n3\n2a0\nLa1\n1a0\n', 'abc\n1\naBc\n', '0Lil\n2\nLIL0\n0Ril\n'] Demo Output: ['Yes\n', 'No\n', 'No\n', 'No\n', 'No\n', 'Yes\n'] Note: In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
```python def liker(data): data = data.upper() data = data.replace('O', "0") data = data.replace("L", "I") data = data.replace("I", "1") return data login = liker(input()) numOfLogins = int(input()) loginsArray = [liker(input()) for x in range(numOfLogins)] if login in loginsArray: print("No") else: print("Yes") ```
3
252
A
Little Xor
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
[ "5\n1 2 1 1 2\n", "3\n1 2 7\n", "4\n4 2 4 8\n" ]
[ "3\n", "7\n", "14\n" ]
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
500
[ { "input": "5\n1 2 1 1 2", "output": "3" }, { "input": "3\n1 2 7", "output": "7" }, { "input": "4\n4 2 4 8", "output": "14" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "15" }, { "input": "20\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10", "output": "15" }, { "input": "100\n28 20 67 103 72 81 82 83 7 109 122 30 50 118 83 89 108 82 92 17 97 3 62 12 9 100 14 11 99 106 10 8 60 101 88 119 104 62 76 6 5 57 32 94 60 50 58 97 1 97 107 108 80 24 45 20 112 1 98 106 49 98 25 57 47 90 74 68 14 35 22 10 61 80 10 4 53 13 90 99 57 100 40 84 22 116 60 61 98 57 74 127 61 73 49 51 20 19 56 111", "output": "127" }, { "input": "99\n87 67 4 84 13 20 35 7 11 86 25 1 58 1 74 64 74 86 98 74 72 46 63 78 84 13 60 38 30 45 45 60 9 44 36 70 33 22 82 15 71 7 43 47 23 2 20 49 42 43 54 27 51 51 53 23 27 37 17 66 90 89 61 0 18 20 49 30 84 20 13 32 64 69 56 68 59 10 91 96 43 64 19 10 2 57 62 23 100 39 32 19 95 55 77 19 24 4 77", "output": "127" }, { "input": "1\n100", "output": "100" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n4 10", "output": "14" }, { "input": "99\n3511 2076 9314 3598 7737 271 4110 4454 5830 8661 8584 8227 2236 2626 1025 3806 3162 2837 6071 9627 1836 7729 6629 4054 9377 3261 1325 8859 3610 7616 5052 9736 1249 6224 7031 6074 4196 8075 4005 5419 5664 8214 4391 731 8714 8622 6122 6976 4057 1770 8025 3778 2792 994 5204 1826 6083 5438 8409 8029 1962 3133 9836 8884 1234 1776 824 1630 6523 2869 9950 8609 5397 1472 7120 5012 6490 5958 8030 7741 5077 2771 7925 9784 9456 8596 6288 8939 4779 4415 3743 5188 5574 9686 1483 4245 4769 4917 1887", "output": "16383" }, { "input": "27\n78 918 443 3900 591 12 4 10 1 24 70 88 429 2 3257 65 275 2 258 62 587 625 25 26 853 728 765", "output": "4027" }, { "input": "2\n3 1", "output": "3" }, { "input": "2\n3 2", "output": "3" }, { "input": "3\n7 3 1", "output": "7" }, { "input": "3\n1 7 2", "output": "7" }, { "input": "2\n7 1", "output": "7" }, { "input": "4\n1 2 7 1", "output": "7" }, { "input": "3\n10 5 1", "output": "15" } ]
1,625,317,190
2,147,483,647
PyPy 3
OK
TESTS
56
218
1,331,200
n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n): x = 0 for j in range(i, n): x = (x ^ a[j]) res = max(res, x) print(res)
Title: Little Xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. Output Specification: Print a single integer — the required maximal *xor* of a segment of consecutive elements. Demo Input: ['5\n1 2 1 1 2\n', '3\n1 2 7\n', '4\n4 2 4 8\n'] Demo Output: ['3\n', '7\n', '14\n'] Note: In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
```python n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n): x = 0 for j in range(i, n): x = (x ^ a[j]) res = max(res, x) print(res) ```
3
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,692,593,983
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n=int(input()) sum=0 f=((-1)**n)*n for i in range(1,f+1): sum+=((-1)**i)*i print(sum)
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python n=int(input()) sum=0 f=((-1)**n)*n for i in range(1,f+1): sum+=((-1)**i)*i print(sum) ```
0
721
C
Journey
PROGRAMMING
1,800
[ "dp", "graphs" ]
null
null
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units. Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it.
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes. It is guaranteed, that there is at most one road between each pair of showplaces.
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line. Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them. If there are multiple answers, print any of them.
[ "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n" ]
[ "3\n1 2 4 \n", "4\n1 2 4 6 \n", "3\n1 3 5 \n" ]
none
1,500
[ { "input": "4 3 13\n1 2 5\n2 3 7\n2 4 8", "output": "3\n1 2 4 " }, { "input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "output": "4\n1 2 4 6 " }, { "input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2", "output": "3\n1 3 5 " }, { "input": "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4", "output": "10\n1 2 7 5 8 9 3 6 4 10 " }, { "input": "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9", "output": "3\n1 6 10 " }, { "input": "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "output": "4\n1 2 3 4 " }, { "input": "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "output": "3\n1 3 4 " }, { "input": "10 45 8\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 8 1\n1 9 1\n1 10 1\n2 3 1\n2 4 1\n2 5 1\n2 6 1\n2 7 1\n2 8 1\n2 9 1\n2 10 1\n3 4 1\n3 5 1\n3 6 1\n3 7 1\n3 8 1\n3 9 1\n3 10 1\n4 5 1\n4 6 1\n4 7 1\n4 8 1\n4 9 1\n4 10 1\n5 6 1\n5 7 1\n5 8 1\n5 9 1\n5 10 1\n6 7 1\n6 8 1\n6 9 1\n6 10 1\n7 8 1\n7 9 1\n7 10 1\n8 9 1\n8 10 1\n9 10 1", "output": "9\n1 2 3 4 5 6 7 8 10 " }, { "input": "2 1 1\n1 2 1", "output": "2\n1 2 " }, { "input": "12 12 8\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1", "output": "6\n1 9 10 11 8 12 " }, { "input": "12 12 5\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1", "output": "6\n1 9 10 11 8 12 " }, { "input": "12 12 4\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 2\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1", "output": "4\n1 7 6 12 " }, { "input": "11 11 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1", "output": "8\n1 4 5 6 3 7 8 11 " }, { "input": "11 11 7\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1", "output": "8\n1 4 5 6 3 7 8 11 " }, { "input": "11 11 6\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1", "output": "6\n1 2 3 7 8 11 " }, { "input": "12 12 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 12 1\n12 10 1\n10 9 1\n11 1 1", "output": "8\n1 4 5 6 3 7 8 12 " }, { "input": "4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100", "output": "3\n1 3 4 " }, { "input": "4 4 10\n2 1 1\n2 3 1\n1 3 1\n3 4 1", "output": "3\n1 3 4 " }, { "input": "5 5 200\n1 2 100\n2 4 100\n1 3 1\n3 4 1\n4 5 1", "output": "4\n1 3 4 5 " }, { "input": "5 5 2\n1 2 1\n1 3 1\n3 4 1\n2 5 1\n4 2 1", "output": "3\n1 2 5 " }, { "input": "4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000", "output": "2\n1 4 " } ]
1,600,616,889
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
265
614,400
import sys def dfs(i, t): if i == n-1 and t >= 0: return (1, [i]) if t < 0: return (-2e9, [-1]) mas = -2e9 ris = [] for k in graph[i]: tmp = dfs(k[0], t-k[1]) if tmp[0] > mas: mas = tmp[0] ris = tmp[1] ris.append(i) return (mas+1, ris) n, m, t = map(int, input().split()) graph = [] for i in range(0, n): graph.append([]) for i in range(0, m): s, e, l = map(int, input().split()) graph[s-1].append((e-1, l)) #print(graph) sk = dfs(0, t) print(sk[0]) for i in sk[1][::-1]: print(i+1, end = " ")
Title: Journey Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units. Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it. Input Specification: The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes. It is guaranteed, that there is at most one road between each pair of showplaces. Output Specification: Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line. Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them. If there are multiple answers, print any of them. Demo Input: ['4 3 13\n1 2 5\n2 3 7\n2 4 8\n', '6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n', '5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n'] Demo Output: ['3\n1 2 4 \n', '4\n1 2 4 6 \n', '3\n1 3 5 \n'] Note: none
```python import sys def dfs(i, t): if i == n-1 and t >= 0: return (1, [i]) if t < 0: return (-2e9, [-1]) mas = -2e9 ris = [] for k in graph[i]: tmp = dfs(k[0], t-k[1]) if tmp[0] > mas: mas = tmp[0] ris = tmp[1] ris.append(i) return (mas+1, ris) n, m, t = map(int, input().split()) graph = [] for i in range(0, n): graph.append([]) for i in range(0, m): s, e, l = map(int, input().split()) graph[s-1].append((e-1, l)) #print(graph) sk = dfs(0, t) print(sk[0]) for i in sk[1][::-1]: print(i+1, end = " ") ```
-1
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 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\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
1,680,020,383
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = list(map(int, input().split())) for i in range(m): x = b[i] l = 0 r = n while r-l>1: m = (l+r)//2 if a[m]<=x: l = m else: r = m print(r, end=" ")
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). Output Specification: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Demo Input: ['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n'] Demo Output: ['3 2 1 4\n', '4 2 4 2 5\n'] Note: none
```python n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = list(map(int, input().split())) for i in range(m): x = b[i] l = 0 r = n while r-l>1: m = (l+r)//2 if a[m]<=x: l = m else: r = m print(r, end=" ") ```
0
595
A
Vitaly and Night
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on. Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively. Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
[ "2 2\n0 0 0 1\n1 0 1 1\n", "1 3\n1 1 0 1 0 0\n" ]
[ "3\n", "2\n" ]
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
500
[ { "input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3" }, { "input": "1 3\n1 1 0 1 0 0", "output": "2" }, { "input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1", "output": "8" }, { "input": "1 5\n1 0 1 1 1 0 1 1 1 1", "output": "5" }, { "input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "99" }, { "input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "6" }, { "input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "100" }, { "input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0", "output": "8" }, { "input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "1 1\n0 0", "output": "0" }, { "input": "1 1\n0 1", "output": "1" }, { "input": "1 1\n1 0", "output": "1" }, { "input": "1 1\n1 1", "output": "1" } ]
1,505,792,912
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
204,800
n,m = input().split() n,m = map(int,[n,m]) an = input() list1 = [] for i in an.split(): list1.append(int(i)) A = [] for j in range(0,n-1): x,y = input().split() x,y = map(int,[x,y]) A.append([x,y,list1[j+1]]) #print(A) B = []#记路过了几条狗 for k in range(0,n-1): B.append(0) count = 0 for l in range(0,n-1): #print(A) if A[l][0] != 1: if B[A[l][0]-2] <m: if A[l][2] == 1: B[l] = B[A[l][0]-2]+1 if B[l]<m: A[l].append(0) #count = count + 1 else: A[l].append(1) elif A[l][2] == 0: A[l].append(0) count = count + 1 elif B[A[l][0]-2] == m: B[l] = m A[l].append(1) elif A[l][0] == 1: if A[l][2] == 1: if m >1: B[l] = B[l] + 1 #count = count + 1 A[l].append(0) elif m <= 1: B[l] = B[l] + 1 A[l].append(1) elif A[l][2] == 0: A[l].append(0) count = count + 1 print(A) print(B) print(count)
Title: Vitaly and Night Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on. Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively. Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'. Output Specification: Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. Demo Input: ['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n'] Demo Output: ['3\n', '2\n'] Note: In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
```python n,m = input().split() n,m = map(int,[n,m]) an = input() list1 = [] for i in an.split(): list1.append(int(i)) A = [] for j in range(0,n-1): x,y = input().split() x,y = map(int,[x,y]) A.append([x,y,list1[j+1]]) #print(A) B = []#记路过了几条狗 for k in range(0,n-1): B.append(0) count = 0 for l in range(0,n-1): #print(A) if A[l][0] != 1: if B[A[l][0]-2] <m: if A[l][2] == 1: B[l] = B[A[l][0]-2]+1 if B[l]<m: A[l].append(0) #count = count + 1 else: A[l].append(1) elif A[l][2] == 0: A[l].append(0) count = count + 1 elif B[A[l][0]-2] == m: B[l] = m A[l].append(1) elif A[l][0] == 1: if A[l][2] == 1: if m >1: B[l] = B[l] + 1 #count = count + 1 A[l].append(0) elif m <= 1: B[l] = B[l] + 1 A[l].append(1) elif A[l][2] == 0: A[l].append(0) count = count + 1 print(A) print(B) print(count) ```
-1
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "output": "11 13" }, { "input": "17", "output": "8 9" }, { "input": "10", "output": "3 7" }, { "input": "69", "output": "34 35" }, { "input": "100", "output": "49 51" }, { "input": "57", "output": "28 29" }, { "input": "1000", "output": "499 501" }, { "input": "999", "output": "499 500" }, { "input": "998", "output": "497 501" }, { "input": "997", "output": "498 499" }, { "input": "996", "output": "497 499" }, { "input": "995", "output": "497 498" }, { "input": "994", "output": "495 499" }, { "input": "5", "output": "2 3" }, { "input": "6", "output": "1 5" }, { "input": "8", "output": "3 5" }, { "input": "9", "output": "4 5" }, { "input": "423", "output": "211 212" }, { "input": "876", "output": "437 439" }, { "input": "29", "output": "14 15" } ]
1,531,901,431
2,147,483,647
PyPy 3
OK
TESTS
26
155
0
from math import gcd n = int(input()) a, b = 1, n - 1 for c in range(1, n): if gcd(c, n - c) == 1 and c < n - c: a, b = c, n - c print(a, b)
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python from math import gcd n = int(input()) a, b = 1, n - 1 for c in range(1, n): if gcd(c, n - c) == 1 and c < n - c: a, b = c, n - c print(a, b) ```
3
702
C
Cellular Network
PROGRAMMING
1,500
[ "binary search", "implementation", "two pointers" ]
null
null
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower. Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*. If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower.
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order. The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=≤<=*b**j*<=≤<=109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order.
Print minimal *r* so that each city will be covered by cellular network.
[ "3 2\n-2 2 4\n-3 0\n", "5 3\n1 5 10 14 17\n4 11 15\n" ]
[ "4\n", "3\n" ]
none
0
[ { "input": "3 2\n-2 2 4\n-3 0", "output": "4" }, { "input": "5 3\n1 5 10 14 17\n4 11 15", "output": "3" }, { "input": "1 1\n-1000000000\n1000000000", "output": "2000000000" }, { "input": "1 1\n1000000000\n-1000000000", "output": "2000000000" }, { "input": "10 10\n1 1 2 2 2 4 4 6 7 9\n0 1 3 3 3 6 7 8 9 10", "output": "1" }, { "input": "10 10\n2 52 280 401 416 499 721 791 841 943\n246 348 447 486 507 566 568 633 953 986", "output": "244" }, { "input": "7 7\n1 2 3 3 4 5 6\n1 1 2 3 4 5 6", "output": "0" }, { "input": "1 3\n-3\n-1 -1 8", "output": "2" }, { "input": "1 2\n8\n-7 5", "output": "3" }, { "input": "2 1\n4 8\n-1", "output": "9" }, { "input": "1 2\n6\n-8 -8", "output": "14" }, { "input": "1 4\n4\n-8 0 1 7", "output": "3" }, { "input": "1 2\n2\n4 7", "output": "2" }, { "input": "2 2\n-5 2\n-7 4", "output": "2" }, { "input": "1 21\n3\n3 10 23 32 34 40 42 49 49 50 50 58 70 71 71 74 76 79 79 80 83", "output": "0" }, { "input": "1 3\n-4\n-8 -1 1", "output": "3" }, { "input": "4 1\n-6 -3 -1 2\n-7", "output": "9" }, { "input": "2 3\n-2 7\n-7 -2 5", "output": "2" }, { "input": "1 1\n-1\n0", "output": "1" }, { "input": "1 3\n0\n-4 0 5", "output": "0" } ]
1,675,911,092
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
92
2,048,000
""" https://codeforces.com/contest/702/problem/C """ def main(): n, m = map(int, input().strip().split()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) a.sort() b.sort() r = 0 cur_tower = b[0] cur_city = a[0] i, j = 0, 0 while i < len(a) or j < len(b): cur_city = a[i] if i < len(a) else cur_city while i < len(a) and j < len(b) and b[j] <= a[i]: cur_r = abs(b[j] - cur_city) cur_tower = b[j] j += 1 cur_r = abs(cur_tower - cur_city) if j < len(b): cur_tower = b[j] cur_r = min(cur_r, abs(cur_tower - a[i])) r = max(r, cur_r) i += 1 print(r) main()
Title: Cellular Network Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower. Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*. If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower. Input Specification: The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order. The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=≤<=*b**j*<=≤<=109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order. Output Specification: Print minimal *r* so that each city will be covered by cellular network. Demo Input: ['3 2\n-2 2 4\n-3 0\n', '5 3\n1 5 10 14 17\n4 11 15\n'] Demo Output: ['4\n', '3\n'] Note: none
```python """ https://codeforces.com/contest/702/problem/C """ def main(): n, m = map(int, input().strip().split()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) a.sort() b.sort() r = 0 cur_tower = b[0] cur_city = a[0] i, j = 0, 0 while i < len(a) or j < len(b): cur_city = a[i] if i < len(a) else cur_city while i < len(a) and j < len(b) and b[j] <= a[i]: cur_r = abs(b[j] - cur_city) cur_tower = b[j] j += 1 cur_r = abs(cur_tower - cur_city) if j < len(b): cur_tower = b[j] cur_r = min(cur_r, abs(cur_tower - a[i])) r = max(r, cur_r) i += 1 print(r) main() ```
-1
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01234567890123456789012345678901234567890123456789", "output": "25" }, { "input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "output": "10" }, { "input": "cjw2dwmr10pku4yxohe0wglktd", "output": "4" }, { "input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "output": "13" }, { "input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1", "output": "13" }, { "input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs", "output": "8" }, { "input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc", "output": "14" }, { "input": "2222", "output": "0" }, { "input": "13579", "output": "5" }, { "input": "1", "output": "1" }, { "input": "0", "output": "0" }, { "input": "a", "output": "1" }, { "input": "y", "output": "0" }, { "input": "w", "output": "0" }, { "input": "oo", "output": "2" }, { "input": "oy", "output": "1" }, { "input": "yo", "output": "1" }, { "input": "yy", "output": "0" }, { "input": "a0", "output": "1" }, { "input": "a9", "output": "2" }, { "input": "y0", "output": "0" }, { "input": "y7", "output": "1" }, { "input": "0a", "output": "1" }, { "input": "3a", "output": "2" }, { "input": "06", "output": "0" }, { "input": "07", "output": "1" }, { "input": "70", "output": "1" }, { "input": "77", "output": "2" }, { "input": "13570", "output": "4" }, { "input": "0000000000011111", "output": "5" }, { "input": "1357", "output": "4" }, { "input": "uuuuuuuuuuuuuuuuuu", "output": "18" }, { "input": "gabieurat", "output": "5" } ]
1,551,933,537
2,147,483,647
Python 3
OK
TESTS
38
109
0
s = input() t = 0 for i in s: if i.isdigit() and int(i) % 2 or i in "aeiou": t += 1 print(t)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. Input Specification: The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. Output Specification: Print a single integer, the minimum number of cards you must turn over to verify your claim. Demo Input: ['ee\n', 'z\n', '0ay1\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
```python s = input() t = 0 for i in s: if i.isdigit() and int(i) % 2 or i in "aeiou": t += 1 print(t) ```
3
108
A
Palindromic Times
PROGRAMMING
1,000
[ "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
500
[ { "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" } ]
1,600,293,651
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
h,m=input().split(":") h=int(h) arr=[6,7,8,9,16,17,18,19,23] def rev(h): h=str(h) return h[::-1] if h not in arr: h+=1 print(str(h)+":"+rev(h)) else: if h==23: print("00:00") elif h<10: print("10:01") else:print("20:02")
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: 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. Input Specification: 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. Output Specification: 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. Demo Input: ['12:21\n', '23:59\n'] Demo Output: ['13:31\n', '00:00\n'] Note: none
```python h,m=input().split(":") h=int(h) arr=[6,7,8,9,16,17,18,19,23] def rev(h): h=str(h) return h[::-1] if h not in arr: h+=1 print(str(h)+":"+rev(h)) else: if h==23: print("00:00") elif h<10: print("10:01") else:print("20:02") ```
0
771
D
Bear and Company
PROGRAMMING
2,500
[ "dp" ]
null
null
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string *s* that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move. Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string *s*. What is the minimum possible number of moves Limak can do?
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string. The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*.
Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".
[ "4\nVKVK\n", "5\nBVVKV\n", "7\nVVKEVKK\n", "20\nVKVKVVVKVOVKVQKKKVVK\n", "5\nLIMAK\n" ]
[ "3\n", "2\n", "3\n", "8\n", "0\n" ]
In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is: 1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK". In the second sample, there are two optimal sequences of moves. One is "BVVKV"  →  "VBVKV"  →  "VVBKV". The other is "BVVKV"  →  "BVKVV"  →  "BKVVV". In the fifth sample, no swaps are necessary.
1,500
[ { "input": "4\nVKVK", "output": "3" }, { "input": "5\nBVVKV", "output": "2" }, { "input": "7\nVVKEVKK", "output": "3" }, { "input": "20\nVKVKVVVKVOVKVQKKKVVK", "output": "8" }, { "input": "5\nLIMAK", "output": "0" }, { "input": "1\nV", "output": "0" }, { "input": "1\nK", "output": "0" }, { "input": "1\nZ", "output": "0" }, { "input": "17\nVAKVAKLIMAKVVVKKK", "output": "4" }, { "input": "10\nVVKAVZVAAZ", "output": "1" }, { "input": "17\nQZVRZKDKMZZAKKZVA", "output": "0" }, { "input": "51\nAVVVVVVVVVVKKKKKKKKKKVVVVVVVVVVVVVVVKKKKKKKKKKKKKKK", "output": "135" }, { "input": "75\nVFZVZRVZAZJAKAZKAVVKZKVHZZZZAVAAKKAADKNAKRFKAAAZKZVAKAAAJAVKYAAZAKAVKASZAAK", "output": "3" }, { "input": "75\nVVKAVKKVAKVXCKKZKKAVVVAKKKKVVKSKVVWVLEVVHVXKKKVKVJKVVVZVVKKKVVKVVVKKKVVKZKV", "output": "19" }, { "input": "2\nVK", "output": "1" }, { "input": "2\nKV", "output": "0" }, { "input": "3\nVKK", "output": "2" }, { "input": "3\nKVV", "output": "0" }, { "input": "75\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKV", "output": "703" }, { "input": "75\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKOOOKVKV", "output": "175" }, { "input": "6\nVVVKKK", "output": "9" }, { "input": "7\nVVVKKKO", "output": "3" }, { "input": "12\nVKVKVKVKVKVK", "output": "21" }, { "input": "5\nVKOVK", "output": "2" }, { "input": "3\nKKV", "output": "0" }, { "input": "6\nVVOKKK", "output": "0" }, { "input": "15\nVOKVOKVVKKKKKKK", "output": "4" }, { "input": "10\nKKZKKVKZKV", "output": "1" }, { "input": "15\nVKKHKKKKZVKKVKV", "output": "4" }, { "input": "22\nVKKVKVKKVKVKZKKVKVAKKK", "output": "14" }, { "input": "46\nVVFVKKVAKVKKVGVKKKKZKKKKKKKAKKZKVVVVKKZVVKFVKK", "output": "9" }, { "input": "50\nKKAKVVNAVVVVKKVKKZVKKKKVKFTVVKKVVVVVZVLKKKKKKVKVVV", "output": "11" }, { "input": "75\nVKVVKVKKKVVZKVZKVKVKVVKIAVKVVVKKKVDKVKKVKAKKAKNAKVZKAAVVAKUKVKKVKKVZVAKKKVV", "output": "27" }, { "input": "75\nAJAKVZASUKAYZFSZRPAAVAGZKFZZHZZZKKKVLQAAVAHQHAZCVEZAAZZAAZIAAAZKKAAUKROVKAK", "output": "1" }, { "input": "75\nKAVVZVKKVVKVKVLVVKKKVVAKVVKEVAVVKKVVKVDVVKKVKKVZKKAKKKVKVZAVVKKKZVVDKVVAKZV", "output": "20" }, { "input": "75\nVKKVKKAKKKVVVVVZKKKKVKAVKKAZKKKKVKVVKVVKVVKCKKVVVVVZKKVKKKVKKKVVKVKVKOVVZKK", "output": "26" }, { "input": "74\nVVVKVKKKAZVVVKKKKKVVVVKKVVVKKVAKVVVVVVKVKVKVVMVVKVVVKVKKVVVVVKVKKKVVVXKVVK", "output": "66" }, { "input": "74\nVJVKVUKVVVVVVKVLVKKVVKZVNZVKKVVVAVVVKKAKZKZVAZVVKVKKZKKVNAVAKVKKCVVVKKVKVV", "output": "19" }, { "input": "75\nZXPZMAKZZZZZZAZXAZAAPOAFAZUZZAZABQZZAZZBZAAAZZFANYAAZZZZAZHZARACAAZAZDPCAVZ", "output": "0" }, { "input": "75\nVZVVVZAUVZZTZZCTJZAVZVSVAAACVAHZVVAFZSVVAZAZVXVKVZVZVVZTAZREOVZZEVAVBAVAAAF", "output": "1" }, { "input": "75\nAZKZWAOZZLTZIZTAYKOALAAKKKZAASKAAZFHVZKZAAZUKAKZZBIAZZWAZZZZZPZZZRAZZZAZJZA", "output": "0" }, { "input": "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ", "output": "1" }, { "input": "52\nAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZK", "output": "1" }, { "input": "64\nVVKKVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZVVVKKKKK", "output": "7" }, { "input": "64\nVVKKAKBKCKDKEKFKGKHKIKJKKKLKMKNKOKPKQKRKSKTKUKVKWKXKYKZKVVVKKKKK", "output": "7" }, { "input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK", "output": "1406" }, { "input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK", "output": "1406" }, { "input": "72\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK", "output": "35" }, { "input": "73\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB", "output": "32" }, { "input": "72\nAVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKB", "output": "30" }, { "input": "67\nVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKXVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKK", "output": "213" }, { "input": "57\nVVVVKKKKKKAAVVVVVVVVKKKKKKKVVVVVVVVVKKKKKKKKKKKKKKKKKKKKO", "output": "34" }, { "input": "13\nVVVVKKAVVKVKK", "output": "10" }, { "input": "65\nVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK", "output": "50" }, { "input": "67\nVVVVKKAVVKVKKVVVVKKAVVKVKKAOVVVVKKAVVKVKKVVVVKKAVVKVKKVVVVKKAVVKVKK", "output": "44" }, { "input": "52\nZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZKZVKVVKKKVKKZK", "output": "28" }, { "input": "63\nKKKVVVKAAKVVVTVVVKAUVKKKVKVKKVKVKVVKVKKVKVKKKQVKVVVKVKKVKKKKKKZ", "output": "43" }, { "input": "75\nVVKVKKKVKVVKKKKKVVKKKKVVVKVKKKAVAKKKVVKVKEVVVVVVVVKKKKKVVVVVKVVVKKKVVKVVKVV", "output": "114" }, { "input": "75\nVVVVVKVKVVKKEVVVVVAKVKKZKVVPKKZKAVKVAKVMZKZVUVKKIVVZVVVKVKZVVVVKKVKVZZVOVKV", "output": "23" }, { "input": "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK", "output": "36" }, { "input": "75\nVVKVKKVZAVVKHKRAVKAKVKKVKKAAVKVVNZVKKKVVKMAVVKKWKKVVKVHKKVKVZVVKZZKVKVIKZVK", "output": "22" }, { "input": "75\nKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK", "output": "0" }, { "input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV", "output": "0" }, { "input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVK", "output": "74" }, { "input": "75\nKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV", "output": "0" }, { "input": "38\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKK", "output": "40" }, { "input": "74\nZKKKVVVVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKK", "output": "98" }, { "input": "71\nZKKKVVVVVVVKKKKKEVVKKVVVKKKVVVVKKKKVVVVVVVVKKKKKKKKKKKVVVVVVVVVVKKKKKKK", "output": "153" }, { "input": "68\nKKVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKV", "output": "400" }, { "input": "75\nKVVKCVKVVVVKVVVKVKVAVVMVVVVVKKVVVKVVVVVKKVVVVVKVVKVVVKKKKKVKKVKAVVVVVVVVVVK", "output": "71" }, { "input": "74\nKKKZKVKKKKVKKKKVKVZKKKZKKKKKZKVKKZZKKBVKKVAKVKVKZVVKKKKKKKKKVKKVVKKVVKKKVK", "output": "45" }, { "input": "75\nKVKVVKVKVKVVVVVKVKKKVKVVKVVKVVKKKKEKVVVKKKVVKVVVVVVVKKVKKVVVKAKVVKKVVVVVKUV", "output": "103" }, { "input": "75\nKKVVAVVVVKVKAVVAKVKVKVVVVKKKKKAZVKVKVKJVVVAKVVKKKVVVVZVAVVVZKVZAKVVVVVVVAKK", "output": "18" } ]
1,489,858,169
6,869
Python 3
WRONG_ANSWER
PRETESTS
8
46
4,608,000
n = int(input()) s = "".join(['O' if x not in ('V', 'K') else x for x in input()]) ar = s.split("O") m = len(ar) k = 0 for i, el in enumerate(ar): for j, c in enumerate(el): if c != "K": continue l = el[:j].count("V") if i != m-1: l = min(l, el[j+1:].count("V") + 1) k += l print(k)
Title: Bear and Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string *s* that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move. Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string *s*. What is the minimum possible number of moves Limak can do? Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the string. The second line contains a string *s*, consisting of uppercase English letters. The length of the string is equal to *n*. Output Specification: Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK". Demo Input: ['4\nVKVK\n', '5\nBVVKV\n', '7\nVVKEVKK\n', '20\nVKVKVVVKVOVKVQKKKVVK\n', '5\nLIMAK\n'] Demo Output: ['3\n', '2\n', '3\n', '8\n', '0\n'] Note: In the first sample, the initial string is "VKVK". The minimum possible number of moves is 3. One optimal sequence of moves is: 1. Swap two last letters. The string becomes "VKKV".1. Swap first two letters. The string becomes "KVKV".1. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK". In the second sample, there are two optimal sequences of moves. One is "BVVKV"  →  "VBVKV"  →  "VVBKV". The other is "BVVKV"  →  "BVKVV"  →  "BKVVV". In the fifth sample, no swaps are necessary.
```python n = int(input()) s = "".join(['O' if x not in ('V', 'K') else x for x in input()]) ar = s.split("O") m = len(ar) k = 0 for i, el in enumerate(ar): for j, c in enumerate(el): if c != "K": continue l = el[:j].count("V") if i != m-1: l = min(l, el[j+1:].count("V") + 1) k += l print(k) ```
0
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,596,705,113
2,147,483,647
PyPy 3
OK
TESTS
43
310
20,172,800
a=int(input()) b=int(input()) c=a+b a=int(''.join(x for x in str(a) if x!='0')) b=int(''.join(x for x in str(b) if x!='0')) c=int(''.join(x for x in str(c) if x!='0')) if(a+b==c): print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a=int(input()) b=int(input()) c=a+b a=int(''.join(x for x in str(a) if x!='0')) b=int(''.join(x for x in str(b) if x!='0')) c=int(''.join(x for x in str(c) if x!='0')) if(a+b==c): print("YES") else: print("NO") ```
3.884925
991
C
Candies
PROGRAMMING
1,500
[ "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$.
1,250
[ { "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,608,303,482
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
n = int(input()) l, r = 1, int(1e9) + 1 m = -1 while l < r - 1: f = 0 m = (l + r) // 2 if n / 10 <= 2 * m: r = m else: l = m print(m)
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. Output Specification: Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. Demo Input: ['68\n'] Demo Output: ['3\n'] Note: 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$.
```python n = int(input()) l, r = 1, int(1e9) + 1 m = -1 while l < r - 1: f = 0 m = (l + r) // 2 if n / 10 <= 2 * m: r = m else: l = m print(m) ```
0
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "/a//aa/a//", "output": "/a/aa/a" }, { "input": "/aa//b/aa", "output": "/aa/b/aa" }, { "input": "////////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/" }, { "input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb" }, { "input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt" }, { "input": "///a//a////a/a//a//a//a/////", "output": "/a/a/a/a/a/a/a" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a" }, { "input": "///////////////////////////////////////////////////////////////////////////////////////////////////z", "output": "/z" }, { "input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/z" } ]
1,623,118,886
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
216
0
s=str(input()) a="/" for i in range(1,len(s)): if((s[i]==s[i-1] and s[i]=='/')): b=1 else: a=a+s[i] print(a)
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input Specification: The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output Specification: The path in normalized form. Demo Input: ['//usr///local//nginx/sbin\n'] Demo Output: ['/usr/local/nginx/sbin\n'] Note: none
```python s=str(input()) a="/" for i in range(1,len(s)): if((s[i]==s[i-1] and s[i]=='/')): b=1 else: a=a+s[i] print(a) ```
0
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input": "4\n3 7 11 13\n4\n51 119 187 221", "output": "4" }, { "input": "4\n2 3 4 5\n3\n1 2 3", "output": "2" }, { "input": "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97", "output": "1" }, { "input": "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28", "output": "1" }, { "input": "10\n24 53 56 126 354 432 442 740 795 856\n10\n273 438 494 619 689 711 894 947 954 958", "output": "1" }, { "input": "10\n3 4 6 7 8 10 14 16 19 20\n10\n3 4 5 7 8 10 15 16 18 20", "output": "1" }, { "input": "10\n1 6 8 14 15 17 25 27 34 39\n10\n1 8 16 17 19 22 32 39 44 50", "output": "1" }, { "input": "10\n5 21 22 23 25 32 35 36 38 39\n10\n3 7 8 9 18 21 23 24 36 38", "output": "4" }, { "input": "50\n5 8 13 16 19 20 21 22 24 27 28 29 30 32 33 34 35 43 45 48 50 51 54 55 58 59 60 61 62 65 70 71 72 76 78 79 80 81 83 84 85 87 89 91 92 94 97 98 99 100\n50\n2 3 5 6 7 10 15 16 17 20 23 28 29 30 31 34 36 37 40 42 45 46 48 54 55 56 58 59 61 62 69 70 71 72 75 76 78 82 84 85 86 87 88 89 90 91 92 97 99 100", "output": "1" }, { "input": "50\n3 5 6 8 9 11 13 19 21 23 24 32 34 35 42 50 51 52 56 58 59 69 70 72 73 75 76 77 78 80 83 88 90 95 96 100 101 102 108 109 113 119 124 135 138 141 142 143 145 150\n50\n5 8 10 11 18 19 23 30 35 43 51 53 55 58 63 68 69 71 77 78 79 82 83 86 88 89 91 92 93 94 96 102 103 105 109 110 113 114 116 123 124 126 127 132 133 135 136 137 142 149", "output": "1" }, { "input": "50\n6 16 24 25 27 33 36 40 51 60 62 65 71 72 75 77 85 87 91 93 98 102 103 106 117 118 120 121 122 123 125 131 134 136 143 148 155 157 160 161 164 166 170 178 184 187 188 192 194 197\n50\n5 9 17 23 27 34 40 44 47 59 62 70 81 82 87 88 89 90 98 101 102 110 113 114 115 116 119 122 124 128 130 137 138 140 144 150 152 155 159 164 166 169 171 175 185 186 187 189 190 193", "output": "1" }, { "input": "50\n14 22 23 31 32 35 48 63 76 79 88 97 101 102 103 104 106 113 114 115 116 126 136 138 145 152 155 156 162 170 172 173 179 180 182 203 208 210 212 222 226 229 231 232 235 237 245 246 247 248\n50\n2 5 6 16 28 44 45 46 54 55 56 63 72 80 87 93 94 96 97 100 101 103 132 135 140 160 164 165 167 168 173 180 182 185 186 192 194 198 199 202 203 211 213 216 217 227 232 233 236 245", "output": "1" }, { "input": "50\n14 19 33 35 38 41 51 54 69 70 71 73 76 80 84 94 102 104 105 106 107 113 121 128 131 168 180 181 187 191 195 201 205 207 210 216 220 238 249 251 263 271 272 275 281 283 285 286 291 294\n50\n2 3 5 20 21 35 38 40 43 48 49 52 55 64 73 77 82 97 109 113 119 121 125 132 137 139 145 146 149 180 182 197 203 229 234 241 244 251 264 271 274 281 284 285 287 291 292 293 294 298", "output": "1" }, { "input": "50\n2 4 5 16 18 19 22 23 25 26 34 44 48 54 67 79 80 84 92 110 116 133 138 154 163 171 174 202 205 218 228 229 234 245 247 249 250 263 270 272 274 275 277 283 289 310 312 334 339 342\n50\n1 5 17 18 25 37 46 47 48 59 67 75 80 83 84 107 115 122 137 141 159 162 175 180 184 204 221 224 240 243 247 248 249 258 259 260 264 266 269 271 274 293 294 306 329 330 334 335 342 350", "output": "1" }, { "input": "50\n6 9 11 21 28 39 42 56 60 63 81 88 91 95 105 110 117 125 149 165 174 176 185 189 193 196 205 231 233 268 278 279 281 286 289 292 298 303 305 306 334 342 350 353 361 371 372 375 376 378\n50\n6 17 20 43 45 52 58 59 82 83 88 102 111 118 121 131 145 173 190 191 200 216 224 225 232 235 243 256 260 271 290 291 321 322 323 329 331 333 334 341 343 348 351 354 356 360 366 379 387 388", "output": "1" }, { "input": "10\n17 239 443 467 661 1069 1823 2333 3767 4201\n20\n51 83 97 457 593 717 997 1329 1401 1459 1471 1983 2371 2539 3207 3251 3329 5469 6637 6999", "output": "8" }, { "input": "20\n179 359 401 467 521 601 919 941 1103 1279 1709 1913 1949 2003 2099 2143 2179 2213 2399 4673\n20\n151 181 191 251 421 967 1109 1181 1249 1447 1471 1553 1619 2327 2551 2791 3049 3727 6071 7813", "output": "3" }, { "input": "20\n79 113 151 709 809 983 1291 1399 1409 1429 2377 2659 2671 2897 3217 3511 3557 3797 3823 4363\n10\n19 101 659 797 1027 1963 2129 2971 3299 9217", "output": "3" }, { "input": "30\n19 47 109 179 307 331 389 401 461 509 547 569 617 853 883 1249 1361 1381 1511 1723 1741 1783 2459 2531 2621 3533 3821 4091 5557 6217\n20\n401 443 563 941 967 997 1535 1567 1655 1747 1787 1945 1999 2251 2305 2543 2735 4415 6245 7555", "output": "8" }, { "input": "30\n3 43 97 179 257 313 353 359 367 389 397 457 547 599 601 647 1013 1021 1063 1433 1481 1531 1669 3181 3373 3559 3769 4157 4549 5197\n50\n13 15 17 19 29 79 113 193 197 199 215 223 271 293 359 485 487 569 601 683 895 919 941 967 1283 1285 1289 1549 1565 1765 1795 1835 1907 1931 1945 1985 1993 2285 2731 2735 2995 3257 4049 4139 5105 5315 7165 7405 7655 8345", "output": "20" }, { "input": "50\n11 17 23 53 59 109 137 149 173 251 353 379 419 421 439 503 593 607 661 773 821 877 941 997 1061 1117 1153 1229 1289 1297 1321 1609 1747 2311 2389 2543 2693 3041 3083 3137 3181 3209 3331 3373 3617 3767 4201 4409 4931 6379\n50\n55 59 67 73 85 89 101 115 211 263 295 353 545 599 607 685 739 745 997 1031 1255 1493 1523 1667 1709 1895 1949 2161 2195 2965 3019 3035 3305 3361 3373 3673 3739 3865 3881 4231 4253 4385 4985 5305 5585 5765 6145 6445 8045 8735", "output": "23" }, { "input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782", "output": "3" }, { "input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428", "output": "4" }, { "input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959", "output": "5" }, { "input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664", "output": "24" }, { "input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782", "output": "3" }, { "input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428", "output": "4" }, { "input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959", "output": "5" }, { "input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664", "output": "24" }, { "input": "47\n66 262 357 457 513 530 538 540 592 691 707 979 1015 1242 1246 1667 1823 1886 1963 2133 2649 2679 2916 2949 3413 3523 3699 3958 4393 4922 5233 5306 5799 6036 6302 6629 7208 7282 7315 7822 7833 7927 8068 8150 8870 8962 9987\n39\n167 199 360 528 1515 1643 1986 1988 2154 2397 2856 3552 3656 3784 3980 4096 4104 4240 4320 4736 4951 5266 5656 5849 5850 6169 6517 6875 7244 7339 7689 7832 8120 8716 9503 9509 9933 9936 9968", "output": "12" }, { "input": "1\n94\n50\n423 446 485 1214 1468 1507 1853 1930 1999 2258 2271 2285 2425 2543 2715 2743 2992 3196 4074 4108 4448 4475 4652 5057 5250 5312 5356 5375 5731 5986 6298 6501 6521 7146 7255 7276 7332 7481 7998 8141 8413 8665 8908 9221 9336 9491 9504 9677 9693 9706", "output": "1" }, { "input": "50\n51 67 75 186 194 355 512 561 720 876 1077 1221 1503 1820 2153 2385 2568 2608 2937 2969 3271 3311 3481 4081 4093 4171 4255 4256 4829 5020 5192 5636 5817 6156 6712 6717 7153 7436 7608 7612 7866 7988 8264 8293 8867 9311 9879 9882 9889 9908\n1\n5394", "output": "1" }, { "input": "50\n26 367 495 585 675 789 855 1185 1312 1606 2037 2241 2587 2612 2628 2807 2873 2924 3774 4067 4376 4668 4902 5001 5082 5100 5104 5209 5345 5515 5661 5777 5902 5907 6155 6323 6675 6791 7503 8159 8207 8254 8740 8848 8855 8933 9069 9164 9171 9586\n5\n1557 6246 7545 8074 8284", "output": "1" }, { "input": "5\n25 58 91 110 2658\n50\n21 372 909 1172 1517 1554 1797 1802 1843 1977 2006 2025 2137 2225 2317 2507 2645 2754 2919 3024 3202 3212 3267 3852 4374 4487 4553 4668 4883 4911 4916 5016 5021 5068 5104 5162 5683 5856 6374 6871 7333 7531 8099 8135 8173 8215 8462 8776 9433 9790", "output": "4" }, { "input": "45\n37 48 56 59 69 70 79 83 85 86 99 114 131 134 135 145 156 250 1739 1947 2116 2315 2449 3104 3666 4008 4406 4723 4829 5345 5836 6262 6296 6870 7065 7110 7130 7510 7595 8092 8442 8574 9032 9091 9355\n50\n343 846 893 1110 1651 1837 2162 2331 2596 3012 3024 3131 3294 3394 3528 3717 3997 4125 4347 4410 4581 4977 5030 5070 5119 5229 5355 5413 5418 5474 5763 5940 6151 6161 6164 6237 6506 6519 6783 7182 7413 7534 8069 8253 8442 8505 9135 9308 9828 9902", "output": "17" }, { "input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 1649 1940 2078 2134 2716 3492 3686 4462 4559 4656 4756 4850 5044 5490 5529 5592 5626 6014 6111 6693 6790 7178 7275 7566 7663 7702 7857 7954 8342 8511 8730 8957 9021 9215 9377 9445 9991", "output": "28" }, { "input": "39\n10 13 21 25 36 38 47 48 58 64 68 69 73 79 86 972 2012 2215 2267 2503 3717 3945 4197 4800 5266 6169 6612 6824 7023 7322 7582 7766 8381 8626 8879 9079 9088 9838 9968\n50\n432 877 970 1152 1202 1223 1261 1435 1454 1578 1843 1907 2003 2037 2183 2195 2215 2425 3065 3492 3615 3637 3686 3946 4189 4415 4559 4656 4665 4707 4886 4887 5626 5703 5955 6208 6521 6581 6596 6693 6985 7013 7081 7343 7663 8332 8342 8637 9207 9862", "output": "15" }, { "input": "50\n7 144 269 339 395 505 625 688 709 950 1102 1152 1350 1381 1641 1830 1977 1999 2093 2180 2718 3308 3574 4168 4232 4259 4393 4689 4982 5154 5476 5581 5635 5721 6159 6302 6741 7010 7152 7315 7417 7482 8116 8239 8640 9347 9395 9614 9661 9822\n20\n84 162 292 1728 1866 2088 3228 3470 4068 5318 5470 6060 6380 6929 7500 8256 8399 8467 8508 9691", "output": "8" }, { "input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692 2759 2931 3173 3217 3441 4201 4878 5106 5129 5253 5647 5968 6130 6276 6286 6409 7488 7694 7713 7765 7828 7899 8003 8064 8081 8244 8264 8685 8900 8946 8965 9133 9638 9673", "output": "38" }, { "input": "3\n3 4 5\n3\n6 20 25", "output": "2" }, { "input": "4\n2 3 5 8\n4\n2 6 8 10", "output": "1" }, { "input": "4\n3 5 7 11\n4\n3 5 7 22", "output": "1" }, { "input": "2\n2 3\n3\n20 30 50", "output": "1" }, { "input": "3\n1 2 3\n4\n2 4 6 49", "output": "1" }, { "input": "2\n4 5\n3\n12 15 20", "output": "1" }, { "input": "3\n2 5 7\n3\n4 5 7", "output": "1" }, { "input": "3\n3 5 8\n3\n6 8 10", "output": "2" }, { "input": "2\n2 3\n4\n4 6 9 33", "output": "1" }, { "input": "2\n2 3\n4\n4 6 21 40", "output": "1" }, { "input": "3\n4 9 10\n3\n8 9 10", "output": "1" }, { "input": "5\n1 5 6 9 51\n5\n5 12 18 27 10000", "output": "1" }, { "input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n1\n14", "output": "1" } ]
1,646,215,871
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
92
0
n=int(input()) q=[int(l) for l in input().split()] m=int(input()) w=[int(q) for q in input().split()] max=0;adet=1 for a in range(m): for b in range(n): if(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-1-a]/q[b]>max): max=w[m-1-a]/q[b] elif(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-1-a]/q[b]==max): adet+=1 print(adet)
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. Output Specification: Print the number of "integer" gears with the maximum ratio among all "integer" gears. Demo Input: ['2\n4 5\n3\n12 13 15\n', '4\n1 2 3 4\n5\n10 11 12 13 14\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
```python n=int(input()) q=[int(l) for l in input().split()] m=int(input()) w=[int(q) for q in input().split()] max=0;adet=1 for a in range(m): for b in range(n): if(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-1-a]/q[b]>max): max=w[m-1-a]/q[b] elif(int(w[m-1-a]/q[b])==w[m-1-a]/q[b] and w[m-1-a]/q[b]==max): adet+=1 print(adet) ```
0
863
C
1-2-3
PROGRAMMING
1,800
[ "graphs", "implementation" ]
null
null
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1,<=2,<=3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (*i*<=+<=1)-th game depends only on the numbers chosen by them in *i*-th game. Ilya knows that the robots will play *k* games, Alice will choose number *a* in the first game, and Bob will choose *b* in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all *k* games, so he asks you to predict the number of points they will have after the final game.
The first line contains three numbers *k*, *a*, *b* (1<=≤<=*k*<=≤<=1018, 1<=≤<=*a*,<=*b*<=≤<=3). Then 3 lines follow, *i*-th of them containing 3 numbers *A**i*,<=1, *A**i*,<=2, *A**i*,<=3, where *A**i*,<=*j* represents Alice's choice in the game if Alice chose *i* in previous game and Bob chose *j* (1<=≤<=*A**i*,<=*j*<=≤<=3). Then 3 lines follow, *i*-th of them containing 3 numbers *B**i*,<=1, *B**i*,<=2, *B**i*,<=3, where *B**i*,<=*j* represents Bob's choice in the game if Alice chose *i* in previous game and Bob chose *j* (1<=≤<=*B**i*,<=*j*<=≤<=3).
Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after *k* games.
[ "10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2\n", "8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3\n", "5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2\n" ]
[ "1 9\n", "5 2\n", "0 0\n" ]
In the second example game goes like this: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e21b6e200707470571d69c9946ace6b56f5279b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
0
[ { "input": "10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2", "output": "1 9" }, { "input": "8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3", "output": "5 2" }, { "input": "5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2", "output": "0 0" }, { "input": "1 1 1\n3 3 1\n1 1 1\n3 2 2\n2 2 2\n1 3 1\n3 3 2", "output": "0 0" }, { "input": "1 3 1\n1 3 3\n2 3 2\n2 1 3\n1 3 2\n3 3 2\n3 1 1", "output": "0 1" }, { "input": "10 2 1\n2 2 1\n3 2 2\n3 1 3\n3 1 3\n1 2 2\n3 3 2", "output": "8 1" }, { "input": "10 1 2\n1 1 2\n2 1 2\n1 3 1\n2 3 3\n3 2 2\n3 2 1", "output": "3 5" }, { "input": "1000000 2 3\n3 1 1\n3 1 1\n1 2 2\n3 1 1\n3 1 1\n1 1 3", "output": "0 333334" }, { "input": "1000000 1 3\n1 2 3\n2 1 2\n2 1 2\n1 2 3\n1 1 1\n2 3 3", "output": "999998 1" }, { "input": "1000000000000 1 3\n3 1 1\n3 2 1\n2 2 2\n2 2 1\n1 2 2\n1 1 3", "output": "500000000001 499999999998" }, { "input": "1000000000000 3 2\n2 3 3\n2 1 2\n1 1 1\n2 3 1\n1 3 3\n3 3 3", "output": "500000000001 499999999999" }, { "input": "1000000000000000000 2 3\n1 3 1\n2 3 3\n2 2 2\n1 2 3\n3 1 2\n2 2 2", "output": "1 500000000000000000" }, { "input": "999999999999999999 2 2\n2 3 2\n2 1 2\n1 3 3\n2 2 2\n1 3 2\n1 2 1", "output": "499999999999999999 0" }, { "input": "1000000000000000000 2 1\n3 1 2\n2 3 3\n1 2 3\n2 2 3\n1 1 3\n2 3 2", "output": "1000000000000000000 0" }, { "input": "1000000000000000000 3 3\n2 1 3\n1 2 3\n1 3 2\n3 2 2\n3 1 3\n3 3 1", "output": "750000000000000000 0" }, { "input": "1000000000000000000 3 1\n2 3 2\n2 2 1\n2 3 3\n3 3 3\n2 1 1\n1 2 1", "output": "500000000000000000 1" }, { "input": "478359268475263455 1 1\n3 2 3\n2 3 3\n2 1 1\n3 3 3\n2 3 3\n1 3 1", "output": "0 0" }, { "input": "837264528963824683 3 3\n3 1 1\n1 3 1\n1 3 1\n3 2 1\n2 3 3\n2 2 2", "output": "0 837264528963824682" }, { "input": "129341234876124184 1 2\n1 3 3\n1 1 2\n1 2 3\n3 1 1\n3 1 3\n3 2 3", "output": "64670617438062091 64670617438062093" }, { "input": "981267318925341267 3 2\n1 2 1\n3 2 2\n3 3 3\n3 2 2\n2 2 3\n2 2 1", "output": "981267318925341267 0" }, { "input": "12 2 2\n1 1 2\n2 2 3\n3 3 1\n2 3 1\n2 3 1\n2 3 1", "output": "3 5" }, { "input": "3 1 3\n1 1 2\n2 1 3\n3 3 3\n2 3 1\n1 1 3\n3 3 3", "output": "3 0" }, { "input": "3 2 2\n1 1 2\n2 1 3\n3 3 3\n2 3 1\n1 1 3\n3 3 3", "output": "0 1" }, { "input": "67 1 1\n1 1 2\n2 2 3\n3 3 1\n2 3 1\n2 3 1\n2 3 1", "output": "23 22" }, { "input": "4991 1 2\n1 1 2\n2 2 3\n3 1 3\n2 3 1\n2 3 1\n2 1 3", "output": "1872 1872" }, { "input": "3 1 1\n1 1 2\n2 1 3\n3 3 3\n2 3 1\n1 1 3\n3 3 3", "output": "1 1" }, { "input": "4 1 1\n1 1 2\n2 2 3\n3 3 1\n2 3 1\n2 3 1\n2 3 1", "output": "2 1" }, { "input": "1 2 1\n1 2 3\n1 3 2\n2 1 3\n1 2 3\n3 3 3\n2 1 3", "output": "1 0" }, { "input": "1000000000002 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3", "output": "666666666668 333333333333" }, { "input": "1000000000005 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3", "output": "666666666670 333333333334" }, { "input": "4 3 1\n1 1 2\n2 1 3\n3 3 3\n2 3 1\n1 1 3\n3 3 3", "output": "0 1" } ]
1,595,653,394
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
6,963,200
alice, bob = 0,0 def put(): return map(int, input().split()) def play(a,b): global alice, bob if a==b: pass elif (a,b) in [(2,1), (1,0), (0,2)]: alice+=1 else: bob+=1 t,a,b = put() A,B = [list(put()) for i in range(3)], [list(put()) for i in range(3)] a,b = a-1,b-1 while t>0: play(a,b) a,b = A[a][b]-1, B[a][b]-1 t-=1 print(alice, bob)
Title: 1-2-3 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1,<=2,<=3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (*i*<=+<=1)-th game depends only on the numbers chosen by them in *i*-th game. Ilya knows that the robots will play *k* games, Alice will choose number *a* in the first game, and Bob will choose *b* in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all *k* games, so he asks you to predict the number of points they will have after the final game. Input Specification: The first line contains three numbers *k*, *a*, *b* (1<=≤<=*k*<=≤<=1018, 1<=≤<=*a*,<=*b*<=≤<=3). Then 3 lines follow, *i*-th of them containing 3 numbers *A**i*,<=1, *A**i*,<=2, *A**i*,<=3, where *A**i*,<=*j* represents Alice's choice in the game if Alice chose *i* in previous game and Bob chose *j* (1<=≤<=*A**i*,<=*j*<=≤<=3). Then 3 lines follow, *i*-th of them containing 3 numbers *B**i*,<=1, *B**i*,<=2, *B**i*,<=3, where *B**i*,<=*j* represents Bob's choice in the game if Alice chose *i* in previous game and Bob chose *j* (1<=≤<=*B**i*,<=*j*<=≤<=3). Output Specification: Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after *k* games. Demo Input: ['10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2\n', '8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3\n', '5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2\n'] Demo Output: ['1 9\n', '5 2\n', '0 0\n'] Note: In the second example game goes like this: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e21b6e200707470571d69c9946ace6b56f5279b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.
```python alice, bob = 0,0 def put(): return map(int, input().split()) def play(a,b): global alice, bob if a==b: pass elif (a,b) in [(2,1), (1,0), (0,2)]: alice+=1 else: bob+=1 t,a,b = put() A,B = [list(put()) for i in range(3)], [list(put()) for i in range(3)] a,b = a-1,b-1 while t>0: play(a,b) a,b = A[a][b]-1, B[a][b]-1 t-=1 print(alice, bob) ```
0
651
B
Beautiful Paintings
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=&gt;<=*a**i*.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting.
Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=&gt;<=*a**i*, after the optimal rearrangement.
[ "5\n20 30 10 50 40\n", "4\n200 100 100 200\n" ]
[ "4\n", "2\n" ]
In the first sample, the optimal order is: 10, 20, 30, 40, 50. In the second sample, the optimal order is: 100, 200, 100, 200.
1,000
[ { "input": "5\n20 30 10 50 40", "output": "4" }, { "input": "4\n200 100 100 200", "output": "2" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0" }, { "input": "1\n1000", "output": "0" }, { "input": "2\n444 333", "output": "1" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14", "output": "95" }, { "input": "1\n995", "output": "0" }, { "input": "10\n103 101 103 103 101 102 100 100 101 104", "output": "7" }, { "input": "20\n102 100 102 104 102 101 104 103 100 103 105 105 100 105 100 100 101 105 105 102", "output": "15" }, { "input": "20\n990 994 996 999 997 994 990 992 990 993 992 990 999 999 992 994 997 990 993 998", "output": "15" }, { "input": "100\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9", "output": "84" } ]
1,633,376,523
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
62
7,168,000
from collections import defaultdict n = int(input()) values = sorted(list(map(int, input().split()))) counts = defaultdict(int) res = 0 for value in values: counts[value] += 1 i = 0 keys = list(counts.keys()) temp = [] while counts: key = keys[i%len(keys)] if key in counts: counts[key] -=1 if not counts[key]: counts.pop(key) temp.append(key) if len(temp) > 1 and key > temp[i-1]: res += 1 i+=1 print(res)
Title: Beautiful Paintings Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=&gt;<=*a**i*. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. Output Specification: Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=&gt;<=*a**i*, after the optimal rearrangement. Demo Input: ['5\n20 30 10 50 40\n', '4\n200 100 100 200\n'] Demo Output: ['4\n', '2\n'] Note: In the first sample, the optimal order is: 10, 20, 30, 40, 50. In the second sample, the optimal order is: 100, 200, 100, 200.
```python from collections import defaultdict n = int(input()) values = sorted(list(map(int, input().split()))) counts = defaultdict(int) res = 0 for value in values: counts[value] += 1 i = 0 keys = list(counts.keys()) temp = [] while counts: key = keys[i%len(keys)] if key in counts: counts[key] -=1 if not counts[key]: counts.pop(key) temp.append(key) if len(temp) > 1 and key > temp[i-1]: res += 1 i+=1 print(res) ```
-1
976
C
Nested Segments
PROGRAMMING
1,500
[ "greedy", "implementation", "sortings" ]
null
null
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments. Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
[ "5\n1 10\n2 9\n3 9\n2 3\n2 9\n", "3\n1 5\n2 6\n6 20\n" ]
[ "2 1\n", "-1 -1\n" ]
In the first example the following pairs are considered correct: - (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
0
[ { "input": "5\n1 10\n2 9\n3 9\n2 3\n2 9", "output": "2 1" }, { "input": "3\n1 5\n2 6\n6 20", "output": "-1 -1" }, { "input": "1\n1 1000000000", "output": "-1 -1" }, { "input": "2\n1 1000000000\n1 1000000000", "output": "2 1" }, { "input": "2\n1 1000000000\n500000000 500000000", "output": "2 1" }, { "input": "2\n1 10\n2 10", "output": "2 1" }, { "input": "2\n10 20\n10 11", "output": "2 1" }, { "input": "3\n1 10\n10 20\n9 11", "output": "-1 -1" }, { "input": "3\n1 1\n2 3\n2 2", "output": "3 2" }, { "input": "4\n1 10\n2 11\n3 10000000\n3 100000000", "output": "3 4" }, { "input": "2\n3 7\n3 9", "output": "1 2" }, { "input": "3\n1 2\n2 3\n1 2", "output": "3 1" }, { "input": "3\n5 6\n4 7\n3 8", "output": "2 3" }, { "input": "3\n2 9\n1 7\n2 8", "output": "3 1" }, { "input": "2\n1 4\n1 5", "output": "1 2" }, { "input": "3\n1 2\n1 3\n4 4", "output": "1 2" }, { "input": "3\n1 2\n1 3\n67 1234567", "output": "1 2" }, { "input": "2\n1 1\n1 1", "output": "2 1" }, { "input": "3\n1 5\n4 7\n3 9", "output": "2 3" }, { "input": "2\n1 1\n1 10", "output": "1 2" }, { "input": "2\n1 2\n1 3", "output": "1 2" }, { "input": "2\n1 10\n1 11", "output": "1 2" }, { "input": "2\n1 1\n1 2", "output": "1 2" }, { "input": "2\n2 3\n2 4", "output": "1 2" }, { "input": "2\n1 3\n3 3", "output": "2 1" }, { "input": "3\n1 10\n11 13\n12 12", "output": "3 2" }, { "input": "2\n2 10\n1 10", "output": "1 2" }, { "input": "3\n1 3\n4 5\n4 4", "output": "3 2" }, { "input": "5\n1 1\n2 6\n3 5\n10 15\n20 25", "output": "3 2" }, { "input": "3\n1 1000\n1001 1007\n1002 1007", "output": "3 2" }, { "input": "3\n1 3\n2 5\n3 4", "output": "3 2" }, { "input": "3\n1 10\n2 11\n3 11", "output": "3 2" }, { "input": "2\n2000000 999999999\n1000000 1000000000", "output": "1 2" }, { "input": "3\n2 10\n11 12\n4 5", "output": "3 1" }, { "input": "2\n1 10\n1 19", "output": "1 2" }, { "input": "4\n1 3\n100 102\n108 110\n1 3", "output": "4 1" }, { "input": "3\n1 3\n5 9\n5 6", "output": "3 2" }, { "input": "3\n1 3\n3 4\n3 5", "output": "2 3" }, { "input": "3\n1 2\n1 3\n1 4", "output": "2 3" }, { "input": "4\n2 3\n1 4\n100 200\n1000 2000", "output": "1 2" }, { "input": "3\n1 1\n2 100\n3 99", "output": "3 2" }, { "input": "3\n1 2\n1 3\n12 1234", "output": "1 2" }, { "input": "3\n1 4\n2 6\n3 5", "output": "3 2" }, { "input": "3\n1 10\n2 12\n1 9", "output": "3 1" }, { "input": "2\n1 3\n1 5", "output": "1 2" }, { "input": "3\n1 2\n2 5\n2 3", "output": "3 2" }, { "input": "4\n1 3\n1 4\n5 10\n11 13", "output": "1 2" }, { "input": "4\n7 15\n6 9\n9 10\n10 11", "output": "3 1" }, { "input": "4\n2 3\n100 200\n1000 2000\n1 4", "output": "1 4" }, { "input": "3\n10 20\n5 9\n11 19", "output": "3 1" }, { "input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10", "output": "6 7" }, { "input": "2\n1 4\n1 7", "output": "1 2" }, { "input": "3\n1 11\n2 12\n2 13", "output": "2 3" }, { "input": "2\n1 4\n1 8", "output": "1 2" }, { "input": "2\n2 5\n1 5", "output": "1 2" }, { "input": "2\n2 9\n1 10", "output": "1 2" }, { "input": "3\n2 4\n2 4\n1 3", "output": "2 1" }, { "input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60", "output": "3 4" }, { "input": "2\n1 3\n1 7", "output": "1 2" }, { "input": "5\n4 6\n7 60\n80 90\n4 5\n8 80", "output": "4 1" }, { "input": "2\n1 3\n1 4", "output": "1 2" }, { "input": "3\n2 9\n1 7\n2 9", "output": "3 1" }, { "input": "2\n1 4\n1 6", "output": "1 2" }, { "input": "3\n4 4\n2 3\n4 5", "output": "1 3" }, { "input": "2\n1 5\n1 7", "output": "1 2" }, { "input": "2\n1 2\n1 4", "output": "1 2" }, { "input": "4\n1 1\n2 2\n5 10\n2 4", "output": "2 4" }, { "input": "3\n11 12\n11 15\n43 45", "output": "1 2" }, { "input": "3\n2 3\n2 4\n2 5", "output": "2 3" }, { "input": "2\n2 3\n2 5", "output": "1 2" }, { "input": "3\n1 3\n1 4\n1 5", "output": "2 3" }, { "input": "3\n1 1\n1 2\n1 3", "output": "2 3" }, { "input": "2\n2 3\n1 3", "output": "1 2" }, { "input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109", "output": "11 5" }, { "input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11", "output": "1 8" }, { "input": "4\n1 10\n12 15\n1 3\n17 18", "output": "3 1" }, { "input": "3\n1 5\n1 10\n1 20", "output": "2 3" }, { "input": "3\n1 1000\n1001 1003\n1 1", "output": "3 1" }, { "input": "3\n1 10\n2 11\n2 11", "output": "3 2" }, { "input": "2\n1 1\n1 3", "output": "1 2" }, { "input": "2\n1 5\n1 6", "output": "1 2" }, { "input": "3\n1 5\n3 6\n1 4", "output": "3 1" }, { "input": "4\n2 8\n1 3\n2 9\n1 2", "output": "4 2" }, { "input": "3\n3 6\n1 3\n3 9", "output": "1 3" }, { "input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111", "output": "1 5" }, { "input": "4\n1 2\n4 4\n3 3\n2 3", "output": "3 4" }, { "input": "4\n1 1\n4 5\n7 9\n1 1", "output": "4 1" }, { "input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281", "output": "2 6" }, { "input": "2\n10 13\n10 14", "output": "1 2" }, { "input": "5\n2 4\n3 6\n4 5\n222 333\n111 444", "output": "3 2" }, { "input": "3\n1 2\n4 5\n1 1", "output": "3 1" }, { "input": "2\n2 100\n1 100", "output": "1 2" }, { "input": "3\n1 10\n9 20\n3 5", "output": "3 1" }, { "input": "2\n1 9\n1 10", "output": "1 2" }, { "input": "3\n1 2\n1 4\n1 6", "output": "2 3" } ]
1,623,081,396
2,147,483,647
Python 3
OK
TESTS
122
1,294
30,617,600
R = lambda :map(int, input().split()) n = int(input()) l = [] for _ in range(n): a,b = R() l.append((a,-b,_+1)) l = sorted(l) for i in range(1,n): if l[i][1]>=l[i-1][1]: print(l[i][2],l[i-1][2]) break else: print(-1,-1)
Title: Nested Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments. Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. Output Specification: Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Demo Input: ['5\n1 10\n2 9\n3 9\n2 3\n2 9\n', '3\n1 5\n2 6\n6 20\n'] Demo Output: ['2 1\n', '-1 -1\n'] Note: In the first example the following pairs are considered correct: - (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
```python R = lambda :map(int, input().split()) n = int(input()) l = [] for _ in range(n): a,b = R() l.append((a,-b,_+1)) l = sorted(l) for i in range(1,n): if l[i][1]>=l[i-1][1]: print(l[i][2],l[i-1][2]) break else: print(-1,-1) ```
3
690
C1
Brain Network (easy)
PROGRAMMING
1,300
[]
null
null
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly: 1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false. If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*).
The output consists of one line, containing either yes or no depending on whether the nervous system is valid.
[ "4 4\n1 2\n2 3\n3 1\n4 1\n", "6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n" ]
[ "no\n", "yes\n" ]
none
0
[ { "input": "4 4\n1 2\n2 3\n3 1\n4 1", "output": "no" }, { "input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "output": "yes" }, { "input": "2 1\n1 2", "output": "yes" }, { "input": "3 3\n2 1\n1 3\n3 2", "output": "no" }, { "input": "3 2\n1 2\n2 3", "output": "yes" }, { "input": "9 8\n1 2\n2 3\n3 4\n4 1\n5 6\n6 7\n7 8\n8 9", "output": "no" }, { "input": "8 7\n6 2\n1 5\n4 8\n4 7\n6 7\n8 3\n8 1", "output": "yes" }, { "input": "200 5\n93 101\n199 164\n14 94\n115 61\n106 156", "output": "no" }, { "input": "10 9\n6 5\n9 2\n4 7\n2 3\n7 3\n3 4\n10 6\n1 2\n5 8", "output": "no" }, { "input": "10 9\n2 3\n6 8\n10 1\n1 8\n6 7\n8 7\n10 5\n7 10\n2 5", "output": "no" }, { "input": "10 9\n3 2\n4 1\n6 1\n7 1\n9 2\n6 9\n5 2\n7 9\n3 7", "output": "no" } ]
1,490,734,950
2,147,483,647
Python 3
OK
TESTS
18
93
6,246,400
def is_valid(): import sys #with open(filename, 'r') as f: with sys.stdin as f: for i, line in enumerate(f): if i == 0: N, M = line.split(' ') N, M = int(N), int(M) if N-1 != M: return False graph = [[] for _ in range(N)] # [[]] * N not working, no deepcopy else: fromVertex, toVertex = line.split(' ') fromVertex, toVertex = int(fromVertex)-1, int(toVertex)-1 graph[fromVertex].append(toVertex) graph[toVertex].append(fromVertex) from queue import LifoQueue def is_single_component(start_node, graph): N = len(graph) visited = [False for _ in range(N)] visited[start_node] = True nodes_queue = LifoQueue() nodes_queue.put(start_node) while not nodes_queue.empty(): node = nodes_queue.get() for neigh in graph[node]: if not visited[neigh]: visited[neigh] = True nodes_queue.put(neigh) #else: not a cycle because edges in both directions return all(visited) return is_single_component(0, graph) if is_valid(): print("yes") else: print("no")
Title: Brain Network (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly: 1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false. If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid. Input Specification: The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*). Output Specification: The output consists of one line, containing either yes or no depending on whether the nervous system is valid. Demo Input: ['4 4\n1 2\n2 3\n3 1\n4 1\n', '6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n'] Demo Output: ['no\n', 'yes\n'] Note: none
```python def is_valid(): import sys #with open(filename, 'r') as f: with sys.stdin as f: for i, line in enumerate(f): if i == 0: N, M = line.split(' ') N, M = int(N), int(M) if N-1 != M: return False graph = [[] for _ in range(N)] # [[]] * N not working, no deepcopy else: fromVertex, toVertex = line.split(' ') fromVertex, toVertex = int(fromVertex)-1, int(toVertex)-1 graph[fromVertex].append(toVertex) graph[toVertex].append(fromVertex) from queue import LifoQueue def is_single_component(start_node, graph): N = len(graph) visited = [False for _ in range(N)] visited[start_node] = True nodes_queue = LifoQueue() nodes_queue.put(start_node) while not nodes_queue.empty(): node = nodes_queue.get() for neigh in graph[node]: if not visited[neigh]: visited[neigh] = True nodes_queue.put(neigh) #else: not a cycle because edges in both directions return all(visited) return is_single_component(0, graph) if is_valid(): print("yes") else: print("no") ```
3
547
B
Mike and Feet
PROGRAMMING
1,900
[ "binary search", "data structures", "dp", "dsu" ]
null
null
Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a**i* feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group. Mike is a curious to know for each *x* such that 1<=≤<=*x*<=≤<=*n* the maximum strength among all groups of size *x*.
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=2<=×<=105), the number of bears. The second line contains *n* integers separated by space, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), heights of bears.
Print *n* integers in one line. For each *x* from 1 to *n*, print the maximum strength among all groups of size *x*.
[ "10\n1 2 3 4 5 4 3 2 1 6\n" ]
[ "6 4 4 3 3 2 2 1 1 1 \n" ]
none
1,000
[ { "input": "10\n1 2 3 4 5 4 3 2 1 6", "output": "6 4 4 3 3 2 2 1 1 1 " }, { "input": "3\n524125987 923264237 374288891", "output": "923264237 524125987 374288891 " }, { "input": "5\n585325539 365329221 412106895 291882089 564718673", "output": "585325539 365329221 365329221 291882089 291882089 " }, { "input": "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499", "output": "954478790 641889899 519361360 452405440 346543678 346543678 208050516 208050516 208050516 208050516 80960260 80960260 80960260 66743034 66743034 16115810 16115810 16115810 16115810 16115810 " }, { "input": "1\n1376", "output": "1376 " }, { "input": "2\n10 10", "output": "10 10 " }, { "input": "2\n10 9", "output": "10 9 " }, { "input": "3\n1 2 3", "output": "3 2 1 " }, { "input": "3\n1 3 2", "output": "3 2 1 " }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754", "output": "983359971 640274071 598196518 598196518 96204862 71550121 71550121 71550121 71550121 71550121 " }, { "input": "19\n519879446 764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759", "output": "943428394 744988123 680293934 680293934 519879446 317088317 317088317 261437390 261437390 239862203 239862203 239862203 239862203 239862203 239862203 239862203 239862203 223751525 223751525 " } ]
1,432,740,100
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
8,499,200
n = int(input()) data = [int(x) for x in input().split()] left = [] stack = [] for i in range(n): while len(stack) and data[i] <= data[stack[len(stack) - 1]]: a = stack.pop() if not stack: left.append(-1) else: left.append(stack[len(stack) - 1]) stack.append(i) stack = [] right = [] for i in range(n - 1, -1, -1): while len(stack) and data[i] <= data[stack[len(stack) - 1]]: stack.pop() if not stack: right.insert(0, n) else: right.insert(0, stack[len(stack) - 1]) stack.append(i) ans = [0 for x in range(n)] for i in range(n): lenCheck = right[i] - left[i] - 1 ans[lenCheck - 1] = max(ans[lenCheck - 1], data[i]) for i in range(n - 2, -1, -1): ans[i] = max(ans[i], ans[i + 1]) print(" ".join([str(x) for x in ans]))
Title: Mike and Feet Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a**i* feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group. Mike is a curious to know for each *x* such that 1<=≤<=*x*<=≤<=*n* the maximum strength among all groups of size *x*. Input Specification: The first line of input contains integer *n* (1<=≤<=*n*<=≤<=2<=×<=105), the number of bears. The second line contains *n* integers separated by space, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), heights of bears. Output Specification: Print *n* integers in one line. For each *x* from 1 to *n*, print the maximum strength among all groups of size *x*. Demo Input: ['10\n1 2 3 4 5 4 3 2 1 6\n'] Demo Output: ['6 4 4 3 3 2 2 1 1 1 \n'] Note: none
```python n = int(input()) data = [int(x) for x in input().split()] left = [] stack = [] for i in range(n): while len(stack) and data[i] <= data[stack[len(stack) - 1]]: a = stack.pop() if not stack: left.append(-1) else: left.append(stack[len(stack) - 1]) stack.append(i) stack = [] right = [] for i in range(n - 1, -1, -1): while len(stack) and data[i] <= data[stack[len(stack) - 1]]: stack.pop() if not stack: right.insert(0, n) else: right.insert(0, stack[len(stack) - 1]) stack.append(i) ans = [0 for x in range(n)] for i in range(n): lenCheck = right[i] - left[i] - 1 ans[lenCheck - 1] = max(ans[lenCheck - 1], data[i]) for i in range(n - 2, -1, -1): ans[i] = max(ans[i], ans[i + 1]) print(" ".join([str(x) for x in ans])) ```
0
701
C
They Are Everywhere
PROGRAMMING
1,500
[ "binary search", "strings", "two pointers" ]
null
null
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1. There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once. Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house. The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
[ "3\nAaA\n", "7\nbcAAcbc\n", "6\naaBCCe\n" ]
[ "2\n", "3\n", "5\n" ]
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
1,000
[ { "input": "3\nAaA", "output": "2" }, { "input": "7\nbcAAcbc", "output": "3" }, { "input": "6\naaBCCe", "output": "5" }, { "input": "1\nA", "output": "1" }, { "input": "1\ng", "output": "1" }, { "input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "52" }, { "input": "2\nAA", "output": "1" }, { "input": "4\nqqqE", "output": "2" }, { "input": "10\nrrrrroooro", "output": "2" }, { "input": "15\nOCOCCCCiCOCCCOi", "output": "3" }, { "input": "20\nVEVnVVnWnVEVVnEVBEWn", "output": "5" }, { "input": "25\ncpcyPPjPPcPPPPcppPcPpppcP", "output": "6" }, { "input": "30\nsssssAsesssssssssssssessssssss", "output": "3" }, { "input": "35\ngdXdddgddddddddggggXdbgdggdgddddddb", "output": "4" }, { "input": "40\nIgsggIiIggzgigIIiiIIIiIgIggIzgIiiiggggIi", "output": "9" }, { "input": "45\neteeeeeteaattaeetaetteeettoetettteyeteeeotaae", "output": "9" }, { "input": "50\nlUlUllUlUllllUllllUllllUlUlllUlllUlllllUUlllUUlkUl", "output": "3" }, { "input": "55\nAAAAASAAAASAASAAAAAAAAAAAAASAAAAAAAAAAAAAAAASAAAAAAAAAA", "output": "2" }, { "input": "60\nRRRrSRRRRRRRRRSSRRRSRRRRRRRRrRSRRRRRRRRRRRRRRSRRRRRSSRSRrRRR", "output": "3" }, { "input": "65\nhhMhMhhhhhhhhhhhMhhMMMhhhhBhhhhMhhhhMhhhhhMhhhBhhhhhhhhhhBhhhhhhh", "output": "5" }, { "input": "70\nwAwwwAwwwwwwwwwwwwwwAwAAwwAwwwwwwwwAwAAAwAAwwwwwwwwwAwwwwwwwwwwwwAAwww", "output": "2" }, { "input": "75\niiiXXiiyiiiXyXiiyXiiXiiiiiiXXyiiiiXXiiXiiXifiXiXXiifiiiiiiXfXiyiXXiXiiiiXiX", "output": "4" }, { "input": "80\nSrSrrrrrrrrrrrrrrSSSrrrrrrSrrrrSrrrrrrrrrrSSrrrrrrrrrrrSrrrSrrrrSrrrrSrrrrSSrSSr", "output": "2" }, { "input": "85\nwkMMMwMMkMMMMMMMkkkkMMMMzkkMMwMMkkwMkMwkMMkMMwwMzMMMkkMwwMMMMMMkMMkMzMMMkMMkwMkMMMkMM", "output": "6" }, { "input": "90\nZllZZZyZlZlllZlylllZlllZZllllllllZZllllllllllyylZZyvZvZlllZZlZllZlZlllZyllZyZlllZlllllllZl", "output": "5" }, { "input": "95\nEmuBuEBmmEBBElBlElmmBEmmmEmmEuBEEmummmEmBBBBEWBBBmEEBmmummBBmmlluBBmElmEBEmBmBBmBmuLmEBBmlEBmBu", "output": "39" }, { "input": "100\nfAfhfNNNhfffAfNffNANhffNffffffNfffffhNfffNfffNfffNfNNNffNfffNfhNNNffffNfNfffAffNffNffNNfhfffNhNffNNN", "output": "4" }, { "input": "7\nabcbbab", "output": "3" }, { "input": "65\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjkkkkkkkkkkkkkkkkkkkllllllljk", "output": "3" }, { "input": "9\nbcdddbddc", "output": "3" }, { "input": "71\nlqcrdopdpfagcilpcmheqhjbmnciqmeoabflrenbkrsaabaanpehdmpqcdqnljcrsplnlco", "output": "36" }, { "input": "8\nabbbbbbc", "output": "8" } ]
1,697,935,867
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
def check_pokedex(pokedex): ans = True for x in pokedex.keys(): if pokedex[x] == 0: ans = False return ans ans = [] n = int(input()) string = input() pokedex = {} types = 0 #How many types are there for x in string: if x not in pokedex: pokedex[x] = 0 else: types +=1 #add first pokemon pokedex[string[0]] += 1 p1 = 0 p2 = 0 #do it until p2, reaches the end of the string while p2 < n - 1: #moving pointer 2 while not check_pokedex(pokedex) and p2 < n - 1: p2 += 1 pokedex[string[p2]] += 1 ans.append(p2-p1 + 1) #moving pointer 1 while check_pokedex(pokedex) and p1 < p2: pokedex[string[p1]] -= 1 p1 += 1 ans.append(p2 - (p1 -1) + 1) #check 1 last time while check_pokedex(pokedex) and p1 < p2: pokedex[string[p1]] -= 1 p1 += 1 ans.append(p2 - (p1 -1) + 1) print(min(ans))
Title: They Are Everywhere Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1. There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once. Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house. The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. Output Specification: Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. Demo Input: ['3\nAaA\n', '7\nbcAAcbc\n', '6\naaBCCe\n'] Demo Output: ['2\n', '3\n', '5\n'] Note: In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
```python def check_pokedex(pokedex): ans = True for x in pokedex.keys(): if pokedex[x] == 0: ans = False return ans ans = [] n = int(input()) string = input() pokedex = {} types = 0 #How many types are there for x in string: if x not in pokedex: pokedex[x] = 0 else: types +=1 #add first pokemon pokedex[string[0]] += 1 p1 = 0 p2 = 0 #do it until p2, reaches the end of the string while p2 < n - 1: #moving pointer 2 while not check_pokedex(pokedex) and p2 < n - 1: p2 += 1 pokedex[string[p2]] += 1 ans.append(p2-p1 + 1) #moving pointer 1 while check_pokedex(pokedex) and p1 < p2: pokedex[string[p1]] -= 1 p1 += 1 ans.append(p2 - (p1 -1) + 1) #check 1 last time while check_pokedex(pokedex) and p1 < p2: pokedex[string[p1]] -= 1 p1 += 1 ans.append(p2 - (p1 -1) + 1) print(min(ans)) ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,676,063,576
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a=int(input()) c=0 for i in range(a): s=(input()) e=s.split(' ') v1=int(e[0]) v2=int(e[1]) v3=int(e[2]) c+=v1+v2+v3 if c : print("no") else: print('yes')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python a=int(input()) c=0 for i in range(a): s=(input()) e=s.split(' ') v1=int(e[0]) v2=int(e[1]) v3=int(e[2]) c+=v1+v2+v3 if c : print("no") else: print('yes') ```
0
380
C
Sereja and Brackets
PROGRAMMING
2,000
[ "data structures", "schedules" ]
null
null
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")". Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries. You can find the definitions for a subsequence and a correct bracket sequence in the notes.
The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query.
Print the answer to each question on a single line. Print the answers in the order they go in the input.
[ "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n" ]
[ "0\n0\n2\n10\n4\n6\n6\n" ]
A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> &lt; *k*<sub class="lower-index">2</sub> &lt; ... &lt; *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|). A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not. For the third query required sequence will be «()». For the fourth query required sequence will be «()(())(())».
1,500
[ { "input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10", "output": "0\n0\n2\n10\n4\n6\n6" }, { "input": "(((((()((((((((((()((()(((((\n1\n8 15", "output": "0" }, { "input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 46\n57 63\n29 48\n51 75\n14 72\n5 70\n51 73\n10 64\n31 56\n50 54\n15 78\n78 82\n1 11\n1 70\n1 19\n10 22\n13 36\n3 10\n34 40\n51 76\n64 71\n36 75\n24 71\n1 63\n5 14\n46 67\n32 56\n39 43\n43 56\n61 82\n2 78\n1 21\n10 72\n49 79\n12 14\n53 79\n15 31\n7 47", "output": "4\n4\n2\n4\n2\n12\n16\n2\n12\n4\n0\n12\n0\n6\n18\n6\n2\n6\n6\n0\n2\n0\n6\n8\n18\n4\n2\n4\n2\n2\n2\n18\n8\n12\n2\n0\n2\n6\n12" }, { "input": "))(()))))())())))))())((()()))))()))))))))))))\n9\n26 42\n21 22\n6 22\n7 26\n43 46\n25 27\n32 39\n22 40\n2 45", "output": "4\n0\n6\n8\n0\n2\n2\n10\n20" }, { "input": "(()((((()(())((((((((()((((((()((((\n71\n15 29\n17 18\n5 26\n7 10\n16 31\n26 35\n2 30\n16 24\n2 24\n7 12\n15 18\n12 13\n25 30\n1 30\n12 13\n16 20\n6 35\n20 28\n18 23\n9 31\n12 35\n14 17\n8 16\n3 10\n12 33\n7 19\n2 33\n7 17\n21 27\n10 30\n29 32\n9 28\n18 32\n28 31\n31 33\n4 26\n15 27\n10 17\n8 14\n11 28\n8 23\n17 33\n4 14\n3 6\n6 34\n19 23\n4 21\n16 27\n14 27\n6 19\n31 32\n29 32\n9 17\n1 21\n2 31\n18 29\n16 26\n15 18\n4 5\n13 20\n9 28\n18 30\n1 32\n2 9\n16 24\n1 20\n4 15\n16 23\n19 34\n5 22\n5 23", "output": "2\n0\n8\n2\n4\n2\n10\n2\n10\n4\n0\n0\n0\n10\n0\n0\n10\n2\n2\n8\n4\n0\n6\n2\n4\n6\n12\n6\n2\n6\n2\n6\n4\n2\n0\n8\n2\n4\n6\n4\n8\n4\n6\n0\n10\n2\n6\n2\n2\n6\n0\n2\n4\n8\n12\n2\n2\n0\n0\n0\n6\n2\n12\n4\n2\n8\n6\n2\n4\n6\n8" }, { "input": "(((())((((()()((((((()((()(((((((((((()((\n6\n20 37\n28 32\n12 18\n7 25\n21 33\n4 5", "output": "4\n0\n2\n6\n4\n2" }, { "input": "(((()((((()()()(()))((((()(((()))()((((()))()((())\n24\n37 41\n13 38\n31 34\n14 16\n29 29\n12 46\n1 26\n15 34\n8 47\n11 23\n6 32\n2 22\n9 27\n17 40\n6 15\n4 49\n12 33\n3 48\n22 47\n19 48\n10 27\n23 25\n4 44\n27 48", "output": "2\n16\n0\n2\n0\n26\n16\n12\n30\n8\n18\n14\n14\n12\n6\n34\n16\n32\n18\n18\n12\n0\n30\n16" }, { "input": ")()((((((((((((((((()(((()()(()((((((()(((((((()()))((((())(((((((((()(((((((((\n51\n29 53\n31 69\n54 59\n3 52\n26 46\n14 62\n6 54\n39 56\n17 27\n46 74\n60 72\n18 26\n38 46\n4 27\n22 52\n44 49\n42 77\n2 20\n39 57\n61 70\n33 54\n10 30\n67 70\n46 66\n17 77\n5 52\n33 77\n26 32\n1 72\n40 78\n38 68\n19 47\n30 53\n19 29\n52 71\n1 11\n22 53\n17 42\n2 51\n4 12\n24 76\n22 34\n21 69\n11 69\n36 52\n17 31\n57 58\n54 62\n23 71\n5 46\n51 53", "output": "12\n14\n4\n18\n6\n22\n18\n8\n4\n12\n2\n4\n2\n4\n16\n2\n14\n2\n8\n2\n10\n6\n2\n10\n24\n18\n16\n4\n26\n14\n14\n10\n12\n6\n6\n2\n16\n10\n18\n0\n22\n6\n20\n22\n10\n8\n2\n4\n22\n10\n0" }, { "input": "(\n1\n1 1", "output": "0" }, { "input": ")\n1\n1 1", "output": "0" }, { "input": "()\n1\n1 2", "output": "2" }, { "input": ")(\n1\n1 2", "output": "0" } ]
1,624,727,034
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
0
import sys import math input=sys.stdin.readline s=input().rstrip() n=len(s) q=int(input()) class segTree: def __init__(self): self.a=[0]*(2*n) self.b=[0]*(2*n) self.c=[0]*(2*n) def build(self,arr): for i in range(n): self.a[i+n]=0 self.b[i+n]=1 if arr[i]=="(" else 0 self.c[i+n]=1 if arr[i]==")" else 0 for i in range(n-1,0,-1): t=min(self.b[i<<1],self.c[i<<1|1]) self.a[i]=self.a[i<<1]+self.a[i<<1|1]+2*t self.b[i]=self.b[i<<1]+self.b[i<<1|1]-t self.c[i]=self.c[i<<1]+self.c[i<<1|1]-t def query(self,l,r): left=[] right=[] l+=n r+=n while l<=r: if (l&1): left.append([self.a[l],self.b[l],self.c[l]]) if not (r&1): right.append([self.a[r],self.b[r],self.c[r]]) r-=1 l>>=1 r>>=1 a1=b1=c1=0 for a2,b2,c2 in left+right[::-1]: t=min(b1,c2) a1+=a2+2*t b1+=b2-t c1+=c2-t return a1 tr=segTree() tr.build(s) for _ in range(q): l,r=map(int,input().split()) print(tr.query(l-1,r-1))
Title: Sereja and Brackets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")". Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries. You can find the definitions for a subsequence and a correct bracket sequence in the notes. Input Specification: The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query. Output Specification: Print the answer to each question on a single line. Print the answers in the order they go in the input. Demo Input: ['())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n'] Demo Output: ['0\n0\n2\n10\n4\n6\n6\n'] Note: A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> &lt; *k*<sub class="lower-index">2</sub> &lt; ... &lt; *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|). A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not. For the third query required sequence will be «()». For the fourth query required sequence will be «()(())(())».
```python import sys import math input=sys.stdin.readline s=input().rstrip() n=len(s) q=int(input()) class segTree: def __init__(self): self.a=[0]*(2*n) self.b=[0]*(2*n) self.c=[0]*(2*n) def build(self,arr): for i in range(n): self.a[i+n]=0 self.b[i+n]=1 if arr[i]=="(" else 0 self.c[i+n]=1 if arr[i]==")" else 0 for i in range(n-1,0,-1): t=min(self.b[i<<1],self.c[i<<1|1]) self.a[i]=self.a[i<<1]+self.a[i<<1|1]+2*t self.b[i]=self.b[i<<1]+self.b[i<<1|1]-t self.c[i]=self.c[i<<1]+self.c[i<<1|1]-t def query(self,l,r): left=[] right=[] l+=n r+=n while l<=r: if (l&1): left.append([self.a[l],self.b[l],self.c[l]]) if not (r&1): right.append([self.a[r],self.b[r],self.c[r]]) r-=1 l>>=1 r>>=1 a1=b1=c1=0 for a2,b2,c2 in left+right[::-1]: t=min(b1,c2) a1+=a2+2*t b1+=b2-t c1+=c2-t return a1 tr=segTree() tr.build(s) for _ in range(q): l,r=map(int,input().split()) print(tr.query(l-1,r-1)) ```
0
775
A
University Schedule
PROGRAMMING
2,900
[ "*special" ]
null
null
In this problem your task is to come up with a week schedule of classes in university for professors and student groups. Consider that there are 6 educational days in week and maximum number of classes per educational day is 7 (classes numerated from 1 to 7 for each educational day). It is known that in university *n* students study, *m* professors work and there are *a* classrooms for conducting classes. Also you have two-dimensional array with *n*<=×<=*m* size which contains the following information. The number which stays in *i*-th row and *j*-th column equals to the number of classes which professor *j* must conduct with the group *i* in a single week. The schedule which you output must satisfy to array described above. There are several other conditions for schedule. Single professor can not conduct more than one class. Similarly, single student group can not be on more than one class at the same time. Let define a fatigue function for professors and student groups. Call this function *f*. To single professor fatigue calculated in the following way. Let look on classes which this professor must conduct in each of the 6-th educational days. Let *x* be the number of class which professor will firstly conduct in day *i* and let *y* — the last class for this professor. Then the value (2<=+<=*y*<=-<=*x*<=+<=1)·(2<=+<=*y*<=-<=*x*<=+<=1) must be added to professor's fatigue. If professor has no classes in day *i*, nothing is added to professor's fatigue. For single student group fatigue is calculated similarly. Lets look at classes of this group in each of the 6 educational days. Let *x* be the number of first class for this group on day *i* and let *y* — the last class for this group. Then the value (2<=+<=*y*<=-<=*x*<=+<=1)·(2<=+<=*y*<=-<=*x*<=+<=1) must be added to this group's fatigue. If student group has no classes in day *i*, nothing is added to group's fatigue. So the value of function *f* equals to total {fatigue} for all *n* student groups and for all *m* professors. Your task is to come up with such a schedule which minimizes the value of function *f*. Jury prepared some solution of this problem. For each test you will get a certain number of points. It equals to result of division of the value of function *f* from the jury solution by the value of function *f* for schedule which your program output (i. e. the smaller value of {fatigue} function your program find the more points you will get), multiplied by 100. In the other words if the value of *f* for jury solution equals to *p* and for your solution — to *q*, you will get 100·*p*<=/<=*q* points (note, that the number of points is a real number). The points will be added together for all tests. The goal is to score as many points as possible.
The first line contains three integers *n*, *m* and *a* (1<=≤<=*n*,<=*m*,<=*a*<=≤<=60) — the number of groups, the number of professors and the number of classrooms. Each of the following *n* lines contains *m* integers from 0 to 24 — *j*-th number in *i*-th line equals to the number of classes with the professor *j* must conduct with the *i*-th student group. It is guaranteed that the number of classes in week for each professor and for each student group does not exceed 24. Also guaranteed that the total number of classes in week does not exceed 75% from a maximum number of classes which can be conducted based on the number of classrooms. For all tests there is at least one schedule satisfying all described conditions.
In the first line print the minimized value of function *f*. After that print blank line. After that print the schedule for each student group in increasing order of group number. For each student group print 7 lines. Each line must contains 6 numbers. Let the number at *i*-th line and *j*-th column equals to *x*. If in *j*-th day current group has no class number *i*, *x* must be equals to zero. Otherwise *x* must be equals to the number of professor who will conduct the corresponding class with the corresponding student group. The number of classes which will be conducted simultaneously must not exceeds the number of classrooms *a*. Separate the description of the schedules for groups with a blank line.
[ "3 3 1\n1 0 0\n0 1 0\n0 0 1\n", "3 1 1\n1\n1\n1\n", "5 7 10\n1 3 6 0 1 2 4\n0 3 0 6 5 1 4\n3 5 1 2 3 2 4\n2 3 1 1 4 1 2\n2 4 3 2 4 3 2\n" ]
[ "54\n\n1 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 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n2 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 \n\n0 0 0 0 0 0 \n0 0 0 0 0 0 \n3 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 \n", "52\n\n1 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 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n1 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 \n\n0 0 0 0 0 0 \n0 0 0 0 0 0 \n1 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 \n", "1512\n\n0 0 6 0 0 2 \n0 7 6 3 3 7 \n3 1 2 3 2 7 \n3 7 0 0 0 0 \n5 3 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 4 0 7 6 \n4 5 7 4 5 5 \n7 2 4 4 5 5 \n7 2 0 4 0 0 \n0 2 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n4 0 7 2 5 7 \n5 0 2 5 7 1 \n2 4 1 2 7 1 \n2 3 0 0 0 0 \n0 6 0 0 0 0 \n0 6 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 0 5 3 5 \n0 2 4 7 2 6 \n0 5 7 0 0 0 \n1 5 1 0 0 0 \n2 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 5 7 2 3 \n0 1 3 2 6 3 \n5 7 6 5 6 4 \n5 4 2 2 0 0 \n1 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n" ]
During the main part of the competition (one week) you solution will be judged on 100 preliminary tests. The first 10 preliminary tests are available for download by a link [http://assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz](//assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz). After the end of the contest (i.e., a week after its start) the last solution you sent (having positive score) will be chosen to be launched on the extended final tests.
0
[]
1,645,437,705
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("Hello, World!")
Title: University Schedule Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem your task is to come up with a week schedule of classes in university for professors and student groups. Consider that there are 6 educational days in week and maximum number of classes per educational day is 7 (classes numerated from 1 to 7 for each educational day). It is known that in university *n* students study, *m* professors work and there are *a* classrooms for conducting classes. Also you have two-dimensional array with *n*<=×<=*m* size which contains the following information. The number which stays in *i*-th row and *j*-th column equals to the number of classes which professor *j* must conduct with the group *i* in a single week. The schedule which you output must satisfy to array described above. There are several other conditions for schedule. Single professor can not conduct more than one class. Similarly, single student group can not be on more than one class at the same time. Let define a fatigue function for professors and student groups. Call this function *f*. To single professor fatigue calculated in the following way. Let look on classes which this professor must conduct in each of the 6-th educational days. Let *x* be the number of class which professor will firstly conduct in day *i* and let *y* — the last class for this professor. Then the value (2<=+<=*y*<=-<=*x*<=+<=1)·(2<=+<=*y*<=-<=*x*<=+<=1) must be added to professor's fatigue. If professor has no classes in day *i*, nothing is added to professor's fatigue. For single student group fatigue is calculated similarly. Lets look at classes of this group in each of the 6 educational days. Let *x* be the number of first class for this group on day *i* and let *y* — the last class for this group. Then the value (2<=+<=*y*<=-<=*x*<=+<=1)·(2<=+<=*y*<=-<=*x*<=+<=1) must be added to this group's fatigue. If student group has no classes in day *i*, nothing is added to group's fatigue. So the value of function *f* equals to total {fatigue} for all *n* student groups and for all *m* professors. Your task is to come up with such a schedule which minimizes the value of function *f*. Jury prepared some solution of this problem. For each test you will get a certain number of points. It equals to result of division of the value of function *f* from the jury solution by the value of function *f* for schedule which your program output (i. e. the smaller value of {fatigue} function your program find the more points you will get), multiplied by 100. In the other words if the value of *f* for jury solution equals to *p* and for your solution — to *q*, you will get 100·*p*<=/<=*q* points (note, that the number of points is a real number). The points will be added together for all tests. The goal is to score as many points as possible. Input Specification: The first line contains three integers *n*, *m* and *a* (1<=≤<=*n*,<=*m*,<=*a*<=≤<=60) — the number of groups, the number of professors and the number of classrooms. Each of the following *n* lines contains *m* integers from 0 to 24 — *j*-th number in *i*-th line equals to the number of classes with the professor *j* must conduct with the *i*-th student group. It is guaranteed that the number of classes in week for each professor and for each student group does not exceed 24. Also guaranteed that the total number of classes in week does not exceed 75% from a maximum number of classes which can be conducted based on the number of classrooms. For all tests there is at least one schedule satisfying all described conditions. Output Specification: In the first line print the minimized value of function *f*. After that print blank line. After that print the schedule for each student group in increasing order of group number. For each student group print 7 lines. Each line must contains 6 numbers. Let the number at *i*-th line and *j*-th column equals to *x*. If in *j*-th day current group has no class number *i*, *x* must be equals to zero. Otherwise *x* must be equals to the number of professor who will conduct the corresponding class with the corresponding student group. The number of classes which will be conducted simultaneously must not exceeds the number of classrooms *a*. Separate the description of the schedules for groups with a blank line. Demo Input: ['3 3 1\n1 0 0\n0 1 0\n0 0 1\n', '3 1 1\n1\n1\n1\n', '5 7 10\n1 3 6 0 1 2 4\n0 3 0 6 5 1 4\n3 5 1 2 3 2 4\n2 3 1 1 4 1 2\n2 4 3 2 4 3 2\n'] Demo Output: ['54\n\n1 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 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n2 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 \n\n0 0 0 0 0 0 \n0 0 0 0 0 0 \n3 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 \n', '52\n\n1 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 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n1 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 \n\n0 0 0 0 0 0 \n0 0 0 0 0 0 \n1 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 \n', '1512\n\n0 0 6 0 0 2 \n0 7 6 3 3 7 \n3 1 2 3 2 7 \n3 7 0 0 0 0 \n5 3 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 4 0 7 6 \n4 5 7 4 5 5 \n7 2 4 4 5 5 \n7 2 0 4 0 0 \n0 2 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n4 0 7 2 5 7 \n5 0 2 5 7 1 \n2 4 1 2 7 1 \n2 3 0 0 0 0 \n0 6 0 0 0 0 \n0 6 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 0 5 3 5 \n0 2 4 7 2 6 \n0 5 7 0 0 0 \n1 5 1 0 0 0 \n2 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 5 7 2 3 \n0 1 3 2 6 3 \n5 7 6 5 6 4 \n5 4 2 2 0 0 \n1 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n'] Note: During the main part of the competition (one week) you solution will be judged on 100 preliminary tests. The first 10 preliminary tests are available for download by a link [http://assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz](//assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz). After the end of the contest (i.e., a week after its start) the last solution you sent (having positive score) will be chosen to be launched on the extended final tests.
```python print("Hello, World!") ```
0
630
L
Cracking the Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives. A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose — to show the developer the imperfection of their protection. The found algorithm looks the following way. At first the digits of the number are shuffled in the following order &lt;first digit&gt;&lt;third digit&gt;&lt;fifth digit&gt;&lt;fourth digit&gt;&lt;second digit&gt;. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455 422 043 125 550 171 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232. Vasya is going to write a keygen program implementing this algorithm. Can you do the same?
The only line of the input contains a positive integer five digit number for which the activation code should be found.
Output exactly 5 digits without spaces between them — the found activation code of the program.
[ "12345\n" ]
[ "71232" ]
none
0
[ { "input": "12345", "output": "71232" }, { "input": "13542", "output": "84443" }, { "input": "71232", "output": "10151" }, { "input": "11111", "output": "36551" }, { "input": "10000", "output": "00000" }, { "input": "99999", "output": "99999" }, { "input": "91537", "output": "27651" }, { "input": "70809", "output": "00000" }, { "input": "41675", "output": "61851" }, { "input": "32036", "output": "82432" } ]
1,695,490,683
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
n = input() n1 = int(n[0] + n[2] + n[4] + n[3] + n[1]) print(n1 ** 5 % 100000)
Title: Cracking the Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives. A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose — to show the developer the imperfection of their protection. The found algorithm looks the following way. At first the digits of the number are shuffled in the following order &lt;first digit&gt;&lt;third digit&gt;&lt;fifth digit&gt;&lt;fourth digit&gt;&lt;second digit&gt;. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455 422 043 125 550 171 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232. Vasya is going to write a keygen program implementing this algorithm. Can you do the same? Input Specification: The only line of the input contains a positive integer five digit number for which the activation code should be found. Output Specification: Output exactly 5 digits without spaces between them — the found activation code of the program. Demo Input: ['12345\n'] Demo Output: ['71232'] Note: none
```python n = input() n1 = int(n[0] + n[2] + n[4] + n[3] + n[1]) print(n1 ** 5 % 100000) ```
0
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Print a single integer — the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98", "output": "24" } ]
1,628,497,521
2,147,483,647
Python 3
OK
TESTS
41
77
7,372,800
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) count = i = 0 for j in range(m): if i >= n: break if b[j] >= a[i]: count += 1 i += 1 print(n-count)
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n'] Demo Output: ['0\n', '2\n', '3\n'] Note: In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
```python n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) count = i = 0 for j in range(m): if i >= n: break if b[j] >= a[i]: count += 1 i += 1 print(n-count) ```
3
986
D
Perfect Encoding
PROGRAMMING
3,100
[ "fft", "math" ]
null
null
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs.
In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros.
Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$.
[ "36\n", "37\n", "12345678901234567890123456789\n" ]
[ "10\n", "11\n", "177\n" ]
none
2,500
[ { "input": "36", "output": "10" }, { "input": "37", "output": "11" }, { "input": "12345678901234567890123456789", "output": "177" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input": "4", "output": "4" }, { "input": "7421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798", "output": "629" }, { "input": "71057885893313745806894531138592341136175030511382512555364579061229040750815096670263802546201989828165866147027119861863385397179695224216202346062872417111920113483747119385957051753101263769591892062039112567316036455789217245754461225443096439906225767290690128677713047690686004149082311677134836383178262318973298581951974863511315252485252083010690948164456205330279738760034861583874764199950445592461479109814313530332776429627014232776723160331462731018692207739471347664936326394313671025", "output": "3144" }, { "input": "515377520732011331036461129765621272702107522001", "output": "300" }, { "input": "515377520732011331036461129765621272702107522002", "output": "301" }, { "input": "515377520732011331036461129765621272702107522000", "output": "300" }, { "input": "2644141638961613273780910519504288731930844065504296335329840736453657194693409799081556627701216123927819555393745164711901909164201237823730685450515907348055240450396641607756029548457929682548780800235177236082257895631246188876123132346108173348981012356250960688811094108794077791634930736509832272441660537127557164580456832796615775793837112808169797875218746484343692719877391033530037881176218120852179342877728205628700771297494331664021228732264346205537805710440002", "output": "3002" } ]
1,545,707,284
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
14
2,000
4,198,400
import math # fileT = open("test.in","r") # n = int(fileT.readline().strip()) n = int(input()) if n == 1 : print(1) exit(0) ans = int(math.log(n,3)) - 1 tmp = pow(3,ans) while 1 : for i in range(2,5) : if tmp*i >= n : print(ans*3+i) exit(0) tmp *= 3 ans += 1
Title: Perfect Encoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs. Input Specification: In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. Output Specification: Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. Demo Input: ['36\n', '37\n', '12345678901234567890123456789\n'] Demo Output: ['10\n', '11\n', '177\n'] Note: none
```python import math # fileT = open("test.in","r") # n = int(fileT.readline().strip()) n = int(input()) if n == 1 : print(1) exit(0) ans = int(math.log(n,3)) - 1 tmp = pow(3,ans) while 1 : for i in range(2,5) : if tmp*i >= n : print(ans*3+i) exit(0) tmp *= 3 ans += 1 ```
0
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,609,828,820
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
186
10,854,400
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1):#nmbr()): n=nmbr() a=lst() p=-1 for i in range(1,n): if a[i]<a[i-1]: p=i break if p!=-1:new=a[p:][::-1]+a[:p] if p==-1:print(0) elif new==sorted(a):print(n-p) else:print(-1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1):#nmbr()): n=nmbr() a=lst() p=-1 for i in range(1,n): if a[i]<a[i-1]: p=i break if p!=-1:new=a[p:][::-1]+a[:p] if p==-1:print(0) elif new==sorted(a):print(n-p) else:print(-1) ```
0
804
A
Find Amir
PROGRAMMING
1,000
[ "constructive algorithms", "greedy", "math" ]
null
null
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools.
Print single integer: the minimum cost of tickets needed to visit all schools.
[ "2\n", "10\n" ]
[ "0\n", "4\n" ]
In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "2", "output": "0" }, { "input": "10", "output": "4" }, { "input": "43670", "output": "21834" }, { "input": "4217", "output": "2108" }, { "input": "17879", "output": "8939" }, { "input": "31809", "output": "15904" }, { "input": "40873", "output": "20436" }, { "input": "77859", "output": "38929" }, { "input": "53022", "output": "26510" }, { "input": "79227", "output": "39613" }, { "input": "100000", "output": "49999" }, { "input": "82801", "output": "41400" }, { "input": "5188", "output": "2593" }, { "input": "86539", "output": "43269" }, { "input": "12802", "output": "6400" }, { "input": "20289", "output": "10144" }, { "input": "32866", "output": "16432" }, { "input": "33377", "output": "16688" }, { "input": "31775", "output": "15887" }, { "input": "60397", "output": "30198" }, { "input": "100000", "output": "49999" }, { "input": "99999", "output": "49999" }, { "input": "99998", "output": "49998" }, { "input": "99997", "output": "49998" }, { "input": "99996", "output": "49997" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "1", "output": "0" }, { "input": "3", "output": "1" } ]
1,509,981,881
2,147,483,647
Python 3
OK
TESTS
31
62
0
a=int(input()) if a%2==0: x= int((a/2-1)) print (x) if a%2 !=0: y= int(((a+1)/2-1)) print(y)
Title: Find Amir Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. Output Specification: Print single integer: the minimum cost of tickets needed to visit all schools. Demo Input: ['2\n', '10\n'] Demo Output: ['0\n', '4\n'] Note: In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a=int(input()) if a%2==0: x= int((a/2-1)) print (x) if a%2 !=0: y= int(((a+1)/2-1)) print(y) ```
3
315
A
Sereja and Bottles
PROGRAMMING
1,400
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
500
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", "output": "2" }, { "input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730", "output": "6" }, { "input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624", "output": "6" }, { "input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987", "output": "6" }, { "input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222", "output": "6" }, { "input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485", "output": "8" }, { "input": "1\n1000 1000", "output": "1" }, { "input": "1\n500 1000", "output": "1" }, { "input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11", "output": "11" }, { "input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2", "output": "0" }, { "input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330", "output": "30" }, { "input": "2\n7 7\n5 359", "output": "2" }, { "input": "2\n465 706\n706 706", "output": "1" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 1\n1 1\n2 2", "output": "1" }, { "input": "5\n1 1\n1 2\n2 3\n3 4\n4 3", "output": "1" }, { "input": "3\n1 2\n1 2\n1 1", "output": "1" } ]
1,609,197,374
2,147,483,647
PyPy 3
OK
TESTS
34
342
1,433,600
n = int(input()) arr = [False] * n des = [] for i in range(n): a,b = map(int, input().split()) des.append([a,b,False]) for i in range(n): open = des[i][1] for j in range(n): if(j != i): if(des[j][0] == open): des[j][2] = True count = 0 for i in des: if not(i[2]): count += 1 print(count)
Title: Sereja and Bottles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n'] Demo Output: ['4\n', '0\n'] Note: none
```python n = int(input()) arr = [False] * n des = [] for i in range(n): a,b = map(int, input().split()) des.append([a,b,False]) for i in range(n): open = des[i][1] for j in range(n): if(j != i): if(des[j][0] == open): des[j][2] = True count = 0 for i in des: if not(i[2]): count += 1 print(count) ```
3
939
A
Love Triangle
PROGRAMMING
800
[ "graphs" ]
null
null
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case.
[ "5\n2 4 5 1 3\n", "5\n5 5 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
500
[ { "input": "5\n2 4 5 1 3", "output": "YES" }, { "input": "5\n5 5 5 5 1", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "10\n4 10 9 5 3 1 5 10 6 4", "output": "NO" }, { "input": "10\n5 5 4 9 10 9 9 5 3 1", "output": "YES" }, { "input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43", "output": "NO" }, { "input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50", "output": "YES" }, { "input": "2\n2 1", "output": "NO" }, { "input": "3\n2 3 1", "output": "YES" }, { "input": "5\n2 1 4 5 3", "output": "YES" }, { "input": "5\n5 4 5 5 2", "output": "YES" } ]
1,647,356,989
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
import sys input_ = input() planes, numbers = input_.split('\n') planes = int(planes) numbers = [int(i) for i in numbers.split()] graph = {i+1:j for i,j in enumerate(numbers)} for i in range(1, planes+1): if graph[graph[graph[i]]]==i: print('YES') break print('NO')
Title: Love Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. Output Specification: Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case. Demo Input: ['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
```python import sys input_ = input() planes, numbers = input_.split('\n') planes = int(planes) numbers = [int(i) for i in numbers.split()] graph = {i+1:j for i,j in enumerate(numbers)} for i in range(1, planes+1): if graph[graph[graph[i]]]==i: print('YES') break print('NO') ```
-1
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n500\n500", "output": "0.5" }, { "input": "1000\n1\n1", "output": "500" }, { "input": "1000\n1\n500", "output": "1.996007984" }, { "input": "1000\n500\n1", "output": "998.003992" }, { "input": "1000\n500\n500", "output": "500" }, { "input": "101\n11\n22", "output": "33.66666667" }, { "input": "987\n1\n3", "output": "246.75" }, { "input": "258\n25\n431", "output": "14.14473684" }, { "input": "979\n39\n60", "output": "385.6666667" }, { "input": "538\n479\n416", "output": "287.9351955" }, { "input": "583\n112\n248", "output": "181.3777778" }, { "input": "978\n467\n371", "output": "545.0190931" }, { "input": "980\n322\n193", "output": "612.7378641" }, { "input": "871\n401\n17", "output": "835.576555" }, { "input": "349\n478\n378", "output": "194.885514" }, { "input": "425\n458\n118", "output": "337.9340278" }, { "input": "919\n323\n458", "output": "380.0729834" }, { "input": "188\n59\n126", "output": "59.95675676" }, { "input": "644\n428\n484", "output": "302.2280702" }, { "input": "253\n80\n276", "output": "56.85393258" }, { "input": "745\n152\n417", "output": "199.0158172" }, { "input": "600\n221\n279", "output": "265.2" }, { "input": "690\n499\n430", "output": "370.6243272" }, { "input": "105\n68\n403", "output": "15.15923567" }, { "input": "762\n462\n371", "output": "422.6218487" }, { "input": "903\n460\n362", "output": "505.3284672" }, { "input": "886\n235\n95", "output": "630.9393939" }, { "input": "655\n203\n18", "output": "601.6515837" }, { "input": "718\n29\n375", "output": "51.53960396" }, { "input": "296\n467\n377", "output": "163.7819905" }, { "input": "539\n61\n56", "output": "281.017094" }, { "input": "133\n53\n124", "output": "39.82485876" }, { "input": "998\n224\n65", "output": "773.5363322" }, { "input": "961\n173\n47", "output": "755.6954545" }, { "input": "285\n468\n62", "output": "251.6603774" }, { "input": "496\n326\n429", "output": "214.1668874" }, { "input": "627\n150\n285", "output": "216.2068966" }, { "input": "961\n443\n50", "output": "863.535497" }, { "input": "623\n422\n217", "output": "411.4334898" }, { "input": "678\n295\n29", "output": "617.3148148" } ]
1,445,764,017
417
Python 3
OK
TESTS
45
77
512,000
import sys from collections import deque read = lambda: list(map(int, sys.stdin.readline().split())) l,= read() p, = read() q, = read() print (l*p/(p+q))
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. Input Specification: The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. Output Specification: Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['100\n50\n50\n', '199\n60\n40\n'] Demo Output: ['50\n', '119.4\n'] Note: In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
```python import sys from collections import deque read = lambda: list(map(int, sys.stdin.readline().split())) l,= read() p, = read() q, = read() print (l*p/(p+q)) ```
3