messages
listlengths
1
1
ground_truth
stringlengths
88
726k
dataset
stringclasses
1 value
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x_1, x_2, ..., x_{k}} (1 ≤ x_{i} ≤ n, 0 < k < n) the sums of elements on that pos...
[{"type": "stdin_stdout", "input": "22\n138499935 195582510 159774498 12295611 37071371 91641202 167958938 119995178 19438466 182405139 207729895 56797798 79876605 152841775 1000000000 149079380 158867321 154637978 72179187 75460169 145092927 103227705\n", "output": "119995178 182405139 158867321 1000000000 19438466 79...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAs technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passwo...
[{"type": "stdin_stdout", "input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGiven are integer sequence of length N, A = (A_1, A_2, \\cdots, A_N), and an integer K.\nFor each X such that 1 \\le X \\le K, find the following value:\n\\left(\\displaystyle \\sum_{L=1}^{N-1} \\sum_{R=L+1}^{N} (A_L+A_R)...
[{"type": "stdin_stdout", "input": "192 275\n426 445 272 81 447 129 497 202 275 325 482 284 417 156 432 402 228 37 357 239 418 211 179 6 340 68 368 16 440 263 93 449 491 310 355 68 431 80 257 218 434 328 176 355 221 80 422 45 11 67 467 174 191 4 335 34 465 480 221 395 1 152 325 231 302 153 396 22 489 399 107 466 432 2 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nWe have a sequence A of N non-negative integers.\nCompute the sum of \\prod _{i = 1} ^N \\dbinom{B_i}{A_i} over all sequences B of N non-negative integers whose sum is at most M, and print it modulo (10^9 + 7).\nHere, \\d...
[{"type": "stdin_stdout", "input": "2000 4000001\n2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOn the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).\nHe can move in arbitrary directions with speed 1.\nHere, we will consider him as a point without size.\nThere are N circular ba...
[{"type": "stdin_stdout", "input": "711627115 480696358 633203014 877112611\n997\n823068082 -750068892 144324195\n-150528283 572165970 8705984\n579786057 146049479 458783401\n-571870801 -833355728 354709151\n-225671601 -182489804 264833500\n816772899 775985943 18276416\n111104358 490248913 465440593\n-508331521 -827309...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGiven positive integers N, K and M, solve the following problem for every integer x between 1 and N (inclusive):\n - Find the number, modulo M, of non-empty multisets containing between 0 and K (inclusive) instances of ea...
[{"type": "stdin_stdout", "input": "100 100 996766481\n", "output": "100\n479013218\n301906461\n76865454\n197164919\n185261994\n562146154\n218533225\n703919664\n761757943\n421733444\n150668448\n939625796\n441056419\n399708797\n265484256\n872130614\n530113978\n956321625\n942851863\n391142590\n196625433\n784864879\n81918...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAn accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (A...
[{"type": "stdin_stdout", "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "oenfnemfddbhhmig]gcd:]:mnnbj::f|ichec:|dkfnjbfjkdgoge]lfihgd[...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAnton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.\n\nYour task is to help Anton and to find the integer that interests him. If there are several such i...
[{"type": "stdin_stdout", "input": "1000000000000000000\n", "output": "999999999999999999\n"}, {"type": "stdin_stdout", "input": "978916546899999999\n", "output": "899999999999999999\n"}, {"type": "stdin_stdout", "input": "999999999999999999\n", "output": "999999999999999999\n"}, {"type": "stdin_stdout", "input": "9999...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nApart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky an...
[{"type": "stdin_stdout", "input": "1000000000\n", "output": "1000000000\n"}, {"type": "stdin_stdout", "input": "100000000\n", "output": "100000000\n"}, {"type": "stdin_stdout", "input": "900000000\n", "output": "100000000\n"}, {"type": "stdin_stdout", "input": "100000001\n", "output": "99999999\n"}, {"type": "stdin_st...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the sn...
[{"type": "stdin_stdout", "input": "42\n15 44\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "26\n04 58\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "35\n15 25\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "50\n01 59\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "46\n06 16\n"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! \n\n $m$ \n\nInitially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal...
[{"type": "stdin_stdout", "input": "5\n4 807989196\n770312657 78181451\n624192034 690910298\n754831733 354913874\n519577171 400120478\n4 491297333\n546432637 76258441\n312107971 75446008\n767483254 958677299\n84044330 577526244\n2 177840791\n197738084 143071228\n23274563 597315796\n7 610054060\n858529462 646280969\n644...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAnton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:\n\n\"Once upon a time, there lived an emperor. He was very rich and had much grain. O...
[{"type": "stdin_stdout", "input": "1000000000000000000 1000000000000000000\n", "output": "1000000000000000000\n"}, {"type": "stdin_stdout", "input": "1000000000000000000 999999999999999999\n", "output": "1000000000000000000\n"}, {"type": "stdin_stdout", "input": "1000000000000000000 999999999999999998\n", "output": "1...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nTokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ra...
[{"type": "stdin_stdout", "input": "1s 2s 3s\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "9m 9m 9m\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3p 9m 2p\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "8p 2s 9m\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5s 8m 5s\n", "output...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?\n\nFortunately, the thief had left a note ...
[{"type": "stdin_stdout", "input": "6\n10 10\n3 6 3 7\n4 9 5 9\n5 4 5 3\n7 1 8 1\n9 10 8 10\n7 7 7 8\n0 5 2 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n4 6\n4 3 3 3\n4 2 4 1\n3 6 2 6\n2 4 2 3\n1 1 1 2\n1 2 2 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "5\n5 7\n5 5 5 6\n2 4 2 5\n2 3 1 3\...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOn the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the ma...
[{"type": "stdin_stdout", "input": "1000000\n", "output": "285714 285715\n"}, {"type": "stdin_stdout", "input": "999999\n", "output": "285714 285714\n"}, {"type": "stdin_stdout", "input": "999998\n", "output": "285713 285714\n"}, {"type": "stdin_stdout", "input": "999997\n", "output": "285712 285714\n"}, {"type": "stdi...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nNow you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.\n\nThe situation is compl...
[{"type": "stdin_stdout", "input": "11 11\n11 6 4 7 8 5 1 3 2 9 10\n5 3 4 7 9 11\n0\n1 2\n1 3\n2 3 4\n6 1 3 4 8 10 11\n1 3\n2 2 4\n3 2 4 11\n5 4 5 7 9 11\n4 2 3 4 7\n", "output": "11\n2 3 4 7 11 9 1 5 8 10 6 \n"}, {"type": "stdin_stdout", "input": "11 10\n9 6 10 3 2 8 4 7 11 5\n1 2\n0\n5 1 8 9 10 11\n4 1 7 8 11\n3 2 7 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLet's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).\n\nYou may perform the following operations until both a and s are empty:\n\n Take the first element of a, push it int...
[{"type": "stdin_stdout", "input": "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "40 38\n32 35 36 4 22 6 15 21 40 13 33 17 5 24 28 9 1 23 25 14 26 3 8 11 37 30 18 16 19 20 27 12 39 2 10 38 29 3...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i...
[{"type": "stdin_stdout", "input": "-1000000000 1000000000 1000000000\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "119057893 -516914539 -39748277\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "479823846 -403424770 -653472589\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "-52536829 -...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA string is called bracket sequence if it does not contain any characters other than \"(\" and \")\". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characte...
[{"type": "stdin_stdout", "input": "1000000000\n1000000000\n1000000000\n1000000000\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1000000000\n1000000000\n1000000000\n999999999\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1000000000\n999999999\n1000000000\n1000000000\n", "output": "1\n"}, {"type": ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nArpa is researching the Mexican wave.\n\nThere are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. \n\n At time 1, the first spectator stands. At time 2, the second spectator sta...
[{"type": "stdin_stdout", "input": "1000000000 1000000000 1000000000\n", "output": "1000000000\n"}, {"type": "stdin_stdout", "input": "1000000000 1000000000 1400000000\n", "output": "600000000\n"}, {"type": "stdin_stdout", "input": "1000000000 100000000 1000000000\n", "output": "100000000\n"}, {"type": "stdin_stdout", ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPetya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of ...
[{"type": "stdin_stdout", "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"}, {"type": "stdin_stdout", "input": "bababaaababaabbbbbabbbbbbaa...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.\n\nAll levels in this game have two stats to them: the number ...
[{"type": "stdin_stdout", "input": "1\n99\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nKaren is getting ready for a new school day!\n\n [Image] \n\nIt is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a pali...
[{"type": "stdin_stdout", "input": "05:51\n", "output": "250\n"}, {"type": "stdin_stdout", "input": "15:52\n", "output": "250\n"}, {"type": "stdin_stdout", "input": "06:59\n", "output": "182\n"}, {"type": "stdin_stdout", "input": "17:31\n", "output": "151\n"}, {"type": "stdin_stdout", "input": "07:59\n", "output": "122...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLet's call a string \"s-palindrome\" if it is symmetric about the middle of the string. For example, the string \"oHo\" is \"s-palindrome\", but the string \"aa\" is not. The string \"aa\" is not \"s-palindrome\", because...
[{"type": "stdin_stdout", "input": "mmmmmmmmmmmmmmmm\n", "output": "NIE\n"}, {"type": "stdin_stdout", "input": "nnnnnnnnnnnnn\n", "output": "NIE\n"}, {"type": "stdin_stdout", "input": "AAAANANAAAA\n", "output": "NIE\n"}, {"type": "stdin_stdout", "input": "HCMoxkgbNb\n", "output": "NIE\n"}, {"type": "stdin_stdout", "inp...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.\n\nIt is allowed to l...
[{"type": "stdin_stdout", "input": "1000000000000000000\n1000000000000000000\n", "output": "1000000000000000000\n"}, {"type": "stdin_stdout", "input": "999999999999999999\n1000000000000000000\n", "output": "999999999999999999\n"}, {"type": "stdin_stdout", "input": "123456789123456789\n276193619183618162\n", "output": "...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top ...
[{"type": "stdin_stdout", "input": "5 24\n", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n"}, {"type": "stdin_stdout", "input": "5 10\n", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n"}, {"type": "stdin_stdout", "input": "5 10\n", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nWet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal poin...
[{"type": "stdin_stdout", "input": "144.6 103.0 193.4\n", "output": "y^x^z\n"}, {"type": "stdin_stdout", "input": "184.1 118.5 129.5\n", "output": "y^z^x\n"}, {"type": "stdin_stdout", "input": "200.0 200.0 200.0\n", "output": "x^y^z\n"}, {"type": "stdin_stdout", "input": "200.0 0.1 200.0\n", "output": "(x^y)^z\n"}, {"t...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.\n\nUnfortunately, the archive with Olympiad's data is a...
[{"type": "stdin_stdout", "input": "20\nphp8vy 1\nkeeona 0\n8 0\nwzf4eb 0\n16 1\n9 0\nf2548d 0\n11 0\nyszsig 0\nyyf4q2 0\n1pon1p 1\njvpwuo 0\nd9stsx 0\ne14bkx 1\n5 0\n17 0\nsbklx4 0\nsfms2u 1\n6 0\n18 1\n", "output": "16\nmove 16 1\nmove 18 2\nmove 5 20\nmove 6 19\nmove php8vy 3\nmove 1pon1p 4\nmove e14bkx 5\nmove sfms...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pol...
[{"type": "stdin_stdout", "input": "10\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "9\n1355 North\n15309 West\n17834 North\n13612 East\n17477 North\n4546 North\n18260 East\n154...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0.\n\n\n-----Input-----\n\nThe only lin...
[{"type": "stdin_stdout", "input": "1789433851 -633540112 1286318222 -1728151682 1438333624 1538194890\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1955378240 -837482305 1743607821 -1623988108 -653286850 178227154\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "735463638 620656007 878587644 5365076...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe flag of Berland is such rectangular field n × m that satisfies following conditions:\n\n Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height s...
[{"type": "stdin_stdout", "input": "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBB...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAyrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of...
[{"type": "stdin_stdout", "input": "1000000000000000000\n", "output": "-418284973 -1154700538\n"}, {"type": "stdin_stdout", "input": "777389199399770518\n", "output": "-328249537 -1018095738\n"}, {"type": "stdin_stdout", "input": "259599671487287531\n", "output": "-252460838 -588330600\n"}, {"type": "stdin_stdout", "in...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nDante is engaged in a fight with \"The Savior\". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.\n\...
[{"type": "stdin_stdout", "input": "63 100 1960\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "73 100 3111\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "11 70 1199\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "19 100 836\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "25...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRunning with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:\n\nThe track is the circle with length L, in distinct po...
[{"type": "stdin_stdout", "input": "50 100\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings \"kek\", \"abacaba\", \"r\" and \"papicipap\" are palindromes, while the strings \"abb\" an...
[{"type": "stdin_stdout", "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow\n", "output": "49\n"}, {"type": "stdin_stdout", "input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy\n", "output": "50\n"}, {"type": "stdin_stdout", "input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n", "output": "...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIs it rated?\n\nHere it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.\n\nAnother Codeforces round has been conducted. No two participants have the same nu...
[{"type": "stdin_stdout", "input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110\n", "output": "unrated\n"}, {"type": "stdin_stdout", "input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a binary string $s$.\n\nFind the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring.\n\nThe cyclical string $t$ contains $s$ as a substring if there is some cyclical sh...
[{"type": "stdin_stdout", "input": "40\n0000000000100000100000000000000000000000\n", "output": "40"}, {"type": "stdin_stdout", "input": "40\n1111111111111011111111101111111111111111\n", "output": "40"}, {"type": "stdin_stdout", "input": "40\n1111110111111111111111011111111111111110\n", "output": "40"}, {"type": "stdin_...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.\n\nNon-oriented angle is non-negative value, min...
[{"type": "stdin_stdout", "input": "11\n-7945 386\n7504 -576\n-6020 -8277\n930 9737\n1682 474\n-8279 1197\n2790 2607\n-5514 -9601\n-3159 5939\n-1806 4207\n-9073 -2138\n", "output": "10 9\n"}, {"type": "stdin_stdout", "input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.\n\nVasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t s...
[{"type": "stdin_stdout", "input": "1000000000000 1000000 999999 1000000 1000000\n", "output": "999999999999000000\n"}, {"type": "stdin_stdout", "input": "997167959139 199252 232602 952690 802746\n", "output": "231947279018960454\n"}, {"type": "stdin_stdout", "input": "244641009859 748096 689016 889744 927808\n", "outp...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal.\n\nGreatest com...
[{"type": "stdin_stdout", "input": "479001600 6\n", "output": "22809600 45619200 68428800 91238400 114048000 136857600\n"}, {"type": "stdin_stdout", "input": "479001600 5\n", "output": "31933440 63866880 95800320 127733760 159667200\n"}, {"type": "stdin_stdout", "input": "479001600 4\n", "output": "47900160 95800320 14...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBizon the Champion isn't just charming, he also is very smart.\n\nWhile some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication t...
[{"type": "stdin_stdout", "input": "500000 500000 250000000000\n", "output": "250000000000\n"}, {"type": "stdin_stdout", "input": "499997 499989 248758432143\n", "output": "225563648440\n"}, {"type": "stdin_stdout", "input": "183656 409931 42943608085\n", "output": "17438143800\n"}, {"type": "stdin_stdout", "input": "2...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLet's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 1234567891011121314151617181920212223242526272829303...
[{"type": "stdin_stdout", "input": "1000000000000\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1000000000000\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "100000000000\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "100000000000\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "99...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nWelcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!\n\nIn the morning, there are $n$ oppo...
[{"type": "stdin_stdout", "input": "29 30 989\n450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450\n451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451\n", "output": "991\n"}, {"type": "st...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nВ Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в од...
[{"type": "stdin_stdout", "input": "wajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk\n", "output": "YES\nwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk\n"}, {"type": "stdin_stdout", "input": "twfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkj...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nDaniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for ...
[{"type": "stdin_stdout", "input": "288230376151711743\n", "output": "144115188344291328\n288230376151711744\n"}, {"type": "stdin_stdout", "input": "72057594037927935\n", "output": "36028797153181696\n72057594037927936\n"}, {"type": "stdin_stdout", "input": "1125899906842623\n", "output": "562949970198528\n112589990684...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1.\n\nIvan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t t...
[{"type": "stdin_stdout", "input": "100\nadebebcdacabaadcbcdebcccdaadaeeedecdbcbdeddcbcaeedbecaeeabaabbdccaebdebabbabdcebbbdaabdbddcadaddadad\n52 62 28 18 100 84 16 53 43 52 49 92 10 64 50 95 90 52 21 14 60 3 94 63 31 70 74 62 93 75 100 96 58 36 76 40 62 74 91 77 92 78 65 11 50 18 79 29 10 25 4 24 44 39 4 91 81 63 97 6...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item w...
[{"type": "stdin_stdout", "input": "1000000000 1000000000\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "441890232 441890232\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "401739553 401739553\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "285681920 285681919\n", "output": "YES\n"}, {...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:\n\nFind k integers such that the sum of two to the power of e...
[{"type": "stdin_stdout", "input": "4 144\n", "output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyr...
[{"type": "stdin_stdout", "input": "10 10000\n", "output": "55\n"}, {"type": "stdin_stdout", "input": "10 1022\n", "output": "53\n"}, {"type": "stdin_stdout", "input": "10 1023\n", "output": "55\n"}, {"type": "stdin_stdout", "input": "10 1024\n", "output": "55\n"}, {"type": "stdin_stdout", "input": "8 10000\n", "output...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAfter making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them....
[{"type": "stdin_stdout", "input": "4\n-474 -894\n-474 -833\n-446 -894\n-446 -833\n", "output": "1708\n"}, {"type": "stdin_stdout", "input": "4\n-414 -891\n-414 896\n346 -891\n346 896\n", "output": "1358120\n"}, {"type": "stdin_stdout", "input": "4\n-796 -330\n-796 758\n171 -330\n171 758\n", "output": "1052096\n"}, {"t...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.\n\nFor some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is...
[{"type": "stdin_stdout", "input": "70\n4 65 66 30 67 16 39 35 57 14 42 51 5 21 61 53 63 13 60 29 68 70 69 46 20 2 43 47 49 52 26 44 54 62 25 19 12 28 27 24 18 36 6 33 7 8 11 1 45 32 64 38 23 22 56 59 15 9 41 37 40 55 3 31 34 48 50 10 17 58\n111111101101111111111110101111111111111101101111010010110011011110010\n", "out...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and ...
[{"type": "stdin_stdout", "input": "1000000000000000000d\n", "output": "3999999999999999994\n"}, {"type": "stdin_stdout", "input": "1000000000000000000a\n", "output": "3999999999999999995\n"}, {"type": "stdin_stdout", "input": "1000000000000000000e\n", "output": "3999999999999999993\n"}, {"type": "stdin_stdout", "input...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAfter seeing the \"ALL YOUR BASE ARE BELONG TO US\" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.\n\nYou're given a number X represented in base b_{x}...
[{"type": "stdin_stdout", "input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 39\n38 38 38 38 38 38 38 38 38 38\n", "output": ">\n"}, {"type": "stdin_stdout", "input": "10 38\n16 19 37 32 16 7 14 33 16 11\n10 39\n10 27 35 15 31 15 17 16 38 35\n", "output": ">\n"}, {"type": "stdin_stdout", "input": "10 39\n35 12 31 35 28...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSince 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 ar...
[{"type": "stdin_stdout", "input": "3\n184 222 102\n", "output": "BitAryo\n"}, {"type": "stdin_stdout", "input": "3\n101 186 223\n", "output": "BitAryo\n"}, {"type": "stdin_stdout", "input": "3\n103 286 100\n", "output": "BitLGM\n"}, {"type": "stdin_stdout", "input": "3\n244 241 295\n", "output": "BitLGM\n"}, {"type": ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVova again tries to play some computer card game.\n\nThe rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each ca...
[{"type": "stdin_stdout", "input": "100 72\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\n", "output": "4549\n"}, {"type": "stdin_stdout", "input": "100 72\n3...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOne day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa...
[{"type": "stdin_stdout", "input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb\n", "...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.\n\n\n-----Input...
[{"type": "stdin_stdout", "input": "85\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1\n", "output": "84\n"}, {"type": "st...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.\n\n [Image] \n\nWillman and Bolt have exactly the same speed, so when th...
[{"type": "stdin_stdout", "input": "5000000000000000000 4999999999999999837 4999999999999999963\n", "output": "1249999999999999959/1250000000000000000\n"}, {"type": "stdin_stdout", "input": "4000000000000000000 3999999999999999691 3999999999999999887\n", "output": "399999999999999969/400000000000000000\n"}, {"type": "s...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nNauuo is a girl who loves writing comments.\n\nOne day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.\n\nIt's known that there were $x$ persons who would upvote, $y$ persons who...
[{"type": "stdin_stdout", "input": "100 100 100\n", "output": "?"}, {"type": "stdin_stdout", "input": "100 0 100\n", "output": "?"}, {"type": "stdin_stdout", "input": "100 100 0\n", "output": "0"}, {"type": "stdin_stdout", "input": "50 100 50\n", "output": "?"}, {"type": "stdin_stdout", "input": "100 50 50\n", "output"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(...
[{"type": "stdin_stdout", "input": "386\nRUDLURLUURDDLLLRLDURLRRDLDUUURLLRDLRRDLDRLDDURDURURDRLUULLDUULRULDLLLLDLUURRLRRRUDULRDDRDLDULRLDDRDDRLRLDLDULLULUDULLLDUUDURURDDLDRLUDDDDLDUDUURLUUDURRUDRLUDRLULLRLRRDLULDRRURUULLRDLDRLURDUDRLDLRLLUURLURDUUDRDURUDDLLDURURLLRRULURULRRLDLDRLLUUURURDRRRLRDRURULUDURRLRLDRUDLRRRRLLRU...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \\dots$ For example, if $s =$ 10010, then $t =$ 1001...
[{"type": "stdin_stdout", "input": "1\n439 -6100238\n100011110101001111000100101001001100010100010101001011100000110000000010011011111100010011100100000010011000110100111010100100100101101101100111100001010000010110000111011100000001110111100111110011110001001001100010110101100101011111010110010110101111001011000111010...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}.\n\nIn the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For ...
[{"type": "stdin_stdout", "input": "1000999999 3\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "1090090090 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1234567890 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1234567890 2\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "1234...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOn the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.\n\nSeating in the class looks like a rectangle, where n rows with m pupils in each. \n\nThe teacher...
[{"type": "stdin_stdout", "input": "1 1 1000000000000000000 1 1\n", "output": "1000000000000000000 1000000000000000000 1000000000000000000"}, {"type": "stdin_stdout", "input": "1 100 1000000000000000000 1 35\n", "output": "10000000000000000 10000000000000000 10000000000000000"}, {"type": "stdin_stdout", "input": "1 35 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAfter the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.\n\nThe three frie...
[{"type": "stdin_stdout", "input": "727\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffee...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.\n\nAt first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from...
[{"type": "stdin_stdout", "input": "1000 500 500 1000 499\n", "output": "501\n"}, {"type": "stdin_stdout", "input": "1000 999 1000 1000 998\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1000 1000 1000 0 999\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1000 500 900 100 300\n", "output": "3\n"}, {"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nDima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.\n\nMore formally...
[{"type": "stdin_stdout", "input": "630045387\n", "output": "3\n11 239 630045137"}, {"type": "stdin_stdout", "input": "999962901\n", "output": "3\n19 109 999962773"}, {"type": "stdin_stdout", "input": "999991817\n", "output": "3\n11 137 999991669"}, {"type": "stdin_stdout", "input": "999991797\n", "output": "3\n19 109 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (\".\") or it can be occupied by a wall (\"*\"). \n\nYou have one bomb. If you lay the bomb at t...
[{"type": "stdin_stdout", "input": "10 20\n....................\n.........*..........\n....................\n....................\n....................\n....................\n....................\n....................\n...*................\n....................\n", "output": "YES\n9 10\n"}, {"type": "stdin_stdout", "in...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBerland Football Cup starts really soon! Commentators from all over the world come to the event.\n\nOrganizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shoul...
[{"type": "stdin_stdout", "input": "500000000001 1000000000000 100 100\n", "output": "49999999999900\n"}, {"type": "stdin_stdout", "input": "1000000000000 750000000001 10 100\n", "output": "5000000000020\n"}, {"type": "stdin_stdout", "input": "1000000000000 750000000001 100 10\n", "output": "2499999999990\n"}, {"type":...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe only difference between easy and hard versions is constraints.\n\nPolycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the un...
[{"type": "stdin_stdout", "input": "15 112\n15 3\n15 2\n13 2\n12 2\n12 1\n15 3\n13 3\n15 2\n15 1\n14 2\n14 2\n14 2\n15 3\n13 3\n14 2\n", "output": "1579680\n"}, {"type": "stdin_stdout", "input": "15 130\n14 2\n13 3\n14 1\n8 3\n9 3\n15 2\n10 2\n10 2\n4 2\n4 2\n12 1\n12 2\n6 3\n3 3\n10 1\n", "output": "159107833\n"}, {"t...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVivek initially has an empty array $a$ and some integer constant $m$.\n\nHe performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the g...
[{"type": "stdin_stdout", "input": "100000\n", "output": "534174612\n"}, {"type": "stdin_stdout", "input": "99991\n", "output": "434191575\n"}, {"type": "stdin_stdout", "input": "30030\n", "output": "723188569\n"}, {"type": "stdin_stdout", "input": "99594\n", "output": "166105505\n"}, {"type": "stdin_stdout", "input": ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nNeko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.\n\nNeko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least c...
[{"type": "stdin_stdout", "input": "1000000000 264865600\n", "output": "102701600"}, {"type": "stdin_stdout", "input": "948248258 533435433\n", "output": "296190217"}, {"type": "stdin_stdout", "input": "999999973 800000007\n", "output": "199999823"}, {"type": "stdin_stdout", "input": "112342324 524224233\n", "output": ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nNoora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.\n\...
[{"type": "stdin_stdout", "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovel...
[{"type": "stdin_stdout", "input": "499999999\n", "output": "1249999995\n"}, {"type": "stdin_stdout", "input": "1000000000\n", "output": "500000000\n"}, {"type": "stdin_stdout", "input": "499999998\n", "output": "1249999991\n"}, {"type": "stdin_stdout", "input": "458679894\n", "output": "1043399471\n"}, {"type": "stdin...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments larg...
[{"type": "stdin_stdout", "input": "906992640 544195584\n906992640 725594112\n", "output": "2\n604661760 544195584\n453496320 725594112\n"}, {"type": "stdin_stdout", "input": "859963392 644972544\n725594112 967458816\n", "output": "6\n214990848 644972544\n143327232 967458816\n"}, {"type": "stdin_stdout", "input": "6449...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn fr...
[{"type": "stdin_stdout", "input": "100000 99999 100000 100000\n", "output": "Polycarp\n"}, {"type": "stdin_stdout", "input": "100000 100000 100000 99999\n", "output": "Vasiliy\n"}, {"type": "stdin_stdout", "input": "55000 60000 55003 60100\n", "output": "Polycarp\n"}, {"type": "stdin_stdout", "input": "23039 21508 541...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPetr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells conta...
[{"type": "stdin_stdout", "input": "11 6\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10 1\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10 2\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10 3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10 4\n", "output": "5\n"}, {"type": ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe year 2015 is almost over.\n\nLimak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 1...
[{"type": "stdin_stdout", "input": "1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "500000000000000000 1000000000000000000\n", "output": "58\n"}, {"type": "stdin_stdout", "input": "500000000000000000 576460752303423488\n", "output": "57\n"}, {"type": "stdin_stdout", "inp...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAnya loves to fold and stick. Today she decided to do just that.\n\nAnya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamat...
[{"type": "stdin_stdout", "input": "25 16 13326087796\n157576937 627434432 942652043 706432863 631136945 714549755 465703470 663358517 695561723 249240606 833566455 396564536 758483017 253748999 978210764 530023233 193812243 317718202 184788435 892848108 150420430 330992298 780787784 196460118 674015883\n", "output": "...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSuppose you are performing the following algorithm. There is an array $v_1, v_2, \\dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you c...
[{"type": "stdin_stdout", "input": "1\n30 2\n16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 7036874417766...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLet's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:\n\n$\\sum_{i = 1}^{a} \\sum_{j = 1}^{b} \\sum_{k = 1}^{c} d(i \\cd...
[{"type": "stdin_stdout", "input": "100 100 100\n", "output": "51103588\n"}, {"type": "stdin_stdout", "input": "98 34 100\n", "output": "13589991\n"}, {"type": "stdin_stdout", "input": "90 82 100\n", "output": "35482866\n"}, {"type": "stdin_stdout", "input": "67 90 100\n", "output": "27880104\n"}, {"type": "stdin_stdou...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid ...
[{"type": "stdin_stdout", "input": "AB\nXC\nXB\nAC\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "AB\nXC\nAX\nCB\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "CB\nAX\nXA\nBC\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "CB\nAX\nCX\nAB\n", "output": "YES\n"}, {"type": "stdin_stdout"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAlexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will ...
[{"type": "stdin_stdout", "input": "2\n110111100000101101101011001110100111011001000000000000000000\n", "output": "1000000000000000000"}, {"type": "stdin_stdout", "input": "2\n1110110101111000010001011110101001011001110000000010111010\n", "output": "267367244641009850"}, {"type": "stdin_stdout", "input": "3\n1210020121...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAt first, let's define function $f(x)$ as follows: $$ \\begin{matrix} f(x) & = & \\left\\{ \\begin{matrix} \\frac{x}{2} & \\mbox{if } x \\text{ is even} \\\\ x - 1 & \\mbox{otherwise } \\end{matrix} \\right. \\end{matrix}...
[{"type": "stdin_stdout", "input": "1000000000000000000 1\n", "output": "1000000000000000000\n"}, {"type": "stdin_stdout", "input": "1000000000000000000 100\n", "output": "31249999999999998\n"}, {"type": "stdin_stdout", "input": "1000000000000000000 10000\n", "output": "244140624999998\n"}, {"type": "stdin_stdout", "in...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider a billiard table of rectangular size $n \\times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). [Image] \n\nThere is one ball at the point $(...
[{"type": "stdin_stdout", "input": "1000000000 999999999 999999998 999999999 -1 -1\n", "output": "1000000000 999999999"}, {"type": "stdin_stdout", "input": "1000000000 999999999 999999998 999999999 -1 1\n", "output": "1000000000 999999999"}, {"type": "stdin_stdout", "input": "827285013 307724101 775951207 175683367 -1 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has sha...
[{"type": "stdin_stdout", "input": "1000 1000\n999 999\n1 1000\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "808 1000\n583 676\n527 416\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "965 1000\n606 895\n533 394\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "958 1000\n326 461\n836 674...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMasha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.\n\nYou are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequen...
[{"type": "stdin_stdout", "input": "-3 0 92055 36\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 7803958...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nInnocentius has a problem — his computer monitor has broken. Now some of the pixels are \"dead\", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the...
[{"type": "stdin_stdout", "input": "8 16\n................\n................\n................\n................\n............w...\n................\n................\n..............w.\n", "output": "................\n................\n................\n................\n............w+++\n............+..+\n...............
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.\n\nFind out if...
[{"type": "stdin_stdout", "input": "10000000\n10000000\n10000000\n", "output": "YES\n0 1\n"}, {"type": "stdin_stdout", "input": "10000000\n9999999\n1\n", "output": "YES\n0 10000000\n"}, {"type": "stdin_stdout", "input": "10000000\n1234523\n1\n", "output": "YES\n0 10000000\n"}, {"type": "stdin_stdout", "input": "1000000...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nToday Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.\n\nHis phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score wit...
[{"type": "stdin_stdout", "input": "73\n", "output": "seventy-three\n"}, {"type": "stdin_stdout", "input": "77\n", "output": "seventy-seven\n"}, {"type": "stdin_stdout", "input": "78\n", "output": "seventy-eight\n"}, {"type": "stdin_stdout", "input": "27\n", "output": "twenty-seven\n"}, {"type": "stdin_stdout", "input"...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \\le a_1 < a_2 < \\ldots < a_n \\le 10^3$, and t...
[{"type": "stdin_stdout", "input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nЕсть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая ква...
[{"type": "stdin_stdout", "input": "1000 1000 1000\n1000000000 990000001\n", "output": "1144\n"}, {"type": "stdin_stdout", "input": "491 980 907\n253658701 421137262\n", "output": "3985\n"}, {"type": "stdin_stdout", "input": "200 970 827\n113595903 145423943\n", "output": "1484\n"}, {"type": "stdin_stdout", "input": "8...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nTop-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.\n\nHer problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove ...
[{"type": "stdin_stdout", "input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111\n", "output": "yes"}, {"type": "stdin_stdout", "input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111\n", "output": "yes"}, {"t...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a string s consisting of |s| small english letters.\n\nIn one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with...
[{"type": "stdin_stdout", "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"}, {"type": "stdin_stdout...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nWhile Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise t...
[{"type": "stdin_stdout", "input": "100000 100000 100000 100000\n", "output": "100000.0000000000\n"}, {"type": "stdin_stdout", "input": "80000 80000 40000 100000\n", "output": "99625.0947119987\n"}, {"type": "stdin_stdout", "input": "51122 86737 45712 45929\n", "output": "45929.0000000000\n"}, {"type": "stdin_stdout", ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nNick had received an awesome array of integers $a=[a_1, a_2, \\dots, a_n]$ as a gift for his $5$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a l...
[{"type": "stdin_stdout", "input": "10\n6 1 -11 -10 -9 -8 8 -1 -10 1\n", "output": "-7 -2 -11 -10 -9 -8 -9 -1 -10 -2 "}, {"type": "stdin_stdout", "input": "10\n2 10 6 8 -4 -11 -10 3 -3 8\n", "output": "-3 -11 -7 -9 -4 -11 -10 -4 -3 -9 "}, {"type": "stdin_stdout", "input": "10\n8 6 3 9 8 7 7 7 7 6\n", "output": "-9 -7 -...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.\n\nDivisor of n is any such natural number, that n can be divided by it without remainder.\n\n\n-----Input-----\n\nThe ...
[{"type": "stdin_stdout", "input": "866421317361600 26880\n", "output": "866421317361600\n"}, {"type": "stdin_stdout", "input": "999999961946176 63\n", "output": "999999961946176\n"}, {"type": "stdin_stdout", "input": "999999999999989 2\n", "output": "999999999999989\n"}, {"type": "stdin_stdout", "input": "100000000000...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAbsent-minded Masha got set of n cubes for her birthday.\n\nAt each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cu...
[{"type": "stdin_stdout", "input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "output": "87"}, {"type": "stdin_stdout", "input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "output": "98"}, {"type": "stdin_stdout", "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9\n", "output": "32"}, {"type": "stdin_stdout", "in...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nFor a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.\n\nFor example, 4-rounding of 375 is 375·80 = 30000. 30000 is...
[{"type": "stdin_stdout", "input": "123456789 8\n", "output": "12345678900000000\n"}, {"type": "stdin_stdout", "input": "999999999 8\n", "output": "99999999900000000\n"}, {"type": "stdin_stdout", "input": "222222222 8\n", "output": "11111111100000000\n"}, {"type": "stdin_stdout", "input": "655360001 8\n", "output": "65...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given two matrices $A$ and $B$. Each matrix contains exactly $n$ rows and $m$ columns. Each element of $A$ is either $0$ or $1$; each element of $B$ is initially $0$.\n\nYou may perform some operations with matrix...
[{"type": "stdin_stdout", "input": "5 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\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\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 ...
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to dif...
[{"type": "stdin_stdout", "input": "100 100 100\n", "output": "0.333333333333 0.333333333333 0.333333333333\n"}, {"type": "stdin_stdout", "input": "100 100 99\n", "output": "0.320730423530 0.341631521601 0.337638054869\n"}, {"type": "stdin_stdout", "input": "100 99 100\n", "output": "0.341631521601 0.337638054869 0.320...
code_stdio