messages
listlengths
1
1
ground_truth
stringlengths
156
726k
dataset
stringclasses
1 value
[ { "content": "Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.\n\nIn this problem you should implement the similar functionality.\n\nYou are given a string which only consists of: uppercase...
[{"input": "255\nT___J(M_XZJlr_lH___mqJA_p__kW)ko__F_M_Aro__ZA_G_M_P_____j_V(J_Jk_dkR_ta_lbIUhKFfo_y_DluW)IVFj_gouRfMhabn()_e___q_vo__QPEGBI_TpVVI_clPwwb_m_yL_cMVKgi___RJb_J_f____tPCyntLOr_s_x_N_SyqQw_zP_mycsW_o_c_o_Yzb_UVa_ATd(BYH_gl___Y__Uzok_Y_IA_XL_D__bkJ____e__K_quk)\n", "output": "10 25\n"}, {"input": "255\ngB(ZK...
code_stdio
[ { "content": "Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.\nIf the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.\n\n-----Input-----\n\nThe first line contains an inte...
[{"input": "3 \n1200\n1258\n242", "output": "12\n16\n7\n"}, {"input": "3 \n1200\n493\n380", "output": "12\n11\n7\n"}, {"input": "3 \n1200\n806\n380", "output": "12\n10\n7\n"}, {"input": "3 \n1200\n360\n242", "output": "12\n5\n7\n"}, {"input": "3 \n1200\n360\n255", "output": "12\n5\n4\n"}, {"input": "3 \n1200\n500\n392"...
code_stdio
[ { "content": "A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.\n\nThere are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker be...
[{"input": "300997\n", "output": "150498\n"}, {"input": "273658\n", "output": "136828\n"}, {"input": "222057\n", "output": "111028\n"}, {"input": "456496\n", "output": "228247\n"}, {"input": "220343\n", "output": "110171\n"}, {"input": "100000\n", "output": "49999\n"}, {"input": "100000\n", "output": "49999\n"}, {"inpu...
code_stdio
[ { "content": "You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly.\n\n<image>\n\nAn ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some ...
[{"input": "10000000\n", "output": "192336614\n"}, {"input": "1000000\n", "output": "266233856\n"}, {"input": "4000000\n", "output": "882155933\n"}, {"input": "9999999\n", "output": "730778875\n"}, {"input": "9999998\n", "output": "576926295\n"}, {"input": "9000000\n", "output": "295060537\n"}, {"input": "1000010\n", "...
code_stdio
[ { "content": "You are given an array of $n$ positive integers $a_1, a_2, \\ldots, a_n$. Your task is to calculate the number of arrays of $n$ positive integers $b_1, b_2, \\ldots, b_n$ such that:\n\n$1 \\le b_i \\le a_i$ for every $i$ ($1 \\le i \\le n$), and\n\n$b_i \\neq b_{i+1}$ for every $i$ ($1 \\le i \\le...
[{"input": "100\n23 39 85 46 97 72 41 70 37 18 8 40 33 61 12 79 51 78 61 66 85 97 78 14 70 47 100 40 15 40 61 52 19 30 14 91 82 56 10 6 68 24 97 61 31 78 18 45 88 6 37 38 51 86 37 42 58 30 79 56 50 14 61 18 13 20 57 3 93 15 24 74 32 21 71 93 2 66 25 75 75 10 86 82 30 31 6 49 15 33 100 35 1 96 87 83 29 21 41 22\n", "out...
code_stdio
[ { "content": "The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. \n\nAdditionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≀ lj ≀ ...
[{"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6\n", "output": "1\n0\n2\n1\n1\n3\n"}, {"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 3\n", "output": "1\n0\n2\n1\n1\n2\n"}, {"input": "6 6\n1 2 2 3 2 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6\n", "output": "1\n0\n2\n1\n0\n1\n"}, {"input": "6 6\n1 2 2 3 3 3\n1 2\n...
code_stdio
[ { "content": "You have a playlist consisting of $n$ songs. The $i$-th song is characterized by two numbers $t_i$ and $b_i$ β€” its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example...
[{"input": "10 1\n135600 59157\n2735 28902\n43406 39542\n24166 178402\n18565 14980\n69958 53925\n23473 81878\n89682 3949\n18757 31637\n35580 45873\n", "output": "8021689200\n"}, {"input": "10 1\n135600 59157\n2735 28902\n43406 39542\n24166 93361\n18565 14980\n69958 53925\n23473 81878\n89682 3949\n18757 31637\n31665 458...
code_stdio
[ { "content": "Filled with optimism, Hyunuk will host a conference about how great this new year will be!\n\nThe conference will have $n$ lectures. Hyunuk has two candidate venues $a$ and $b$. For each of the $n$ lectures, the speaker specified two time intervals $[sa_i, ea_i]$ ($sa_i \\le ea_i$) and $[sb_i, eb_...
[{"input": "4\n544431836 544432042 793496989 793497079\n544429970 544430041 793496343 793496350\n544432412 544432541 793497670 793498269\n544431029 544431033 793494552 793494859\n", "output": "YES\n"}, {"input": "4\n922033367 922033530 246113700 246113747\n922034178 922034457 246112224 246112584\n922032889 922035756 24...
code_stdio
[ { "content": "On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $k$ ($k \\ge 3$). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.\n\nMountains are des...
[{"input": "5\n8 6\n1 2 4 1 2 7 1 2\n5 3\n3 2 3 2 1\n10 8\n7 4 7 6 2 3 0 1 -1 1\n15 10\n3 14 4 8 2 1 4 5 21 2 0 4 2 1 3\n7 5\n1 2 3 4 2 6 2\n", "output": "3 2\n2 2\n4 2\n4 1\n3 3\n"}, {"input": "5\n8 6\n1 2 4 1 2 7 1 2\n5 3\n3 2 3 2 1\n10 8\n7 4 7 6 2 3 0 1 -1 1\n15 10\n3 14 4 8 2 1 4 5 21 2 0 4 2 0 3\n7 5\n1 2 3 2 2 6...
code_stdio
[ { "content": "Kode Festival is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for \"hardness\".)\n\nThis year, 2^N stones participated. The hardness of the i-th stone is A_i.\n\nIn the contest, stones are thrown at each other in a knockout tournament.\n\nWhen two s...
[{"input": "3\n2\n1\n-3\n4\n-1\n25\n110\n1014", "output": "872\n"}, {"input": "3\n2\n1\n-3\n4\n-1\n25\n111\n1014", "output": "871\n"}, {"input": "3\n2\n1\n-3\n4\n-2\n25\n111\n1014", "output": "870\n"}, {"input": "3\n2\n1\n-3\n4\n-3\n25\n111\n1014", "output": "869\n"}, {"input": "3\n2\n-1\n-3\n7\n-2\n25\n101\n309", "out...
code_stdio
[ { "content": "Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≀ i1 < i2 < ... < ik ≀ n) a group of size k. \n\nJzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≀ k ≀ n)? Help him and print this number modulo 1000000007 (109 + ...
[{"input": "55\n0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 3 4 5 6 7 8 9 4 5 6 7 8 9 5 6 7 8 9 6 7 8 9 7 8 9 8 9 9\n", "output": "621247139\n"}, {"input": "55\n0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 2 3 4 10 6 7 8 9 3 4 5 6 7 8 9 4 5 6 7 8 9 5 6 7 8 9 6 7 8 9 7 8 9 8 9 9\n", "output": "186945693"}, {"input": ...
code_stdio
[ { "content": "On an xy plane, in an area satisfying 0 ≀ x ≀ W, 0 ≀ y ≀ H, there is one house at each and every point where both x and y are integers.\n\nThere are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y c...
[{"input": "1 1\n1\n-1\n-1\n3\n21\n1\n0", "output": "-1\n"}, {"input": "1 2\n1\n-1\n-1\n6\n21\n1\n0", "output": "-3\n"}, {"input": "1 2\n1\n-1\n-2\n0\n21\n1\n0", "output": "-5\n"}, {"input": "1 1\n0\n-1\n-6\n2\n21\n1\n2", "output": "-2\n"}, {"input": "1 2\n1\n-1\n-4\n0\n21\n2\n0", "output": "-9\n"}, {"input": "2 1\n2\n...
code_stdio
[ { "content": "Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, she decreases the number by one; if the last digit of th...
[{"input": "1000000000 0\n", "output": "1000000000\n"}, {"input": "1559848638 5\n", "output": "1559848633\n"}, {"input": "1100000000 0\n", "output": "1100000000\n"}, {"input": "1086932676 10\n", "output": "108693264\n"}, {"input": "1000010000 0\n", "output": "1000010000\n"}, {"input": "1086932676 2\n", "output": "10869...
code_stdio
[ { "content": "Illumination\n\nIlluminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.\n\nA machine that oper...
[{"input": "10\n0 4 2 -1 18 -6 -1 -1 4 5", "output": "10\n"}, {"input": "10\n0 4 2 -2 18 -6 -1 -1 4 5", "output": "10\n"}, {"input": "10\n0 4 2 -2 18 -2 -1 -1 4 5", "output": "10\n"}, {"input": "10\n0 4 2 -2 18 -2 -1 -1 5 5", "output": "10\n"}, {"input": "10\n0 4 2 -2 18 -4 -1 -1 5 5", "output": "10\n"}, {"input": "10\...
code_stdio
[ { "content": "Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k β‰₯ 1 non-overl...
[{"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n", "output": "2728075\n"}, {"input": "vvvvwvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n", "output": "1295664\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n", "output": "943392\n"}, {"input": "kpjmawawa...
code_stdio
[ { "content": "Parsa has a humongous tree on $n$ vertices.\n\nOn each vertex $v$ he has written two integers $l_v$ and $r_v$.\n\nTo make Parsa's tree look even more majestic, Nima wants to assign a number $a_v$ ($l_v \\le a_v \\le r_v$) to each vertex $v$ such that the beauty of Parsa's tree is maximized.\n\nNim...
[{"input": "3\n2\n2 10\n6 6\n1 2\n3\n1 3\n13 6\n7 15\n1 2\n2 3\n6\n10 14\n12 20\n21 19\n2 12\n10 17\n3 17\n3 2\n6 5\n1 5\n2 6\n4 6\n", "output": "4\n18\n48\n"}, {"input": "3\n2\n0 6\n3 13\n1 2\n3\n1 3\n10 6\n12 9\n1 2\n2 3\n6\n3 14\n9 20\n12 19\n1 12\n11 17\n3 17\n3 3\n6 5\n1 2\n2 6\n4 6\n", "output": "13\n11\n57\n"}, ...
code_stdio
[ { "content": "This problem is a complicated version of D1, but it has significant differences, so read the whole statement.\n\nPolycarp has an array of $n$ ($n$ is even) integers $a_1, a_2, \\dots, a_n$. Polycarp conceived of a positive integer $k$. After that, Polycarp began performing the following operations...
[{"input": "10\n10\n-30 45 -37 -11 25 61 97 7 7 35\n10\n48 -2 13 88 97 -27 40 88 41 -67\n10\n-13 -31 94 -43 19 95 -35 5 41 10\n10\n-28 -88 17 17 2 -43 -73 -73 -13 2\n10\n46 -73 47 54 -13 67 7 -33 1 -33\n10\n60 92 -100 -76 -12 -52 4 84 -38 36\n10\n50 62 56 -58 -10 87 29 52 14 -22\n10\n-78 50 -52 -28 -6 -28 17 51 40 -30\...
code_stdio
[ { "content": "The phantom thief \"Lupin IV\" is told by the beautiful \"Fujiko Mine\", a descendant of the Aizu clan, that the military funds left by the Aizu clan are sleeping in Aizuwakamatsu city. According to a report by Lupine's longtime companion, \"Ishikawa Koshiemon,\" military funds are stored in sever...
[{"input": "5\n13 199 1\n93 1000 1\n37 350 10\n27 300 2\n123 200 1100", "output": "93 37 27 13 123\n"}, {"input": "5\n11 199 0\n93 1000 1\n37 350 10\n27 300 2\n123 200 1100", "output": "93 37 27 11 123\n"}, {"input": "5\n11 91 0\n124 1000 1\n37 350 3\n12 300 2\n123 200 1111", "output": "124 37 12 11 123\n"}, {"input": ...
code_stdio
[ { "content": "Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] \n\nwhere: <protocol> can equal either \"http\" (without the quotes) o...
[{"input": "ftpprutpfrutrutptpfrutpfrutfrutrfrutpfrutprutruruu\n", "output": "ftp://p.ru/tpfrutrutptpfrutpfrutfrutrfrutpfrutprutruruu\n"}, {"input": "ftpprutufrutrutptpfrutpfrutfrutrfrutpfrptprutruruu\n", "output": "ftp://p.ru/tufrutrutptpfrutpfrutfrutrfrutpfrptprutruruu"}, {"input": "ftpprutufrutrutptpfrutpfrutfrutrfr...
code_stdio
[ { "content": "Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence c...
[{"input": "100000000000000\n", "output": "1749820\n"}, {"input": "99999998250180\n", "output": "14142135\n"}, {"input": "99999998250180\n", "output": "14142135\n"}, {"input": "100000000000000\n", "output": "1749820\n"}, {"input": "1001000000000\n", "output": "1404260\n"}, {"input": "1001000001000\n", "output": "140526...
code_stdio
[ { "content": "Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the wi...
[{"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "1000000000000000000\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "1000000000000000000\n"}, {"input": "1000000000000000000 1000000000000000000 999999...
code_stdio
[ { "content": "Guy-Manuel and Thomas are going to build a polygon spaceship.\n\nYou're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \\overrightarrow {(x,y)}. The picture belo...
[{"input": "8\n-440365664 -897818514\n107345267 -994221803\n248590739 -968608613\n473576011 -880752952\n105203574 994450706\n-164464580 1061907476\n-522092561 852888831\n-874210729 485546704\n", "output": "NO\n"}, {"input": "8\n-845415846 -897818514\n107345267 -994221803\n248590739 -968608613\n473576011 -880752952\n105...
code_stdio
[ { "content": "Find the union of two sets $A = \\\\{a_0, a_1, ..., a_{n-1}\\\\}$ and $B = \\\\{b_0, b_1, ..., b_{m-1}\\\\}$.\n\nConstraints\n\n* $1 \\leq n, m \\leq 200,000$\n* $0 \\leq a_0 < a_1 < ... < a_{n-1} \\leq 10^9$\n* $0 \\leq b_0 < b_1 < ... < b_{m-1} \\leq 10^9$\n\nInput\n\nThe input is given in the f...
[{"input": "3\n2 4 15\n2\n11 64", "output": "2\n4\n11\n15\n64\n"}, {"input": "3\n-1 5 10\n2\n3 16", "output": "-1\n3\n5\n10\n16\n"}, {"input": "3\n-1 4 10\n2\n3 16", "output": "-1\n3\n4\n10\n16\n"}, {"input": "3\n-1 4 10\n2\n5 16", "output": "-1\n4\n5\n10\n16\n"}, {"input": "3\n2 9 15\n2\n7 11", "output": "2\n7\n9\n11\...
code_stdio
[ { "content": "Lunar New Year is approaching, and you bought a matrix with lots of \"crosses\".\n\nThis matrix $M$ of size $n \\times n$ contains only 'X' and '.' (without quotes). The element in the $i$-th row and the $j$-th column $(i, j)$ is defined as $M(i, j)$, where $1 \\leq i, j \\leq n$. We define a cros...
[{"input": "14\nXXX.XXXXX..X.X\nX..XX..X...X..\n.....X.XX..XXX\n.X..X..XXX.XX.\n...XXXX.XX..XX\n.X..XX...XXX..\nXX.XX.XX..XXX.\n.X..X.....X.XX\n...XXX...XX.XX\nXXX.XX.XX.X.XX\nX.XXXX..XX.XX.\n.X.XX....X....\nX..XX..X.XX.X.\n..X...XX....XX\n", "output": "2\n"}, {"input": "14\nXXX.XXXXX..X.X\nX..XX..X...X..\n.....X.XX..X...
code_stdio
[ { "content": "Petya has an array of integers a_1, a_2, …, a_n. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it.\n\nPetya likes to challenge himself, so he wants to sort array using only 3-cycles. More formally, in one operation he can pick 3 pairwise dis...
[{"input": "7\n1\n1\n2\n2 2\n2\n2 2\n3\n1 2 3\n3\n1 1 1\n3\n3 1 2\n4\n2 1 4 3\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\n"}, {"input": "7\n1\n1\n2\n1 2\n2\n1 1\n3\n1 2 3\n3\n2 1 1\n3\n3 1 1\n4\n4 1 4 3\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\n"}, {"input": "7\n1\n1\n2\n1 2\n2\n1 1\n3\n1 3 3\n3\n2 1 1\n3...
code_stdio
[ { "content": "You are given a picture consisting of $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from the top to the bottom, columns are numbered from $1$ to $m$ from the left to the right. Each cell is painted either black or white. \n\nYou think that this picture is not interesting enough. You ...
[{"input": "9\n5 5\n..*..\n..*..\n*****\n..*..\n..*..\n3 4\n****\n.*..\n.*..\n4 3\n***\n*..\n*..\n*..\n5 5\n*****\n*.*.*\n*****\n..*.*\n..***\n1 4\n****\n5 5\n.....\n..*..\n.***.\n..*..\n.....\n5 3\n...\n.*.\n.*.\n***\n.*.\n3 3\n.*.\n*.*\n.*.\n4 4\n*.**\n....\n*.**\n*.**\n", "output": "0\n0\n0\n0\n0\n4\n1\n1\n2\n"}, {"...
code_stdio
[ { "content": "For two permutations p and q of the integers from 1 through N, let f(p,q) be the permutation that satisfies the following:\n\n* The p_i-th element (1 \\leq i \\leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.\n\n\n\nYou are given two permutations p and q ...
[{"input": "10 1000001000\n7 10 6 5 4 2 9 1 3 8\n4 1 9 2 3 7 8 10 6 5", "output": "8 4 6 5 2 7 9 10 1 3"}, {"input": "10 1001000001\n7 10 6 5 4 2 9 1 3 8\n4 1 9 2 3 7 8 10 6 5", "output": "4 8 10 6 9 2 1 3 5 7"}, {"input": "10 1000000001\n7 10 6 5 4 2 9 1 3 8\n4 1 9 2 3 7 8 10 6 5", "output": "10 3 7 6 4 8 2 1 5 9"}, {...
code_stdio
[ { "content": "Problem\n\nThere are coins with front and back sides and dice with rolls from $ 1 $ to $ N $. Gacho decided to play the following games using these.\n\nThe game starts with a score of $ 0 $ and proceeds as follows.\n\n\n1. Roll the dice $ 1 $ and add the number of rolls to the score.\n2. If the cu...
[{"input": "12 110 467", "output": "469611202\n"}, {"input": "12 100 467", "output": "732809678\n"}, {"input": "12 13 187", "output": "455459798\n"}, {"input": "12 60 467", "output": "654858060\n"}, {"input": "13 31 187", "output": "681077066\n"}, {"input": "10 31 187", "output": "611384855\n"}, {"input": "6 13 187", "...
code_stdio
[ { "content": "Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a \"plus\") and negative (a \"minus\"). If two magnets are put together at a close distance, then the like poles will rep...
[{"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\...
code_stdio
[ { "content": "Let's introduce some definitions that will be needed later.\n\nLet $prime(x)$ be the set of prime divisors of $x$. For example, $prime(140) = \\{ 2, 5, 7 \\}$, $prime(169) = \\{ 13 \\}$.\n\nLet $g(x, p)$ be the maximum possible integer $p^k$ where $k$ is an integer such that $x$ is divisible by $p...
[{"input": "1000000000 1000000000000000000\n", "output": "997440007\n"}, {"input": "1000000000 1000000000000000000\n", "output": "997440007\n"}, {"input": "1000000000 1000000000010000000\n", "output": "778038345\n"}, {"input": "1000001001 1000000000010000000\n", "output": "141474221\n"}, {"input": "732253291 1106035102...
code_stdio
[ { "content": "Alice has just learned addition. However, she hasn't learned the concept of \"carrying\" fully β€” instead of carrying to the next column, she carries to the column two columns to the left.\n\nFor example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:\n\nHowever, Alice evaluat...
[{"input": "2\n352942581\n1100110000\n", "output": "192407906\n102030199\n"}, {"input": "2\n178886702\n1100110000\n", "output": "148360651\n102030199\n"}, {"input": "2\n139544809\n1100110000\n", "output": "69014088\n102030199\n"}, {"input": "2\n217736582\n1100110000\n", "output": "48387455\n102030199\n"}, {"input": "2\...
code_stdio
[ { "content": "A: Union Ball\n\nProblem Statement\n\nThere are N balls in a box. The i-th ball is labeled with a positive integer A_i.\n\nYou can interact with balls in the box by taking actions under the following rules:\n\n* If integers on balls in the box are all odd or all even, you cannot take actions anymo...
[{"input": "3\n17 1 12", "output": "1\n"}, {"input": "3\n17 0 12", "output": "2\n"}, {"input": "3\n12 2 2", "output": "0\n"}, {"input": "3\n12 1 2", "output": "2\n"}, {"input": "3\n10 2 2", "output": "0\n"}, {"input": "3\n19 2 2", "output": "2\n"}, {"input": "3\n17 1 4", "output": "1\n"}, {"input": "3\n17 0 4", "output...
code_stdio
[ { "content": "You are standing at the point $0$ on a coordinate line. Your goal is to reach the point $n$. In one minute, you can move by $2$ or by $3$ to the left or to the right (i. e., if your current coordinate is $x$, it can become $x-3$, $x-2$, $x+2$ or $x+3$). Note that the new coordinate can become nega...
[{"input": "10\n999999999\n999999990\n999999995\n999999951\n999999999\n999999990\n999999999\n999999992\n999999997\n999999999\n", "output": "333333333\n333333330\n333333332\n333333317\n333333333\n333333330\n333333333\n333333331\n333333333\n333333333\n"}, {"input": "1\n84123456\n", "output": "28041152\n"}, {"input": "1\n...
code_stdio
[ { "content": "You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should ru...
[{"input": "7938986881993\n", "output": "1\n378028993"}, {"input": "1477562914357\n", "output": "1\n41161181\n"}, {"input": "472670214391\n", "output": "1\n23020027"}, {"input": "1468526771489\n", "output": "1\n613783"}, {"input": "1245373417369\n", "output": "1\n908209"}, {"input": "365292057641\n", "output": "1\n1260...
code_stdio
[ { "content": "On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in anothe...
[{"input": "100 20\n.....G.#.#..................#.........##....#...................#.#..........#...#.#.T..#.......#...\n", "output": "YES\n"}, {"input": "100 33\nG..................................................................................................T\n", "output": "YES\n"}, {"input": "100 33\nG..............
code_stdio
[ { "content": "You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly t_{i} milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.\n\nUnfortunate...
[{"input": "10 481\n6 25\n0 85\n8 96\n6 7\n1 16\n4 32\n2 5\n3 42\n9 126\n7 70\n", "output": "5\n5\n4 1 10 3 9"}, {"input": "10 481\n6 25\n0 85\n8 96\n6 7\n1 16\n4 32\n2 9\n3 42\n9 126\n7 70\n", "output": "5\n5\n4 1 10 3 9"}, {"input": "10 481\n6 25\n0 85\n8 96\n6 7\n1 16\n4 32\n2 0\n3 42\n9 126\n7 70\n", "output": "5\n...
code_stdio
[ { "content": "You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.\n\nYour favorite rational number in the [0;1] range is p / q. Now y...
[{"input": "5\n99999997 999999998 999999998 999999999\n99999996 999999997 999999997 999999999\n99999997 999999998 999999998 999999999\n99999996 999999997 999999997 999999999\n99999997 999999998 999999998 999999999\n", "output": "899999999100000001\n449999999550000002\n899999999100000001\n449999999550000002\n89999999910...
code_stdio
[ { "content": "You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1. The edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge.\n\nEach vertex i has a value a_i. You want to add edges in the given forest so that the forest bec...
[{"input": "7 -1\n1 2 3 4 5 6 0\n3 0\n4 0\n1 2\n1 3\n5 6", "output": "Impossible\n"}, {"input": "7 -1\n1 2 3 4 5 6 0\n3 0\n4 0\n1 2\n2 3\n5 6", "output": "Impossible\n"}, {"input": "7 -1\n1 2 3 4 5 6 0\n0 0\n4 0\n1 2\n2 3\n5 6", "output": "Impossible\n"}, {"input": "7 -1\n1 4 3 4 5 6 0\n0 0\n4 0\n1 2\n2 3\n5 6", "outpu...
code_stdio
[ { "content": "Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses (\"+\") in the line between certain digits in the line so that the result was a correct arithmetic e...
[{"input": "200 100\n56988719755815575893282254081467698462485803782142631369385180999746639622554559884281193367342283559238834106917388166048020056852911293394377949964185368886333934084399980368238188117302968424219707\n", "output": "295455656\n"}, {"input": "200 100\n655255749193583406396355747768874383520958452063...
code_stdio
[ { "content": "Connect the countless points with lines, till we reach the faraway yonder.\n\nThere are n points on a coordinate plane, the i-th of which being (i, y_{i}).\n\nDetermine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of the...
[{"input": "20\n-975467170 758268840 -975467171 758268839 -975467172 758268838 -975467173 758268837 -975467174 1015089897 -975467175 758268835 -975467176 758268834 -975467177 967684266 -975467178 758268832 -975467179 1082851919\n", "output": "No\n"}, {"input": "20\n-975467170 758268840 -975467171 758268839 -975467172 7...
code_stdio
[ { "content": "You are given a permutation $a$ consisting of $n$ numbers $1$, $2$, ..., $n$ (a permutation is an array in which each element from $1$ to $n$ occurs exactly once).\n\nYou can perform the following operation: choose some subarray (contiguous subsegment) of $a$ and rearrange the elements in it in an...
[{"input": "3\n4\n1 3 2 10\n3\n1 2 3\n5\n3 1 4 0 0\n", "output": "1\n0\n2\n"}, {"input": "3\n4\n1 3 2 7\n3\n1 2 3\n5\n2 1 4 5 -1\n", "output": "1\n0\n2\n"}, {"input": "3\n4\n1 3 2 4\n3\n1 2 3\n5\n2 1 4 5 3\n", "output": "\n1\n0\n2\n"}, {"input": "3\n4\n1 3 2 4\n3\n1 2 3\n5\n2 1 4 5 3\n", "output": "1\n0\n2\n"}, {"input...
code_stdio
[ { "content": "After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only along those Corridors that are not going to be used a...
[{"input": "10 26\n9 5 277429172\n10 8 789225932\n5 2 992601916\n9 8 277294258\n8 6 245446241\n6 2 439001127\n7 1 447891377\n10 6 699661758\n1 9 865851152\n2 8 299785854\n7 10 756200111\n8 3 431547893\n5 6 465205287\n7 4 957301499\n3 4 308491540\n3 7 252157788\n10 5 282875145\n1 8 262659451\n5 4 981921705\n2 4 16048245...
code_stdio
[ { "content": "Основой любой ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½ΠΎΠΉ сСти являСтся ΠΎΡ‚Π½ΠΎΡˆΠ΅Π½ΠΈΠ΅ Π΄Ρ€ΡƒΠΆΠ±Ρ‹ ΠΌΠ΅ΠΆΠ΄Ρƒ двумя ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡΠΌΠΈ Π² Ρ‚ΠΎΠΌ ΠΈΠ»ΠΈ ΠΈΠ½ΠΎΠΌ смыслС. Π’ ΠΎΠ΄Π½ΠΎΠΉ извСстной ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½ΠΎΠΉ сСти Π΄Ρ€ΡƒΠΆΠ±Π° симмСтрична, Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ Ссли a являСтся Π΄Ρ€ΡƒΠ³ΠΎΠΌ b, Ρ‚ΠΎ b Ρ‚Π°ΠΊΠΆΠ΅ являСтся Π΄Ρ€ΡƒΠ³ΠΎΠΌ a. \n\nΠ’ этой ΠΆΠ΅ сСти Π΅ΡΡ‚ΡŒ функция, которая дСмонстрируСт мноТСство людСй, ΠΈΠΌ...
[{"input": "10 50\n946010975 207263044\n923545573 749203275\n862015642 426425906\n749203275 839134958\n910721783 289091881\n827003531 333726912\n49704846 538788252\n382891592 207263044\n333726912 438209022\n974360048 49704846\n", "output": "49704846: 0\n207263044: 0\n289091881: 0\n333726912: 0\n382891592: 1 946010975\n...
code_stdio
[ { "content": "Polycarp has come up with a new game to play with you. He calls it \"A missing bigram\".\n\nA bigram of a word is a sequence of two adjacent letters in it.\n\nFor example, word \"abbaaba\" contains bigrams \"ab\", \"bb\", \"ba\", \"aa\", \"ab\" and \"ba\".\n\nThe game goes as follows. First, Polyc...
[{"input": "4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\n", "output": "abbaaba\nabaabaa\naaa\nbbabb\n"}, {"input": "4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\n", "output": "abbaaba\nabaabaa\naaa\nbbabb\n"}, {"input": "4\n7\nab bb ba aa ba\n7\nab ba aa ab ab\n3\naa\n5\nbb ab bb\n", "out...
code_stdio
[ { "content": "Absent-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 cubes all integers from 1 to x.\n\nTo make a number Masha can rotate her cubes ...
[{"input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7\n", "output": "10\n"}, {"input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0\n", "output": "10\n"}, {"input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4\n", "output": "10\n"}, {"input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1\n", "output": "19\n"}, {"input": "3\n3 4 5...
code_stdio
[ { "content": "Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facilities including supercomputers and many personal computers connected to the Internet.\n\nOne of the policies of the ...
[{"input": "8\n2\nomura\ntoshio\nraku\ntanaka\ninura\nyoshoi\nhayashi\nmiura\n3\n1\ntasaka\nnakata\ntanaka\n1\n1\nfoo\n5\n2\npsqt\nabcdef\nabzdefa\npqrst\nabdxcef\n0", "output": "inura,miura\ninura,omura\nmiura,omura\ntoshio,yoshoi\n4\ntanaka,tasaka\n1\n0\nabcdef,abdxcef\nabcdef,abzdefa\npqrst,psqt\n3\n"}, {"input": "8...
code_stdio
[ { "content": "There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.\n\nWhat is the minimum number of new roads that need to be built to make all the cities reachable from the capital?\n\nNew roads will also be one-way.\n\n\n-----Input-----\n\nThe f...
[{"input": "39 40 38\n4 8\n24 28\n16 17\n7 25\n4 29\n34 35\n16 24\n21 10\n23 36\n36 14\n28 16\n34 19\n15 21\n22 38\n22 37\n37 27\n28 33\n3 29\n32 22\n12 30\n9 15\n5 19\n23 27\n19 17\n25 17\n24 11\n39 10\n6 20\n16 6\n3 18\n34 21\n15 38\n11 19\n11 3\n32 4\n15 13\n16 11\n11 7\n33 7\n3 33\n", "output": "12\n"}, {"input": "...
code_stdio
[ { "content": "In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to ...
[{"input": "1 3\n3 4\n3 5\n3 6\n4 6\n4 7\n4 6\n5 6\n6 3\n5 8\n1 16\n1 8\n2 14\n7 0\n11 9\n9 2\n0 0\n1 3\n3 4\n5 5\n4 2\n0 0", "output": "NG\nOK\n"}, {"input": "1 3\n3 4\n3 5\n3 6\n4 6\n4 7\n4 6\n5 6\n6 3\n5 8\n1 16\n3 8\n6 14\n7 0\n8 9\n9 2\n0 0\n1 3\n3 4\n5 5\n4 2\n0 0", "output": "NG\nOK\n"}, {"input": "1 3\n3 4\n3 5...
code_stdio
[ { "content": "You are given two strings $s$ and $t$, each of length $n$ and consisting of lowercase Latin alphabets. You want to make $s$ equal to $t$. \n\nYou can perform the following operation on $s$ any number of times to achieve itΒ β€” Choose any substring of $s$ and rotate it clockwise once, that is, if t...
[{"input": "16\n3\naaa\naaa\n3\nabb\naab\n3\naab\nbaa\n3\naab\naba\n3\naca\naba\n3\naba\nbaa\n3\naba\naab\n3\nabb\nabb\n3\nabb\nbab\n3\nabb\nbba\n3\nabc\nabc\n3\ncba\nbad\n3\nabc\ndab\n3\nabc\nacb\n3\ncba\ncba\n3\nabc\nbca\n", "output": "0\n-1\n1\n1\n-1\n1\n1\n0\n1\n2\n0\n-1\n-1\n1\n0\n2\n"}, {"input": "16\n3\naaa\naaa...
code_stdio
[ { "content": "Little Petya loves playing with squares. Mum bought him a square 2n Γ— 2n in size. Petya marked a cell inside the square and now he is solving the following task.\n\nThe task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting ...
[{"input": "100 100 100\n", "output": "YES\n"}, {"input": "100 110 100\n", "output": "YES\n"}, {"input": "110 110 100\n", "output": "YES\n"}, {"input": "110 110 110\n", "output": "YES\n"}, {"input": "110 110 101\n", "output": "YES\n"}, {"input": "110 111 101\n", "output": "YES\n"}, {"input": "010 111 101\n", "output": ...
code_stdio
[ { "content": "A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.\n\nYou are given user's friends' opinions about a list of items. You are also given a threshold T β€” the minimal number of \"likes\" nec...
[{"input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\n", "output": "10\n"}, {"input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\n", "output": "1...
code_stdio
[ { "content": "Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.\n\nIn this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as \"21 o'clock\".\n\nThe current time is A o'clock, and a contest will begin in exactly B hours.\nWhen will the contest begin? Ans...
[{"input": "23 23\n", "output": "22\n"}, {"input": "405 14", "output": "11\n"}, {"input": "9 12\n", "output": "21\n"}, {"input": "19 0\n", "output": "19\n"}, {"input": "22 1\n", "output": "23\n"}, {"input": "3 12\n", "output": "15\n"}, {"input": "0 15\n", "output": "15\n"}, {"input": "17 -1", "output": "16\n"}, {"input...
code_stdio
[ { "content": "Input\n\nThe input contains two integers N, M (1 ≀ N ≀ 1024, 2 ≀ M ≀ 16), separated by a single space.\n\nOutput\n\nOutput \"YES\" or \"NO\".\n\nExamples\n\nInput\n\n\n2 3\n\n\nOutput\n\n\nYES\n\n\nInput\n\n\n3 2\n\n\nOutput\n\n\nNO\n\n\nInput\n\n\n33 16\n\n\nOutput\n\n\nYES\n\n\nInput\n\n\n26 5\n...
[{"input": "33 16\n", "output": "\nYES\n"}, {"input": "11 11\n", "output": "YES\n"}, {"input": "12 16\n", "output": "YES\n"}, {"input": "11 20\n", "output": "YES\n"}, {"input": "15 11\n", "output": "YES\n"}, {"input": "26 11\n", "output": "YES\n"}, {"input": "12 26\n", "output": "YES\n"}, {"input": "13 11\n", "output":...
code_stdio
[ { "content": "Did you ever hear about 'crossing the bridge noodle' ? Let me tell you that it's not some kind of bridge made of noodles. It's a dish, a kind of rice noodle soup. Mr.Ping makes the best noodle soup and his son Po is eagerly waiting for the user reviews in his father's blog. Users can vote with a (...
[{"input": "2\nQ 0\nP 14\n\n2\nO -1\nM -16\n\n0", "output": "13\n15\n"}, {"input": "2\nQ -1\nP 14\n\n2\nN -1\nM -3\n\n0", "output": "13\n2\n"}, {"input": "2\nQ -1\nP 8\n\n2\nM -1\nM -14\n\n0", "output": "7\n13\n"}, {"input": "2\nQ -1\nP 8\n\n2\nM -1\nM -13\n\n0", "output": "7\n12\n"}, {"input": "2\nQ 1\nP 7\n\n2\nO 0\n...
code_stdio
[ { "content": "Takahashi has two integers X and Y.\nHe computed X + Y and X - Y, and the results were A and B, respectively.\nNow he cannot remember what X and Y were. Find X and Y for him.\n\n-----Constraints-----\n - -100 \\leq A, B \\leq 100\n - For the given integers A and B, there uniquely exist integers X ...
[{"input": "-100 -100\n", "output": "-100 0\n"}, {"input": "-100 100\n", "output": "0 -100\n"}, {"input": "-39 -69\n", "output": "-54 15\n"}, {"input": "100 -100\n", "output": "0 100\n"}, {"input": "-98 4\n", "output": "-47 -51\n"}, {"input": "-23 71\n", "output": "24 -47\n"}, {"input": "17 -95\n", "output": "-39 56\n"...
code_stdio
[ { "content": "You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:\n - The string does not contain characters other than A, C, G and T.\n - The string does not contain AGC as a substring.\n - The condition above cannot be violated by swapping t...
[{"input": "100\n", "output": "388130742\n"}, {"input": "18\n", "output": "261943303\n"}, {"input": "26\n", "output": "858533109\n"}, {"input": "50\n", "output": "113468411\n"}, {"input": "90\n", "output": "252858375\n"}, {"input": "97\n", "output": "329869205\n"}, {"input": "98\n", "output": "616680192\n"}, {"input": ...
code_stdio
[ { "content": "Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises on the back cover of each book.\nHarry has ...
[{"input": "6\n14 hrilgne\n6 mathematics\n-1 geography\n-1\n3 grcphias\n-1", "output": "0 mathematics\n0 hrilgne\n0 grcphias\n"}, {"input": "6\n9 english\n7 nathematics\n-1 geography\n-1\n3 gchpsias\n-1", "output": "0 nathematics\n0 english\n0 gchpsias\n"}, {"input": "6\n1 hsilgne\n-1 lathematics\n14 georgaphy\n-1\n2 s...
code_stdio
[ { "content": "Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $n$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.\n\nThe pieces of sushi are of two types: either with tuna or with eel. Let's denote t...
[{"input": "100\n2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 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": "54\n"}, {"input": "100\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 1 ...
code_stdio
[ { "content": "You are given three integers $a \\le b \\le c$.\n\nIn one move, you can add $+1$ or $-1$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. N...
[{"input": "10\n3351 6383 6479\n7051 9793 9929\n1 1061 9572\n5401 5401 5865\n9777 9987 9987\n3393 7229 9665\n8014 8533 8665\n9549 9917 9998\n3336 6686 9962\n5351 8201 9241\n", "output": "208\n3239 6478 6478\n2223\n4964 9928 9928\n7\n1 1063 9567\n464\n5401 5401 5401\n210\n9987 9987 9987\n2608\n3221 9663 9663\n651\n8533 ...
code_stdio
[ { "content": "Find the minimum area of a square land on which you can place two identical rectangular $a \\times b$ houses. The sides of the houses should be parallel to the sides of the desired square land.\n\nFormally, You are given two identical rectangles with side lengths $a$ and $b$ ($1 \\le a, b \\le 1...
[{"input": "8\n3 2\n4 2\n1 1\n3 1\n4 13\n1 3\n12 4\n100 100\n", "output": "16\n16\n4\n9\n169\n9\n144\n40000\n"}, {"input": "8\n3 2\n2 2\n1 1\n4 2\n2 11\n1 4\n7 4\n100 101\n", "output": "16\n16\n4\n16\n121\n16\n64\n40000\n"}, {"input": "8\n3 2\n4 2\n1 1\n3 1\n12 7\n1 3\n12 4\n100 001\n", "output": "16\n16\n4\n9\n196\n9\...
code_stdio
[ { "content": "There are N integers written on a blackboard. The i-th integer is A_i.\n\nTakahashi will repeatedly perform the following operation on these numbers:\n\n* Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them.\n* Then, write a new...
[{"input": "5\n1 18 1 14 0", "output": "YES\n"}, {"input": "5\n2 18 0 14 0", "output": "YES\n"}, {"input": "5\n4 3 -1 16 4", "output": "YES\n"}, {"input": "5\n2 3 -1 16 4", "output": "YES\n"}, {"input": "5\n2 3 -1 16 2", "output": "YES\n"}, {"input": "5\n4 3 -1 16 2", "output": "YES\n"}, {"input": "5\n6 3 -1 16 2", "ou...
code_stdio
[ { "content": "problem\n\nAt IOI Confectionery, rice crackers are baked using the traditional method since the company was founded. This traditional method is to bake the front side for a certain period of time with charcoal, turn it over when the front side is baked, and bake the back side for a certain period ...
[{"input": "2 5\n0 1 1 1 0\n1 0 0 0 1\n3 6\n1 0 0 0 1 0\n1 1 1 0 1 0\n1 0 1 1 0 1\n0 0", "output": "10\n15\n"}, {"input": "2 5\n1 1 1 1 0\n0 0 0 0 1\n3 6\n1 0 0 0 0 1\n0 1 1 0 1 0\n1 0 1 1 0 1\n0 0", "output": "10\n16\n"}, {"input": "2 5\n1 1 1 1 0\n0 0 0 0 1\n3 6\n1 0 0 0 1 0\n0 1 1 0 1 1\n1 0 1 1 0 1\n0 0", "output":...
code_stdio
[ { "content": "Alice is visiting New York City. To make the trip fun, Alice will take photos of the city skyline and give the set of photos as a present to Bob. However, she wants to find the set of photos with maximum beauty and she needs your help.\n\nThere are $n$ buildings in the city, the $i$-th of them has...
[{"input": "50\n5 42 16 13 20 2 39 49 33 1 11 4 46 3 48 44 12 7 27 41 35 38 26 6 31 37 10 50 24 9 32 15 47 30 17 28 22 29 23 34 8 18 40 21 19 36 25 43 45 14\n427 -3 -165 -161 302 -337 285 -418 227 -78 -453 -122 -162 -249 -194 119 -127 322 -238 467 -236 254 263 -57 225 391 270 -96 -173 329 -45 133 -36 449 -3 168 -490 15...
code_stdio
[ { "content": "Given is an integer S.\nFind how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S.\nThe answer can be very large, so output it modulo 10^9 + 7.\n\n-----Constraints-----\n - 1 \\leq S \\leq 2000\n - All values in input are integers.\n\n--...
[{"input": "1729\n", "output": "294867501\n"}, {"input": "2000\n", "output": "883312678\n"}, {"input": "1445\n", "output": "157799856\n"}, {"input": "1447\n", "output": "185357934\n"}, {"input": "1497\n", "output": "661810862\n"}, {"input": "1202\n", "output": "751905815\n"}, {"input": "522\n", "output": "272885863\n"}...
code_stdio
[ { "content": "There is a building with 2N floors, numbered 1, 2, \\ldots, 2N from bottom to top.\nThe elevator in this building moved from Floor 1 to Floor 2N just once.\nOn the way, N persons got on and off the elevator. Each person i (1 \\leq i \\leq N) got on at Floor A_i and off at Floor B_i. Here, 1 \\leq ...
[{"input": "100\n65 165\n6 106\n41 141\n1 101\n4 104\n33 133\n5 105\n57 157\n98 198\n15 115\n52 152\n53 153\n46 146\n29 129\n42 142\n8 108\n12 112\n69 169\n47 147\n87 187\n79 179\n88 188\n67 167\n26 126\n55 155\n73 173\n72 172\n74 174\n95 195\n36 136\n61 161\n10 110\n17 117\n7 107\n23 123\n30 130\n14 114\n90 190\n66 16...
code_stdio
[ { "content": "There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \\dots, x_N) and (y_1, y_2, \\dots, y_N) are both permuations of (1, 2, \\dots, N).\n\nFor each k = 1,2,\\dots,N, find the answer to the following question:\n\nRng is in City k. Rng can perform the fol...
[{"input": "7\n6 4\n4 2\n3 5\n7 1\n2 7\n5 3\n1 6", "output": "3\n3\n1\n1\n2\n3\n2\n"}, {"input": "7\n6 4\n4 3\n3 5\n7 1\n2 6\n5 2\n1 7", "output": "3\n3\n1\n1\n1\n3\n1\n"}, {"input": "7\n6 4\n4 3\n3 5\n7 1\n2 7\n5 2\n1 6", "output": "3\n3\n1\n1\n2\n3\n2"}, {"input": "4\n2 4\n1 3\n3 1\n4 2", "output": "2\n2\n2\n2\n"}, {...
code_stdio
[ { "content": "Contest T-shirts\n\nSegtree has $ M $ contest T-shirts.\n\nHe decided to spend $ N $ days on the contest T-shirt alone, and told $ i = 1, 2, 3, \\ dots, N $ \"$ A_i $ T-shirt on the $ i $ day.\" I made a plan for $ N $ to wear.\n\nHowever, if you keep the current plan, you may not be able to do th...
[{"input": "11 0\n2 2 -1", "output": "0\n"}, {"input": "-1 0\n3 0 -1", "output": "0\n"}, {"input": "0 1\n2 -1 -2", "output": "0\n"}, {"input": "0 0\n-1 3 -2", "output": "0\n"}, {"input": "-1 0\n2 3 -1", "output": "0\n"}, {"input": "11 0\n2 0 -2", "output": "0\n"}, {"input": "-1 0\n-1 0 0", "output": "0\n"}, {"input": "...
code_stdio
[ { "content": "Vasya has recently got a job as a cashier at a local store. His day at work is $L$ minutes long. Vasya has already memorized $n$ regular customers, the $i$-th of which comes after $t_{i}$ minutes after the beginning of the day, and his service consumes $l_{i}$ minutes. It is guaranteed that no cus...
[{"input": "1 1000000000 1\n0 1000000000\n", "output": "0\n"}, {"input": "1 1000000000 1\n0 1000000000\n", "output": "0"}, {"input": "0 1000000000 1\n", "output": "1000000000\n"}, {"input": "0 1000000000 1000000000\n", "output": "1\n"}, {"input": "0 1000000000 1000000010\n", "output": "0\n"}, {"input": "0 1000010000 10...
code_stdio
[ { "content": "There is a directed graph with N vertices and M edges.\nThe i-th edge (1≀i≀M) points from vertex a_i to vertex b_i, and has a weight c_i.\nWe will play the following single-player game using this graph and a piece.\nInitially, the piece is placed at vertex 1, and the score of the player is set to ...
[{"input": "6 5\n1 2 -1000000000\n2 3 -1000000000\n3 4 -1000000000\n4 5 -1000000000\n5 6 -1000000000\n", "output": "-5000000000\n"}, {"input": "6 5\n1 2 -1000000000\n2 3 -1000000000\n3 5 -1000000000\n4 5 -1000000000\n5 6 -1000000000", "output": "-4000000000\n"}, {"input": "6 5\n1 2 -1000000000\n2 3 -1000000000\n3 5 -12...
code_stdio
[ { "content": "Bridge Removal\n\nICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is to remove all the bridges connecting the isl...
[{"input": "4\n1 2 3\n10 37 30\n10\n1 2 2 1 1 5 1 10 8\n10 2 1 20 2 1 30 1 1\n3\n1 1\n1 1\n0", "output": "114\n139\n2\n"}, {"input": "4\n1 2 3\n10 37 52\n10\n1 2 2 1 1 5 1 10 8\n10 2 1 20 2 1 30 1 1\n3\n1 1\n1 1\n0", "output": "136\n139\n2\n"}, {"input": "4\n1 2 3\n10 30 30\n10\n1 2 2 1 1 5 1 8 8\n10 1 1 20 2 1 30 1 1\...
code_stdio
[ { "content": "Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an.\n\nLet's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. \n\n...
[{"input": "10\n375813 659427 484038 348181 432640 368050 271089 721588 345312 630771\n", "output": "29\n"}, {"input": "10\n1 1 3 4 5 12 1 2 9 10\n", "output": "12\n"}, {"input": "10\n6 8 11 5 1 9 10 2 4 7\n", "output": "13\n"}, {"input": "10\n1 1 3 1 5 12 1 2 9 10\n", "output": "11\n"}, {"input": "10\n1 1 3 1 5 12 1 2...
code_stdio
[ { "content": "Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. \n\nChef likes problems involving arrays. Unfortunately, the last one he tried to solve didn't quite get solved.\n\nChef has an array A of N positive numbers. He wants to find the number of subarrays for which the sum an...
[{"input": "3\n3\n3 0 0\n4\n3 2 0 1\n6\n1 0 -1 0 1 0", "output": "4\n4\n12\n"}, {"input": "3\n3\n1 0 0\n4\n3 2 0 1\n6\n0 0 -1 0 1 0", "output": "4\n4\n13\n"}, {"input": "3\n3\n1 3 2\n4\n4 2 6 -1\n6\n2 1 2 -1 2 1", "output": "4\n4\n6\n"}, {"input": "3\n3\n1 0 2\n4\n4 1 2 1\n6\n1 3 2 2 2 2", "output": "3\n5\n10\n"}, {"in...
code_stdio
[ { "content": "We have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.\nYou can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.\nPrint YES if you can sor...
[{"input": "50\n43 20 27 29 33 34 2 15 50 18 23 3 13 19 12 1 11 7 32 48 35 36 41 44 22 24 6 30 45 46 5 25 37 16 26 4 47 39 28 8 42 9 31 21 10 49 40 17 14 38\n", "output": "NO\n"}, {"input": "44\n1 2 3 4 5 6 7 8 9 10 22 12 13 14 15 16 17 18 19 20 21 11 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44\n"...
code_stdio
[ { "content": "Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that: 1 ≀ a ≀ n. If it's Mahmoud's turn, a has to be even, but if it's Ehab...
[{"input": "1001000000\n", "output": "Mahmoud\n"}, {"input": "1011000000\n", "output": "Mahmoud\n"}, {"input": "1165278070\n", "output": "Mahmoud\n"}, {"input": "1425124860\n", "output": "Mahmoud\n"}, {"input": "1000000000\n", "output": "Mahmoud"}, {"input": "1000000000\n", "output": "Mahmoud"}, {"input": "691838234\n"...
code_stdio
[ { "content": "Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way t...
[{"input": "63 20\n35 26\n54 5\n32 56\n56 53\n59 46\n37 31\n46 8\n4 1\n2 47\n59 42\n55 11\n62 6\n30 7\n60 24\n41 36\n34 22\n24 34\n21 2\n12 52\n8 44\n60 21\n24 30\n48 35\n48 25\n32 57\n20 37\n11 54\n11 62\n42 58\n31 43\n12 23\n55 48\n51 55\n41 27\n25 33\n21 18\n42 12\n4 15\n51 60\n62 39\n46 41\n57 9\n30 61\n31 4\n58 13...
code_stdio
[ { "content": "Takahashi recorded his daily life for the last few days as a integer sequence of length 2N, as follows:\n\n* a_1, b_1, a_2, b_2, ... , a_N, b_N\n\n\n\nThis means that, starting from a certain time T, he was:\n\n* sleeping for exactly a_1 seconds\n* then awake for exactly b_1 seconds\n* then sleepi...
[{"input": "10\n43196 57600\n4800 9600\n6000 1200\n600 600\n300 600\n5400 600\n6000 5760\n6760 2880\n6000 12000\n9000 600", "output": "5\n"}, {"input": "10\n43196 57600\n4800 9600\n6000 1200\n600 600\n300 600\n5400 600\n6000 5760\n6760 2880\n6000 12000\n9000 794", "output": "5\n"}, {"input": "10\n43196 21072\n8364 1124...
code_stdio
[ { "content": "You are given a string s of length n consisting of lowercase English letters.\n\nFor two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping...
[{"input": "10 30\naccbaaccac\n6 8 3\n2 9 1\n6 8 3\n10 5 1\n6 2 2\n1 4 7\n3 10 1\n6 9 1\n7 7 3\n7 3 2\n8 4 1\n4 9 1\n7 6 4\n6 8 2\n10 2 1\n1 3 5\n5 10 1\n7 10 1\n4 1 2\n8 5 3\n9 8 1\n8 6 2\n6 9 2\n10 3 1\n3 9 1\n5 5 5\n1 5 6\n4 2 6\n10 7 1\n9 8 2\n", "output": "NO\nYES\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nNO\...
code_stdio
[ { "content": "You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.\n\nA sequence $a$ is a subsequence of an array $b$ if $a$ ca...
[{"input": "8\n6 15 35 129 143 221 34 26\n", "output": "3\n"}, {"input": "8\n6 15 35 129 143 221 3 26\n", "output": "-1\n"}, {"input": "8\n6 15 35 129 143 221 3 51\n", "output": "-1\n"}, {"input": "8\n6 11 35 129 143 221 3 51\n", "output": "5\n"}, {"input": "8\n6 15 35 77 143 221 34 26\n", "output": "3"}, {"input": "8\...
code_stdio
[ { "content": "Taro and Jiro will play the following game against each other.\n\nInitially, they are given a sequence a = (a_1, a_2, \\ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:\n\n* Remove the element at the beginning or the end of a. The...
[{"input": "10\n1000000000 0 1000000000 1 1000000000 1 1000000000 1 1000000000 1", "output": "4999999996\n"}, {"input": "10\n1000000000 1 1000000000 1 1000000000 2 1000000000 1 1000000000 1", "output": "4999999994\n"}, {"input": "10\n1000000000 0 1000000000 1 1000000000 1 1010000000 1 1000000000 1", "output": "50099999...
code_stdio
[ { "content": "Given are three positive integers A, B, and C. Compute the following value modulo 998244353:\n\\sum_{a=1}^{A} \\sum_{b=1}^{B} \\sum_{c=1}^{C} abc\n\n-----Constraints-----\n - 1 \\leq A, B, C \\leq 10^9\n\n-----Input-----\nInput is given from standard input in the following format:\nA B C\n\n-----O...
[{"input": "1000000000 987654321 123456789\n", "output": "951633476\n"}, {"input": "192279221 156648747 154396385\n", "output": "152138957\n"}, {"input": "264704198 120999147 136987925\n", "output": "24444247\n"}, {"input": "682152024 451794315 2028038\n", "output": "579633067\n"}, {"input": "693 299 737\n", "output": ...
code_stdio
[ { "content": "The only difference between easy and hard versions is the constraints.\n\nVova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful t...
[{"input": "25 4 15\n172043124 384297369 650214870 426077944 587045971 576701397 865475689 261462255 763837593 285228401 629011531 611623799 456424430 820020943 166915939 903479811 357808031 561107351 177427070 14589838 994169358 1227795556 193684940 439658261 237500762\n", "output": "10512644504\n"}, {"input": "25 4 1...
code_stdio
[ { "content": "Problem statement\n\nAOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \\ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is. AOR Ika-chan decided to use the cabbage ...
[{"input": "16 6 10 -1\n24 1 4 -1 0", "output": "1\n"}, {"input": "16 6 10 -1\n24 1 5 -1 0", "output": "1\n"}, {"input": "21 10 0 4\n5 2 13 -1 0", "output": "3\n"}, {"input": "16 6 10 -1\n24 1 4 0 1", "output": "1\n"}, {"input": "16 6 10 -1\n24 1 4 0 0", "output": "1\n"}, {"input": "16 6 10 0\n24 1 5 -1 0", "output": "...
code_stdio
[ { "content": "The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. \"Do I give such a hard task?\" β€” the HR manager thought. \"Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one can...
[{"input": "2000000000000000000\n", "output": "25\n"}, {"input": "1000000000000000000\n", "output": "25\n"}, {"input": "1000001000000000000\n", "output": "25\n"}, {"input": "1440563777463828705\n", "output": "25\n"}, {"input": "1000001000000010000\n", "output": "25\n"}, {"input": "1000001000000000100\n", "output": "25\...
code_stdio
[ { "content": "Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I know for sure that either x or y did it!'\n\nT...
[{"input": "10 2\n10 2\n9 3\n9 4\n7 2\n4 6\n10 1\n9 2\n3 10\n7 1\n5 1\n", "output": "43\n"}, {"input": "10 3\n6 3\n6 10\n2 5\n5 7\n6 2\n9 2\n8 1\n10 5\n5 10\n7 6\n", "output": "34\n"}, {"input": "10 2\n10 2\n9 3\n9 4\n7 2\n4 6\n10 1\n9 2\n3 10\n7 1\n5 1\n", "output": "43\n"}, {"input": "10 3\n6 3\n6 10\n2 5\n5 7\n6 2\n...
code_stdio
[ { "content": "The only difference between the easy and the hard versions is constraints.\n\nA subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there ca...
[{"input": "100 1000000000000\ndjgykfqaywhkhpocyxcpvbiiouyielmighclnuopadzuvrirbecucwnzwahahagvfstbxxaednajfauscxwttiglbbxtomnnalcl\n", "output": "8854753825335\n"}, {"input": "100 1000000000000\ndjgykfqaywhkhpocyxcpvbiiouyielmighclnuopadzuvrirbecucwnzwahahagvfstbxxaednajfauscxwttiglbbxtomnnalcl\n", "output": "88547538...
code_stdio
[ { "content": "C: Only one subsequence --Unique Subsequence-\n\nproblem\n\nOne day Ebi-chan noticed that a text string T of length n and a pattern string P (m \\ leq n) of length m were placed on the desk. Ebi-chan loves the \"only one subsequence\" that appears in strings, so she immediately began investigating...
[{"input": "aziucamp\nazu", "output": "yes\n"}, {"input": "azjucamp\nazu", "output": "yes\n"}, {"input": "aizucamp\nuza", "output": "no\n"}, {"input": "azjucamp\nazt", "output": "no\n"}, {"input": "azjucamp\nzat", "output": "no\n"}, {"input": "pmacujza\nzat", "output": "no\n"}, {"input": "pmacuiza\nzat", "output": "no\...
code_stdio
[ { "content": "Suppose you are given a string $s$ of length $n$ consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.\n\nTo compress the string, you have to represent $s$ as a concatenation of several non-empty strings: $s = t_{1} t_{2} \\ldots t_{k}$. The ...
[{"input": "255 3880 4590\nwgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwewgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwkwgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwewgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwawgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwewgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwkwgwzwgwuwgwzwgwxwgwzwgwuwgwzwgwewgwzwgwuwgwzwgwxwgwzwgwuwgwzwgw\n", "output": "62460\n"}, {"input": "...
code_stdio
[ { "content": "Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.\n\nArithmetic progression is a sequence a_1, a_1 + d, a_1 + 2d, ..., a_1 + (n - 1)d, where a...
[{"input": "64 160 400 1000\n", "output": "2500\n"}, {"input": "992 994 1419 1000\n", "output": "42\n"}, {"input": "1000 980 1495 906\n", "output": "42\n"}, {"input": "992 429 1419 1000\n", "output": "42\n"}, {"input": "836 624 412 200\n", "output": "-12\n"}, {"input": "1 334 667 1000\n", "output": "1333\n"}, {"input":...
code_stdio
[ { "content": "You are given an array a consisting of n integers.\n\nLet min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r.\n\nYour task is to choose three positive (greater than 0) integers x, y and z such that:\n\n * x + y + z = n; \n ...
[{"input": "8\n3\n1000000000 1000000000 1000000000\n3\n1 1000000000 1000000000\n3\n1000000000 1 1000000000\n3\n1 1 1000000000\n3\n1000000000 1000000000 1\n3\n1 1000000000 1\n3\n1000000000 1 1\n3\n1 1 1\n", "output": "YES\n1 1 1\nNO\nNO\nNO\nNO\nNO\nNO\nYES\n1 1 1\n"}, {"input": "8\n3\n1000000000 1000000000 1000000000\n...
code_stdio
[ { "content": "Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.\n...
[{"input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\n", "output": "1406\n"}, {"input": "75\nVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\n", "output": "1406\n"}, {"input": "75\nVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVK...
code_stdio
[ { "content": "It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k β‰₯ 0, 0 < r ≀ 2k. Let's call that representation prairie partition of x.\n\nFor example, the prairie partitions of 12, 17, 7 and 1 are: \n\n12 = 1 + 2 + 4 + 5,\...
[{"input": "100\n1 1 1 1 1 1 1 2 2 2 2 2 2 2 4 4 4 4 4 4 4 6 8 8 8 8 8 8 8 10 16 16 16 16 16 16 16 17 22 24 24 30 32 32 32 46 32 32 48 62 64 108 65 65 67 70 74 88 89 98 99 101 101 109 121 127 128 128 137 143 152 153 155 156 160 161 114 183 186 196 196 214 220 226 228 230 238 240 241 245 249 249 250 253 254 256 256 512 ...
code_stdio
[ { "content": "For any positive integer, we define a digit rotation as either moving the first digit\nto the end of the number (left digit rotation), or the last digit to the front of the number (right digit rotation).\nFor example, the number 12345 could be left digit rotated to 23451, or right digit rotated to...
[{"input": "6\n12345\n43634\n21427\n211011\n7\n166", "output": "51234\n63443\n72142\n211011\n7\n661\n"}, {"input": "6\n23325\n43634\n21427\n211011\n7\n166", "output": "52332\n63443\n72142\n211011\n7\n661\n"}, {"input": "6\n23325\n43634\n21427\n211011\n1\n166", "output": "52332\n63443\n72142\n211011\n1\n661\n"}, {"input...
code_stdio
[ { "content": "We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.\nIf we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost ...
[{"input": "155776 1 112696\n", "output": "837491985\n"}, {"input": "200000 1 134405\n", "output": "945631888\n"}, {"input": "491 405 148903\n", "output": "206234613\n"}, {"input": "435 448 126173\n", "output": "779238467\n"}, {"input": "454 424 168618\n", "output": "804548732\n"}, {"input": "488 405 176503\n", "output...
code_stdio
[ { "content": "Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.\n\nUnfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the follo...
[{"input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 54657213...
code_stdio
[ { "content": "Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.\n\nThere is a sequence a that consists of n integers a_1, a_2, ..., a_{n}. Let's denote f...
[{"input": "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n", "output": "114\n"}, {"input": "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n", "output": "114\n"}, {"input": "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 1 4\n", "output": "114\n"}, {"input": "24\n1 2 3 4 1 2 3 2 1 2 3 4 1 2 3 4 1 2 3 4 1 2...
code_stdio
[ { "content": "You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t.\n\nA path in the tree is said to be palindromic if at least one permutation of the labels in the path is a palindrome.\n\nFor each verte...
[{"input": "20\n10 9\n15 14\n11 12\n2 3\n15 16\n2 1\n18 19\n20 19\n8 9\n7 6\n8 7\n12 13\n5 6\n4 3\n13 14\n18 17\n11 10\n16 17\n5 4\naabbccddeeffgghhiijj\n", "output": "20 29 45 52 64 69 77 80 84 85 85 84 80 77 69 64 52 45 29 20\n"}, {"input": "20\n10 9\n15 14\n11 12\n2 3\n15 16\n2 1\n18 19\n20 19\n8 9\n7 6\n8 7\n12 13\...
code_stdio
[ { "content": "Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. \n\nVasya has two numbers x and y, and he wants to calculate f(x, y). He tried to do it by himself, but found o...
[{"input": "999999999989 999999999988\n", "output": "999999999988\n"}, {"input": "414654652183 366894205623\n", "output": "366894205623\n"}, {"input": "999999999958 999999999957\n", "output": "499999999979\n"}, {"input": "999999999989 999999999988\n", "output": "999999999988\n"}, {"input": "999999999958 999999999957\n"...
code_stdio
[ { "content": "A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily $7$ days!\n\nIn detail, she can choose any integer $k$ which satisfies $1 \\leq k \\leq r$, and set $k$ days as the number of days in...
[{"input": "5\n5 4\n2 4\n5 1\n13 9\n1010000 14106652\n", "output": "10\n2\n1\n45\n510049495001\n"}, {"input": "5\n6 4\n3 2\n3 1\n13 7\n1010000 14106652\n", "output": "10\n3\n1\n28\n510049495001\n"}, {"input": "5\n5 4\n2 4\n5 1\n13 9\n1010000 12964098\n", "output": "10\n2\n1\n45\n510049495001\n"}, {"input": "5\n3 4\n3 2...
code_stdio
[ { "content": "A 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 characters \"+\" and \"1\" into this sequence. For example, \"\", \"(())\" and \"()()...
[{"input": "1000000000\n1000000000\n1000000000\n1000000000\n", "output": "1\n"}, {"input": "1000000000\n1000000000\n1000000000\n1000000000\n", "output": "1\n"}, {"input": "1000000000\n1000000000\n1000000000\n999999999\n", "output": "0\n"}, {"input": "1000000000\n999999999\n1000000000\n1000000000\n", "output": "1\n"}, {...
code_stdio
[ { "content": "Masha has three sticks of length $a$, $b$ and $c$ centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.\n\nWhat is the minimum number of minutes she needs to spend increasing the stick's length in o...
[{"input": "100 100 100\n", "output": "0\n"}, {"input": "100 100 100\n", "output": "0\n"}, {"input": "100 10 10\n", "output": "81\n"}, {"input": "100 100 99\n", "output": "0\n"}, {"input": "100 100 99\n", "output": "0\n"}, {"input": "100 10 10\n", "output": "81\n"}, {"input": "12 34 56\n", "output": "11\n"}, {"input": ...
code_stdio