messages
listlengths
1
1
ground_truth
stringlengths
88
726k
dataset
stringclasses
2 values
[ { "content": "Solve the following coding problem using the programming language python:\n\nStepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. [Image] \n\nSo, for example, to show the...
[{"type": "stdin_stdout", "input": "255\n", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n"}, {"type": "stdin_stdout", "input": "156\n", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n.\n\nEa...
[{"type": "stdin_stdout", "input": "4 2\n1 2\n3 4\n1 2 3 3\n", "output": "3\n2\n1\n3\n"}, {"type": "stdin_stdout", "input": "4 3\n1 2\n2 3\n3 4\n1 1 3 2\n", "output": "-1"}, {"type": "stdin_stdout", "input": "4 3\n4 3\n3 2\n2 1\n3 4 4 4\n", "output": "-1"}, {"type": "stdin_stdout", "input": "4 3\n1 2\n2 3\n3 4\n1 1 1 2...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a string, consisting of lowercase Latin letters.\n\nA pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string \"abaca\" contains ...
[{"type": "stdin_stdout", "input": "4\nabcd\ngg\ncodeforces\nabaca\n", "output": "bdac\ngg\ndfrcceeoos\nNo answer\n"}, {"type": "stdin_stdout", "input": "1\neefbhgeabache\n", "output": "bbfhhaaceeeeg\n"}, {"type": "stdin_stdout", "input": "1\nheaghhcgfb\n", "output": "bfhhhacegg\n"}, {"type": "stdin_stdout", "input": "...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOn a chessboard with a width of $10^9$ and a height of $10^9$, the rows are numbered from bottom to top from $1$ to $10^9$, and the columns are numbered from left to right from $1$ to $10^9$. Therefore, for each cell of t...
[{"type": "stdin_stdout", "input": "0 5\n1 96762320 50510976\n243235878 312125306 50510976\n326016273 338641867 50510976\n385105810 445224816 50510976\n456157384 569789185 50510976\n", "output": "0"}, {"type": "stdin_stdout", "input": "4 7\n1\n2\n3\n4\n1 1000000000 1\n1 1000000000 2\n1 1000000000 3\n1 1000000000 4\n1 1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOne day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and s...
[{"type": "stdin_stdout", "input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in...
[{"type": "stdin_stdout", "input": "6\n4 1 12 9 3 11\n12 20 19 12 19 11\n", "output": "917\n"}, {"type": "stdin_stdout", "input": "6\n16 20 18 7 14 2\n17 12 4 10 7 4\n", "output": "741\n"}, {"type": "stdin_stdout", "input": "3\n1 1000 10000\n10 100 100000\n", "output": "543210\n"}, {"type": "stdin_stdout", "input": "6\...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.\n\nAt some points on the road there are n friends...
[{"type": "stdin_stdout", "input": "10\n20 11 17 38 15 27 2 40 24 37\n22 30 22 30 28 16 7 20 22 13\n", "output": "1.750000000000\n"}, {"type": "stdin_stdout", "input": "3\n1 1000000000 2\n1 2 1000000000\n", "output": "333333332.999999999971\n"}, {"type": "stdin_stdout", "input": "5\n1 15 61 29 43\n15 11 19 19 19\n", "o...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. \n\nThere are n directed roads in the Udayland. i-th of them goes from town i to ...
[{"type": "stdin_stdout", "input": "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 21 62 33 16 81 14 19 48 80 73 69 78 39 6 76 46 75 72 84 29 58 59 13 17 82 9 83 4 36 56 53 7 64 44\n", "output": "428380105\n"}, {"type"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJack 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.\n\nMunhattan consists of n streets and m ...
[{"type": "stdin_stdout", "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 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAs Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n...
[{"type": "stdin_stdout", "input": "1980 464\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))(()))))))(())((())))()())()((())())()())))(())()(()))(()())()((((()))())()(())))))(()()(()(((((()(()()))(((()))(())))))()())(())))))())()()((())))))))((()(())))))()()(()((()((()()))(()))(())(()))()((((())()()))))))()(()...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAlice is playing with some stones.\n\nNow there are three numbered heaps of stones. The first of them contains $a$ stones, the second of them contains $b$ stones and the third of them contains $c$ stones.\n\nEach time she...
[{"type": "stdin_stdout", "input": "64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 3 3\n1 0 0\n1 0 1\n1 0 2\n1 0 3\n1 1 0\n1 1 1\n1 1 2\n1 1 3\n1 2 0\n1 2 1\n1 2 2\n1 2 3\n1 3 0\n1 3 1\n1 3 2\n1 3 3\n2 0 0\n2 0 1\n2 0 2\n2 0 3\n2 1 0\n2 1 1\n2 1 2\n2 1 3\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nToday Johnny wants to increase his contribution. His plan assumes writing $n$ blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of ...
[{"type": "stdin_stdout", "input": "25 50\n25 2\n6 17\n11 4\n3 18\n11 20\n6 7\n24 15\n1 8\n13 5\n12 25\n15 18\n14 21\n13 6\n5 10\n3 14\n1 2\n23 13\n12 20\n6 4\n8 9\n3 5\n10 7\n20 2\n20 18\n7 4\n8 25\n15 6\n24 14\n2 23\n2 13\n11 3\n16 21\n18 10\n22 1\n5 24\n6 18\n22 23\n4 13\n8 18\n5 20\n22 17\n20 7\n19 15\n10 12\n2 3\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere is a square of size $10^6 \\times 10^6$ on the coordinate plane with four points $(0, 0)$, $(0, 10^6)$, $(10^6, 0)$, and $(10^6, 10^6)$ as its vertices.\n\nYou are going to draw segments on the plane. All segments a...
[{"type": "stdin_stdout", "input": "3 3\n2 3 1000000\n4 0 4\n3 0 1000000\n4 0 1\n2 0 5\n3 1 1000000\n", "output": "7"}, {"type": "stdin_stdout", "input": "1 1\n231451 171893 1000000\n355017 0 1000000\n", "output": "3"}, {"type": "stdin_stdout", "input": "1 1\n999999 999999 1000000\n999999 0 999999\n", "output": "2"}, {...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.\n\nInitially the bus is empty. On each of $2n$ s...
[{"type": "stdin_stdout", "input": "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111\n", "output": "6 3 3 7 1 9 10 2 8 5 4 4 5 8 2 10 9 1 7 6 \n"}, {"type": "stdin_stdout", "input": "6\n10 8 9 11 13 5\n010010011101\n", "output": "6 6 2 3 3 1 4 4 1 2 5 5 \n"}, {"type": "stdin_stdout", "input": "2\n1000000000 99999...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the ...
[{"type": "stdin_stdout", "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 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOf course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains a_{i} animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Nat...
[{"type": "stdin_stdout", "input": "10 19\n13637 26970 19043 3616 12880 19387 12539 25190 2452 1261\n1 2\n1 3\n1 4\n2 5\n3 6\n6 7\n3 8\n5 9\n3 10\n4 10\n9 3\n2 8\n4 3\n2 3\n7 10\n7 8\n5 10\n5 6\n7 4\n", "output": "8241.422222\n"}, {"type": "stdin_stdout", "input": "10 19\n15704 19758 26631 25050 22778 15041 8487 26418 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn this problem you will have to deal with a real algorithm that is used in the VK social network.\n\nAs in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regul...
[{"type": "stdin_stdout", "input": "19 3 1.333333\n12 15 11 10 16 4 9 2 24 3 6 3 21 21 2 16 13 12 2\n17\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n", "output": "12.666667 7.250003 0.427631\n12.000000 7.937505 0.338541\n12.333333 9.953131 0.192989\n10.000000 8.464850 0.153515\n9.666667 8.598640 0.110486\n5.000000 6.9...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe marmots have prepared a very easy problem for this year's HC^2 – this one. It involves numbers n, k and a sequence of n positive integers a_1, a_2, ..., a_{n}. They also came up with a beautiful and riveting story for...
[{"type": "stdin_stdout", "input": "100 60\n1443 3849 6174 8249 696 8715 3461 9159 4468 2496 3044 2301 2437 7559 7235 7956 8959 2036 4399 9595 8664 9743 7688 3730 3705 1203 9332 7088 8563 3823 2794 8014 6951 1160 8616 970 9885 2421 6510 4885 5246 6146 8849 5141 8602 9486 7257 3300 8323 4797 4082 7135 80 9622 4543 6567 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRidhiman challenged Ashish to find the maximum valued subsequence of an array $a$ of size $n$ consisting of positive integers. \n\nThe value of a non-empty subsequence of $k$ elements of $a$ is defined as $\\sum 2^i$ over...
[{"type": "stdin_stdout", "input": "20\n541032394951352952 204302388514120798 548305186805250399 743987576790520671 332874928746186630 60150973547887825 600093435051546090 862815570651991829 798946884837606574 383607230476788640 748981752333005915 317959714195378963 824508576221039025 547099154391774856 411018774272655...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no ...
[{"type": "stdin_stdout", "input": "100\n6072 8210 6405 1191 2533 8552 7594 8793 2207 8855 7415 6252 3433 2339 5532 3118 3054 5750 3690 9843 3881 1390 936 8611 7099 988 7730 3835 7065 5030 6932 6936 5531 5173 1331 8975 5454 1592 8516 328 1091 4368 8275 6462 8638 4002 5534 113 6295 5960 1688 3668 6604 9632 4214 8687 795...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enu...
[{"type": "stdin_stdout", "input": "10\n1 1 2 4 2 4 1 8 8\n", "output": "1 1 1 1 1 1 2 2 3 6 \n"}, {"type": "stdin_stdout", "input": "10\n1 2 2 3 3 4 4 5 5\n", "output": "1 1 1 1 1 2 2 3 5 5 \n"}, {"type": "stdin_stdout", "input": "10\n1 1 1 1 1 1 1 1 1\n", "output": "1 1 1 1 1 1 1 1 1 9 \n"}, {"type": "stdin_stdout", ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLittle town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any oth...
[{"type": "stdin_stdout", "input": "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5 4 1 5\n1 2\n2 3\n3 4\n4 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 4 3 5\n1 2\n2 3\n3 4\n4 5\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "3 3 2 3\n1 2\n2 3\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou have a playlist consisting of $n$ songs. The $i$-th song is characterized by two numbers $t_i$ and $b_i$ — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of ...
[{"type": "stdin_stdout", "input": "10 1\n74069 59157\n2735 28902\n43406 39542\n24166 93361\n18565 14980\n69958 53925\n23473 81878\n89682 3949\n18757 31637\n31665 45873\n", "output": "4381699833\n"}, {"type": "stdin_stdout", "input": "8 1\n769 58454\n48687 67740\n51730 90641\n39410 27719\n63633 23862\n39951 40870\n5652...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThis is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.\n\nYou are given a s...
[{"type": "stdin_stdout", "input": "10\nu\nxqpczgnzazxyrvx\ncfjgfhxmzqmjgzzjthziuomldylspyfuxvjlgdc\nooydbldio\nyvaamavy\nrzjjebcgotjffuzr\nhtfkwvihzuwxczopzqujdnaorgxibjfcmlzntskawxhyoymwynitukttewfpajuph\nfactnjajntcaf\nywowyovhrgradhtrqkgurkjpudnrrqhmmwiaqicfxnoyejdsmmurusdzqgjjntocryhqsgr\nqq\n", "output": "u\nxqx\...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are playing a computer game, where you lead a party of $m$ soldiers. Each soldier is characterised by his agility $a_i$.\n\nThe level you are trying to get through can be represented as a straight line segment from po...
[{"type": "stdin_stdout", "input": "53 1 27 3\n44 28 48 60 29 42 59 32 9 58 3 11 7 53 4 19 37 41 36 52 29 9 24 8 31 39 52 41 37 44 26 37 37 48 6 21 20 42 25 3 33 2 35 39 33 23 10 60 48 4 1 28 21\n1 1 11\n1 1 21\n1 1 3\n1 1 42\n1 1 16\n1 1 32\n1 1 52\n1 1 17\n1 1 39\n1 1 22\n1 1 31\n1 1 50\n1 1 23\n1 1 14\n1 1 41\n1 1 5...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYour program fails again. This time it gets \"Wrong answer on test 233\".\n\nThis is the harder version of the problem. In this version, $1 \\le n \\le 2\\cdot10^5$. You can hack this problem if you locked it. But you can...
[{"type": "stdin_stdout", "input": "100 100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 2...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLittle Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.\n\nThere are n toy cars. Each pair...
[{"type": "stdin_stdout", "input": "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\n-1 0 0\n0 -1 1\n0 2 -1\n", "output": "2\n1 3 "}, {"type": "stdin_stdout", "input": "2\n-1 0\n0 -1\n", "output": "2\n1 2 "}, {"type": "stdin_stdout", "input": "2\n-1 1\n2 -1\n", "outp...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGuy-Manuel and Thomas have an array $a$ of $n$ integers [$a_1, a_2, \\dots, a_n$]. In one step they can add $1$ to any element of the array. Formally, in one step they can choose any integer index $i$ ($1 \\le i \\le n$) ...
[{"type": "stdin_stdout", "input": "1\n100\n64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 -64 64 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMonocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from $1$ to $n$. For every edge $e$ of this tree, Monocarp has written two number...
[{"type": "stdin_stdout", "input": "15\n10 15\n12 15\n6 15\n8 15\n2 15\n3 15\n10 15\n13 15\n5 15\n7 15\n11 15\n4 14\n1 15\n14 15\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "15\n9 15\n6 15\n12 15\n3 14\n14 15\n11 15\n6 15\n7 15\n10 15\n4 15\n1 15\n13 15\n2 15\n9 15\n", "output": "NO\n"}, {"type": "stdin_st...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user re...
[{"type": "stdin_stdout", "input": "10 3 30000\n00:06:54\n00:42:06\n03:49:45\n04:38:35\n05:33:30\n05:51:46\n10:46:34\n14:34:59\n14:40:06\n14:53:13\n", "output": "6\n1\n2\n3\n3\n3\n3\n4\n5\n6\n6\n"}, {"type": "stdin_stdout", "input": "7 4 30000\n05:08:54\n05:35:53\n06:03:20\n06:17:50\n09:29:46\n11:35:29\n14:49:02\n", "o...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOne foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any ...
[{"type": "stdin_stdout", "input": "15\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\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1\n", "out...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given three multisets of pairs of colored sticks: $R$ pairs of red sticks, the first pair has length $r_1$, the second pair has length $r_2$, $\\dots$, the $R$-th pair has length $r_R$; $G$ pairs of green stick...
[{"type": "stdin_stdout", "input": "16 26 8\n44 13 2 24 56 74 72 4 87 98 43 4 17 30 82 8\n31 6 76 32 88 37 19 64 44 55 18 67 72 75 10 45 47 89 33 100 76 1 58 38 34 38\n31 37 82 36 67 86 81 6\n", "output": "73851\n"}, {"type": "stdin_stdout", "input": "9 4 7\n17 19 19 9 20 6 1 14 11\n15 12 10 20\n15 10 3 20 1 16 7\n", "...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAfter battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the ...
[{"type": "stdin_stdout", "input": "58260522 77914575 2436426 24979445 61648772 23690081\n10\n582107247 906728404 411434947 673536177 411497300 488012525 561127307 800305059 992325267 112738006\n", "output": "804109112\n"}, {"type": "stdin_stdout", "input": "158260522 877914575 602436426 24979445 861648772 623690081\n1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGiven an array $a$ of length $n$, find another array, $b$, of length $n$ such that:\n\n for each $i$ $(1 \\le i \\le n)$ $MEX(\\{b_1$, $b_2$, $\\ldots$, $b_i\\})=a_i$. \n\nThe $MEX$ of a set of integers is the smallest n...
[{"type": "stdin_stdout", "input": "10\n1 2 3 4 4 4 7 7 7 10\n", "output": "0 1 2 3 5 6 4 8 9 7 "}, {"type": "stdin_stdout", "input": "7\n0 0 2 2 5 5 6\n", "output": "1 3 0 4 2 7 5 "}, {"type": "stdin_stdout", "input": "4\n0 0 0 2\n", "output": "1 3 4 0 "}, {"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "0 1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nHappy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.\n\...
[{"type": "stdin_stdout", "input": "10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\n", "output": "sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c_1, c_2, ..., c_{n}. The Old Peykan wants to travel from city c_1 to c_{n...
[{"type": "stdin_stdout", "input": "100 6\n15 20 32 8 29 10 33 15 9 26 28 21 34 7 41 23 9 17 16 15 14 29 25 31 24 26 13 18 19 40 9 16 36 32 39 11 4 31 37 28 32 40 7 18 45 21 15 45 6 15 27 22 27 41 28 7 22 43 25 40 6 7 32 31 36 14 5 27 31 28 23 9 13 14 7 25 28 33 40 22 44 9 29 26 41 30 16 15 31 42 13 40 36 44 17 29 32 2...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nDima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one...
[{"type": "stdin_stdout", "input": "11 11 9 11\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 2 2 1\n1 1 1 1 1 1 1 1 3 1 1\n1 1 1 1 1 1 1 3 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1 1 2 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1\n3 3 3 3 3 3 3 3 3 2...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an undirected graph without self-loops or multiple edges which consists of $n$ vertices and $m$ edges. Also you are given three integers $n_1$, $n_2$ and $n_3$.\n\nCan you label each vertex with one of three...
[{"type": "stdin_stdout", "input": "5000 5\n1000 1000 3000\n4 11\n11 7\n7 127\n127 999\n999 4\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5 9\n0 2 3\n1 2\n1 3\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "6 3\n2 2 2\n3 1\n5 4\n2 5\n", "output": "YES\n112323\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: \n\n The product of all numbers in the first set is less than zero ( < 0). The...
[{"type": "stdin_stdout", "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000\n", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000\n"}, {"type": "stdin_stdout", "input": "5\n-1 -2 -3 -4 0\n", "output...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are many freight trains departing from Kirnes planet every day. One day on that planet consists of $h$ hours, and each hour consists of $m$ minutes, where $m$ is an even number. Currently, there are $n$ freight trai...
[{"type": "stdin_stdout", "input": "10 24 60 8\n10 59\n21 56\n0 42\n21 27\n5 24\n5 53\n16 5\n5 22\n10 11\n10 46\n", "output": "1 5\n1 \n"}, {"type": "stdin_stdout", "input": "9 24 60 21\n1 36\n2 35\n2 16\n2 55\n1 16\n0 35\n0 55\n1 56\n0 15\n", "output": "5 16\n1 2 6 8 9 \n"}, {"type": "stdin_stdout", "input": "9 3 24 9...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAndrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.\n\nA bar of chocolate can be presented as an n × n table, where each cell represents one piece...
[{"type": "stdin_stdout", "input": "20 10\n10 11 U\n12 9 U\n6 15 L\n17 4 U\n11 10 L\n7 14 L\n4 17 U\n2 19 L\n8 13 L\n14 7 U\n", "output": "11\n9\n6\n4\n1\n7\n2\n2\n8\n7\n"}, {"type": "stdin_stdout", "input": "10 10\n5 6 U\n4 7 U\n8 3 L\n8 3 L\n1 10 U\n9 2 U\n10 1 L\n10 1 L\n8 3 U\n8 3 U\n", "output": "6\n7\n3\n0\n10\n2...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct.\n\nYou have two types of spells which you may cast: Fireball: you spend $x$ mana and destroy exactly $k$ conse...
[{"type": "stdin_stdout", "input": "23 5\n10 3 3\n2 1 4 11 8 10 5 6 7 9 12 3 14 13 16 18 21 15 17 19 20 23 22\n4 6 3 18 23\n", "output": "56\n"}, {"type": "stdin_stdout", "input": "23 5\n10 3 4\n2 1 4 11 8 10 5 6 7 9 12 3 14 13 16 18 21 15 17 19 20 23 22\n4 6 3 18 23\n", "output": "64\n"}, {"type": "stdin_stdout", "inp...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.\n\nA tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can ...
[{"type": "stdin_stdout", "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6\n", "output": "16\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nEgor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!\n\nBefore you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook move...
[{"type": "stdin_stdout", "input": "12\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 \n24 23 22 21 20 19 18 17 16 15 14 13 \n25 26 27 28 29 30 31 32 33 34 35 36 \n48 47 46 45 44 43 42 41 40 39 38 37 \n49 50 51 52 53 54 55 56 57 58 59 60 \n72 71 70 69 68 67 66 65 64 63 62 61 \n73 74 75 76 77 78 79 80 81 82 83 84 \n96 95 94 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a sequence of positive integers a_1, a_2, ..., a_{n}. \n\nWhile possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmo...
[{"type": "stdin_stdout", "input": "4\n1000000000 1000000000 1000000000 1000000000\n", "output": "1\n1000000002 "}, {"type": "stdin_stdout", "input": "7\n4 10 22 11 12 5 6\n", "output": "7\n4 10 22 11 12 5 6 "}, {"type": "stdin_stdout", "input": "7\n5 5 4 4 5 6 7\n", "output": "3\n7 6 7 "}, {"type": "stdin_stdout", "in...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAyush is a cashier at the shopping center. Recently his department has started a ''click and collect\" service which allows users to shop online. \n\nThe store contains k items. n customers have already used the above ser...
[{"type": "stdin_stdout", "input": "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99 65 20 52 35 85 16 12 94 100 59 56 18 33 47 46 71 8 38 57 2 92 3 95 6 4 87 22 48 80 15 29 11 45 72 76 44 60 91 90 39 74 41 36 13 27 53 83 32 5 30 63 89 64 49 17 9 97 69 14 50 77 37 96 10 42 28 34 61 19...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe Resistance is trying to take control over as many planets of a particular solar system as possible. Princess Heidi is in charge of the fleet, and she must send ships to some planets in order to maximize the number of ...
[{"type": "stdin_stdout", "input": "24\n19 14\n8 15\n13 4\n18 16\n1 17\n10 3\n22 21\n10 14\n6 11\n9 12\n15 22\n11 3\n21 7\n2 12\n7 4\n4 19\n16 9\n24 17\n5 15\n8 2\n23 10\n20 6\n18 24\n", "output": "1 21 22 23 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 "}, {"type": "stdin_stdout", "input": "23\n5 14\n6 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMerge sort is a well-known sorting algorithm. The main function that sorts the elements of array a with indices from [l, r) can be implemented as follows: If the segment [l, r) is already sorted in non-descending order (...
[{"type": "stdin_stdout", "input": "10 17\n", "output": "3 1 4 6 2 8 5 9 7 10 "}, {"type": "stdin_stdout", "input": "10000 20001\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "10000 30001\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4 1\n", "output": "1 2 3 4 "}, {"type": "stdin_stdout", "input"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya owns three big integers — $a, l, r$. Let's define a partition of $x$ such a sequence of strings $s_1, s_2, \\dots, s_k$ that $s_1 + s_2 + \\dots + s_k = x$, where $+$ is a concatanation of strings. $s_i$ is the $i$-...
[{"type": "stdin_stdout", "input": "12212222221212222221221221222222121222222122\n22222111112222222222221221222222121222222122\n22222111112222222222221221222222121222222122\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "125429881687275810781487376863889485121533477240648754964022073352435412308497715179924461...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nWhereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.\n\n\n-----Input-----\n\nSame as the easy v...
[{"type": "stdin_stdout", "input": "11 1\n1 2 3 5 1 10 10 1 1 3 5\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "4 100\n1 2 2 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 2\n1 2 3 1 2\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "4 1\n1 2 2 1\n", "output": "3\n"}, {"type": "stdin_st...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nCaisa solved the problem with the sugar and now he is on the way back to home. \n\nCaisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has ze...
[{"type": "stdin_stdout", "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nInnokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \\cdot m$ colored pieces that form a rectangle with $n$ ...
[{"type": "stdin_stdout", "input": "10 10\naaaaarpppp\nbbbbsssssu\ncciiiiiiqq\nddmmgggggg\neeebbbbbbb\nfffffqoooo\ngxxxxrrrrr\nhhfuuuuuuu\niiillqqqqq\njjjjjppwww\n", "output": "138\n"}, {"type": "stdin_stdout", "input": "10 10\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeeeeee\nffffffffff\ngggggggggg\nhhhhhhhh...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLuckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.\n\nHe has a special interest to create difficult problems for others to so...
[{"type": "stdin_stdout", "input": "2 58 77\n0 0 0 0 6 0 0 0 40 0 0 0 0 22 0 0 41 74 0 0 0 0 0 0 0 15 0 0 60 5 69 0 0 30 0 0 23 60 0 35 0 0 0 0 0 0 69 0 0 0 0 0 0 0 0 0 0 0\n0 74\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\n0 0 0 0 1 0 0 0 1 0 0 0...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.\n\nBerland bills somehow come in lots of different sizes. However, all of them are shaped as rec...
[{"type": "stdin_stdout", "input": "69\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n+ 1 2\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nCreatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror \"Am I beautiful?\". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\\frac{p_i}{100}$ for all $1 \\...
[{"type": "stdin_stdout", "input": "100\n60 79 48 35 18 24 87 1 44 65 60 78 11 43 71 79 90 6 94 49 22 91 58 93 55 21 22 31 7 15 17 65 76 9 100 89 50 96 14 38 27 87 29 93 54 12 99 35 27 51 36 44 6 26 91 1 53 8 49 63 18 4 31 55 95 15 77 1 16 98 75 26 26 43 2 11 18 70 3 65 11 74 64 69 26 54 9 51 25 82 98 12 90 75 19 23 78...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. I...
[{"type": "stdin_stdout", "input": "4\n9 17\n3 6\n2 6\n6 9\n4 1\n2 8\n1 9\n7 9\n8 5\n1 7\n4 9\n6 7\n3 4\n9 3\n8 4\n2 1\n3 8\n2 7\n5 6\n2 5\n3 4\n1 3\n4 5\n5 3\n2 3\n12 8\n10 2\n9 2\n6 9\n10 6\n8 2\n4 10\n11 2\n4 11\n19 10\n6 2\n3 12\n17 7\n2 19\n17 4\n1 13\n7 1\n13 7\n6 8\n11 7\n", "output": "7\n1 9\n9 7\n7 6\n6 9\n5 8...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence $a_1, \\ldots, a_n$. In order to not reveal the secret earlier...
[{"type": "stdin_stdout", "input": "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 7 7 7 7 15 15 31\n", "output": "Yes\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 \n"}, {"type": "stdin_stdout", "input": "6\n4 7 7 12 31 61\n", "output": "Yes\n4 12 7 31 7 61 \n"}, {"type": "stdin_stdout", "inpu...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRamesses knows a lot about problems involving trees (undirected connected graphs without cycles)!\n\nHe created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!\n\nThe d...
[{"type": "stdin_stdout", "input": "5\n1 2\n1 3\n1 4\n1 5\n", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5\n"}, {"type": "stdin_stdout", "input": "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8\n", "output": "No\n"}, {"type": "stdin_stdo...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.\n\n speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign ...
[{"type": "stdin_stdout", "input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10\n1 5\n4\n5\n4\n1 21\n6\n1 10\n1 1\n2\n3 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10\n1 37\n6\n5\n2\n5\n6\n5\n2\n4\n2\n", "output": "2\n"}, {"type":...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAnton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.\n\nThere are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored tre...
[{"type": "stdin_stdout", "input": "42\n1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0\n35 6\n35 39\n4 31\n31 5\n14 35\n1 2\n40 32\n35 31\n37 35\n32 38\n1 36\n3 25\n35 11\n26 35\n24 35\n3 2\n35 23\n21 1\n20 27\n16 26\n2 18\n34 39\n39 28\n3 32\n26 30\n41 7\n13 35\n1 8\n31 22\n33 21\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMarcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.\n\nLet's focus on the st...
[{"type": "stdin_stdout", "input": "10\n206158430208 206162624513 68719476737 137506062337 206162624513 4194305 68719476737 206225539072 137443147777 68719476736\n202243898 470292528 170057449 290025540 127995253 514454151 607963029 768676450 611202521 68834463\n", "output": "2773043292\n"}, {"type": "stdin_stdout", "i...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThey say \"years are like dominoes, tumbling one after the other\". But would a year fit into a grid? I don't think so.\n\nLimak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows...
[{"type": "stdin_stdout", "input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n...................................
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPink Floyd are pulling a prank on Roger Waters. They know he doesn't like walls, he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.\n\nRoger Waters has a square...
[{"type": "stdin_stdout", "input": "1\n10\nS000000000\n0000000000\n0000000000\n0000000000\n0000001000\n0000000101\n0000000000\n0000000000\n0000000000\n000000000F\n", "output": "2\n9 10\n10 9\n"}, {"type": "stdin_stdout", "input": "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n", ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGhosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.\n\nThere are $n$ ghosts in the universe, they move in the $OXY$ plane, each one of them has its own...
[{"type": "stdin_stdout", "input": "10 7 -626288749\n795312099 49439844 266151109\n-842143911 23740808 624973405\n-513221420 -44452680 -391096559\n-350963348 -5068756 -160670209\n690883790 11897718 3356227\n-509035268 -45646185 -210137445\n-121282138 -32581578 230716703\n491731655 9500548 -13423963\n-665038289 48170248...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.\n...
[{"type": "stdin_stdout", "input": "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 34 16 25 14 45 35 38 46 48 49 27 49...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a chess board with $n$ rows and $n$ columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.\n\nA knight is a chess piece that can attac...
[{"type": "stdin_stdout", "input": "13\n", "output": "WBWBWBWBWBWBW\nBWBWBWBWBWBWB\nWBWBWBWBWBWBW\nBWBWBWBWBWBWB\nWBWBWBWBWBWBW\nBWBWBWBWBWBWB\nWBWBWBWBWBWBW\nBWBWBWBWBWBWB\nWBWBWBWBWBWBW\nBWBWBWBWBWBWB\nWBWBWBWBWBWBW\nBWBWBWBWBWBWB\nWBWBWBWBWBWBW\n"}, {"type": "stdin_stdout", "input": "10\n", "output": "WBWBWBWBWB\nBW...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two arrays of integers $a_1,\\ldots,a_n$ and $b_1,\\ldots,b_m$.\n\nYour task is to find a non-empty array $c_1,\\ldots,c_k$ that is a subsequence of $a_1,\\ldots,a_n$, and also a subsequence of $b_1,\\ldots,...
[{"type": "stdin_stdout", "input": "5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n", "output": "YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 5\n"}, {"type": "stdin_stdout", "input": "1\n4 4\n1 1 1 1\n1 2 3 4\n", "output": "YES\n1 1\n"}, {"type": "stdin_stdout", "inp...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.\n\nMike has $n$ s...
[{"type": "stdin_stdout", "input": "20\n43 48 38 34 23 18 8 22 12 7 47 1 13 20 3 15 49 6 10 26\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "6\n99997 99995 100000 99992 99994 99999\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5\n99905 99931 99902 99909 99984\n", "output": "1\n"}, {"type": "stdin_...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two integers $a$ and $m$. Calculate the number of integers $x$ such that $0 \\le x < m$ and $\\gcd(a, m) = \\gcd(a + x, m)$.\n\nNote: $\\gcd(a, b)$ is the greatest common divisor of $a$ and $b$.\n\n\n-----In...
[{"type": "stdin_stdout", "input": "10\n164 252\n94 253\n171 254\n196 255\n35 256\n174 257\n251 258\n239 259\n9 260\n98 261\n", "output": "36\n220\n126\n128\n128\n256\n84\n216\n96\n168\n"}, {"type": "stdin_stdout", "input": "10\n36 202\n79 203\n4 204\n140 205\n73 206\n41 207\n61 208\n200 209\n118 210\n75 211\n", "outpu...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRecently Petya walked in the forest and found a magic stick.\n\nSince Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a posit...
[{"type": "stdin_stdout", "input": "7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234\n", "output": "YES\nYES\nNO\nYES\nNO\nYES\nYES\n"}, {"type": "stdin_stdout", "input": "1\n858993461 1000000000\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "1\n98989876 98989877\n", "output": "YES\n"}, {"type": "stdin_stdout...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRecently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.\n\nCity consists of n intersections numbered from 1 to n. Mike starts walking from ...
[{"type": "stdin_stdout", "input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 90 90 90 90 90 90 90 90 90 90 90 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 95 95 95 9...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in gre...
[{"type": "stdin_stdout", "input": "10\n10 10 6\n2 5 1\n3 1 8\n7 5 2\n8 1 6\n7 4 8\n1 10 7\n3 8 2\n5 8 5\n10 3 6\n2 6 10\n4 7 4\n6 6 2\n9 4 9\n4 2 3\n2 2 1\n3 9 2\n5 9 9\n8 1 4\n5 6 2\n8 8 1\n7 8 10\n6 9 3\n4 7 5\n9 4 2\n6 9 10\n1 9 3\n4 5 8\n5 3 7\n8 1 8\n3 10 4\n9 5 7\n2 7 7\n1 5 10\n10 6 6\n6 4 4\n1 10 7\n10 5 9\n9 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nCarol is currently curling.\n\nShe has n disks each with radius r on the 2D plane. \n\nInitially she has all these disks above the line y = 10^100.\n\nShe then will slide the disks towards the line y = 0 one by one in ord...
[{"type": "stdin_stdout", "input": "5 300\n939 465 129 611 532\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\n"}, {"type": "stdin_stdout", "input": "6 2\n5 5 6 8 3 12\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\n"}, {"type": "stdin_stdout", "input": "5 1\n416...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAlicia has an array, $a_1, a_2, \\ldots, a_n$, of non-negative integers. For each $1 \\leq i \\leq n$, she has found a non-negative integer $x_i = max(0, a_1, \\ldots, a_{i-1})$. Note that for $i=1$, $x_i = 0$.\n\nFor exa...
[{"type": "stdin_stdout", "input": "35\n15 13 -19 -7 -28 -16 4 -10 2 -23 -6 -5 -26 -27 -24 -27 -22 1 -32 -19 -16 -15 -29 -26 -25 -17 -11 -20 -2 -11 -20 -30 -1 -7 -27\n", "output": "15 28 9 21 0 12 32 22 34 11 28 29 8 7 10 7 12 35 3 16 19 20 6 9 10 18 24 15 33 24 15 5 34 28 8 "}, {"type": "stdin_stdout", "input": "10\n1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a sequence $s$ consisting of $n$ digits from $1$ to $9$.\n\nYou have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators be...
[{"type": "stdin_stdout", "input": "21\n3\n123\n3\n123\n3\n123\n3\n123\n3\n123\n3\n213\n3\n123\n3\n123\n3\n123\n3\n321\n3\n123\n3\n321\n3\n132\n3\n322\n3\n321\n3\n341\n3\n123\n3\n421\n3\n421\n3\n421\n3\n421\n", "output": "YES\n2\n1 23\nYES\n2\n1 23\nYES\n2\n1 23\nYES\n2\n1 23\nYES\n2\n1 23\nYES\n2\n2 13\nYES\n2\n1 23\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are $n$ beautiful skyscrapers in New York, the height of the $i$-th one is $h_i$. Today some villains have set on fire first $n - 1$ of them, and now the only safety building is $n$-th skyscraper.\n\nLet's call a ju...
[{"type": "stdin_stdout", "input": "5\n100 1 100 1 100\n", "output": "2"}, {"type": "stdin_stdout", "input": "5\n1 3 1 4 5\n", "output": "3"}, {"type": "stdin_stdout", "input": "5\n1 5 5 1 4\n", "output": "2"}, {"type": "stdin_stdout", "input": "4\n4 2 2 4\n", "output": "1"}, {"type": "stdin_stdout", "input": "4\n2 3 4...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share...
[{"type": "stdin_stdout", "input": "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 130 163 282 298 605 349 270 198 24 179 243 92 115 56 83 26 3 456 622 325 366 360 299 153 140 552 216 117 61 307...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSince Sonya has just learned the basics of matrices, she decided to play with them a little bit.\n\nSonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all o...
[{"type": "stdin_stdout", "input": "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\n", "output": "4 5\n2 2\n"}, {"type": "stdin_stdout", "input": "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\n", "output": "3 6\n2 3\n"}, {"type": "stdin_stdout", "input": "7\n0 1 2 3 4 2 6\n", "output": "-1\n"}, {"type": "stdin_stdout", "input"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider a sequence of digits of length $2^k$ $[a_1, a_2, \\ldots, a_{2^k}]$. We perform the following operation with it: replace pairs $(a_{2i+1}, a_{2i+2})$ with $(a_{2i+1} + a_{2i+2})\\bmod 10$ for $0\\le i<2^{k-1}$. F...
[{"type": "stdin_stdout", "input": "20\n4 8 6 6 3 0 1 8 3 6 1 4 3 2 1 3 6 4 5 4\n15\n16 19\n3 10\n9 9\n3 18\n6 7\n15 18\n12 19\n17 18\n12 12\n6 9\n3 10\n1 2\n2 3\n4 19\n16 16\n", "output": "1\n3\n0\n5\n0\n1\n2\n1\n0\n1\n3\n1\n1\n5\n0\n"}, {"type": "stdin_stdout", "input": "10\n6 6 8 8 2 5 0 1 2 1\n5\n5 6\n3 6\n8 9\n7 8...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe little girl loves the problems on array queries very much.\n\nOne day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there...
[{"type": "stdin_stdout", "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nHeidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked...
[{"type": "stdin_stdout", "input": "11\n1 0 6646\n2 0 8816\n3 2 9375\n4 2 5950\n5 1 8702\n6 2 2657\n7 2 885\n8 7 2660\n9 2 5369\n10 6 3798\n", "output": "18191\n"}, {"type": "stdin_stdout", "input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n", "output": "555...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAlice and Bob are playing a game on a line with $n$ cells. There are $n$ cells labeled from $1$ through $n$. For each $i$ from $1$ to $n-1$, cells $i$ and $i+1$ are adjacent.\n\nAlice initially has a token on some cell on...
[{"type": "stdin_stdout", "input": "50 75\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 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 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "50000 30...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.\n\nVasya decided to organize information about the phone numbers of frie...
[{"type": "stdin_stdout", "input": "20\no 10 6 6 97 45 6 6 6 6 5 6\nl 8 5 5 5 19 59 5 8 5\nj 9 2 30 58 2 2 1 0 30 4\nc 10 1 1 7 51 7 7 51 1 1 1\no 9 7 97 87 70 2 19 2 14 6\ne 6 26 6 6 6 26 5\ng 9 3 3 3 3 3 78 69 8 9\nl 8 8 01 1 5 8 41 72 3\nz 10 1 2 2 2 9 1 9 1 6 7\ng 8 7 78 05 36 7 3 67 9\no 5 6 9 9 7 7\ne 10 30 2 1 1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA team of three programmers is going to play a contest. The contest consists of $n$ problems, numbered from $1$ to $n$. Each problem is printed on a separate sheet of paper. The participants have decided to divide the pro...
[{"type": "stdin_stdout", "input": "11 7 9\n4 8 9 12 14 16 19 21 22 23 27\n1 2 3 11 17 18 26\n5 6 7 10 13 15 20 24 25\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "5 10 6\n14 3 6 12 21\n7 1 5 8 10 11 13 17 18 20\n9 2 4 15 16 19\n", "output": "11\n"}, {"type": "stdin_stdout", "input": "1 5 1\n6\n5 1 2 4 7\n3...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nFor a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).\n\nYou are given two positive integers n and m. Let S be the set of all...
[{"type": "stdin_stdout", "input": "1000000 1000000\n", "output": "247171672\n"}, {"type": "stdin_stdout", "input": "1 1000000\n", "output": "2000000\n"}, {"type": "stdin_stdout", "input": "1000000 1\n", "output": "1000001\n"}, {"type": "stdin_stdout", "input": "500 500\n", "output": "383255233\n"}, {"type": "stdin_std...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThis is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.\n\nYou are given a s...
[{"type": "stdin_stdout", "input": "10\nu\nxqpczgnzazxyrvx\ncfjgfhxmzqmjgzzjthziuomldylspyfuxvjlgdc\nooydbldio\nyvaamavy\nrzjjebcgotjffuzr\nhtfkwvihzuwxczopzqujdnaorgxibjfcmlzntskawxhyoymwynitukttewfpajuph\nfactnjajntcaf\nywowyovhrgradhtrqkgurkjpudnrrqhmmwiaqicfxnoyejdsmmurusdzqgjjntocryhqsgr\nqq\n", "output": "u\nxqx\...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to a_{i} ml per second (this amount may be a real number). The water deliver...
[{"type": "stdin_stdout", "input": "20 30\n70 97 14 31 83 22 83 56 19 87 59 7 7 89 24 82 34 40 6 24\n10 4 47 46 11 18 32 55 16 32 53 37 43 32 41 46 57 14 60 44\n", "output": "916.518518518518519\n"}, {"type": "stdin_stdout", "input": "1 1000000\n1000000\n1000000\n", "output": "999999.999999999944407\n"}, {"type": "stdi...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes t...
[{"type": "stdin_stdout", "input": "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "output": "927799753\n"}, {"type": "stdin_stdout", "input": "10\n4 10 -1 1 6 8 9 2 -1 -1\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6\n-1 -1 -1 -1 -1 -1\n", "output": "265\n"}, {"type": "stdin_stdout", ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarpus has an array, consisting of n integers a_1, a_2, ..., a_{n}. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus perf...
[{"type": "stdin_stdout", "input": "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -791 -217 -959 -892 886 -593 427 890 223 -425 -342 -262 693...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA conglomerate consists of $n$ companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies,...
[{"type": "stdin_stdout", "input": "20\n1 773\n7 957 657 854 608 621 874 617\n6 159 43 43 122 116 194\n7 813 984 847 953 808 801 900\n2 693 844\n12 903 910 764 949 990 959 987 884 876 743 838 864\n1 636\n8 107 201 779 203 159 67 550 948\n1 919\n14 934 742 1000 707 801 958 889 980 781 841 927 676 918 841\n7 590 569 480 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nWe have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).\nThe integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,...
[{"type": "stdin_stdout", "input": "5 5 4\n13 25 7 15 17\n16 22 20 2 9\n14 11 12 1 19\n10 6 23 8 18\n3 21 5 24 4\n3\n13 13\n2 10\n13 13\n", "output": "0\n5\n0\n"}, {"type": "stdin_stdout", "input": "1 1 1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"}, {"type": ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nCount the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \\cdots, A_{N} and B_1, B_2, \\cdots, B_{N}, that satisfy all of the following conditions:\n - A_i \\neq B_i, for every i...
[{"type": "stdin_stdout", "input": "141421 356237\n", "output": "881613484\n"}, {"type": "stdin_stdout", "input": "500000 500000\n", "output": "869509376\n"}, {"type": "stdin_stdout", "input": "436426 479445\n", "output": "710501305\n"}, {"type": "stdin_stdout", "input": "148772 190081\n", "output": "685499830\n"}, {"t...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThis morning Chef wants to jump a little. In a few minutes he will arrive at the point 0. Then he will perform a lot of jumps in such a sequence: 1-jump, 2-jump, 3-jump, 1-jump, 2-jump, 3-jump, 1-jump, and so on.\n1-jump ...
[{"type": "stdin_stdout", "input": "0\n", "output": "yes\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "yes\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "yes\n"}, {"type": "stdin_stdout", "input": "6\n", "output": "yes\n"}, {"type": "stdin_stdout", "input": "7\n", "output": "yes\n"}, {"type": "stdi...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou 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.\n\nYou know two languages, and the professor is giving the lecture in th...
[{"type": "stdin_stdout", "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 qrnbv...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOne very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.\n\nThere are n users on the site, for each user we know the r...
[{"type": "stdin_stdout", "input": "10\n20 19 12 1 12 15 2 12 6 10\n", "output": "20 19 12 1 13 15 2 14 6 10\n"}, {"type": "stdin_stdout", "input": "10\n4 5 10 5 2 14 15 6 10 6\n", "output": "4 5 10 6 2 14 15 7 11 8\n"}, {"type": "stdin_stdout", "input": "10\n1 10 1 10 1 1 7 8 6 7\n", "output": "1 10 2 11 3 4 7 9 6 8\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPermutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n ...
[{"type": "stdin_stdout", "input": "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 91 -44 46 51 51 -58 95 77 20 30 76 79 91 60 76 2 82 42 -93 94 -57 88 65 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a sequence of $n$ pairs of integers: $(a_1, b_1), (a_2, b_2), \\dots , (a_n, b_n)$. This sequence is called bad if it is sorted in non-descending order by first elements or if it is sorted in non-descending ...
[{"type": "stdin_stdout", "input": "4\n2 3\n2 2\n2 1\n2 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\n1 1\n2 2\n3 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3\n1 1\n1 1\n2 3\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "3\n3 3\n3 3\n3 3\n", "output": "0\n"}, {"type": "stdin_st...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two integers $A$ and $B$, calculate the number of pairs $(a, b)$ such that $1 \\le a \\le A$, $1 \\le b \\le B$, and the equation $a \\cdot b + a + b = conc(a, b)$ is true; $conc(a, b)$ is the concatenation ...
[{"type": "stdin_stdout", "input": "3\n1 11\n4 2\n191 31415926\n", "output": "1\n0\n1337\n"}, {"type": "stdin_stdout", "input": "1\n12112004 98798745\n", "output": "84784028\n"}, {"type": "stdin_stdout", "input": "1\n8585 8976\n", "output": "25755\n"}, {"type": "stdin_stdout", "input": "1\n8585 99\n", "output": "17170\...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya has got $n$ books, numbered from $1$ to $n$, arranged in a stack. The topmost book has number $a_1$, the next one — $a_2$, and so on. The book at the bottom of the stack has number $a_n$. All numbers are distinct.\n...
[{"type": "stdin_stdout", "input": "10\n4 7 10 2 1 8 3 5 9 6\n4 2 7 1 8 10 5 3 9 6\n", "output": "1 3 0 1 1 0 2 0 1 1 \n"}, {"type": "stdin_stdout", "input": "7\n7 6 3 1 5 4 2\n2 3 1 6 4 7 5\n", "output": "7 0 0 0 0 0 0 \n"}, {"type": "stdin_stdout", "input": "6\n6 5 4 3 2 1\n6 5 3 4 2 1\n", "output": "1 1 2 0 1 1 \n"}...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to ...
[{"type": "stdin_stdout", "input": "15\n", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n"}, {"...
code_stdio