messages
listlengths
1
1
ground_truth
stringlengths
156
726k
dataset
stringclasses
1 value
[ { "content": "You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k. \n\nFind the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.\n\nInput\n\nThe first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is gua...
[{"input": "7 7 3\n4 0 5 3 1 2 6\n", "output": "0"}, {"input": "6 11 2\n1 2 3 4 5 6\n", "output": "1\n"}, {"input": "6 10 2\n1 2 3 4 5 6\n", "output": "1\n"}, {"input": "6 10 2\n1 2 3 4 5 0\n", "output": "1\n"}, {"input": "6 17 2\n1 2 3 4 5 0\n", "output": "0\n"}, {"input": "6 17 2\n1 2 3 4 8 0\n", "output": "1\n"}, {"...
code_stdio
[ { "content": "You and your friend are participating in a TV show \"Run For Your Prize\".\n\nAt the start of the show n prizes are located on a straight line. i-th prize is located at position a_{i}. Positions of all prizes are distinct. You start at position 1, your friend — at position 10^6 (and there is no pr...
[{"input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055\n", "output": "98054\n"}, {"input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055\n", "output": "98054\n"}, {"input": "6\n2 3 500000 999997 999998 999999\n", "output": "499999\n"}, {"input": "6\n2 3 500000 999997 999998 999999\...
code_stdio
[ { "content": "The fearless Ikta has finally hunted down the infamous Count Big Bridge! Count Bigbridge is now trapped in a rectangular room w meters wide and h meters deep, waiting for his end.\n\nIf you select a corner of the room and take the coordinate system so that the width direction is the x-axis and the...
[{"input": "1 3 1000 1000 1 0 0 4", "output": "1047197552288\n"}, {"input": "1 2 1000 1000 1 0 0 4", "output": "1570796325024\n"}, {"input": "1 3 1000 1000 0 0 0 4", "output": "1047197542296\n"}, {"input": "1 3 1001 1000 1 0 0 4", "output": "1049292990824\n"}, {"input": "2 3 1001 1000 1 1 1 2", "output": "524646496019\...
code_stdio
[ { "content": "The circle line of the Roflanpolis subway has $n$ stations.\n\nThere are two parallel routes in the subway. The first one visits stations in order $1 \\to 2 \\to \\ldots \\to n \\to 1 \\to 2 \\to \\ldots$ (so the next stop after station $x$ is equal to $(x+1)$ if $x < n$ and $1$ otherwise). The se...
[{"input": "100 26 63 60 23\n", "output": "YES\n"}, {"input": "100 26 63 60 20\n", "output": "YES\n"}, {"input": "100 26 77 60 20\n", "output": "YES\n"}, {"input": "100 45 77 77 20\n", "output": "YES\n"}, {"input": "100 45 90 77 20\n", "output": "YES\n"}, {"input": "100 45 10 77 20\n", "output": "YES\n"}, {"input": "10...
code_stdio
[ { "content": "Orac is studying number theory, and he is interested in the properties of divisors.\n\nFor two positive integers $a$ and $b$, $a$ is a divisor of $b$ if and only if there exists an integer $c$, such that $a\\cdot c=b$.\n\nFor $n \\ge 2$, we will denote as $f(n)$ the smallest positive divisor of $n...
[{"input": "5\n497347 19283\n2568 1000000000\n499979 123987\n93 19\n13 5\n", "output": "536584\n2000002568\n1247930\n132\n34\n"}, {"input": "5\n497347 19283\n2568 1000000000\n499979 123987\n93 19\n13 5\n", "output": "536584\n2000002568\n1247930\n132\n34\n"}, {"input": "5\n497347 19283\n2568 1000000000\n499979 202537\n9...
code_stdio
[ { "content": "<image>\n\nYou can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png)\n\nInput\n\nThe only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be...
[{"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n", "output": "-1300\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzyzzzzzzzzzzzzzzzzzz\n", "output": "-1299\n"}, {"input": "zzzzzzyzzzzzzzzzzzzzzzzzzzzzzzzyzzzzzzzzzzzzzzzzzz\n", "output": "-1298\n"}, {"input": "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ...
code_stdio
[ { "content": "Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.\n\nEmbosser is a special devise that allows to \"print\" the text of a plastic tape. Text is printed sequential...
[{"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs\n", "output": "1236\n"}, {"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh\n", "output": "1293\n"}, {"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh...
code_stdio
[ { "content": "Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their ...
[{"input": "94 58\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1\n", "output": "5\n"}, {"input": "94 58\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58...
code_stdio
[ { "content": "Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a...
[{"input": "1000000000\n", "output": "500000000\n"}, {"input": "1000000000\n", "output": "500000000\n"}, {"input": "1001000000\n", "output": "500500000\n"}, {"input": "1393488002\n", "output": "696744001\n"}, {"input": "1001000100\n", "output": "500500050\n"}, {"input": "1001000110\n", "output": "500500055\n"}, {"input...
code_stdio
[ { "content": "Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:\n\n* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).\n\n* Let A be \\sum_{i=1}^{N} c_i \\tim...
[{"input": "10 1000\n451 4593 6263\n324 310 6991\n225 1431 7068\n133 1757 4072\n204 3676 4328\n840 6600 9080\n415 1545 15200\n709 5467 8674\n862 6504 9835\n283 4965 9980", "output": "2373\n"}, {"input": "10 1000\n451 4593 6263\n324 310 9662\n378 1431 7068\n120 1757 9218\n204 3676 4328\n840 6221 9080\n684 1545 8511\n709...
code_stdio
[ { "content": "Takahashi has decided to give a string to his mother.\n\nThe value of a string T is the length of the longest common subsequence of T and T', where T' is the string obtained by reversing T. That is, the value is the longest length of the following two strings that are equal: a subsequence of T (po...
[{"input": "ssgtnscdnaqreedocoa\n14", "output": "19"}, {"input": "tsetnocdnargredocta\n3", "output": "15"}, {"input": "tsetnocdnargredocta\n2", "output": "13"}, {"input": "tsetnocdnargredocta\n1", "output": "11"}, {"input": "atcodergrandcontest\n6", "output": "17"}, {"input": "atcodergrandcontest\n5", "output": "16"}, ...
code_stdio
[ { "content": "Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!\n\nSince you are so curious about Bitland, I'll give you the chance of peeking at one of the...
[{"input": "3\n184 222 102\n", "output": "BitAryo\n"}, {"input": "3\n101 186 223\n", "output": "BitAryo\n"}, {"input": "3\n101 186 223\n", "output": "BitAryo\n"}, {"input": "3\n184 222 102\n", "output": "BitAryo\n"}, {"input": "3\n103 286 100\n", "output": "BitLGM\n"}, {"input": "3\n244 241 295\n", "output": "BitLGM\n"...
code_stdio
[ { "content": "A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, \"abcba\", \"a\", and \"abba\" are palindromes, while \"abab\" and \"xy\" are not.\n\nA string is called a substring of another string, if it can be obtained from t...
[{"input": "21\narozauprlanalapuazoaa\n", "output": "aaaaaaaallnoopprruuzz\n"}, {"input": "21\narozbuprlanalapuazoaa\n", "output": "aaaaaaabllnoopprruuzz\n"}, {"input": "21\narozbuarlpnalapuayoaa\n", "output": "aaaaaaabllnoopprruuyz\n"}, {"input": "21\naaoyaupalanplrbubzora\n", "output": "aaaaaabbllnoopprruuyz\n"}, {"i...
code_stdio
[ { "content": "Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).\n\n<image>\n\n\nTo translate this format into a decimal representation that is easy for ...
[{"input": "8\n00101110\n66920828\n00000080\n00000040\n000000c0\n00100110\n45306216\n07f00009", "output": "8226.125\n13444112.3125\n1.0\n0.5\n1.5\n8194.125\n9068740.171875\n1040384.0703125\n"}, {"input": "8\n00100100\n45780507\n00000080\n00000040\n0c000000\n00000101\n15330257\n80000f70", "output": "8194.0\n9105418.0546...
code_stdio
[ { "content": "You are given an integer N. Consider an infinite N-ary tree as shown below:\n\n<image>\n\nFigure: an infinite N-ary tree for the case N = 3\n\nAs shown in the figure, each vertex is indexed with a unique positive integer, and for every positive integer there is a vertex indexed with it. The root o...
[{"input": "3 3\n11 11\n1 15\n3 15", "output": "11\n1\n1\n"}, {"input": "2 3\n7 7\n8 59\n5 16", "output": "7\n1\n2\n"}, {"input": "10 2\n7 5\n23 23\n0 3", "output": "1\n23\n"}, {"input": "2 3\n7 7\n5 83\n5 16", "output": "7\n5\n2\n"}, {"input": "3 3\n7 7\n5 83\n5 16", "output": "7\n1\n5\n"}, {"input": "3 3\n7 2\n5 83\n...
code_stdio
[ { "content": "You are given a number $n$ (divisible by $3$) and an array $a[1 \\dots n]$. In one move, you can increase any of the array elements by one. Formally, you choose the index $i$ ($1 \\le i \\le n$) and replace $a_i$ with $a_i + 1$. You can choose the same index $i$ multiple times for different moves....
[{"input": "4\n6\n0 2 5 5 4 1\n6\n2 0 2 0 0 0\n9\n14 1 3 4 2 10 3 1 12\n6\n1 1 2 3 4 5\n", "output": "1\n2\n1\n2\n"}, {"input": "4\n6\n0 2 1 4 4 1\n6\n0 0 2 1 0 0\n9\n7 1 3 0 2 12 2 13 5\n6\n1 0 2 10 1 8\n", "output": "3\n3\n0\n2\n"}, {"input": "4\n6\n0 2 1 4 4 1\n6\n0 0 2 1 0 0\n9\n7 1 3 0 2 12 2 13 9\n6\n1 0 2 10 1 8...
code_stdio
[ { "content": "There is a very long bench. The bench is divided into M sections, where M is a very large integer.\n\nInitially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action:\n\n* We call a section comfortable if the section is currently unoccupied and is not ...
[{"input": "100\n-X-X-X--X-X--X--X-X--X-X-X--X-X-X--X--X-X-X-X--X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X", "output": "0 0 435664291\n"}, {"input": "100\nX-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-", "output": "0 0 435664291"}, {"input": "20\nX-X-X--X...
code_stdio
[ { "content": "[Chopsticks (singular: chopstick) are short, frequently tapered sticks used in pairs of equal length, which are used as the traditional eating utensils of China, Japan, Korea and Vietnam. Originated in ancient China, they can also be found in some areas of Tibet and Nepal that are close to Han Chi...
[{"input": "5 3\n13\n-2\n3\n9\n1", "output": "1\n"}, {"input": "5 3\n13\n-3\n3\n9\n1", "output": "1\n"}, {"input": "5 3\n13\n-3\n3\n1\n1", "output": "1\n"}, {"input": "5 4\n17\n-1\n3\n9\n2", "output": "1\n"}, {"input": "5 1\n13\n-3\n3\n1\n1", "output": "1\n"}, {"input": "5 2\n10\n-1\n3\n9\n6", "output": "1\n"}, {"input...
code_stdio
[ { "content": "It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right...
[{"input": "95 97575868 5\n4612 1644 3613 5413 5649 2419 5416 3926 4610 4419 2796 5062 2112 1071 3790 4220 3955 2142 4638 2832 2702 2115 2045 4085 3599 2452 5495 4767 1368 2344 4625 4132 5755 5815 2581 6259 1330 4938 815 5430 1628 3108 4342 3692 2928 1941 3714 4498 4471 4842 1822 867 3395 2587 3372 6394 6423 3728 3720 ...
code_stdio
[ { "content": "Problem statement\n\nThere is a tree consisting of $ N $ vertices $ N-1 $ edges, and the $ i $ th edge connects the $ u_i $ and $ v_i $ vertices.\n\nEach vertex has a button, and the button at the $ i $ th vertex is called the button $ i $.\n\nFirst, the beauty of the button $ i $ is $ a_i $.\n\nE...
[{"input": "4\n1 2\n2 3\n1 4\n1 3 2 -1\n-5 2 9 -1", "output": "33\n"}, {"input": "4\n1 2\n2 3\n1 4\n0 3 0 -1\n-4 2 5 -1", "output": "23\n"}, {"input": "4\n1 2\n1 4\n3 4\n-1 3 2 0\n-8 4 8 -1", "output": "27\n"}, {"input": "4\n1 2\n2 4\n3 4\n1 5 2 1\n-4 1 10 -1", "output": "38\n"}, {"input": "4\n1 2\n2 3\n1 4\n1 5 0 -1\n...
code_stdio
[ { "content": "You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right.\n\nAlso, you are given a positive integer k < n.\n\nLet's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k.\n\nYou need to find the s...
[{"input": "20 19\n19999999999999999999\n", "output": "20\n20000000000000000002\n"}, {"input": "20 10\n21474836472147483648\n", "output": "20\n21474836482147483648\n"}, {"input": "20 10\n19999999999999999999\n", "output": "20\n20000000002000000000\n"}, {"input": "20 10\n30583716933544117071\n", "output": "20\n305837169...
code_stdio
[ { "content": "You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest subsequence of a with the value l ≤ m.\n\nA subsequence of a is an array we can get by erasing some elements of a. ...
[{"input": "100 343\n999 284 486 785 176 742 856 415 992 601 600 122 460 214 338 92 627 913 376 835 384 914 335 179 409 957 96 784 531 43 584 206 971 799 592 801 870 978 437 517 466 952 1 327 731 689 816 681 383 969 452 298 114 687 314 436 267 154 827 197 805 207 284 550 351 700 94 567 524 329 414 561 284 666 702 226 7...
code_stdio
[ { "content": "Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer.\n\nThe poor boy was very upse...
[{"input": "10 10\n1101001\n0110000\n0111010\n0010000\n1010000\n0111000\n1011011\n1010010\n1101011\n1111110\n", "output": "9941743758\n"}, {"input": "10 10\n0101111\n0000000\n1111011\n1011011\n1011011\n1111011\n0010010\n1010010\n1101111\n0000000\n", "output": "8993391761\n"}, {"input": "10 10\n1101001\n0110000\n0111010...
code_stdio
[ { "content": "n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a_1, a_2, ..., a_{n} of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.\n\nThe game consists of m steps. On each step the current lead...
[{"input": "100 100\n96 73 23 74 35 44 75 13 62 50 76 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63...
code_stdio
[ { "content": "Consider a long corridor which can be divided into $n$ square cells of size $1 \\times 1$. These cells are numbered from $1$ to $n$ from left to right.\n\nThere are two people in this corridor, a hooligan and a security guard. Initially, the hooligan is in the $a$-th cell, the guard is in the $b$-...
[{"input": "3\n25 2 3 5\n2 7\n11 2 11 10\n1 1\n4 2 3 6\n4 4\n", "output": "1\n0\n1\n"}, {"input": "3\n11 2 3 20\n4 4\n7 2 3 -1\n5 1\n1 2 4 10\n0 1\n", "output": "2\n2\n2\n"}, {"input": "3\n13 2 3 1\n1 8\n7 2 1 6\n13 2\n7 2 3 12\n2 4\n", "output": "1\n1\n2\n"}, {"input": "3\n25 2 3 7\n2 7\n11 2 3 10\n1 1\n4 2 3 6\n4 4\n...
code_stdio
[ { "content": "It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road...
[{"input": "100 50\n79 24\n65 69\n44 6\n49 53\n26 22\n24 76\n10 2\n19 44\n44 10\n87 82\n91 87\n23 92\n69 66\n95 30\n90 24\n95 20\n76 36\n82 24\n63 80\n70 72\n34 76\n42 40\n17 100\n66 64\n85 96\n34 30\n36 69\n45 56\n36 62\n26 38\n31 28\n79 64\n78 69\n41 62\n36 40\n64 67\n21 13\n90 88\n28 30\n59 6\n59 56\n63 1\n24 91\n12...
code_stdio
[ { "content": "There are two rectangles whose bases are parallel to the x-axis. Read the lower left coordinates (xa1, ya1) and upper right coordinates (xa2, ya2) of rectangle A, the lower left coordinates (xb1, yb1) and upper right coordinates (xb2, yb2) of rectangle B, and rectangle A and B Create a program tha...
[{"input": "2.223070606524155 1.4960198812761343 6.988386378768428 7.000508921833194 4.205136917017809 2.2424931885142083 5.1569216527923185 5.191516114177997\n1.1891195386027824 2.2619900314452366 6.37960763673212 8.721050113941343 1.5944937676218054 1.5944269037686163 7.4405536026925985 7.593208053380714\n1.948236149...
code_stdio
[ { "content": "Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.\n\nTwo integers x, y are written on the blackboard. It is allowed to erase one of them and replace it wi...
[{"input": "-1000000000000000000 -1000000000000000000 -1000000000000000000\n", "output": "0\n"}, {"input": "-1000000000000000000 -1000000000000000000 -999999999999999999\n", "output": "-1\n"}, {"input": "-1000000000000000000 -1000000000000000000 -1000000000000000000\n", "output": "0\n"}, {"input": "-1000000000000000000...
code_stdio
[ { "content": "На тренировку по подготовке к соревнованиям по программированию пришли n команд. Тренер для каждой команды подобрал тренировку, комплект задач для i-й команды занимает a_{i} страниц. В распоряжении тренера есть x листов бумаги, у которых обе стороны чистые, и y листов, у которых только одна сторон...
[{"input": "100 1019 35\n34 50 60 47 49 49 59 60 37 51 3 86 93 33 78 31 75 87 26 74 32 30 52 57 44 10 33 52 78 16 36 77 53 49 98 82 93 85 16 86 19 57 17 24 73 93 37 46 27 87 35 76 33 91 96 55 34 65 97 66 7 30 45 68 18 51 77 43 99 76 35 47 6 1 83 49 67 85 89 17 20 7 49 33 43 59 53 71 86 71 3 47 65 59 40 34 35 44 46 64\n...
code_stdio
[ { "content": "Takahashi is playing with N cards.\n\nThe i-th card has an integer X_i on it.\n\nTakahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:\n\n* The integers on the two cards are the same.\n* The sum of the integers on the two cards is a multiple o...
[{"input": "15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 124 99", "output": "6\n"}, {"input": "15 10\n0 5 6 10 11 11 11 20 21 25 25 26 99 131 99", "output": "5\n"}, {"input": "15 10\n0 5 6 10 11 11 11 20 21 46 25 26 99 131 99", "output": "5\n"}, {"input": "15 10\n0 5 6 10 11 11 17 20 21 46 25 26 99 131 99", "output": "5\...
code_stdio
[ { "content": "There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.\nFor each square, you will perform either of the following operations once:\n - Decrease the height of the square by 1.\n - Do nothing.\nDetermine if it is possible to perform the operatio...
[{"input": "1\n1000000000\n", "output": "Yes\n"}, {"input": "5\n1 2 1 1 3\n", "output": "Yes\n"}, {"input": "5\n1 2 3 4 5\n", "output": "Yes\n"}, {"input": "1\n1000010000", "output": "Yes\n"}, {"input": "1\n1000011000", "output": "Yes\n"}, {"input": "1\n1000011100", "output": "Yes\n"}, {"input": "1\n1000001100", "outpu...
code_stdio
[ { "content": "Given are an N \\times N matrix and an integer K. The entry in the i-th row and j-th column of this matrix is denoted as a_{i, j}. This matrix contains each of 1, 2, \\dots, N^2 exactly once.\nSigma can repeat the following two kinds of operation arbitrarily many times in any order.\n - Pick two i...
[{"input": "49 4643\n1 50 99 148 197 246 295 344 393 442 491 540 589 638 687 736 785 834 883 932 981 1030 1079 1128 1177 1226 1275 1324 1373 1422 1471 1520 1569 1618 1667 1716 1765 1814 1863 1912 1961 2010 2059 2108 2157 2185 2255 2304 2353\n2 51 742 149 198 247 296 345 394 443 1148 541 590 639 688 737 786 835 1431 933...
code_stdio
[ { "content": "Alice and Bob are playing a game with n piles of stones. It is guaranteed that n is an even number. The i-th pile has a_i stones.\n\nAlice and Bob will play a game alternating turns with Alice going first.\n\nOn a player's turn, they must choose exactly n/2 nonempty piles and independently remove ...
[{"input": "50\n42 31 49 11 28 38 49 32 15 22 10 18 43 39 46 32 10 19 13 32 19 40 34 28 28 39 19 3 1 47 10 18 19 31 21 7 39 37 34 45 19 21 35 46 10 24 45 33 20 40\n", "output": "Alice\n"}, {"input": "50\n42 31 49 11 28 13 49 32 15 22 10 18 43 39 46 32 10 19 13 32 19 40 34 28 28 39 19 3 1 47 10 18 19 31 21 7 39 37 34 45...
code_stdio
[ { "content": "There are $n$ block towers in a row, where tower $i$ has a height of $a_i$. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation:\n\nChoose two indices $i$ and $j$ ($1 \\leq i, j \\leq n$; $i \\neq j$)...
[{"input": "3\n3\n10 14 10\n4\n4 1 1 2\n5\n2 1 3 1 10\n", "output": "1\n0\n1\n"}, {"input": "3\n3\n10 10 10\n4\n3 2 1 2\n5\n1 2 3 1 5\n", "output": "0\n0\n1\n"}, {"input": "3\n3\n10 10 10\n4\n3 2 0 2\n5\n1 2 3 1 5\n", "output": "0\n1\n1\n"}, {"input": "3\n3\n10 10 10\n4\n3 2 1 2\n5\n1 2 3 1 4\n", "output": "0\n0\n1\n"}...
code_stdio
[ { "content": "There is a complete graph of m vertices. Initially, the edges of the complete graph are uncolored. Sunuke did the following for each i (1 ≤ i ≤ n): Select ai vertices from the complete graph and color all edges connecting the selected vertices with color i. None of the sides were painted in multip...
[{"input": "5\n2\n3\n4\n10\n6", "output": "17\n"}, {"input": "5\n2\n3\n3\n5\n6", "output": "11\n"}, {"input": "5\n2\n3\n5\n5\n6", "output": "13\n"}, {"input": "5\n2\n3\n3\n2\n6", "output": "9\n"}, {"input": "5\n2\n3\n4\n5\n6", "output": "12"}, {"input": "2\n80\n22", "output": "101\n"}, {"input": "2\n139\n5", "output": ...
code_stdio
[ { "content": "Given are two strings S and T.\nLet us change some of the characters in S so that T will be a substring of S.\nAt least how many characters do we need to change?\nHere, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.\n\n-----Constra...
[{"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
code_stdio
[ { "content": "Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.\n\nSergey gives Nastya the word t and wants to get the word p out of it. Nastya remov...
[{"input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33...
code_stdio
[ { "content": "Example\n\nInput\n\n6 3\n1 0 0 1 0 1\n1 3 2\n\n\nOutput\n\n1\n\nWrite Python code to solve this problem. Your program should read the input from stdin and write the output to stdout. Enclose your complete solution in a single ```python code block.", "role": "user" } ]
[{"input": "1 3\n1 -1 0 1 -1 1\n2 1 -1", "output": "0\n"}, {"input": "1 3\n1 -1 0 1 0 1\n-1 3 2", "output": "0\n"}, {"input": "1 3\n1 0 -1 1 0 1\n-1 3 2", "output": "0\n"}, {"input": "1 3\n1 -1 0 1 0 1\n-1 1 2", "output": "0\n"}, {"input": "1 3\n1 -1 0 1 -1 1\n2 1 0", "output": "0\n"}, {"input": "1 3\n1 0 0 1 0 1\n-1 3...
code_stdio
[ { "content": "Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.\n\nOver the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite...
[{"input": "20 15\n6 8719.787178\n10 13066.663722\n15 58623.690996\n9 184321.819759\n3 227999.294560\n2 279836.330518\n9 282806.308675\n8 311056.507765\n1 312315.562927\n5 459200.373445\n14 563454.265947\n7 647364.984868\n13 679762.0281866578\n4 684192.647497\n1 733119.607626\n7 748637.778398\n12 828048.945890\n11 8936...
code_stdio
[ { "content": "One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. \n\nThe author would need to spend too much time and effort to make the sum of his marks strictly more t...
[{"input": "45 104\n", "output": "31\n"}, {"input": "50 100\n", "output": "50\n"}, {"input": "47 128\n", "output": "13\n"}, {"input": "46 127\n", "output": "11\n"}, {"input": "42 104\n", "output": "22\n"}, {"input": "56 128\n", "output": "40\n"}, {"input": "50 101\n", "output": "49\n"}, {"input": "53 116\n", "output": ...
code_stdio
[ { "content": "The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a ...
[{"input": "10 10\n8530 -3814\n-9330 -6035\n3951 -217\n-9276 8291\n636 -3118\n5024 -2403\n4601 7977\n-3620 -1428\n4954 -9632\n-9852 6553\n-3457 5430\n-8866 -7343\n1020 -5748\n5043 -3820\n-2832 1528\n-5058 -825\n2406 -3530\n9152 -7463\n-8547 7108\n2492 8953\n", "output": "Yes\n"}, {"input": "10 10\n8530 -3814\n-9330 -60...
code_stdio
[ { "content": "Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.\n\nThe players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes ...
[{"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n", "output": "7000 7000\n"}, {"input": "3\n3 1000 1000 1001\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n", "output": "7000 7001\n"}, {"input": "3\n3 1000 1000 1001\n6 1000 1000 1000 1000 1000 1001\n5 1000 100...
code_stdio
[ { "content": "Input Format\n\n\nN K\na_1 a_2 a_3 ... a_N\n\n\nOutput Format\n\nPrint the minimum cost in one line. In the end put a line break.\n\n\nConstraints\n\n* 1 ≤ K ≤ N ≤ 15\n* 1 ≤ a_i ≤ 10^9\n\n\n\nScoring\n\nSubtask 1 [120 points]\n\n\n* N = K\n\nSubtask 2 [90 points]\n\n\n* N ≤ 5\n* a_i ≤ 7\n\nSubtask...
[{"input": "5 5\n11683 3774 3598 4173 3424", "output": "31773\n"}, {"input": "5 4\n11683 3774 3598 4173 3424", "output": "23510\n"}, {"input": "5 5\n3949 3208 13644 3469 3424", "output": "21140\n"}, {"input": "5 5\n4931 3208 13644 3469 3424", "output": "22122\n"}, {"input": "5 5\n2312 3208 13644 3469 3424", "output": "...
code_stdio
[ { "content": "Let's play Amidakuji.\n\nIn the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.\n\n<image>\n\n\nIn the starting points (top of the figure), numbers are assigned to vertical lines in ascending order fro...
[{"input": "5\n-1\n1,4\n4,5\n,12\n43,", "output": "1\n2\n3\n4\n5\n"}, {"input": "5\n-1\n1,4\n5,4\n,12\n43,", "output": "1\n2\n3\n4\n5\n"}, {"input": "5\n-1\n1,4\n5,4\n-12\n43,", "output": "1\n2\n3\n4\n5\n"}, {"input": "5\n4\n2,4\n3,5\n2,1\n3,4", "output": "4\n1\n2\n5\n3\n"}, {"input": "5\n4\n2,4\n4,5\n2,1\n3,4", "outpu...
code_stdio
[ { "content": "Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.\n\nYou have a sequence of positive integer numbers a_1, a_2, ..., a_{k}. We say that this sequence occurs in table G if it coincides with consec...
[{"input": "1000000000000 1000000000000 116\n1587924000 7 2 3 4 5 6 1 56 9 10 1 12 13 2 105 16 1 18 1 620 3 14 1 24 25 26 27 4 203 30 1 32 3 2 5 252 1 2 39 40 1 6 7 4 45 2 1 48 1 350 93 52 1 54 5 8 21 58 1 60 1 2 9 224 65 6 1 4 3 10 7 72 1 2 75 4 1 546 1 80 81 62 1 12 35 2 87 8 1 90 13 28 3 2 5 96 1 2 63 100 1 6 1 104 ...
code_stdio
[ { "content": "You are given three integers, A, B and C.\n\nAmong them, two are the same, but the remaining one is different from the rest.\n\nFor example, when A=5,B=7,C=5, A and C are the same, but B is different.\n\nFind the one that is different from the rest among the given three integers. \n\n-----Constra...
[{"input": "-100 100 100\n", "output": "-100\n"}, {"input": "-123 100 100", "output": "-123\n"}, {"input": "-157 100 100", "output": "-157\n"}, {"input": "-100 100 100", "output": "-100"}, {"input": "-25 100 100", "output": "-25\n"}, {"input": "-19 100 100", "output": "-19\n"}, {"input": "-27 100 100", "output": "-27\n...
code_stdio
[ { "content": "You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.\n\nThe i-th operation is as follows:\n\n1. Append a_i to the end of b.\n2. Reverse the order of the elements in b.\n\n\n\nFind the sequence b obtained after t...
[{"input": "6\n-1 22 1 75 15 0", "output": "0 75 22 -1 1 15\n"}, {"input": "6\n2 20 0 59 10 1", "output": "1 59 20 2 0 10\n"}, {"input": "6\n2 20 0 59 10 0", "output": "0 59 20 2 0 10\n"}, {"input": "6\n2 20 0 59 12 0", "output": "0 59 20 2 0 12\n"}, {"input": "6\n0 20 0 59 12 0", "output": "0 59 20 0 0 12\n"}, {"input...
code_stdio
[ { "content": "This is yet another problem dealing with regular bracket sequences.\n\nWe should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «((...
[{"input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((\n", "output": "80 1\n"}, {"input": ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))\n", "output": "68 1\n"}, {"input": "))(((((((()((((())(((((((((()())))...
code_stdio
[ { "content": "Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:\n\n* The sum of the digits in base ten is a multiple of D.\n\nConstraints\n\n* All values in input are integers.\n* 1 \\leq K < 10^{10000}\n* 1 \\leq D \\leq 100\n\nInput\n\nInput is given ...
[{"input": "98765432109876543210\n66", "output": "678072802\n"}, {"input": "98765432109876543210\n18", "output": "852803440\n"}, {"input": "98765432109876543210\n11", "output": "501683936\n"}, {"input": "98765432109876543210\n12", "output": "209841644\n"}, {"input": "98765432109876543210\n10", "output": "851852334\n"},...
code_stdio
[ { "content": "In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.\nThe name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.\n\nGiven a string S of length N and an integer k (k \\geq 3), he defines the k-DMC n...
[{"input": "54\nDIALUPWIDEAREADETWORKGAMINGOPERATIONCORPORATIONLIMITEN\n3\n20 30 40", "output": "0\n2\n3\n"}, {"input": "54\nDIALUPWIDEAREADETWORKGAMINGOPERATIONCORPORATIONLIMITEN\n3\n20 38 40", "output": "0\n3\n3\n"}, {"input": "54\nDIALUPWIDEAREADETWORKGAMINGOPERATIONCORPORATIONLIMITEN\n3\n20 30 32", "output": "0\n2\...
code_stdio
[ { "content": "Read problems statements in Mandarin Chinese here \n\n------ Problem Statement ------ \n\nMaxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city.\n \nIf you remember, lucky numbers are positive integers whose decimal representation contains only t...
[{"input": "10\n1\n2\n1\n10\n5\n11\n10\n8\n14\n4", "output": "0\n0\n0\n0\n0\n0\n0\n1\n2\n1\n"}, {"input": "10\n2\n2\n1\n7\n5\n13\n14\n8\n18\n5", "output": "0\n0\n0\n1\n0\n0\n2\n1\n0\n0\n"}, {"input": "10\n2\n2\n1\n10\n5\n11\n7\n8\n14\n4", "output": "0\n0\n0\n0\n0\n0\n1\n1\n2\n1\n"}, {"input": "10\n2\n2\n2\n9\n7\n13\n14...
code_stdio
[ { "content": "She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since ...
[{"input": "2\n2\nYYZNNNNY\n4\nNNNYYNYNNNYYONYN", "output": "6\n10\n"}, {"input": "2\n2\nYYZNYNNN\n4\nNNNYYNYNNNYYNNYN", "output": "5\n10\n"}, {"input": "2\n2\nYYZNNNNY\n4\nNNNYNNYNYNYYONYN", "output": "6\n11\n"}, {"input": "2\n2\nYYZLXNNN\n3\nNYNNYNYNNNYYNNYN", "output": "4\n10\n"}, {"input": "2\n2\nNNONYZYY\n4\nNNNYY...
code_stdio
[ { "content": "Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.\n\nFilya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then he adds x to some elements of the array (no...
[{"input": "10\n1 1 1 1 1 2 2 2 2 2\n", "output": "YES\n"}, {"input": "10\n1 1 1 1 1 2 2 2 2 2\n", "output": "YES\n"}, {"input": "10\n1 1 1 1 1 3 2 2 2 2\n", "output": "YES\n"}, {"input": "3\n99999999 1 50000000\n", "output": "YES\n"}, {"input": "2\n100000001 100000003\n", "output": "YES\n"}, {"input": "2\n100000001 10...
code_stdio
[ { "content": "AtCoder Mart sells 1000000 of each of the six items below:\n\n* Riceballs, priced at 100 yen (the currency of Japan) each\n* Sandwiches, priced at 101 yen each\n* Cookies, priced at 102 yen each\n* Cakes, priced at 103 yen each\n* Candies, priced at 104 yen each\n* Computers, priced at 105 yen eac...
[{"input": "386", "output": "0\n"}, {"input": "115", "output": "0\n"}, {"input": "173", "output": "0\n"}, {"input": "145", "output": "0\n"}, {"input": "192", "output": "0\n"}, {"input": "160", "output": "0\n"}, {"input": "604", "output": "1\n"}, {"input": "248", "output": "0\n"}, {"input": "368", "output": "0\n"}, {"in...
code_stdio
[ { "content": "It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the curr...
[{"input": "10\n100000000 200000000 300000000 400000000 500000000 600000000 555489806 1596475927 1262387014 1000000000\n", "output": "Alice\n"}, {"input": "10\n100000000 200000000 300000000 400000000 500000000 600000000 555489806 1596475927 1262387014 1000000100\n", "output": "Alice\n"}, {"input": "10\n100000000 200000...
code_stdio
[ { "content": "Real stupidity beats artificial intelligence every time.\n\n— Terry Pratchett, Hogfather, Discworld\n\nYou are given a string $s$ of length $n$ and a number $k$. Let's denote by $rev(s)$ the reversed string $s$ (i.e. $rev(s) = s_n s_{n-1} ... s_1$). You can apply one of the two kinds of operations...
[{"input": "4\n3 2\naab\n3 3\naab\n7 1\nabacaba\n2 0\nab\n", "output": "2\n2\n1\n1\n"}, {"input": "1\n4 1\nabcd\n", "output": "2\n"}, {"input": "1\n4 2\nabca\n", "output": "2\n"}, {"input": "1\n3 1\naab\n", "output": "2\n"}, {"input": "1\n3 1\nabc\n", "output": "2\n"}, {"input": "1\n2 1\nab\n", "output": "2\n"}]
code_stdio
[ { "content": "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.\n\nWe are allowed to arranged pictures in any order. What is the maximum possible number of times the visito...
[{"input": "100\n9 9 49 55 14 8 55 58 35 67 3 6 106 169 41 49 15 60 18 66 3 26 97 47 43 88 71 98 12 34 48 17 134 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 20 4 65 37 74 7 6 24 210 55 72 89 4 78 27 29 82 13 83 18 4 32 69 89 91 66 13 92 54 38 5 26 56 17 98 29 4 17 39 29 181 3 67 85 98 21 26\n", "output": ...
code_stdio
[ { "content": "In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's so...
[{"input": "2\n-1000000000 1000000000\n", "output": "2000000000\n"}, {"input": "2\n-1000000000 1000000100\n", "output": "2000000100\n"}, {"input": "2\n-1000000000 1000010100\n", "output": "2000010100\n"}, {"input": "2\n-1000000000 1010010100\n", "output": "2010010100\n"}, {"input": "2\n-1000000000 1010011100\n", "outpu...
code_stdio
[ { "content": "Vasya had three strings $a$, $b$ and $s$, which consist of lowercase English letters. The lengths of strings $a$ and $b$ are equal to $n$, the length of the string $s$ is equal to $m$. \n\nVasya decided to choose a substring of the string $a$, then choose a substring of the string $b$ and concaten...
[{"input": "100 200\ndddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\ndddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\nddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...
code_stdio
[ { "content": "Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.\n\nHowever, all Mike has is lots of identical resistors with unit resistance R_0 = 1. Elements with other resistance can be constructed from these resistors. In...
[{"input": "999999999999999999 1000000000000000000\n", "output": "1000000000000000000\n"}, {"input": "999999999999999999 1000000000000000000\n", "output": "1000000000000000000\n"}, {"input": "999999999999999991 1000000000000000000\n", "output": "111111111111111120\n"}, {"input": "999999999999999991 1000000000000000000\...
code_stdio
[ { "content": "Petya has n positive integers a_1, a_2, ..., a_{n}. \n\nHis friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so...
[{"input": "50\ng\nha\nhd\ndi\nac\nfdhhb\ng\nhgeag\nafafb\nb\nb\najjj\ncaiadi\nhciifa\nhb\ncaih\ncdbbi\ngjff\nbfe\neddci\ndijfie\nacjj\nef\ng\njdc\nahg\ne\nhbbh\ncdc\njifdc\ne\nffaehj\nhjhi\ng\neag\nfbbc\nchg\njhahfg\nbb\njd\njchh\nbefifj\nejac\ne\nh\njfhb\nedhe\nf\nag\nca\n", "output": "2673136\n"}, {"input": "50\ng\n...
code_stdio
[ { "content": "Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.\n\nFor example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he ca...
[{"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...
code_stdio
[ { "content": "You are given two integers $a$ and $b$.\n\nIn one move, you can choose some integer $k$ from $1$ to $10$ and add it to $a$ or subtract it from $a$. In other words, you choose an integer $k \\in [1; 10]$ and perform $a := a + k$ or $a := a - k$. You may use different values of $k$ in different move...
[{"input": "11\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\n5 5\n13 42\n18 4\n2524 420\n123456789 1000000000\n", "output": "0\n3\n2\n92\n87654322\n9150\n0\n3\n2\n211\n87654322\n"}, {"input": "11\n10 5\n4 42\n17 4\n1337 420\n123456789 1000000000\n100500 9000\n5 5\n13 42\n18 4\n2524 420\n123456789 1000...
code_stdio
[ { "content": "Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. F...
[{"input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401\...
code_stdio
[ { "content": "This problem is same as the next one, but has smaller constraints.\n\nIt was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power ...
[{"input": "42\n-5391 -2932\n-5391 -2868\n-5391 1744\n-5391 2236\n-5391 4148\n-5391 5217\n-5391 6188\n-3584 -2932\n-3584 -2868\n-3584 1744\n-3584 2236\n-3584 4148\n-3584 5217\n-3584 6188\n-1657 -2932\n-1657 -2868\n-1657 1744\n-1657 2236\n-1657 4148\n-1657 5217\n-1657 6188\n3218 -2932\n3218 -2868\n3218 1744\n3218 2236\n...
code_stdio
[ { "content": "In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.\n\n(Cultural note: standing in huge and disorganized queue...
[{"input": "20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n"}, {"input": "20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", "output": "2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n"}, {"input": "10 1\n0 7 0 10 ...
code_stdio
[ { "content": "Takahashi is organizing a party.\nAt the party, each guest will receive one or more snack pieces.\nTakahashi predicts that the number of guests at this party will be A or B.\nFind the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.\nWe assume t...
[{"input": "100000 99999\n", "output": "9999900000\n"}, {"input": "110000 99999", "output": "10999890000\n"}, {"input": "110001 118998", "output": "4363299666\n"}, {"input": "110000 138162", "output": "7598910000\n"}, {"input": "110000 121574", "output": "6686570000\n"}, {"input": "111001 118998", "output": "1200808818...
code_stdio
[ { "content": "A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called \"Guess That Car!\".\n\nThe game show takes place on a giant parking lot, which is 4n meters long from north to south and...
[{"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 1585 1564 3603 1095 1364 1029 3189 1331\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 1749\n0 3495 1540 641 1093 702 2249 983 1218 2108\n0 1397 1105 3119 1194 839 1286 2979 2941 1911\n0 1818 2264 631 3342 3511 2434 2960...
code_stdio
[ { "content": "There are $n$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $1$ to $n$.\n\nTwo fairs are currently taking place in Berland — they are held in two different ci...
[{"input": "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "output": "4\n0\n1\n"}, {"input": "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n4 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "output": "4\n0\n1\n"}, {"input": "3\n7 7 3 5\n1 2\n2 3\n...
code_stdio
[ { "content": "Constanze is the smartest girl in her village but she has bad eyesight.\n\nOne day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine w...
[{"input": "nnnnnnnnnnnnnnnnnnnnnuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuunnnnnnnnnnnnnnnnnnnnnuuuuuuuuuunnunnu\n", "output": "281595619\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuunnnnnnnnnnnnnnnnnnnnnuuuuuuuuuunnunnu\n", "output": "281595619\n"}, {"input": "unnunnuuuuuuuuuunnnnnnnn...
code_stdio
[ { "content": "Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.\n\nYou are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of ...
[{"input": "10000\n", "output": "277 9\n"}, {"input": "18864\n", "output": "524 0\n"}, {"input": "13473\n", "output": "374 3\n"}, {"input": "25368\n", "output": "704 8\n"}, {"input": "9999\n", "output": "277 9\n"}, {"input": "9876\n", "output": "274 4\n"}, {"input": "01000\n", "output": "27 9\n"}, {"input": "1233\n", "...
code_stdio
[ { "content": "Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from ...
[{"input": "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417\n", "output": "4\n"}, {"input": "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417\n", "output": "4\n"}, {"input": "10\n18 30\n71 471\n121 362\n467 107\n170 127\n13 337\n499 373\n337...
code_stdio
[ { "content": "ICPC Ranking\n\nYour mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings.\n\nThe log is a sequence of records of program submission in the order of submission. A record has four fields: el...
[{"input": "300 19 8 5\n50 5 2 1\n70 5 2 0\n75 1 1 0\n100 3 1 0\n150 2 2 0\n240 5 5 7\n50 1 1 0\n60 2 2 0\n41 2 3 0\n90 1 3 0\n120 3 5 0\n196 4 1 0\n150 2 4 1\n180 3 5 4\n15 2 2 1\n20 2 2 1\n25 2 2 0\n60 1 1 0\n120 5 5 4\n15 5 4 1\n20 5 4 0\n40 1 1 0\n40 2 2 0\n120 2 3 4\n30 1 1 0\n40 2 1 0\n13 2 2 0\n60 1 2 0\n120 6 3...
code_stdio
[ { "content": "We have a sequence of N integers: x=(x_0,x_1,\\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \\leq i \\leq N-1).\n\nSnuke will perform the following operation exactly M times:\n\n* Choose two distinct indices i, j (0 \\leq i,j \\leq N-1,\\ i \\neq j). Then, replace x_i with x_i+2 and x_j with x_j...
[{"input": "100001 50000", "output": "546347865\n"}, {"input": "100001 27098", "output": "949668337\n"}, {"input": "101000 27098", "output": "277745716\n"}, {"input": "101000 14296", "output": "338861381\n"}, {"input": "100011 27098", "output": "506486948\n"}, {"input": "101101 27098", "output": "454736313\n"}, {"input...
code_stdio
[ { "content": "A bracketed sequence is called correct (regular) if by inserting \"+\" and \"1\" you can get a well-formed mathematical expression from it. For example, sequences \"(())()\", \"()\" and \"(()(()))\" are correct, while \")(\", \"(()\" and \"(()))(\" are not.\n\nThe teacher gave Dmitry's class a ver...
[{"input": "100\n)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "100\n"}, {"input": "101\n(())))))()))()())(()))((())))((())(()()()(()()((()()((()((())))((()))()(())(()(())((()))(()))()(((()(\n", "output": "-1\n"}, {"input": "100\n)()()()()()()()()()()...
code_stdio
[ { "content": "A mischievous notice has arrived from the primitive slow-life organization \"Akaruda\". Akaruda is famous for mischief such as throwing a pie at the face of a VIP, but recently it has become more radical, such as using gunpowder to sprinkle rat fireworks at the reception venue. The notice is the f...
[{"input": "4\n03:05\n05:11\n11:54\n10:40", "output": "warning\nwarning\nwarning\nwarning\n"}, {"input": "4\n03:25\n10:61\n11:65\n10:41", "output": "warning\nwarning\nalert\nwarning\n"}, {"input": "4\n12:15\n10:50\n11:44\n10:40", "output": "warning\nalert\nwarning\nwarning\n"}, {"input": "4\n12:05\n00:50\n11:44\n10:40"...
code_stdio
[ { "content": "Alice and Bob are playing One Card Poker.\n\nOne Card Poker is a two-player game using playing cards. \nEach card in this game shows an integer between 1 and 13, inclusive.\n\nThe strength of a card is determined by the number written on it, as follows: \nWeak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 ...
[{"input": "1 13\n", "output": "Alice\n"}, {"input": "11 11\n", "output": "Draw\n"}, {"input": "-1 -4", "output": "Alice\n"}, {"input": "-2 -3", "output": "Alice\n"}, {"input": "-2 -4", "output": "Alice\n"}, {"input": "-2 -6", "output": "Alice\n"}, {"input": "-2 -8", "output": "Alice\n"}, {"input": "8 6\n", "output": "...
code_stdio
[ { "content": "During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of $n$ high school students numbered from $1$ to $n$. Initially, each student $i$ is on position $i$. Each student $i$ is characterized by two numbers — $a_i$ and $b_i$. Dissatisfaction of th...
[{"input": "30\n61 23\n30 93\n4 18\n34 97\n63 77\n45 95\n51 13\n41 8\n86 19\n38 24\n2 67\n20 61\n95 48\n95 1\n28 26\n92 110\n6 78\n64 28\n1 82\n61 37\n77 35\n152 21\n10 24\n52 12\n80 63\n64 61\n16 87\n118 19\n21 34\n54 49\n", "output": "29529\n"}, {"input": "30\n61 23\n30 93\n4 18\n34 97\n63 77\n45 95\n51 13\n41 8\n86 ...
code_stdio
[ { "content": "B: Parentheses Number\n\nproblem\n\nDefine the correct parenthesis string as follows:\n\n* The empty string is the correct parenthesis string\n* For the correct parenthesis string S, `(` S `)` is the correct parenthesis string\n* For correct parentheses S, T ST is the correct parentheses\n\n\n\nHe...
[{"input": "2\n2 -107", "output": ":(\n"}, {"input": "2\n2 -187", "output": ":(\n"}, {"input": "2\n2 -155", "output": ":(\n"}, {"input": "2\n2 -142", "output": ":(\n"}, {"input": "2\n2 -100", "output": ":(\n"}, {"input": "2\n2 -125", "output": ":(\n"}, {"input": "2\n2 -149", "output": ":(\n"}, {"input": "2\n2 -131", "o...
code_stdio
[ { "content": "Given an integer $n$, find the maximum value of integer $k$ such that the following condition holds:\n\n$n$ & ($n-1$) & ($n-2$) & ($n-3$) & ... ($k$) = $0$\n\nwhere & denotes the bitwise AND operation. \n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 3 \\cdot 10^4$...
[{"input": "1\n168457447\n", "output": "134217727\n"}, {"input": "1\n276490162\n", "output": "268435455\n"}, {"input": "1\n109011159\n", "output": "67108863\n"}, {"input": "1\n99888383\n", "output": "67108863\n"}, {"input": "1\n99888383\n", "output": "67108863\n"}, {"input": "1\n95529231\n", "output": "67108863\n"}, {"...
code_stdio
[ { "content": "Chef has just finished the construction of his new garden. He has sown the garden with patches of the most beautiful carpet grass he could find. He has filled it with patches of different color and now he wants to evaluate how elegant his garden is.\nChef's garden looks like a rectangular grid of ...
[{"input": "3\n2 1\naa\nA`\n3 -1\naba\nbab\naab\n-1 1\naabb\nbaba\nbcaa\nbbaa", "output": "0\n0\n0\n"}, {"input": "3\n2 1\n`a\nA`\n3 -1\naba\nbab\naab\n-1 1\naabb\nbaba\nbcaa\nbbaa", "output": "0\n0\n0\n"}, {"input": "3\n2 1\na`\nA`\n3 -1\naba\nbab\naab\n-1 1\naabb\nbaba\nbcaa\nbbaa", "output": "0\n0\n0\n"}, {"input": ...
code_stdio
[ { "content": "You are given the array $a$ consisting of $n$ positive (greater than zero) integers.\n\nIn one move, you can choose two indices $i$ and $j$ ($i \\ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \\le 1$) and remove the smallest of these two element...
[{"input": "5\n2\n2 6\n4\n2 2 7 14\n3\n3 3 4\n4\n10 5 10 5\n4\n1 2 1 1\n", "output": "NO\nNO\nYES\nNO\nYES\n"}, {"input": "5\n2\n2 6\n4\n2 0 7 14\n3\n3 3 4\n4\n10 5 10 5\n4\n1 2 1 1\n", "output": "NO\nNO\nYES\nNO\nYES\n"}, {"input": "5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1\n", "output": "YES\nNO\nYES\nY...
code_stdio
[ { "content": "Problem Statement\n\nWe found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the ...
[{"input": "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nd\nb\nb\n0", "output": "yes\nno\nyes\nyes\n"}, {"input": "4\nbba\nbab\nc\na\n3\ncba\nba\na\n5\ncba\nacb\nb\nc\nc\n5\nabc\nacc\nd\nb\nb\n0", "output": "yes\nyes\nno\nyes\n"}, {"input": "4\naac\ncab\nb\na\n3\nbca\nca\na\n5\nabc\nacb\nb\nb\nc...
code_stdio
[ { "content": "You are given two huge binary integer numbers $a$ and $b$ of lengths $n$ and $m$ respectively. You will repeat the following process: if $b > 0$, then add to the answer the value $a~ \\&~ b$ and divide $b$ by $2$ rounding down (i.e. remove the last digit of $b$), and repeat the process again, othe...
[{"input": "5 5\n11111\n11111\n", "output": "57\n"}, {"input": "5 5\n11111\n11111\n", "output": "57\n"}, {"input": "5 5\n11111\n10111\n", "output": "42\n"}, {"input": "5 5\n11011\n11111\n", "output": "45\n"}, {"input": "5 5\n11001\n11111\n", "output": "37\n"}, {"input": "5 5\n11011\n11110\n", "output": "44\n"}, {"input...
code_stdio
[ { "content": "You are given an array $a$ consisting of $n$ integer numbers.\n\nYou have to color this array in $k$ colors in such a way that: Each element of the array should be colored in some color; For each $i$ from $1$ to $k$ there should be at least one element colored in the $i$-th color in the array; ...
[{"input": "50 20\n1 1 1 1 1 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\n", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 \n"}, {"input": "...
code_stdio
[ { "content": "Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\\times N square. We denote with 1, 2,\\dots, N the viewers in the first row (from left to right); with N+1, \\dots, 2N the viewers in the sec...
[{"input": "6\n11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}, {"input": "4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3"}, {"input": "3\n2 3 7 9 5 4 8 6 1", "output": "0\n"}, {"input": "3\n1 3 7 9 5 8 4 6 2", "output": "1\n"}, {"input": "3...
code_stdio
[ { "content": "Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.\n\nIvar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right aft...
[{"input": "100 55\n1 2 4 4 3 5 5 2 3 1 2 2 1 2 4 5 0 5 4 2 5 4 5 3 3 5 4 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 0 4 5 3 4 4 1 9 1 5 2 0 1 4 0 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 0 2 1 5 5 4 5 4 2 5 2 1 5 1 4 0 1 5 4 5 1 4 4 2 5 3 0 5 4 4 0 3 3 10 4 2 4 ...
code_stdio
[ { "content": "Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. ...
[{"input": "7\n21\n33\n**\n33\n12\n**\n32\n31\n**\n21\n33\n**\n33\n12\n**\n32\n31\n**\n13\n23\n", "output": "1\n"}, {"input": "7\n21\n33\n**\n33\n12\n**\n32\n31\n**\n21\n38\n**\n33\n12\n**\n32\n31\n**\n13\n23\n", "output": "2\n"}, {"input": "7\n21\n33\n**\n33\n12\n**\n63\n31\n**\n25\n38\n**\n33\n12\n**\n32\n62\n**\n13\...
code_stdio
[ { "content": "Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:\n\n\nBubbleSort(A)\n1 for i = 0 to A.length-1\n2 for j = A.length-1 downto i+1\n3 if A[j] < A[j-1]\n4 swap A[j] and A[j-1]\n\...
[{"input": "6\n3 1 -1 2 -1 -1", "output": "-1 -1 -1 1 2 3\n10\n"}, {"input": "6\n2 1 -1 11 -1 0", "output": "-1 -1 0 1 2 11\n9\n"}, {"input": "6\n3 1 -1 4 -1 -1", "output": "-1 -1 -1 1 3 4\n9\n"}, {"input": "6\n3 2 -1 4 -1 -1", "output": "-1 -1 -1 2 3 4\n9\n"}, {"input": "6\n4 1 -1 2 -1 0", "output": "-1 -1 0 1 2 4\n10...
code_stdio
[ { "content": "It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.\n\nNow you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than ...
[{"input": "1987\n", "output": "2013\n"}, {"input": "2013\n", "output": "2014\n"}, {"input": "1000\n", "output": "1023\n"}, {"input": "1001\n", "output": "1023\n"}, {"input": "1234\n", "output": "1235\n"}, {"input": "5555\n", "output": "5601\n"}, {"input": "9000\n", "output": "9012\n"}, {"input": "1111\n", "output": "1...
code_stdio
[ { "content": "problem\n\nIn one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.\n\n* The Bingo card is divided into squares of N rows a...
[{"input": "3 21 80\n3 100 60\n5 50 538\n0 0 0", "output": "3466\n157\n96557\n"}, {"input": "3 21 80\n3 100 60\n5 44 538\n0 0 0", "output": "3466\n157\n25088\n"}, {"input": "3 24 80\n3 000 69\n2 162 487\n0 1 1", "output": "4955\n0\n28431\n"}, {"input": "3 36 80\n3 000 69\n2 162 487\n0 1 1", "output": "6570\n0\n28431\n"...
code_stdio
[ { "content": "We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands.\n\nWrite a program to find the time at which \"No two hands overlap each other\" and \"Two angles between th...
[{"input": "12 0 0 0\n12 11 59 59\n12 1 56 0\n12 1 56 3\n12 1 56 34\n12 3 9 43\n12 3 10 14\n12 2 17 58\n12 7 18 0\n10 7 23 0\n12 7 23 31\n2 0 38 19\n2 0 39 0\n2 0 39 30\n2 1 6 14\n2 1 20 1\n2 1 20 31\n3 2 19 0\n3 2 59 30\n4 0 28 48\n5 1 5 37\n5 1 10 10\n5 1 7 41\n11 0 36 0\n0 0 0 0", "output": "0 0 43200 1427\n0 0 4320...
code_stdio
[ { "content": "Recently you've discovered a new shooter. They say it has realistic game mechanics.\n\nYour character has a gun with magazine size equal to $k$ and should exterminate $n$ waves of monsters. The $i$-th wave consists of $a_i$ monsters and happens from the $l_i$-th moment of time up to the $r_i$-th m...
[{"input": "10 79\n2 2 70\n2 10 35\n10 10 76\n11 11 66\n12 12 75\n12 14 88\n15 16 76\n17 18 97\n19 20 105\n20 20 46\n", "output": "862\n"}, {"input": "10 79\n2 2 70\n2 10 35\n10 10 76\n11 11 66\n12 12 75\n12 14 88\n15 16 76\n17 18 97\n19 20 105\n20 20 46\n", "output": "862\n"}, {"input": "10 79\n2 2 70\n2 10 35\n10 10 ...
code_stdio
[ { "content": "B: 階層的計算機 (Hierarchical Calculator)\n\nProblem\n\nEbi-chan has N formulae: y = a_i x for i =1, ..., N (inclusive). Now she considers a subsequence of indices with length k: s_1, s_2, ..., s_k. At first, let x_0 be 1 and evaluate s_1-th formulae with x = x_0. Next, let x_1 be the output of s_1 and ...
[{"input": "4\n-1 2 -2 2", "output": "4\n1\n2\n3\n4\n"}, {"input": "4\n2 -1 -2 -1", "output": "3\n1\n2\n3\n"}, {"input": "4\n2 -1 -2 1", "output": "3\n1\n2\n3\n"}, {"input": "4\n-1 -2 0 2", "output": "3\n1\n2\n4\n"}, {"input": "4\n1 2 -2 -1", "output": "3\n2\n3\n4\n"}, {"input": "4\n2 -1 -2 0", "output": "3\n1\n2\n3\n"...
code_stdio
[ { "content": "There are $n$ points on a plane. The $i$-th point has coordinates $(x_i, y_i)$. You have two horizontal platforms, both of length $k$. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same $y$-coordinate) and have integer borders. If the left border of t...
[{"input": "4\n7 1\n1 5 0 2 1 10 7\n1 3 6 7 2 5 4\n1 1\n1000000000\n1000001000\n5 10\n10 7 5 15 12\n38 199 192 219 1904\n10 10\n12 19 8 29 20 10 9 2 10 19\n12 4 0 17 1 15 7 18 14 3\n", "output": "4\n1\n5\n10\n"}, {"input": "4\n7 1\n1 5 0 2 1 10 7\n1 3 6 7 0 5 4\n1 1\n1000000000\n1000001000\n5 10\n10 7 5 15 12\n38 199 1...
code_stdio
[ { "content": "If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.\n - The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)\n - The s_i-th digit from th...
[{"input": "3 3\n1 7\n3 2\n1 7\n", "output": "702\n"}, {"input": "3 3\n3 1\n2 1\n1 4\n", "output": "411\n"}, {"input": "3 1\n1 7\n3 2\n0 28", "output": "700\n"}, {"input": "2 3\n2 0\n2 0\n2 0\n", "output": "10\n"}, {"input": "3 3\n1 14\n3 2\n1 7", "output": "-1\n"}, {"input": "3 3\n1 7\n3 4\n1 7", "output": "704\n"}, {...
code_stdio
[ { "content": "N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points.\n\nM judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1.\n\nAfter ...
[{"input": "10 14 8 5\n13 2 3 11 1 11 5 4 3 7", "output": "10\n"}, {"input": "10 14 8 5\n13 2 3 11 1 11 5 7 3 7", "output": "10\n"}, {"input": "10 14 8 5\n13 2 0 11 1 11 5 4 3 7", "output": "10\n"}, {"input": "10 14 8 9\n13 2 3 11 1 11 5 7 3 7", "output": "10\n"}, {"input": "10 14 8 5\n13 2 0 11 1 11 6 4 3 7", "output"...
code_stdio
[ { "content": "Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is t_{i} and its pages' width is equal to w_{i}. The thickness of each book is either 1 or 2. All books have the same page heights. $1$...
[{"input": "100\n2 2\n1 2\n1 1\n2 1\n1 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n2 2\n2 1\n1 1\n1 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 2\n1 2\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n2 2\n1 2\n1 1\n1 1\n1 1\n2 1\n2 1\n1 2\n1 2\n2 2\n1 2\n1 2\n1 1\n2 1\n2 1\n2 2\n1 2\n2 1\n1 1\n2 1\n1 2\n2 2...
code_stdio
[ { "content": "2N players are running a competitive table tennis training on N tables numbered from 1 to N.\n\nThe training consists of rounds. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one l...
[{"input": "2 -2 269", "output": "-131\n"}, {"input": "-1 2 189", "output": "-96\n"}, {"input": "11 -2 81", "output": "-28\n"}, {"input": "-1 4 189", "output": "-97\n"}, {"input": "0 4 249", "output": "-126\n"}, {"input": "0 -1 104", "output": "-51\n"}, {"input": "0 -1 172", "output": "-85\n"}, {"input": "0 0 459", "ou...
code_stdio
[ { "content": "Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b dots on the other half. The set contains exactly 21 dominoes. Here is an exact illustration of his set:\n\...
[{"input": "7 21\n3 5\n7 2\n2 3\n6 5\n5 2\n4 7\n2 6\n2 4\n6 7\n5 1\n1 4\n4 5\n5 7\n4 6\n3 1\n1 2\n3 4\n7 1\n3 7\n6 1\n3 6\n", "output": "16\n"}, {"input": "7 21\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7\n", "output": "16\n"}, {"input": "7 20\n4 7\n1 4\n2 3\...
code_stdio