messages
listlengths
1
1
ground_truth
stringlengths
156
726k
dataset
stringclasses
1 value
[ { "content": "Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to n. Each student i (1 ≤ i ≤ n) has a best friend p[i] (1 ≤ p[i] ≤ n). In fact, each ...
[{"input": "10\n9 10 6 8 5 3 1 7 4 2\n7 6 2 9 5 10 8 4 1 3\n", "output": "8 3 10 1 5 2 4 9 7 6 "}, {"input": "10\n2 9 1 7 6 8 5 4 10 3\n6 8 5 1 9 10 2 3 4 7\n", "output": "5 6 7 3 2 9 1 10 8 4 "}, {"input": "10\n5 9 7 1 4 10 3 6 2 8\n8 3 9 10 6 5 2 1 7 4\n", "output": "10 7 2 6 8 1 9 4 3 5 "}, {"input": "5\n4 1 2 5 3\n...
code_stdio
[ { "content": "You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.\n\nWe define the distance betwe...
[{"input": "20\n-2967010 48581504\n-2967318 48581765\n-2967443 48581988\n-2967541 48582265\n-2967443 48582542\n-2967318 48582765\n-2967010 48583026\n-2966691 48583154\n-2966252 48583234\n-2965813 48583154\n-2965494 48583026\n-2965186 48582765\n-2965061 48582542\n-2964963 48582265\n-2965061 48581988\n-2965186 48581765\n...
code_stdio
[ { "content": "There is an H \\times W grid (H vertical, W horizontal), where each square contains a lowercase English letter.\nSpecifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i.\nSnuke can apply the following operation to this grid any number...
[{"input": "12 12\nbimonigaloaf\nfaurwlkbleht\ndexwimqxzxbb\nlxdgyoifcxid\nydxiliocfdgx\nnfoabgilamoi\nibxbdqmzxxwe\npqirylfrcrnf\nwtehfkllbura\nyfrnpflcrirq\nwvcclwgiubrk\nlkbrwgwuiccv\n", "output": "YES\n"}, {"input": "12 12\ntcjbfnoikqgi\nqnnpryzflcef\nagdzieukjutu\nffzyepnqclrn\nkuuetzdaujig\noywsialqlusj\nkqjvjhyc...
code_stdio
[ { "content": "You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.\n\nHere, a subsequenc...
[{"input": "5\naabbc", "output": "17\n"}, {"input": "5\nabcda", "output": "23\n"}, {"input": "5\nbdacf", "output": "31\n"}, {"input": "5\nabcaa", "output": "15\n"}, {"input": "5\nabbaa", "output": "11\n"}, {"input": "5\naabba", "output": "11\n"}, {"input": "5\nabbba", "output": "11\n"}, {"input": "5\nbbbaa", "output": ...
code_stdio
[ { "content": "There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.\nBetween these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \\leq i \\leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).\nWhen...
[{"input": "4347\n260851 113568 146755 277208 291368 365593 306158 216020 344668 347475 275144 352224 284362 117882 195739 364750 445348 416819 269652 99635 82915 80392 51627 75388 237943 322687 343290 419290 298882 162789 250158 343046 283281 278723 215017 105840 263209 271290 119076 276553 322767 277981 268358 302036...
code_stdio
[ { "content": "The only difference between easy and hard versions is the maximum value of $n$.\n\nYou are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$.\n\nThe positive integer is called good if it can be represented as...
[{"input": "100\n2\n8\n5\n6\n5\n4\n4\n6\n12\n2\n9\n5\n10\n8\n4\n10\n9\n6\n9\n4\n5\n6\n4\n4\n7\n1\n2\n2\n5\n6\n1\n5\n10\n9\n10\n16\n3\n2\n2\n3\n2\n7\n9\n2\n9\n5\n7\n8\n1\n5\n2\n5\n1\n3\n8\n4\n7\n9\n3\n1\n7\n1\n2\n4\n7\n2\n7\n1\n1\n10\n8\n5\n7\n12\n10\n8\n1\n7\n5\n10\n7\n6\n6\n6\n7\n4\n9\n3\n4\n9\n10\n7\n1\n1\n6\n9\n3\n8...
code_stdio
[ { "content": "A car number in Berland consists of exactly n digits. A number is called beautiful if it has at least k equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of n digits Vasya has to pay the sum of money, equal to the absolute differ...
[{"input": "490 406\n69376206583505466779821214863898994183223683064168986020986087427466188663988162816834873783630551758344308091300551677259892974326315461675692547390099840313192163258859011559750513086756892636598304230038445861422033560468535920495378496152301219687339355030990474992436599674672102617346048230206...
code_stdio
[ { "content": "Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.\n\nYour house has $n$ rooms. In the $i$-th room you can install at most $c_i$ heating radiators. Each radiator c...
[{"input": "69\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 15\n2 6\n2 6\n2 6\n2 6\n2 6\n2 11\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 7\n2 11\n2 6\n2 6\n2 6\n2 6\n4 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2...
code_stdio
[ { "content": "Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can c...
[{"input": "aaaaaaaaaa\naaaaaaaaaa\n50\na a 47\na a 40\na a 22\na a 48\na a 37\na a 26\na a 40\na a 28\na a 8\na a 46\na a 42\na a 37\na a 1\na a 0\na a 16\na a 34\na a 12\na a 50\na a 45\na a 49\na a 12\na a 8\na a 32\na a 17\na a 13\na a 1\na a 1\na a 33\na a 1\na a 15\na a 9\na a 11\na a 31\na a 5\na a 18\na a 13\na...
code_stdio
[ { "content": "Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which?\n\nNote that they...
[{"input": "2 2\n1\n6\n3\n14\n6 5\n3\n4\n5\n2\n4\n7\n11\n2\n7\n4\n1\n4 5\n10\n-1\n3\n11\n1\n9\n6\n0\n1\n7 4\n1\n0\n4\n0\n2\n1\n4\n4\n2\n1\n-1\n2 3\n0\n1\n2\n4\n2\n0 0", "output": "-1\n2 2\n3 0\n2 -1\n-1\n"}, {"input": "2 2\n1\n6\n3\n14\n6 5\n3\n4\n5\n2\n4\n7\n11\n2\n7\n4\n1\n4 5\n10\n-1\n3\n11\n1\n9\n6\n0\n1\n7 4\n1\n0...
code_stdio
[ { "content": "Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.\n\nRuling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from ...
[{"input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 11\n7 8\n8 9\n9 10\n10 11\n", "output": "0\n\n"}, {"input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n", "output": "0\n"}, {"input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n", "output": "0\n"}, {"input": "10 1 5\n5\n1 2\n1...
code_stdio
[ { "content": "There is a frog living in a big pond. He loves jumping between lotus leaves floating on the pond. Interestingly, these leaves have strange habits. First, a leaf will sink into the water after the frog jumps from it. Second, they are aligned regularly as if they are placed on the grid points as in ...
[{"input": "10 10\n.o....o...\no.oo......\n..oo..oo..\n..o.......\n..oo..oo..\n.o.o...o..\no..U.o....\noo......oo\noo........\noo..oo....", "output": "RDLLLURUUURDDLLUURRDDLULLDDRR\n"}, {"input": "10 10\n.o....o...\no.oo......\n..oo..oo..\n..o.......\n..oo..oo..\n..o...o.o.\no..U.o....\noo......oo\noo........\noo..oo.....
code_stdio
[ { "content": "Given any integer x, Aoki can do the operation below.\nOperation: Replace x with the absolute difference of x and K.\nYou are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.\n\n-----Constraints-----\n - 0 ≤ N ≤ 1...
[{"input": "999999482938498888 1000000000000000000\n", "output": "517061501112\n"}, {"input": "34439284758432890 4389039281938432\n", "output": "673029497074566\n"}, {"input": "542309233112233445 542309233112233445\n", "output": "0\n"}, {"input": "435893948572830341 43\n", "output": "12\n"}, {"input": "10 9999999999999...
code_stdio
[ { "content": "Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount.\n\nYou are given an array a of length n and an integer c. \n\nThe value of some array b of length k is the sum of its elements except for the $\\lfloor \\frac{k}{c} \\rfloor$ smallest. ...
[{"input": "100 20\n9149 9142 7686 5769 1871 4565 5670 8587 663 637 3421 4267 6884 8142 7634 5748 936 316 9300 771 6906 9230 8994 9690 7155 9393 6274 3183 932 7460 1611 6122 4031 6922 5466 1499 5290 4907 4673 5665 9744 1602 9891 8260 6351 4640 9930 9756 5242 3752 82 3287 824 6897 5579 9095 883 6231 5738 6690 10553 1195...
code_stdio
[ { "content": "Consider a sequence of digits of length $2^k$ $[a_1, a_2, \\ldots, a_{2^k}]$. We perform the following operation with it: replace pairs $(a_{2i+1}, a_{2i+2})$ with $(a_{2i+1} + a_{2i+2})\\bmod 10$ for $0\\le i<2^{k-1}$. For every $i$ where $a_{2i+1} + a_{2i+2}\\ge 10$ we get a candy! As a result, ...
[{"input": "20\n4 8 6 6 3 0 1 8 3 6 1 4 3 2 1 3 6 4 5 4\n15\n16 19\n3 10\n9 9\n3 18\n6 7\n15 18\n12 19\n17 18\n12 12\n6 9\n3 10\n1 2\n2 3\n4 19\n16 16\n", "output": "1\n3\n0\n5\n0\n1\n2\n1\n0\n1\n3\n1\n1\n5\n0\n"}, {"input": "20\n4 8 6 6 3 0 1 8 3 6 1 4 3 2 1 3 6 4 5 4\n15\n16 19\n3 10\n9 9\n3 18\n6 7\n15 18\n12 19\n17...
code_stdio
[ { "content": "<image>\n\n\nA directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B ...
[{"input": "26 0\n1 0\n0 6\n-1 1\n18 9\n12 1\n0 2", "output": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n"}, {"input": "21 -1\n1 2\n0 6\n-1 1\n11 4\n7 1\n0 1", "output": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n"}, {"input": "17 0\n1 ...
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 91 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": "There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards.\n\nA blue card and a red card can be paired when both of the numbers printed on them have a common divisor greater than 1. ...
[{"input": "4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n2 7\n5 5\n2 3 5 1001 1001\n7 11 13 17 34\n10 10\n2 3 5 7 12 11 13 15 17 29\n3 11 1 22 18 22 26 30 34 38\n20 20\n314 144 903 63 137 609 44 626 75 473\n876 421 909 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\n373 984 564 54 823 477...
code_stdio
[ { "content": "During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed.\n\nThe collection of porcelain is arranged neatly on n shelves. Within each shelf the items are placed in one row, so that one can access only the outermost items...
[{"input": "1 68\n100 26 58 15 8 69 66 49 97 18 74 27 39 19 76 37 25 4 88 75 17 79 41 21 44 39 7 42 63 82 92 87 41 85 25 30 43 80 165 106 98 88 16 15 97 74 81 76 33 19 64 3 14 72 17 36 33 21 34 59 38 75 48 1 57 20 81 56 74 67 14 89 51 30 1 66 20 58 64 58 16 99 33 97 31 5 54 87 6 64 70 40 93 25 50 62 53 80 75 68 13\n", ...
code_stdio
[ { "content": "You are given a integer $n$ ($n > 0$). Find any integer $s$ which satisfies these conditions, or report that there are no such numbers:\n\nIn the decimal representation of $s$: $s > 0$, $s$ consists of $n$ digits, no digit in $s$ equals $0$, $s$ is not divisible by any of it's digits. \n\n\n-...
[{"input": "4\n7648\n1421\n37753\n53050\n", "output": "2333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
code_stdio
[ { "content": "There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.\n\nAohashi would like to fill the empty squares with integers so that the following condition is satisfied:\n\n* For any two adjacent squares, the (absol...
[{"input": "491995 412925347 465710940 59999126 59999339", "output": "NO\n"}, {"input": "1788 122437383 681218449 90629745 148553464", "output": "YES\n"}, {"input": "1788 122437383 541607279 90629745 148553464", "output": "YES\n"}, {"input": "1788 122437383 943846071 90629745 148553464", "output": "YES\n"}, {"input": "...
code_stdio
[ { "content": "Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.\n\nLet next(x) be the minimum lucky number which is larger than or equals x. Pe...
[{"input": "117335682 1000000001\n", "output": "1373020883634915584\n"}, {"input": "696386388 1000000010\n", "output": "1049164104211999364\n"}, {"input": "777777777 1000000000\n", "output": "987654325123456789\n"}, {"input": "777777778 1000000000\n", "output": "987654324345679012\n"}, {"input": "777777777 1000000010\n...
code_stdio
[ { "content": "A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares ba...
[{"input": "6\nK.......\n........\n.##..##.\n#..##..#\n........\n...##...\n.#....#.\n..####.K\n\n.......K\n........\n.##..##.\n#..##..#\n........\n...##...\n.#....#.\nK.####..\n\nK.......\n........\n.##..##.\n#..##..#\n........\n...##...\n.#....#.\nK.####..\n\n.......K\n........\n.##..##.\n#..##..#\n........\n...##...\...
code_stdio
[ { "content": "One day, Ikta, an elementary school student, received a piece of paper with mathematical formulas from his grandfather. Apparently, the grandfather will give you as much money as the answer to the formula. Ikta has only learned addition, subtraction, and multiplication, so only addition, subtracti...
[{"input": "(198876743*1-210*4-89)", "output": "3533045339395\n"}, {"input": "(198876744*1-210*4-89)", "output": "3533045357160\n"}, {"input": "(198776744*1-210*4-89)", "output": "3531268857160\n"}, {"input": "(198777744*1-210*4-89)", "output": "3531286622160\n"}, {"input": "(198777744*1-120*4-89)", "output": "20106368...
code_stdio
[ { "content": "Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.\n\nGukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possibl...
[{"input": "brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n", "output": "takotakotakotakotakoaaaaaaaaaaaaaaaaaaaaaabddddddddddddddddddeffffffffffffffffffghhhhhhhhhiiiiiiiiijjjjjloooooooooo...
code_stdio
[ { "content": "Example\n\nInput\n\n6\n2\n3\n1\n1\n4\n2\n\n\nOutput\n\nYes\nYes\nYes\nNo\nYes\nNo\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": "6\n2\n3\n2\n1\n11\n2", "output": "Yes\nYes\nYes\nNo\nYes\nYes\n"}, {"input": "6\n2\n10\n0\n4\n4\n1", "output": "Yes\nYes\nNo\nYes\nYes\nYes\n"}, {"input": "6\n6\n8\n1\n2\n5\n3", "output": "Yes\nYes\nYes\nYes\nYes\nYes\n"}, {"input": "6\n2\n6\n2\n1\n11\n2", "output": "Yes\nYes\nYes\nNo\nYes\nYes\n"}, {"input...
code_stdio
[ { "content": "A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chess...
[{"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB\n", "output": "12\n"}, {"input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\n", "output": "10\n"}, {"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\n",...
code_stdio
[ { "content": "It's now the season of TAKOYAKI FESTIVAL!\nThis year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.\nAs is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \\times y health poi...
[{"input": "50\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\n", "output": "12250000\n"}, {"input": "41\n49 91 82 7 70 97 50 3 58 42 57 3 46 10 46 36 78 58 29 7 49 5...
code_stdio
[ { "content": "There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints \"YES\" and if not prints \"NO\".\n\n\n\nInput\n\nInput consists...
[{"input": "2\n2.926287414400688 0.6174638399148507 2.2117258079089996 2.51039017960215 2.2432914589132955 0.3458310450303873 3.950438914943076 1.6292131026754104\n5.957858300757107 3.314602021400227 10.473008708157936 7.081122407685485 15.460510197185764 6.858362845609268 7.533578119892425 12.180352827357845", "output...
code_stdio
[ { "content": "There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.\nPerson i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} ...
[{"input": "15\n14\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n14\n1 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n14\n1 1\n2 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n14\n1 1\n2 1\n3 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13...
code_stdio
[ { "content": "Problem\n\nLet $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary.\nGiven a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $.\n\n\nExample of calculating the function $ f (5) $:\nWhen 5 is expressed in binary, it is 101 a...
[{"input": "10830", "output": "13\n"}, {"input": "1663", "output": "10\n"}, {"input": "2604", "output": "11\n"}, {"input": "5020", "output": "12\n"}, {"input": "170", "output": "7\n"}, {"input": "264", "output": "8\n"}, {"input": "585", "output": "9\n"}, {"input": "120", "output": "6\n"}, {"input": "119", "output": "6\...
code_stdio
[ { "content": "All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position x_{i} — a coordinate on the Ox axis. No two cities are located at a single point.\n\nLineland residents love to send letters to each other. A person may send a letter only if the recipient...
[{"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37...
code_stdio
[ { "content": "You are given an array of positive integers $a = [a_0, a_1, \\dots, a_{n - 1}]$ ($n \\ge 2$).\n\nIn one step, the array $a$ is replaced with another array of length $n$, in which each element is the greatest common divisor (GCD) of two neighboring elements (the element itself and its right neighbo...
[{"input": "1\n97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "1\n97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
code_stdio
[ { "content": "There is a grid with H rows and W columns.\n\nThe square at the i-th row and j-th column contains a string S_{i,j} of length 5.\n\nThe rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet...
[{"input": "15 10\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake sna...
code_stdio
[ { "content": "In some other world, today is December D-th.\nWrite a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.\n\n-----Constraints-----\n - 22 \\leq D \\leq 25\n - D is an integer.\n\n-----Input-----\nInput is given from Sta...
[{"input": "-1279", "output": "Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve...
code_stdio
[ { "content": "Your company’s next product will be a new game, which is a three-dimensional variant of the classic game “Tic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length.\n\nPeople believe that it is fun to play the game, but they still ca...
[{"input": "3 3 3\n1 1\n1 1\n1 1\n3 3 7\n3 2\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n2 2\n1 1\n3 3\n3 3\n1 1\n3 3\n3 3\n4 4\n1 1\n4 4\n4 4\n4 4\n4 1\n2 2\n0 0 0", "output": "Draw\nWhite 6\nBlack 15\n"}, {"input": "3 3 3\n1 1\n1 1\n1 1\n3 3 7\n3 3\n1 3\n1 1\n2 3\n2 1\n3 3\n3 1\n4 3 15\n1 1\n2 2\n1 1\n3 3\n3 3\n1 1\n...
code_stdio
[ { "content": "This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved.\n\nFirst, Aoi came up with the following idea for the competitive programming problem:\n\nYuzu is a girl who collecting c...
[{"input": "123 79\n49 100 128 149 148 22 89 81 46 142 119 70 22 134 134 80 69 145 144 33 28 127 70 27 91 94 98 29 153 53 102 138 113 123 135 143 87 77 84 27 106 8 156 27 97 150 53 31 126 135 40 79 150 79 69 7 3 49 84 14 24 39 13 103 54 98 122 95 71 157 79 114 136 101 38 25 150 103 150 158 109 121 74 76 3 46 133 31 38 ...
code_stdio
[ { "content": "Read problems statements in Mandarin Chinese and Russian. \n\nYou are given two positive integers – A and B. You have to check whether A is divisible by all the prime divisors of B.\n\n------ Input ------ \n\nThe first line of the input contains an integer T denoting the number of test cases. The...
[{"input": "3\n120 75\n184 16\n16 18", "output": "Yes\nYes\nNo\n"}, {"input": "3\n120 75\n184 16\n16 36", "output": "Yes\nYes\nNo\n"}, {"input": "3\n120 75\n184 16\n0 11", "output": "Yes\nYes\nYes\n"}, {"input": "3\n120 75\n128 16\n7 11", "output": "Yes\nYes\nNo\n"}, {"input": "3\n120 137\n128 16\n7 11", "output": "No\...
code_stdio
[ { "content": "The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.\n\nThere is a permutation $p_i$ of numbers from 1 to $2n$. You can make two types o...
[{"input": "15\n11 22 13 24 15 26 17 28 19 30 21 2 23 4 25 6 27 8 29 10 1 12 3 14 5 16 7 18 9 20\n", "output": "10\n"}, {"input": "15\n11 22 13 24 15 26 17 28 19 30 21 2 23 4 25 6 27 8 29 10 1 12 3 14 5 16 7 18 9 20\n", "output": "10\n"}, {"input": "9\n16 5 18 7 2 9 4 11 6 13 8 15 10 17 12 1 14 3\n", "output": "7\n"}, ...
code_stdio
[ { "content": "There is a new attraction in Singapore Zoo: The Infinite Zoo.\n\nThe Infinite Zoo can be represented by a graph with an infinite number of vertices labeled $1,2,3,\\ldots$. There is a directed edge from vertex $u$ to vertex $u+v$ if and only if $u\\&v=v$, where $\\&$ denotes the bitwise AND operat...
[{"input": "5\n1 4\n3 12\n2 15\n6 6\n10 5\n", "output": "YES\nYES\nNO\nYES\nNO\n"}, {"input": "5\n1 4\n3 6\n1 8\n10 3\n5 5\n", "output": "YES\nYES\nYES\nNO\nYES\n"}, {"input": "5\n1 2\n3 12\n2 6\n3 4\n3 5\n", "output": "YES\nYES\nNO\nYES\nYES\n"}, {"input": "5\n1 1\n3 17\n2 18\n6 4\n3 5\n", "output": "YES\nYES\nNO\nNO\...
code_stdio
[ { "content": "Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use.\n\nIn this problem we consider the following model of #define constructions (also called macros). Each macro h...
[{"input": "5\n#define iiXEqDYeyVmIYsOaO fj/x-9-6/x*x+ 1/ 7*2-x -x+9+235*23*Ww+x-2*K+2-x/70\n#define XVgLzhoTUxoBr ( x+x/x/x*6-x)* x+K/24206-2 /5/8-x-7/Ww/K-x+6 \n#define QdfRBaJk 470551685-( 54-x)-30\n#define gEJcAGnF x+x-x+(x/x+9)/x-41-1/fj/1157561+x/x -x/26/x+K*x\n#define lO 7-1*(x*58 )-K*fj /722113691/x/K+2\n2+4*...
code_stdio
[ { "content": "A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.\n\nA simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + ...
[{"input": "40 43\n1 2\n1 3\n1 4\n4 5\n5 6\n1 7\n5 8\n7 9\n2 10\n10 11\n11 12\n2 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 2\n3 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 3\n4 33\n33 34\n34 35\n35 36\n36 37\n37 4\n5 38\n38 39\n39 40\n40 5\n25\n6 24\n31 14\n40 34\n1...
code_stdio
[ { "content": "There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have ...
[{"input": "10\n0 1 1 0 -1 -2 1 0 0 0\n1 0 0 0 1 0 0 0 0 0\n0 0 1 2 1 0 1 1 0 0\n0 0 1 0 0 0 0 -1 0 0\n-1 0 -1 0 0 0 0 0 1 0\n0 0 -1 0 0 1 -1 0 0 1\n2 0 0 0 0 0 1 0 0 2\n0 -1 0 0 0 0 0 0 0 0\n0 0 0 0 0 -1 0 0 0 0\n0 1 0 -2 0 0 -1 -1 0 0\n", "output": "0\n"}, {"input": "10\n0 1 1 0 -1 -2 1 0 0 0\n1 0 0 0 1 0 0 0 0 0\n0 ...
code_stdio
[ { "content": "Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.\n\nKyota Ootori has just learned about cyclic representation of a p...
[{"input": "50 20365011074\n", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49\n"}, {"input": "50 5608642004\n", "output": "1 2 4 3 5 6 8 7 9 10 11 13 12 15 14 17 16 18 20 19 22 21 23 24 25 26 28 27 30 29 31 32 33 34...
code_stdio
[ { "content": "This problem is same as the previous one, but has larger 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 pow...
[{"input": "25\n-10000 -10000\n-10000 -5000\n-10000 0\n-10000 5000\n-10000 10000\n-7452 -10000\n-5000 -5000\n-5000 0\n-5000 5000\n-5000 10000\n-1 -10000\n0 -5000\n0 0\n0 5000\n0 10000\n5000 -13650\n5000 -5000\n5000 0\n5000 5000\n5000 10000\n10000 -10000\n10000 -5000\n10000 0\n10000 5000\n10000 10000\n", "output": "1410...
code_stdio
[ { "content": "The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.\n\nKirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is ask...
[{"input": "0111001100111011101000\n", "output": "0011001100001011101000\n"}, {"input": "0111001100111111101000\n", "output": "0011001100000011101000\n"}, {"input": "0111011100111111101000\n", "output": "0001001100000011101000\n"}, {"input": "0111011100111101101000\n", "output": "0001001100001101101000\n"}, {"input": "...
code_stdio
[ { "content": "Surrounding Area\n\nLand fence\n\nEnglish text is not available in this practice contest.\n\nTwo real estate agents were boarding a passenger ship to the southern island. Blue sky, refreshing breeze ... The two enjoyed a voyage with other passengers. However, one day a tornado suddenly sank a pass...
[{"input": "10 10\n.....W....\n....W.W...\n...W...W..\n....W...W.\n.....W...W\n......W.W.\nBBB....W..\n..BB.BB.BB\n....B..B..\n...B.B..W.\n5 3\n...B.\n...BB\n.....\n1 1\n.\n0 0", "output": "10 21\n12 0\n0 0\n"}, {"input": "10 10\n.....W....\n....W.W...\n...W...W..\n....W...W.\n.....W...W\n......W.W.\nBBB....W..\n..B..B...
code_stdio
[ { "content": "Consider some set of distinct characters $A$ and some string $S$, consisting of exactly $n$ characters, where each character is present in $A$.\n\nYou are given an array of $m$ integers $b$ ($b_1 < b_2 < \\dots < b_m$). \n\nYou are allowed to perform the following move on the string $S$:\n\n Choo...
[{"input": "1000000000 2 2\n1 500000000\n", "output": "933660593\n"}, {"input": "1000000000 2 2\n1 500000000\n", "output": "933660593\n"}, {"input": "1000000000 2 2\n2 500000000\n", "output": "811805447\n"}, {"input": "1000000000 2 3\n1 500000000\n", "output": "947751250\n"}, {"input": "1000000000 2 2\n2 182433767\n", ...
code_stdio
[ { "content": "There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.\n\nEach of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions ...
[{"input": "100\nRDRRDRDDDDRDRRDDRDRRDDRRDDRRRDRRRDDDRDDRDDRRDRDRRRDRDRRRDRRDDDRDDRRRDRDRRRDDRDRDDDDDDDRDRRDDDDDDRRDD\n", "output": "D\n"}, {"input": "100\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD\n", "output": "R\n"}, {"input": "100\nRRDRRDDDDDDDRDRRRDRDRDDDR...
code_stdio
[ { "content": "Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.\n\nThe girl finds an important p...
[{"input": "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "output": "927799753\n"}, {"input": "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "output": "927799753\n"}, {"input": "10\n4 10 -1 1 6 8 9 2 -1 -1\n", "output": "4\n"}, {"input": "10\n4 10 -1 1 6 8 9 2 -1 -1\n", "outp...
code_stdio
[ { "content": "Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.\n\nVasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new...
[{"input": "1000 1000\n", "output": "1001\n"}, {"input": "1000 1000\n", "output": "1001\n"}, {"input": "1000 2\n", "output": "1999\n"}, {"input": "1000 3\n", "output": "1499\n"}, {"input": "1000 4\n", "output": "1333\n"}, {"input": "1000 3\n", "output": "1499\n"}, {"input": "1000 2\n", "output": "1999\n"}, {"input": "1...
code_stdio
[ { "content": "Eve is a beginner stand-up comedian. Her first show gathered a grand total of two spectators: Alice and Bob.\n\nEve prepared $a_1 + a_2 + a_3 + a_4$ jokes to tell, grouped by their type:\n\ntype 1: both Alice and Bob like them;\n\ntype 2: Alice likes them, but Bob doesn't;\n\ntype 3: Bob likes the...
[{"input": "15\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 100000000 100000000 100000000\n1 10000...
code_stdio
[ { "content": "After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.\n\nAt the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the nig...
[{"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n", "output": "7000000000 0\n"}, {"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n", "output": "7000000000 0\n"}, {"input": "6 1000000000\n+ 1000000000...
code_stdio
[ { "content": "This is the easy version of this problem. The only difference between easy and hard versions is the constraints on $k$ and $m$ (in this version $k=2$ and $m=3$). Also, in this version of the problem, you DON'T NEED to output the answer by modulo.\n\nYou are given a sequence $a$ of length $n$ consi...
[{"input": "10\n3\n1 1 1\n1\n1\n4\n3 4 3 3\n1\n1\n7\n7 1 1 3 3 4 5\n3\n3 2 1\n9\n4 1 7 1 1 6 1 1 7\n5\n3 5 3 3 3\n1\n1\n9\n8 9 5 7 4 1 3 5 4\n", "output": "1\n0\n4\n0\n8\n1\n11\n10\n0\n12\n"}, {"input": "10\n3\n1 1 1\n1\n1\n4\n3 4 3 3\n1\n1\n7\n7 1 1 3 3 4 5\n3\n3 2 1\n9\n4 1 7 1 1 6 1 1 7\n5\n3 5 3 3 3\n1\n1\n9\n8 9 5...
code_stdio
[ { "content": "You are given an array $a$ of length $n$ consisting of integers. You can apply the following operation, consisting of several steps, on the array $a$ zero or more times:\n\nyou select two different numbers in the array $a_i$ and $a_j$;\n\nyou remove $i$-th and $j$-th elements from the array.\n\nFo...
[{"input": "5\n6\n1 6 1 1 4 4\n2\n1 2\n2\n1 1\n5\n4 5 4 5 4\n6\n2 3 2 1 3 1\n", "output": "\n0\n0\n2\n1\n0\n"}, {"input": "5\n6\n1 6 1 1 4 4\n2\n1 2\n2\n1 1\n5\n4 5 4 5 4\n6\n2 3 2 1 3 1\n", "output": "0\n0\n2\n1\n0\n"}, {"input": "5\n6\n2 6 1 1 4 4\n2\n1 2\n2\n1 1\n5\n4 5 4 5 4\n6\n2 3 2 1 3 1\n", "output": "0\n0\n2\n...
code_stdio
[ { "content": "You are given n patterns p_1, p_2, ..., p_n and m strings s_1, s_2, ..., s_m. Each pattern p_i consists of k characters that are either lowercase Latin letters or wildcard characters (denoted by underscores). All patterns are pairwise distinct. Each string s_j consists of k lowercase Latin letters...
[{"input": "10 10 4\n_a_c\n_aac\nb__a\n__cb\nab__\n__ab\n_c__\n____\n_bbd\nb_bc\nbcbc 8\nabac 8\ncadc 8\ncaac 8\ndaab 8\naccb 8\ncbcd 8\nabbd 8\nbdba 8\nbcac 8\n", "output": "YES\n8 9 10 7 6 5 4 3 2 1 \n"}, {"input": "10 10 4\n_a_c\n_aac\nb__a\n__cb\nab__\n__ab\n_c__\n____\n_bbd\nb_bc\nbcbc 8\nabac 8\ncadc 8\ncaac 8\nd...
code_stdio
[ { "content": "You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.\n\nYou perform a sequence of ope...
[{"input": "aaaaaaaaabbbbbaaaabaaaaaaaaaaaaaaaaabaaaaaabbbbbbbaaabbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "12\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbddddddddddddddddaaaaaaaaaaaaaccccccccbbbbbbbaaaaaaaaaabbbbbbbbaaaaaaaaaacccccc\n", "output": "11\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddd...
code_stdio
[ { "content": "Given is a positive integer N.\nWe will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K.\n - Operation: if K divides N, replace N with N/K; otherwise, replace N with N-K.\nIn how many choices of K will N become 1 in the end?\n\n-...
[{"input": "1000000000000\n", "output": "266\n"}, {"input": "523968956449\n", "output": "385\n"}, {"input": "145329450841\n", "output": "289\n"}, {"input": "642507465600\n", "output": "12\n"}, {"input": "540024979445\n", "output": "12\n"}, {"input": "962623690081\n", "output": "96\n"}, {"input": "171518565905\n", "outp...
code_stdio
[ { "content": "During a New Year special offer the \"Sudislavl Bars\" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar \"Mosquito Shelter\". Of course, all the promocodes differ.\n\nAs the \"Mosquito Shelter\" opens only at 9, and partying in S...
[{"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n...
code_stdio
[ { "content": "For a given sequence $A = \\\\{a_0, a_1, ..., a_{n-1}\\\\}$ which is sorted by ascending order, find a specific value $k$ given as a query.\n\nConstraints\n\n* $1 \\leq n \\leq 100,000$\n* $1 \\leq q \\leq 200,000$\n* $0 \\leq a_0 \\leq a_1 \\leq ... \\leq a_{n-1} \\leq 1,000,000,000$\n* $0 \\leq ...
[{"input": "4\n-1 0 1 4\n3\n-3\n4\n14", "output": "0\n1\n0\n"}, {"input": "4\n-1 0 1 4\n3\n-2\n4\n14", "output": "0\n1\n0\n"}, {"input": "4\n-1 0 1 4\n3\n-4\n4\n14", "output": "0\n1\n0\n"}, {"input": "4\n-1 0 1 4\n3\n-4\n0\n14", "output": "0\n1\n0\n"}, {"input": "4\n-1 0 1 4\n3\n-4\n1\n14", "output": "0\n1\n0\n"}, {"in...
code_stdio
[ { "content": "Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.\n\nNow she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions:\n\n * The sequence is strictly incr...
[{"input": "49\n10 34 58 72 126 166 176 180 198 200 208 228 238 248 302 332 340 344 350 354 380 406 418 428 438 442 482 532 536 544 546 554 596 626 642 682 684 704 714 792 804 820 862 880 906 946 954 966 970\n", "output": "49\n"}, {"input": "44\n1 5 37 97 107 147 185 187 195 241 249 295 311 323 341 345 363 391 425 431 ...
code_stdio
[ { "content": "Polycarp knows that if the sum of the digits of a number is divisible by $3$, then the number itself is divisible by $3$. He assumes that the numbers, the sum of the digits of which is divisible by $4$, are also somewhat interesting. Thus, he considers a positive integer $n$ interesting if its sum...
[{"input": "1000\n", "output": "1003\n"}, {"input": "1000\n", "output": "1003\n"}, {"input": "997\n", "output": "1003\n"}, {"input": "999\n", "output": "1003\n"}, {"input": "997\n", "output": "1003\n"}, {"input": "999\n", "output": "1003\n"}, {"input": "432\n", "output": "435\n"}, {"input": "237\n", "output": "237\n"},...
code_stdio
[ { "content": "Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.\n\nEating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live,...
[{"input": "-2 -101 -9", "output": "-203\n"}, {"input": "-1 -101 -1", "output": "-202\n"}, {"input": "-1 -5 -143", "output": "-148\n"}, {"input": "-2 -74 -4", "output": "-149\n"}, {"input": "-2 -82 -4", "output": "-165\n"}, {"input": "0 -101 -1", "output": "-201\n"}, {"input": "1 -2 -180", "output": "-182\n"}, {"input"...
code_stdio
[ { "content": "In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \\dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. (Takoyaki is the name of a Japanese snac...
[{"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170\n", "output": "243\n"}, {"input": "476640020082194381531155118436783393866726953614433851622190777875571135215042541028243752681838573", "output": "259\n"}, {"input": "4024190595003667858693588822821631596741...
code_stdio
[ { "content": "Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., aj is equal to k.\n\nInput\n\nThe first li...
[{"input": "5 3 1\n0 1 1 1 1\n1 5\n2 4\n1 3\n", "output": "8\n4\n3\n"}, {"input": "5 3 1\n0 1 1 1 1\n1 5\n2 4\n1 2\n", "output": "8\n4\n2\n"}, {"input": "5 3 0\n0 1 1 1 1\n1 5\n2 4\n1 2\n", "output": "7\n2\n1\n"}, {"input": "5 3 1\n0 1 2 1 1\n1 5\n2 4\n1 2\n", "output": "4\n2\n2\n"}, {"input": "5 3 1\n0 1 2 1 1\n1 5\n3...
code_stdio
[ { "content": "Let's denote a function $f(x)$ in such a way: we add $1$ to $x$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, $f(599) = 6$: $599 + 1 = 600 \\rightarrow 60 \\rightarrow 6$; $f(7) = 8$: $7 + 1 = 8$; $f(9) = 1$: $9 + 1 = 10 \\rightarro...
[{"input": "1000000000\n", "output": "91\n"}, {"input": "1000000000\n", "output": "91\n"}, {"input": "1472811722\n", "output": "57\n"}, {"input": "1660033091\n", "output": "63\n"}, {"input": "1100000000\n", "output": "90\n"}, {"input": "1516433257\n", "output": "55\n"}, {"input": "932415950\n", "output": "53\n"}, {"inp...
code_stdio
[ { "content": "Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.\n\nWe know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth...
[{"input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692...
code_stdio
[ { "content": "Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:\n\n if the character $w_{i-x}$ exists a...
[{"input": "3\n100110\n2\n01\n1\n111\n1\n", "output": "011001\n10\n111\n"}, {"input": "3\n100110\n2\n01\n1\n101\n1\n", "output": "011001\n10\n010\n"}, {"input": "3\n100110\n2\n01\n0\n101\n1\n", "output": "011001\n01\n010\n"}, {"input": "3\n111110\n1\n01\n0\n101\n1\n", "output": "111101\n01\n010\n"}, {"input": "3\n10010...
code_stdio
[ { "content": "A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\\cdot 2\\cdot \\ldots \\cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful n...
[{"input": "100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161...
code_stdio
[ { "content": "Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.\n\nWhat is the least number of flagstones needed...
[{"input": "1000000000 1000000000 1\n", "output": "1000000000000000000\n"}, {"input": "1000000000 987654321 1\n", "output": "987654321000000000\n"}, {"input": "1000000000 989104164 1\n", "output": "989104164000000000\n"}, {"input": "1000000000 980932347 1\n", "output": "980932347000000000\n"}, {"input": "1000000000 100...
code_stdio
[ { "content": "You're given an array $b$ of length $n$. Let's define another array $a$, also of length $n$, for which $a_i = 2^{b_i}$ ($1 \\leq i \\leq n$). \n\nValerii says that every two non-intersecting subarrays of $a$ have different sums of elements. You want to determine if he is wrong. More formally, you ...
[{"input": "2\n6\n4 3 0 1 2 0\n2\n2 5\n", "output": "YES\nNO\n"}, {"input": "2\n6\n0 3 0 1 2 0\n2\n2 5\n", "output": "YES\nNO\n"}, {"input": "2\n6\n4 3 0 1 2 0\n2\n4 5\n", "output": "YES\nNO\n"}, {"input": "2\n6\n4 3 0 1 2 0\n2\n4 3\n", "output": "YES\nNO\n"}, {"input": "2\n6\n4 3 0 1 2 0\n2\n4 6\n", "output": "YES\nNO...
code_stdio
[ { "content": "F: Tea Party\n\nYun decided to hold a tea party at the company.\n\nThe shop sells $ N $ sets of bread, each containing $ A_1, A_2, A_3, \\ dots, A_N $.\n\nYun decided to make a sandwich by combining two breads into a pair.\n\nYun-san is very careful, so I want to make sure that I don't have any le...
[{"input": "5\n11 1 59 18 30", "output": "59\n"}, {"input": "5\n4 0 13 10 17", "output": "22\n"}, {"input": "5\n7 4 11 10 10", "output": "21\n"}, {"input": "5\n4 0 35 14 17", "output": "35\n"}, {"input": "5\n30 21 2 0 15", "output": "34\n"}, {"input": "5\n4 0 35 17 30", "output": "43\n"}, {"input": "5\n30 21 3 0 15", "...
code_stdio
[ { "content": "On the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.\nYou are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.\n\n-----Constraints-----\n - b is one of the ...
[{"input": "A\n", "output": "T\n"}, {"input": "G\n", "output": "C\n"}, {"input": "C\n", "output": "G\n"}, {"input": "T\n", "output": "A\n"}, {"input": "C", "output": "G\n"}, {"input": "T", "output": "A\n"}, {"input": "C", "output": "G\n"}, {"input": "T", "output": "A\n"}, {"input": "G", "output": "C"}, {"input": "A", "...
code_stdio
[ { "content": "When Mr. Kay was browsing a certain SNS as usual, the problem that \"there are people who can solve IQ150 or more\" came to the timeline. Mr. Kay has an IQ of over 150, so he solved the problem in an instant without even looking at it. For him, he doesn't have to work on such a mystery. It is enou...
[{"input": "2286", "output": "3\n"}, {"input": "1020", "output": "2\n"}, {"input": "1809", "output": "1\n"}, {"input": "2465", "output": "0\n"}, {"input": "4598", "output": "2\n"}, {"input": "4112", "output": "2\n"}, {"input": "2725", "output": "0\n"}, {"input": "3645", "output": "1\n"}, {"input": "2071", "output": "0\...
code_stdio
[ { "content": "You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not connected.\n\nA set of painted squares is called conne...
[{"input": "20 20\n.....######.........\n.....#....#.........\n.....#....#.........\n.....#....#.........\n.....############...\n.........##.....#...\n..........#.....#...\n..........#.....#...\n..........###...#...\n............#...#...\n............#...#...\n............#...#...\n............#...#...\n............###...
code_stdio
[ { "content": "Takahashi has A cookies, and Aoki has B cookies.\nTakahashi will do the following action K times:\n - If Takahashi has one or more cookies, eat one of his cookies.\n - Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.\n - If they both have no cookies, do nothing.\nIn the end, ...
[{"input": "498881727339 49011419508 0000000100000", "output": "498881627339 49011419508\n"}, {"input": "498881727339 49011419508 0000001100000", "output": "498880627339 49011419508\n"}, {"input": "498881727339 50858735181 0000001100000", "output": "498880627339 50858735181\n"}, {"input": "498881727339 64133142411 0000...
code_stdio
[ { "content": "Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:\n\n\\begin{equation*} fib(n)= \\left \\\\{ \\begin{array}{ll} 1 & (n = 0) \\\\\\ 1 & (n = 1) \\\\\\ fib(n - 1) + fib(n - 2) & \\\\\\ \\end{array}...
[{"input": "44", "output": "1134903170\n"}, {"input": "44", "output": "1134903170\n"}, {"input": "41", "output": "267914296\n"}, {"input": "42", "output": "433494437\n"}, {"input": "43", "output": "701408733\n"}, {"input": "39", "output": "102334155\n"}, {"input": "40", "output": "165580141\n"}, {"input": "43", "output...
code_stdio
[ { "content": "Everlasting Sa-Ga, a new, hot and very popular role-playing game, is out on October 19, 2008. Fans have been looking forward to a new title of Everlasting Sa-Ga.\n\nLittle Jimmy is in trouble. He is a seven-year-old boy, and he obtained the Everlasting Sa-Ga and is attempting to reach the end of t...
[{"input": "10 24\n30 20\n0 0", "output": "a\nb\n"}, {"input": "19 24\n30 20\n0 0", "output": "a\nb\n"}, {"input": "10 3\n11 106\n0 0", "output": "b\nb\n"}, {"input": "10 3\n11 150\n0 0", "output": "b\na\n"}, {"input": "10 15\n58 20\n0 0", "output": "a\na\n"}, {"input": "11 24\n30 20\n0 0", "output": "a\nb\n"}, {"input...
code_stdio
[ { "content": "Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?\n\nEach toy appears in the shop exactly once. Pai...
[{"input": "100000000000000 100000000000000\n", "output": "49999999999999\n"}, {"input": "100000000000000 100000000000000\n", "output": "49999999999999\n"}, {"input": "100000000010000 100000000000000\n", "output": "49999999999999\n"}, {"input": "105925489085800 100000000001000\n", "output": "50000000000499\n"}, {"input...
code_stdio
[ { "content": "There are N integers written on a blackboard. The i-th integer is A_i, and the greatest common divisor of these integers is 1.\n\nTakahashi and Aoki will play a game using these integers. In this game, starting from Takahashi the two player alternately perform the following operation:\n\n* Select ...
[{"input": "5\n7 2 10 12 2", "output": "Second\n"}, {"input": "5\n7 8 4 5 11", "output": "Second\n"}, {"input": "5\n7 2 8 8 8", "output": "Second\n"}, {"input": "4\n0 -1 1 22", "output": "Second\n"}, {"input": "4\n-1 0 1 22", "output": "Second\n"}, {"input": "5\n7 8 4 8 11", "output": "First\n"}, {"input": "5\n7 2 8 12...
code_stdio
[ { "content": "A game is played on a strip consisting of N cells consecutively numbered from 1 to N.\n\nAlice has her token on cell A. Borys has his token on a different cell B.\n\nPlayers take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell...
[{"input": "-1 -1 -1", "output": "Alice\n"}, {"input": "9 23 42", "output": "Borys\n"}, {"input": "9 23 18", "output": "Borys\n"}, {"input": "9 23 23", "output": "Alice\n"}, {"input": "9 44 23", "output": "Borys\n"}, {"input": "2 31 -1", "output": "Alice\n"}, {"input": "2 53 -1", "output": "Alice\n"}, {"input": "2 64 -...
code_stdio
[ { "content": "You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second:\n\n * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x-1} to each corresponding position of a. Formally, a_{i...
[{"input": "6\n3\n1000000100 0 -1000000000\n1\n6\n2\n-1000000000 1000000000\n2\n1000000000 -1000000000\n2\n1001000000 1000000000\n2\n-1000000000 -1000000000\n", "output": "31\n0\n0\n31\n20\n0\n"}, {"input": "6\n3\n1000000100 0 -1000000000\n1\n6\n2\n-1000000000 1000000000\n2\n1000000000 -1000000000\n2\n1001000000 100000...
code_stdio
[ { "content": "Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked ...
[{"input": "2\n11405\n58469\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
code_stdio
[ { "content": "Monocarp has forgotten the password to his mobile phone. The password consists of $4$ digits from $0$ to $9$ (note that it can start with the digit $0$).\n\nMonocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. M...
[{"input": "12\n8\n1 2 3 5 6 7 8 9\n6\n4 5 6 7 8 9\n7\n0 4 5 6 7 8 9\n7\n1 4 5 6 7 8 9\n8\n0 1 4 5 6 7 8 9\n7\n2 4 5 6 7 8 9\n8\n0 2 4 5 6 7 8 9\n8\n1 2 4 5 6 7 8 9\n7\n3 4 5 6 7 8 9\n8\n0 3 4 5 6 7 8 9\n8\n1 3 4 5 6 7 8 9\n8\n2 3 4 5 6 7 8 9\n", "output": "6\n36\n18\n18\n6\n18\n6\n6\n18\n6\n6\n6\n"}, {"input": "7\n1\n...
code_stdio
[ { "content": "The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one.\n\nSoon the Hedgehog came up wi...
[{"input": "20 20\nABBBAAABABAAAAABBABB\nBABABBAABAABBAAABABB\nBABBBAABAABBABBBBABA\nBAAABBAAABABBABBAAAA\nABBAABAABBBBAAABBBAA\nBAAAAAAAABABBAAAAABB\nAAAAAAABABBBBBAABAAB\nABBBBABAABBAAAAABAAA\nBAAAAABBABAAAAABAAAB\nABABAABABBBABBAABBAA\nBAAABBBAAAABBBBBABAA\nAAABBABABAABBABAABAB\nABBABABABABAAABABABA\nBAABAAAAABBAABB...
code_stdio
[ { "content": "Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:\n\n In one second we can add an arbitrary (possibly negative) integer to all elements of the array t...
[{"input": "13\n-2075 -32242 27034 -37618 -96962 145894 64846 29532 -71761 28908 -21222 -61370 46899\n", "output": "13\n"}, {"input": "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899\n", "output": "13\n"}, {"input": "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 2...
code_stdio
[ { "content": "problem\n\nThere are $ N $ propositions, named $ 1, 2, \\ cdots, N $, respectively. Also, $ M $ information about the propositions is given. The $ i $ th information is \"$ a_i $$\". Given in the form \"b_i $\", which means that $ a_i $ is $ b_i $. (\"If\" is a logical conditional and the transiti...
[{"input": "211 0\n4 2\n0 3", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n...
code_stdio