messages
listlengths
1
1
ground_truth
stringlengths
156
726k
dataset
stringclasses
1 value
[ { "content": "Prime numbers are widely applied for cryptographic and communication technology. A twin prime is a prime number that differs from another prime number by 2. For example, (5, 7) and (11, 13) are twin prime pairs.\n\nIn this problem, we call the greater number of a twin prime \"size of the twin prim...
[{"input": "12\n110\n200\n300\n0", "output": "5 7\n107 109\n197 199\n281 283\n"}, {"input": "12\n110\n200\n227\n0", "output": "5 7\n107 109\n197 199\n197 199\n"}, {"input": "12\n110\n200\n329\n0", "output": "5 7\n107 109\n197 199\n311 313\n"}, {"input": "12\n110\n200\n239\n0", "output": "5 7\n107 109\n197 199\n227 229\...
code_stdio
[ { "content": "DO YOU EXPECT ME TO FIND THIS OUT?\n\nWHAT BASE AND/XOR LANGUAGE INCLUDES string?\n\nDON'T BYTE OF MORE THAN YOU CAN CHEW\n\nYOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR\n\nSAYING \"ABRACADABRA\" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD\n\nTHE LAST STACK RUPTURES. ALL DIE. OH, THE EMBAR...
[{"input": "10\n5 5 10 10 10 2 4 3 4 10\n", "output": "0\n"}, {"input": "10\n5 5 10 10 10 2 4 3 4 10\n", "output": "0\n"}, {"input": "10\n5 5 10 10 10 1 4 3 4 10\n", "output": "0\n"}, {"input": "10\n3 5 10 10 10 1 4 3 4 10\n", "output": "0\n"}, {"input": "10\n3 5 10 10 10 1 4 3 5 10\n", "output": "0\n"}, {"input": "10\...
code_stdio
[ { "content": "Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message \"Play Me\". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of ...
[{"input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa\naab\na\n?a?\n??\n?aa?bb?\n?aa?aa?\n??aaa?\n", "output": "0\n4\n2\n5\n6\n7\n"}, {"input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbc\naa\naa\naab\na\n?a?\n?...
code_stdio
[ { "content": "Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.\n\nThe players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes ...
[{"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1010\n5 1000 1000 1000 1000 1000\n", "output": "7000 7010\n"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1010\n5 1000 1000 0000 1000 1000\n", "output": "7000 6010\n"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1011\n5 1000 100...
code_stdio
[ { "content": "You are given two arrays $a$ and $b$ both consisting of $n$ positive (greater than zero) integers. You are also given an integer $k$.\n\nIn one move, you can choose two indices $i$ and $j$ ($1 \\le i, j \\le n$) and swap $a_i$ and $b_j$ (i.e. $a_i$ becomes $b_j$ and vice versa). Note that $i$ and ...
[{"input": "5\n2 1\n1 2\n3 4\n5 5\n5 5 6 11 5\n1 2 5 4 3\n5 3\n1 2 3 4 5\n10 9 10 10 9\n4 0\n2 2 4 3\n2 4 2 3\n4 4\n1 2 2 1\n4 4 5 4\n", "output": "6\n32\n39\n11\n17\n"}, {"input": "5\n2 1\n1 2\n3 4\n5 5\n5 10 6 6 5\n1 2 5 4 3\n5 5\n1 2 3 4 5\n10 9 10 10 9\n4 0\n2 2 4 3\n2 4 2 0\n4 4\n1 2 0 1\n4 4 5 4\n", "output": "6\...
code_stdio
[ { "content": "Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€” mathematical expectation of the minimal element among all k-element subsets.\n\nBut only function does ...
[{"input": "7\n4 12 5 15 8 2 5\n2 1 2 0 1 1 1\n", "output": "4 12 2 15 8 5 5\n"}, {"input": "7\n4 12 5 8 10 2 3\n2 1 2 1 1 1 2\n", "output": "4 12 3 10 8 5 2\n"}, {"input": "7\n4 12 5 8 10 2 3\n2 2 2 1 1 1 2\n", "output": "5 4 3 12 10 8 2\n"}, {"input": "7\n4 12 5 15 8 2 5\n2 1 2 1 1 1 2\n", "output": "5 15 4 12 8 5 2\...
code_stdio
[ { "content": "This is the hard version of the problem. The only difference is that in this version $n \\leq 200000$. You can make hacks only if both versions of the problem are solved.\n\nThere are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase ...
[{"input": "12\n-3 -3 -7 -1 -1 -7 4 2 -4 -1 0 -11\n", "output": "5\n"}, {"input": "12\n-3 -3 -5 -1 -1 -7 4 2 -4 -1 0 -11\n", "output": "5\n"}, {"input": "12\n-1 -3 -5 -1 -1 -7 4 2 -4 -1 0 -11\n", "output": "5\n"}, {"input": "12\n-1 -3 -5 -1 -1 -7 4 2 -5 -1 0 -11\n", "output": "5\n"}, {"input": "12\n-1 -3 -5 -1 -1 -7 2 ...
code_stdio
[ { "content": "Write a program which computes the digit number of sum of two integers a and b.\n\nConstraints\n\n* 0 ≀ a, b ≀ 1,000,000\n* The number of datasets ≀ 200\n\nInput\n\nThere are several test cases. Each test case consists of two non-negative integers a and b which are separeted by a space in a line. ...
[{"input": "-2 -1\n2 -15\n0110 -1", "output": "2\n3\n3\n"}, {"input": "10 10\n2 36\n1000 25", "output": "2\n2\n4\n"}, {"input": "-1 -1\n0 -1\n0111 14", "output": "2\n2\n3\n"}, {"input": "-2 -1\n0 -1\n0011 14", "output": "2\n2\n2\n"}, {"input": "2 -1\n-6 1\n1001 -14", "output": "1\n2\n3\n"}, {"input": "6 7\n1 99\n1000 1...
code_stdio
[ { "content": "Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.\nWhen all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.\n\n-----Constrai...
[{"input": "100 100\n", "output": "0\n"}, {"input": "100 10\n", "output": "0\n"}, {"input": "111 136", "output": "1\n"}, {"input": "110 112", "output": "1\n"}, {"input": "011 127", "output": "1\n"}, {"input": "99 33\n", "output": "0\n"}, {"input": "100 1\n", "output": "0\n"}, {"input": "99 49\n", "output": "1\n"}, {"in...
code_stdio
[ { "content": "You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them.\n\nFor example, if K = 3, print `ACLACLACL`.\n\nConstraints\n\n* 1 \\leq K \\leq 5\n* All values in input are integers.\n\nInput\n\nInput is given from Standard Input in the followin...
[{"input": "451", "output": "ACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACLACL...
code_stdio
[ { "content": "Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, ...
[{"input": "10\n3\n-14 -33 142\n16\n45 -84 35 85 69 -64 93 -70 0 -102 2 -52 -55 38 33 -98\n2\n5 0\n4\n-65 -113 5 6\n5\n82 -66 113 -81 -35\n5\n-125 107 -1 2 -10\n1\n25\n1\n-19\n1\n-8\n12\n32 41 43 -157 57 8 -86 111 -25 96 28 -44\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nNO\n"}, {"input": "10\n3\n-14 -33 142\...
code_stdio
[ { "content": "A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck.\n\nYour task is to write a program that reports how ...
[{"input": "6 12\n2 18\n0 0", "output": "4\n872\n"}, {"input": "5 18\n18 4\n0 0", "output": "10\n25\n"}, {"input": "14 14\n8 3\n0 0", "output": "2\n10\n"}, {"input": "8 10\n18 4\n0 0", "output": "1\n25\n"}, {"input": "8 9\n18 3\n0 0", "output": "2\n110\n"}, {"input": "7 2\n18 4\n0 0", "output": "13\n25\n"}, {"input": "...
code_stdio
[ { "content": "We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball.\n\nSnuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i.\n\nFind the...
[{"input": "4 4\n1 1\n-1 3\n4 0\n3 4", "output": "1\n"}, {"input": "7 4\n-1 2\n1 3\n7 0\n0 0", "output": "1\n"}, {"input": "7 4\n-1 2\n1 6\n7 0\n0 0", "output": "1\n"}, {"input": "10 4\n1 2\n2 3\n4 0\n0 0", "output": "2\n"}, {"input": "4 4\n1 2\n-1 3\n4 0\n3 4", "output": "1\n"}, {"input": "7 4\n-1 0\n1 6\n7 0\n0 0", "...
code_stdio
[ { "content": "Brave Ponta and his best friend, Brave Gonta, have come to Luida's bar in search of friends to embark on an epic adventure. There are many warriors, monks and wizards in the tavern who are itching to go on an adventure.\n\nGonta, who is kind-hearted, cared for Ponta and said, \"You can choose your...
[{"input": "5\n1 4 3 2 20\n19\n1 3 4 10\n0", "output": "10\n2\n"}, {"input": "5\n1 4 3 2 20\n19\n2 3 4 10\n0", "output": "10\n1\n"}, {"input": "5\n2 0 3 4 20\n29\n1 3 4 10\n0", "output": "11\n2\n"}, {"input": "5\n2 0 3 4 20\n29\n1 6 4 10\n0", "output": "11\n1\n"}, {"input": "5\n2 0 3 4 20\n29\n1 6 4 16\n0", "output": "...
code_stdio
[ { "content": "As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they ...
[{"input": "10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\n10 1 7 8 3 2 4 6 5 9\n3 2 10 4 7 8 5 6 1 9\n5 6 3 10 8 7 2 9 4 1\n6 5 1 3 2 7 9 10 8 4\n1 10 9 3 7 8 4 2 6 5\n6 8 4 5 9 1 2 10 7 3\n9 6 8 5 10 3 1 7 2 4\n5 7 4 8 9 6 1 10 3 2\n", "output": "5 1 1 1 4 5 5 1 4 5 \n"}, {"input": "10\n5 1 6 2...
code_stdio
[ { "content": "You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).\nIn how many ways can we select some of these coins so that they are X yen in total?\nCoins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin,...
[{"input": "30\n40\n50\n6000\n", "output": "213\n"}, {"input": "30\n40\n77\n6000", "output": "293\n"}, {"input": "30\n47\n77\n6000", "output": "319\n"}, {"input": "30\n112\n134\n6415", "output": "0\n"}, {"input": "30\n112\n134\n8208", "output": "0\n"}, {"input": "30\n112\n134\n3602", "output": "0\n"}, {"input": "30\n16...
code_stdio
[ { "content": "A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.\n\nThe Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≀ X ≀ M) such that the number of digits 4 in the substring T[1,...
[{"input": "4\n47\n47\n477\n4747477", "output": "2\n2\n3\n23\n"}, {"input": "4\n44\n74\n477\n4747477", "output": "3\n2\n3\n23\n"}, {"input": "4\n47\n44\n477\n4747477", "output": "2\n3\n3\n23\n"}, {"input": "4\n44\n44\n477\n4747477", "output": "3\n3\n3\n23\n"}, {"input": "4\n74\n47\n477\n4747477", "output": "2\n2\n3\n23...
code_stdio
[ { "content": "There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$.\n\nA salesman wants to start at city $1$, visit every city exactly once, and return to city $1$.\n\nFor all $i\\ne j$, a flight from city $i$ to city $j$ costs $\\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor...
[{"input": "30\n13 1\n111 5\n50 5\n61 0\n76 98\n110 1\n17 1\n4 17\n72 28\n75 90\n16 0\n13 12\n57 0\n47 12\n34 13\n61 120\n3 1\n134 100\n89 94\n88 10\n42 3\n93 33\n6 5\n81 48\n31 17\n32 0\n11 5\n69 1\n58 1\n3 21\n", "output": "750\n"}, {"input": "30\n13 1\n59 5\n50 5\n61 0\n76 98\n110 1\n17 1\n4 17\n72 28\n75 90\n16 0\n...
code_stdio
[ { "content": "Example\n\nInput\n\n5 3\n4\n2\n5\n\n\nOutput\n\n5\n2\n4\n1\n3\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": "92 1\n1\n-2\n2", "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\n7...
code_stdio
[ { "content": "There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. \n\nYou're giv...
[{"input": "100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 73 94 78 60 20 42 84 97 83 16 81 67 64 74 46 82 5 88 80 14 48 53 79 30 11 62 21 41 70 63 58 51 56 57 17 87 72 27 85 68 49 52 8 12 98 43 37 35 69 55 32 26 40 29 65 19 24 34 33 15 45 36 7\n", "output...
code_stdio
[ { "content": "You are given a tree consisting exactly of $n$ vertices. Tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a value $a_v$ assigned to it.\n\nLet $dist(x, y)$ be the distance between the vertices $x$ and $y$. The distance between the vertices is the number of ed...
[{"input": "8\n9 4 1 7 10 1 1 10\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "output": "121\n"}, {"input": "8\n9 4 1 8 10 1 1 10\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "output": "124\n"}, {"input": "8\n9 3 1 8 10 1 1 10\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "output": "123\n"}, {"input": "8\n9 4 1 7 10 1 6 5\n1 2\n2 3\n1 4\...
code_stdio
[ { "content": "Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.\n\nTo solve the issue, Dima decided to split the strip into two non-empty parts so that each of t...
[{"input": "100\n8820100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026601\n", "output": "88201000000000000000000000000000000000000000000000000000000000000000000000000000000000000026601\n"}, {"input": "100\n8820100000000000000000000000000000000000000000000000000000000000000000...
code_stdio
[ { "content": "You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.\n\n\n-----Input-----\n\nThe first line contains a single positive integer n (2 ≀ n ≀ 10^5).\n\nThe following n lines c...
[{"input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5\n", "output": "Yes\n"}, {"input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14...
code_stdio
[ { "content": "Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another oneΒ β€” xor of all pairwise sums of elements in...
[{"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 44 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 41 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 115 86 87 88 89 90 91 92 93 94 95 133 97 98 99 100\n", "outp...
code_stdio
[ { "content": "We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≀ li ≀ ri ≀ n) meaning that value <image> should be equal to qi. \n\nYour task is to find any interesting array of n e...
[{"input": "3 2\n1 2 536870912\n2 3 536870911\n", "output": "YES\n536870912 1073741823 536870911 "}, {"input": "3 2\n1 2 193688642\n2 3 942984520\n", "output": "YES\n193688642 1002437962 942984520\n"}, {"input": "3 2\n1 2 536870912\n2 3 942984520\n", "output": "YES\n536870912 942984520 942984520\n"}, {"input": "3 2\n1 ...
code_stdio
[ { "content": "Read problems statements in Mandarin Chinese and Russian. \nA new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :)\n\nHowever, due to budget and logistic reasons, it's onl...
[{"input": "2\n8\n29", "output": "255\n536870911\n"}, {"input": "2\n8\n49", "output": "255\n949480668\n"}, {"input": "2\n21\n9", "output": "2097151\n511\n"}, {"input": "2\n4\n22", "output": "15\n4194303\n"}, {"input": "2\n0\n20", "output": "0\n1048575\n"}, {"input": "2\n8\n15", "output": "255\n32767\n"}, {"input": "2\n...
code_stdio
[ { "content": "A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $n$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again.\n\nEach round has the same scenario. It is described by a sequence of $n$ numbers: $d_1, d_2, \\do...
[{"input": "1000000000000 10\n-10 5 -2 -2 -10 -7 -5 -9 -3 -4\n", "output": "212765957448\n"}, {"input": "1000000000000 10\n-10 9 -2 -2 -10 -7 -5 -9 -3 -4\n", "output": "232558139536\n"}, {"input": "1000000000000 10\n-14 9 -2 -2 -10 -7 -5 -9 -3 -4\n", "output": "212765957448\n"}, {"input": "1000000000000 10\n-6 5 -2 -2 ...
code_stdio
[ { "content": "Ikta, who hates to lose, has recently been enthusiastic about playing games using the Go board. However, neither Go nor Gomoku can beat my friends at all, so I decided to give a special training to the lesser-known game Phutball.\n\nThis game is a difficult game, so I decided to give special train...
[{"input": "...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n....../........\n...............\n...............\n...............\n...............\n...............\n......O........\n.....
code_stdio
[ { "content": "We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings \"ab\" in the string and replace it with the string \"bba\". If we have no \"ab\" as a substring, our job is done. Print the minimum number of steps we should perform to make...
[{"input": "abaaaaaabaaaabbabbaaabbbbabababaaaaabbaabbaaaaabbbaababaaaaaaabbbbbaaaaabaababbabababbabbbbaabbaabbabbbabaabbaabbaaaaaab\n", "output": "235606597\n"}, {"input": "abaaaaaabaaaabbabbaaabbbbabababaaaaabbaabbaaaaabbbaababaaaaaaabbbbbaaaaabaababbabababbabbbbaabbaabbabbbabaabbaabbaaaaaab\n", "output": "235606597\...
code_stdio
[ { "content": "There is a $n \\times m$ grid. You are standing at cell $(1, 1)$ and your goal is to finish at cell $(n, m)$.\n\nYou can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $(x, y)$. You can:\n\nmove right to the cell $(x, y + 1)$ β€” it costs $x$ bur...
[{"input": "9\n1 1 0\n2 2 4\n2 2 3\n2 2 -2\n1 1 1\n100 100 11000\n2 3 7\n3 1 9\n2 6 11\n", "output": "YES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\n"}, {"input": "9\n1 1 0\n2 2 4\n2 2 3\n2 2 -1\n2 1 1\n100 100 10000\n2 4 7\n3 1 9\n2 6 8\n", "output": "YES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\n"}, {"input": "9\n1 1 0\n2 1 4\n2 2...
code_stdio
[ { "content": "A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d.\n\nFor each point from 1 t...
[{"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101\n", "output": "10\n"}, {"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011\n", "output": "12\n"}, {"input": "100 11\n10000000001000...
code_stdio
[ { "content": "Bees Alice and Alesya gave beekeeper Polina famous card game \"Set\" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to ...
[{"input": "24 4\nSETS\nETES\nSSST\nESTE\nTSES\nSSES\nTESS\nSEEE\nETEE\nETSS\nSSEE\nESTT\nSTSS\nTTTT\nTEEE\nTSEE\nESET\nTTTE\nETTT\nSTEE\nSTTE\nESSS\nTEET\nTETE\n", "output": "31\n"}, {"input": "24 4\nSETS\nETES\nSSST\nESTE\nTSES\nSSES\nTESS\nEESE\nETEE\nETSS\nSSEE\nESTT\nSTSS\nTTTT\nTEEE\nTSEE\nESET\nTTTE\nETTT\nSTEE\...
code_stdio
[ { "content": "There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate.\n\nYou will given M pieces of information regarding the positions of these p...
[{"input": "10 0\n12 2 100\n7 18 010\n10 12 100", "output": "Yes\n"}, {"input": "10 0\n12 2 100\n7 18 011\n10 12 100", "output": "Yes\n"}, {"input": "10 0\n12 2 100\n7 18 011\n10 22 100", "output": "Yes\n"}, {"input": "10 0\n12 2 110\n7 18 011\n10 22 100", "output": "Yes\n"}, {"input": "10 0\n12 2 000\n11 13 100\n12 8 ...
code_stdio
[ { "content": "You've got a list of program warning logs. Each record of a log stream is a string in this format: \"2012-MM-DD HH:MM:SS:MESSAGE\" (without the quotes). \n\nString \"MESSAGE\" consists of spaces, uppercase and lowercase English letters and characters \"!\", \".\", \",\", \"?\". String \"2012-MM-D...
[{"input": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "output": "2012-03-16 16:16:43\n"}, {"input": "60 3\n201...
code_stdio
[ { "content": "There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop.\n\nDepending on the location of your home, you may have to travel long distances to go shopping, which is very inconvenient...
[{"input": "10 3 1\n1 2 5\n3 3 2\n3 1 1\n2", "output": "7\n"}, {"input": "11 3 1\n1 1 1\n2 3 0\n3 1 1\n1", "output": "1\n"}, {"input": "10 3 1\n1 2 2\n2 3 2\n3 1 1\n1", "output": "3\n"}, {"input": "10 3 1\n1 2 2\n2 3 2\n2 1 1\n1", "output": "3\n"}, {"input": "10 3 1\n1 2 3\n2 3 2\n3 1 1\n1", "output": "3\n"}, {"input":...
code_stdio
[ { "content": "If the strings are consecutive, you can replace the characters with a rule to shorten the string. For example, for the string AAAA, the expression @ 4A will compress one character. Create a program that restores the character string compressed by this rule to the original character string. However...
[{"input": "ab@5C1@8050\n@99,1=1@90", "output": "abCCCCC10000000050\n999999999,1=1000000000"}, {"input": "ab@5C2@8050\n@99,1=1@90", "output": "abCCCCC20000000050\n999999999,1=1000000000"}, {"input": "ab@5C1@8050\n@99+1<1@90", "output": "abCCCCC10000000050\n999999999+1<1000000000"}, {"input": "ab@5C1@8050\n@99,1=1@9/", ...
code_stdio
[ { "content": "Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).\n\nThis priority factor will be affected by three types of actions: \n\n * 1...
[{"input": "kmircqsffq\n14\nfrnf likes xgmmp's post\nfnfdpupayp commented on syz's post\nxefshpn commented on xgmmp's post\nm posted on gdwydzktok's wall\neskm likes pqmbnuc's post\npnqiapduhz likes zzqvjdz's post\nx likes nouuurc's post\nvnyxhoukuo posted on uhblapjab's wall\nblpjpxn likes zvwbger's post\nj posted on ...
code_stdio
[ { "content": "Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h_1 and height of Abol is h_2. Each second, Mike waters Abol and Xaniar.\n\n [Image] \n\nSo, if height of Xaniar is h_1 and height of Abol is h_2, after one second height ...
[{"input": "999983\n651224 992349\n803017 393514\n258455 402487\n888310 244420\n", "output": "126531\n"}, {"input": "999983\n651224 992349\n803017 393514\n258455 402487\n888310 244420\n", "output": "126531\n"}, {"input": "1000000\n220036 846131\n698020 485511\n656298 242999\n766802 905433\n", "output": "5297\n"}, {"inp...
code_stdio
[ { "content": "You are given two non-negative integers L and R.\nWe will choose two integers i and j such that L \\leq i < j \\leq R.\nFind the minimum possible value of (i \\times j) \\mbox{ mod } 2019.\n\n-----Constraints-----\n - All values in input are integers.\n - 0 \\leq L < R \\leq 2 \\times 10^9\n\n----...
[{"input": "1999999216 1999999234\n", "output": "650\n"}, {"input": "1999999264 1999999270\n", "output": "26\n"}, {"input": "1999999266 1999999276\n", "output": "18\n"}, {"input": "1999997173 1999999190\n", "output": "0\n"}, {"input": "1999999262 1999999281\n", "output": "2\n"}, {"input": "1999999218 1999999237\n", "ou...
code_stdio
[ { "content": "Advanced Creative Mobile (ACM) has decided to develop a GUI application to be installed in a new portable computer.\n\nAs shown in the figure below, the GUI has a nested structure in which it has one main panel, several panels are arranged on it, and some panels are arranged on top of those panels...
[{"input": "5\n<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,180,140</primary></main>\n9 10\n0 17\n40 190\n2 3\n130 80\n0", "output": "OUT OF MAIN PANEL 1\nOUT OF MAIN PANEL 1\nOUT OF MAIN PANEL 1\nOUT OF MAIN PANEL 1\nprimary 0\n"}, {"input": "5\n<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,...
code_stdio
[ { "content": "A total of n depots are located on a number line. Depot i lies at the point x_i for 1 ≀ i ≀ n.\n\nYou are a salesman with n bags of goods, attempting to deliver one bag to each of the n depots. You and the n bags are initially at the origin 0. You can carry up to k bags at a time. You must collect...
[{"input": "4\n5 1\n1 2 3 4 5\n9 1\n-5 -10 -15 6 7 8 3 14 7\n5 1\n2 3 3 5 3\n4 5\n1000000000 1000000000 1000000010 1010010000\n", "output": "25\n135\n27\n1010010000\n"}, {"input": "4\n5 1\n0 2 3 4 5\n9 1\n-5 -10 -15 6 7 8 3 14 7\n5 1\n2 3 3 5 3\n4 5\n1000000000 1000000001 1000000010 1010010000\n", "output": "23\n135\n2...
code_stdio
[ { "content": "Snuke has an empty sequence a.\n\nHe will perform N operations on this sequence.\n\nIn the i-th operation, he chooses an integer j satisfying 1 \\leq j \\leq i, and insert j at position j in a (the beginning is position 1).\n\nYou are given a sequence b of length N. Determine if it is possible tha...
[{"input": "9\n1 1 1 1 2 1 2 3 2", "output": "1\n2\n2\n3\n1\n2\n1\n1\n1\n"}, {"input": "9\n1 1 1 2 1 1 2 3 2", "output": "1\n2\n2\n3\n1\n1\n2\n1\n1\n"}, {"input": "9\n1 1 1 1 2 1 4 3 2", "output": "1\n2\n1\n3\n2\n4\n1\n1\n1\n"}, {"input": "9\n1 1 1 2 2 1 4 3 2", "output": "1\n2\n1\n3\n2\n4\n2\n1\n1\n"}, {"input": "9\n1...
code_stdio
[ { "content": "Heidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another invasion on the entire Space and Time. In order to counter the invasion, she plans to deploy a trap in the Tim...
[{"input": "10 26\n9 5 277429172\n10 8 789225932\n5 2 992601916\n9 8 277294258\n8 6 245446241\n9 2 378979732\n7 1 895407000\n10 6 699661758\n1 9 865851152\n2 8 397672809\n7 10 756200111\n8 3 431547893\n5 6 465205287\n7 4 957301499\n3 4 308491540\n3 7 258504473\n10 5 282875145\n1 8 262659451\n5 4 981921705\n2 4 16048245...
code_stdio
[ { "content": "Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of we...
[{"input": "62 47 14 888621154\n202 268 300 401 422 660 782 822 1164 1300 1571 1670 1713 1807 2677 2700 2747 2873 2956 3068 3798 4159 4221 4232 4485 4507 4803 5071 5161 5161 5595 5600 5623 5846 5867 5949 6140 6560 6727 6781 6873 7159 7218 7232 7241 7333 7369 7415 7486 7506 7538 7681 7781 8074 8783 8861 9208 9313 9339 9...
code_stdio
[ { "content": "A team of three programmers is going to play a contest. The contest consists of $n$ problems, numbered from $1$ to $n$. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three parts: the first programmer took some prefix of th...
[{"input": "11 7 9\n4 8 9 12 14 16 19 21 22 23 27\n1 2 3 11 17 18 26\n5 6 7 10 13 15 20 24 25\n", "output": "15\n"}, {"input": "11 7 9\n4 8 9 12 14 16 19 21 22 23 27\n1 2 3 11 17 18 26\n5 6 7 10 13 15 20 24 25\n", "output": "15"}, {"input": "5 10 6\n14 3 6 12 21\n7 1 5 8 10 11 13 17 18 20\n9 2 4 15 16 19\n", "output": ...
code_stdio
[ { "content": "Mahmoud has n line segments, the i-th of them has length a_{i}. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of ...
[{"input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 1412788259 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 35413486...
code_stdio
[ { "content": "You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:\n - Wield one of the katana you have. When you wield Katana i (1 ≀ i ≀ N), the monster rec...
[{"input": "2 1000000000\n1 1\n1 00000000\n0 30000000\n2 164820504", "output": "1000000000\n"}, {"input": "4 1000000000\n1 1\n1 10000000\n1 30000000\n1 99999999\n", "output": "860000004\n"}, {"input": "4 1000000000\n1 1\n1 00000000\n1 30000000\n1 164820504", "output": "805179498\n"}, {"input": "4 1000000000\n1 1\n1 000...
code_stdio
[ { "content": "The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tourn...
[{"input": "02.05.90\n08.03.50\n", "output": "YES\n"}, {"input": "29.02.80\n29.02.60\n", "output": "YES\n"}, {"input": "15.12.62\n17.12.21\n", "output": "YES\n"}, {"input": "08.07.20\n27.01.01\n", "output": "YES\n"}, {"input": "28.02.20\n11.01.29\n", "output": "YES\n"}, {"input": "06.08.91\n05.12.73\n", "output": "YES\...
code_stdio
[ { "content": "Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree.\n\nAlice starts at vertex 1 and Bob starts at vertex x (x β‰  1). The moves are made ...
[{"input": "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 1\n9 7\n10 12\n11 7\n12 7\n13 8\n14 2\n15 10\n16 1\n17 2\n18 14\n19 1\n20 2\n21 16\n22 21\n23 1\n24 6\n25 2\n26 20\n27 5\n28 20\n29 2\n30 10\n31 14\n32 12\n33 15\n34 8\n", "output": "12\n"}, {"input": "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 1\n9 7\n10 8\n11 7\n12 10\n1...
code_stdio
[ { "content": "problem\n\nYou are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than t...
[{"input": "5\n8 5\n6 4\n4 3\n7 10\n0 10\n10\n10 5\n2 7\n9 7\n8 10\n10 2\n1 2\n8 1\n6 7\n6 0\n0 0\n5\n904207 809784\n845370 244806\n499091 59863\n638406 182509\n435076 362268\n10\n757559 866424\n114810 239537\n519926 989458\n461089 424480\n674361 448440\n81851 150384\n459107 795405\n299682 6700\n254125 362183\n50795 54...
code_stdio
[ { "content": "Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.\n\nOn the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator....
[{"input": "69\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\n", "output": "35\n"}, {"input": "69\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 ...
code_stdio
[ { "content": "A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the $source$ to the $sink$.\n\nC...
[{"input": "6 2\n0 1 0\n0 2 1\n1 2 1\n1 3 1\n3 3 10", "output": "0\n"}, {"input": "6 2\n0 1 0\n0 2 1\n1 2 1\n1 0 1\n3 3 10", "output": "0\n"}, {"input": "6 2\n0 1 0\n0 2 1\n1 2 1\n1 0 1\n3 3 20", "output": "0\n"}, {"input": "6 2\n0 1 0\n0 2 1\n1 2 1\n1 0 1\n3 5 20", "output": "0\n"}, {"input": "6 2\n1 1 0\n0 2 1\n1 2 1...
code_stdio
[ { "content": "Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.\n\nFrom the top view each magical box looks like a square with side length equal to 2^{k} (k is an integer, k β‰₯ 0) units. A magica...
[{"input": "15\n999999986 268435456\n999999987 67108864\n999999988 16777216\n999999989 4194304\n999999990 1048576\n999999991 262144\n999999992 65536\n999999993 16384\n999999994 4096\n999999995 1024\n999999996 256\n999999997 64\n999999998 16\n999999999 4\n1000000000 1\n", "output": "1000000001\n"}, {"input": "15\n999999...
code_stdio
[ { "content": "Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β€” he just leaves some blank space t...
[{"input": "kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAd...
code_stdio
[ { "content": "A programming contest will be held at White Tiger University this year as well. There are several questions in the contest, each of which is assigned a score according to the difficulty level.\n\nThe executive committee decided to calculate the score for each team based on the following rules, tak...
[{"input": "7\n-1 -1 19 1 0 4 -2", "output": "2\n"}, {"input": "7\n-1 -1 19 2 0 4 -2", "output": "2\n"}, {"input": "7\n-1 1 19 2 2 4 -1", "output": "2\n"}, {"input": "7\n-1 1 19 2 3 4 -1", "output": "3\n"}, {"input": "7\n-2 1 19 2 3 4 -1", "output": "3\n"}, {"input": "7\n-2 1 19 3 3 4 -1", "output": "3\n"}, {"input": "...
code_stdio
[ { "content": "Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).\n\nConstraints\n\n* 1 ≀ |V| ≀ 100\n* 0 ≀ |E| ≀ 1,000\n* 0 ≀ wi ≀ 10,000\n* G has arborescence(s) with the root r\n\nInput\n\n\n|V| |E| r\ns0 t0 w0\ns1 t1 w1\n:\ns|E...
[{"input": "6 10 0\n0 2 14\n0 0 1\n0 3 5\n1 4 7\n2 1 6\n1 3 2\n4 1 3\n4 2 2\n1 3 10\n0 5 3", "output": "32\n"}, {"input": "6 10 0\n0 2 14\n0 0 1\n0 3 5\n1 4 7\n2 1 6\n1 3 2\n4 1 3\n4 2 2\n1 3 0\n0 5 3", "output": "30\n"}, {"input": "6 10 0\n0 2 14\n0 0 1\n0 3 5\n1 4 7\n2 1 6\n1 2 2\n4 1 3\n4 2 2\n1 3 1\n0 5 3", "output...
code_stdio
[ { "content": "You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:\n\n 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≀ i ≀ n) of array s equals <image>. The opera...
[{"input": "42 42\n42 42 42 42 42 42 42 42 42 42 24 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 14 17 42 10 42 42 42 42 42 42 42 42 42 42 42 42\n", "output": "42 1806 39732 595980 6853770 64425438 515403504 607824507 548903146 777117811 441012574 397605357 289211244 684954865 738091104 190263863 460871887 121426337 37...
code_stdio
[ { "content": "Find the difference of two sets $A = \\\\{a_0, a_1, ..., a_{n-1}\\\\}$ and $B = \\\\{b_0, b_1, ..., b_{m-1}\\\\}$, $A - B$.\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 ...
[{"input": "5\n-1 2 4 13 17\n1\n-2 2", "output": "-1\n2\n4\n13\n17\n"}, {"input": "5\n-1 2 4 13 25\n1\n-2 1", "output": "-1\n2\n4\n13\n25\n"}, {"input": "5\n-2 2 3 9 14\n0\n-1 28", "output": "-2\n2\n3\n9\n14\n"}, {"input": "5\n-2 2 4 9 14\n0\n-1 28", "output": "-2\n2\n4\n9\n14\n"}, {"input": "5\n-1 2 3 5 27\n0\n0 18", ...
code_stdio
[ { "content": "Welcome! Everything is fine.\n\nYou have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.\n\nYou have a list of $k$ pairs of people who have arrived in a new inhabited neighbo...
[{"input": "2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3\n", "output": "15 33\n6 6\n"}, {"input": "2\n3\n1 2 0\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3\n", "output": "12 30\n6 6\n"}, {"input": "2\n3\n1 2 0\n3 1 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 2\n", "output": "12 30\n5 5\n"}, {...
code_stdio
[ { "content": "Alice and Bob are decorating a Christmas Tree. \n\nAlice wants only $3$ types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have $y$ yellow ornaments, $b$ blue ornaments and $r$ red ornaments.\n\nIn Bob's opinion, a Christmas Tree will be beautiful if: the number of bl...
[{"input": "100 100 100\n", "output": "297\n"}, {"input": "156 101 100\n", "output": "297\n"}, {"input": "156 111 100\n", "output": "297\n"}, {"input": "100 100 100\n", "output": "297"}, {"input": "99 100 100\n", "output": "297\n"}, {"input": "99 101 100\n", "output": "297\n"}, {"input": "65 122 115\n", "output": "198\...
code_stdio
[ { "content": "New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $h$ hours and $m$ minutes, where $0 \\le hh < 24$ and $0 \\le mm < 60$. We use 24-hour time format!\n\nYour task is to find the number of minutes before the New Year....
[{"input": "5\n3 55\n22 30\n21 10\n20 21\n19 59\n", "output": "1205\n90\n170\n219\n241\n"}, {"input": "5\n4 55\n22 30\n21 10\n20 21\n19 59\n", "output": "1145\n90\n170\n219\n241\n"}, {"input": "5\n15 14\n22 45\n21 2\n0 21\n19 59\n", "output": "526\n75\n178\n1419\n241\n"}, {"input": "5\n14 14\n22 45\n21 2\n0 21\n19 59\n...
code_stdio
[ { "content": "You are given a rooted tree. Each vertex contains a_i tons of gold, which costs c_i per one ton. Initially, the tree consists only a root numbered 0 with a_0 tons of gold and price c_0 per ton.\n\nThere are q queries. Each query has one of two types: \n\n 1. Add vertex i (where i is an index of q...
[{"input": "5 5 2\n2 0 2\n1 0 3 4\n2 2 4\n1 0 1 3\n2 4 2\n", "output": "\n2 4\n4 10\n1 3\n"}, {"input": "5 5 2\n2 0 2\n1 0 1 4\n2 2 4\n1 0 1 3\n2 4 2\n", "output": "2 4\n4 10\n1 3\n"}, {"input": "5 10 2\n2 0 2\n1 0 3 4\n2 2 4\n1 0 1 3\n2 4 2\n", "output": "2 4\n4 8\n2 4\n"}, {"input": "5 3 2\n2 0 2\n1 0 3 4\n2 2 4\n1 0...
code_stdio
[ { "content": "Bajtek, known for his unusual gifts, recently got an integer array $x_0, x_1, \\ldots, x_{k-1}$.\n\nUnfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website ano...
[{"input": "100\n57 81 176 211 251 311 346 404 469 506 563 587 682 717 757 817 852 910 975 1012 1069 1093 1188 1223 1263 1323 1358 1416 1481 1518 1575 1599 1694 1729 1769 1829 1864 1922 1987 2024 2081 2105 2200 2235 2275 2335 2370 2428 2493 2530 2587 2611 2706 2741 2781 2841 2876 2934 2999 3036 3093 3117 3212 3247 3287...
code_stdio
[ { "content": "You are given an integer array $a$ of length $n$.\n\nDoes there exist an array $b$ consisting of $n+1$ positive integers such that $a_i=\\gcd (b_i,b_{i+1})$ for all $i$ ($1 \\leq i \\leq n$)?\n\nNote that $\\gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$.\n\n\n-----In...
[{"input": "3\n7\n48 27 99 27 93 72 2\n5\n86 73 29 1 37\n9\n45 59 22 6 75 4 14 57 23\n", "output": "NO\nYES\nNO\n"}, {"input": "4\n1\n343\n2\n4 2\n3\n4 2 4\n4\n1 1 1 1\n", "output": "YES\nYES\nNO\nYES\n"}, {"input": "1\n8\n157 5487 4421 1774 4662 5343 1366 5393\n", "output": "NO\n"}, {"input": "1\n3\n101 1 101\n", "out...
code_stdio
[ { "content": "You are given two integers $n$ and $k$.\n\nYour task is to construct such a string $s$ of length $n$ that for each $i$ from $1$ to $k$ there is at least one $i$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters exce...
[{"input": "66\n1 1\n1 1\n2 1\n1 1\n1 1\n1 1\n1 1\n2 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\...
code_stdio
[ { "content": "This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.\n\nAlice received a set of Toy Trainβ„’ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train...
[{"input": "100 50\n29 35\n10 75\n29 34\n10 87\n29 13\n29 38\n41 21\n10 6\n29 94\n10 47\n31 27\n41 24\n41 8\n10 93\n41 52\n41 36\n31 32\n85 81\n31 32\n41 79\n41 99\n85 88\n41 25\n31 68\n41 93\n10 87\n85 97\n41 85\n10 64\n10 68\n85 22\n10 45\n85 15\n10 16\n10 21\n41 66\n29 68\n41 96\n29 34\n10 22\n41 72\n85 54\n29 48\n1...
code_stdio
[ { "content": "You have a string of decimal digits s. Let's define bij = siΒ·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.\n\nA rectangle in a matrix is a group of four integers (x, y, z, t) (x ≀ y, z ≀ t...
[{"input": "700\n100101011011001100111101100101000100000000011001111000111110001011011100010110000000000100100000001100000011110011101110011101101110111011011100001001101011000100000000000110001000101001100011111110011010101011010100010100001011011111001011000101001101000111010100110000100100110011111100010111100010000...
code_stdio
[ { "content": "Let us denote by f(x, m) the remainder of the Euclidean division of x by m.\nLet A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M).\nFind \\displaystyle{\\sum_{i=1}^N A_i}.\n\n-----Constraints-----\n - 1 \\leq N \\leq 10^{10}\n - 0 \\leq...
[{"input": "10000000000 99201 99975\n", "output": "992010000000000\n"}, {"input": "9999999995 82382 99996\n", "output": "309280000028478\n"}, {"input": "9999999997 38566 99996\n", "output": "309280000067758\n"}, {"input": "9999999999 91639 99996\n", "output": "463120000035189\n"}, {"input": "8376384666 27793 31932\n", ...
code_stdio
[ { "content": "A string $s$ of length $n$ can be encrypted by the following algorithm: iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), for each divisor $d$, reverse the substring $s[1 \\dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). \n\nFor exa...
[{"input": "100\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf\n", "output": "fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi\n"}, {"input": "100\nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...
code_stdio
[ { "content": "Chef Palin, as his name suggests, is always very interested in palindromic strings. Recently, he made a pretty interesting discovery on palindromes and that made him feel really Lucky. He came across something known as Lucky Palindromes. He defines a string as being a lucky palindrome if it is a p...
[{"input": "3\nlatbcdkfy\nfeicedocljbux\naaaaaaba", "output": "luckykcul 8\nfluckyoykculf 10\nunlucky\n"}, {"input": "3\nytkdadfbl\ntobjlcedechwf\naabaaaba", "output": "luckykcul 8\nfluckyeykculf 10\nunlucky\n"}, {"input": "3\nytkdadfbl\ntobjlcfdechwf\naabaaaba", "output": "luckykcul 8\nfluckyfykculf 10\nunlucky\n"}, {...
code_stdio
[ { "content": "William has an array of $n$ integers $a_1, a_2, \\dots, a_n$. In one move he can swap two neighboring items. Two items $a_i$ and $a_j$ are considered neighboring if the condition $|i - j| = 1$ is satisfied.\n\nWilliam wants you to calculate the minimal number of swaps he would need to perform to m...
[{"input": "5\n3\n2 4 6\n5\n4 4 4 4 4\n5\n1 3 5 10 12\n5\n1 1 1 1 1\n5\n4 8 10 6 2\n", "output": "-1\n-1\n3\n-1\n-1\n"}, {"input": "5\n3\n2 4 12\n5\n4 4 4 4 4\n5\n1 2 5 14 9\n5\n2 2 0 1 2\n5\n4 0 10 6 2\n", "output": "-1\n-1\n0\n-1\n-1\n"}, {"input": "5\n3\n2 4 6\n5\n4 4 4 4 4\n5\n1 3 5 7 12\n5\n1 1 1 1 1\n5\n4 8 10 6 ...
code_stdio
[ { "content": "Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately...
[{"input": "1000000000000000000\n", "output": "85\n"}, {"input": "1000000000000000000\n", "output": "85\n"}, {"input": "123456789123456789\n", "output": "81\n"}, {"input": "679891637638612257\n", "output": "84\n"}, {"input": "679891637638612258\n", "output": "85\n"}, {"input": "679891637638612259\n", "output": "85\n"},...
code_stdio
[ { "content": "There are N students in a school.\nWe will divide these students into some groups, and in each group they will discuss some themes.\nYou think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students...
[{"input": "1000\n", "output": "333\n"}, {"input": "303\n", "output": "101\n"}, {"input": "807\n", "output": "269\n"}, {"input": "596\n", "output": "198\n"}, {"input": "604\n", "output": "201\n"}, {"input": "296\n", "output": "98\n"}, {"input": "100\n", "output": "33\n"}, {"input": "8\n", "output": "2\n"}, {"input": "2...
code_stdio
[ { "content": "Does the card fit in a snack? (Are Cards Snacks?)\n\nsquare1001 You have $ N $ cards.\n\nEach of these cards has an integer written on it, and the integer on the $ i $ th card is $ A_i $.\n\nsquare1001 Your random number today is $ K $. square1001 You want to choose some of these $ N $ cards so th...
[{"input": "0 9\n22 11 57 2 -1", "output": "0\n"}, {"input": "0 9\n10 11 57 2 -1", "output": "0\n"}, {"input": "10 9\n18 6 37 2 0", "output": "0\n"}, {"input": "0 10\n22 6 57 2 0", "output": "0\n"}, {"input": "0 10\n26 6 57 2 0", "output": "0\n"}, {"input": "0 10\n26 6 57 2 1", "output": "0\n"}, {"input": "7 9\n18 6 23...
code_stdio
[ { "content": "Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.\n\nIn Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.\n\nDu will chat in the group for n days. On the i-th day:\n\n * If Du can speak...
[{"input": "100 61 71\n11 18 0 47 33 75 91 13 8 21 73 64 50 97 62 50 2 36 68 32 64 74 32 77 81 41 23 44 40 36 45 33 21 68 57 79 75 23 67 37 99 27 30 56 75 62 75 63 46 19 79 42 11 66 21 25 2 12 89 48 75 7 57 85 80 14 82 29 66 47 29 10 1 84 79 39 33 81 73 51 80 67 52 25 38 68 57 53 38 83 83 3 86 29 50 46 3 68 88 10\n", "...
code_stdio
[ { "content": "The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).\n\nYou are given a sequence $a$ consisting of $n$ integers.\n\nYou are making a sequence of moves. During each move you must take either the leftmost ...
[{"input": "93\n6 6 10 10 8 4 7 10 2 3 4 10 7 2 8 8 4 2 4 4 7 7 3 2 3 1 5 3 7 2 4 9 10 8 10 5 1 6 2 1 10 3 5 6 6 9 3 10 1 10 1 6 2 3 8 7 1 5 4 10 4 3 5 8 8 1 3 8 2 3 10 7 2 4 5 2 6 4 10 4 4 8 5 1 6 3 1 9 5 4 9 4 3\n", "output": "4\nRRLR\n"}, {"input": "93\n6 6 10 10 9 4 7 10 2 3 4 10 7 2 8 8 4 2 4 4 7 7 3 2 3 1 5 3 7 2...
code_stdio
[ { "content": "Read problems statements in Russian here \nPolo, the Penguin, has a lot of tests tomorrow at the university.\nHe knows that there are N different questions that will be on the tests. For each question i (i = 1..N), he knows C[i] - the number of tests that will contain this question, P[i] - the num...
[{"input": "1\n3 20\n1 -2 0\n6 4 8\n4 -1 3", "output": "24\n"}, {"input": "1\n3 12\n1 0 1\n1 3 14\n13 4 3", "output": "52\n"}, {"input": "1\n3 7\n0 -1 1\n4 0 5\n12 5 3", "output": "60\n"}, {"input": "1\n3 7\n1 1 0\n2 3 20\n3 11 3", "output": "34\n"}, {"input": "1\n3 7\n1 2 3\n1 3 5\n9 12 3", "output": "110\n"}, {"input...
code_stdio
[ { "content": "There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has $n$ different matryoshkas. Any matryoshka is a figure of volume $out_i$ with an empty space inside of volume $in_i$ (of course, $out_i > in_i$).\...
[{"input": "20\n51 47\n46 42\n25 22\n41 31\n11 2\n27 24\n18 13\n49 45\n16 11\n19 14\n10 1\n30 27\n10 1\n41 31\n16 11\n10 1\n41 31\n41 31\n31 28\n49 45\n", "output": "256\n"}, {"input": "20\n51 47\n46 42\n25 22\n41 31\n11 2\n27 24\n18 13\n49 45\n16 11\n19 14\n10 1\n30 27\n10 1\n41 31\n16 11\n10 1\n41 31\n41 31\n31 28\n4...
code_stdio
[ { "content": "There are N computers and N sockets in a one-dimensional world. The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It is guaranteed that these 2N coordinates are pairwise distinct.\n\nSnuke wants to connect each computer to a socket using a cable. Each socket...
[{"input": "3\n3\n4\n18\n11\n0\n10", "output": "1\n"}, {"input": "3\n3\n4\n18\n20\n0\n10", "output": "1\n"}, {"input": "3\n3\n10\n8\n7\n0\n10", "output": "1\n"}, {"input": "3\n3\n10\n9\n7\n0\n10", "output": "1\n"}, {"input": "3\n3\n11\n8\n7\n0\n10", "output": "1\n"}, {"input": "3\n5\n10\n9\n7\n0\n10", "output": "1\n"},...
code_stdio
[ { "content": "For a positive integer n\n\n* If n is even, divide by 2.\n* If n is odd, multiply by 3 and add 1.\n\n\n\nIf you repeat the above operation, the result will be 1. A problem called \"Colatz conjecture\" is that repeating this operation for any positive integer n will always result in 1. This problem...
[{"input": "3\n1043\n0", "output": "7\n124\n"}, {"input": "3\n3340\n0", "output": "7\n136\n"}, {"input": "3\n109\n0", "output": "7\n113\n"}, {"input": "3\n440\n0", "output": "7\n115\n"}, {"input": "3\n125\n0", "output": "7\n108\n"}, {"input": "3\n221\n0", "output": "7\n114\n"}, {"input": "3\n259\n0", "output": "7\n122\...
code_stdio
[ { "content": "Let's define $p_i(n)$ as the following permutation: $[i, 1, 2, \\dots, i - 1, i + 1, \\dots, n]$. This means that the $i$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $i$ is on the first position. Examples: $p_1(4) = [1, 2, 3, 4]$; $p_2(...
[{"input": "30 5\n4 2 8 3 4\n", "output": "14 16 16 14 12 12 12 8 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14\n"}, {"input": "30 5\n4 4 8 3 4\n", "output": "10 10 14 14 8 8 8 8 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\n"}, {"input": "25 5\n4 2 8 3 4\n", "output": "14 16 16...
code_stdio
[ { "content": "Aizuwakamatsu City is known as the \"City of History\". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the half-brother of Tokugawa's third shogun Iem...
[{"input": "4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,500\n0", "output": "23\n"}, {"input": "4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,400\n0", "output": "22\n"}, {"input": "4\n4\n0,1,0500\n0,2,2000\n0,2,600\n2,3,400\n0", "output": "12\n"}, {"input": "4\n4\n0,1,0400\n0002,2,0\n0,2,600\n2,3,400\n0", "output": "11\n"}, {"input...
code_stdio
[ { "content": "Takahashi is practicing shiritori alone again today.\nShiritori is a game as follows:\n - In the first turn, a player announces any one word.\n - In the subsequent turns, a player announces a word that satisfies the following conditions:\n - That word is not announced before.\n - The first charact...
[{"input": "100\nlkykrymhey\nyujwmjhnzx\nxgmkqgsajk\nkkvqjyapln\nnkcubvbxdx\nxheccrzfne\neqeizvicxx\nxesnssfeuz\nzsjdhxndds\nsuvxanfkpe\neodirlsywl\nlmiwshvenl\nluomflsyiq\nqcjuajhxme\nelfadfvxvm\nmknedshbyv\nvnboqueaai\niwexnqgqvj\njzfofokvkg\nggzhwrtktd\nderapdnumy\nyfobbqcozo\noivhkngvyy\nytjgsdfnos\nslrxpzfenf\nfhw...
code_stdio
[ { "content": "The Little Elephant very much loves sums on intervals.\n\nThis time he has a pair of integers l and r (l ≀ r). The Little Elephant has to find the number of such integers x (l ≀ x ≀ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 4...
[{"input": "100000000000000000 1000000000000000000\n", "output": "90000000000000000\n"}, {"input": "645762257531682046 885295120956158518\n", "output": "23953286342447648\n"}, {"input": "819875140559301752 946247219812473271\n", "output": "12637207925317152\n"}, {"input": "522842183413115088 853628713003942530\n", "out...
code_stdio
[ { "content": "Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can't control them during the operation. Help hi...
[{"input": "3\n5 2\n10 4\n10 5", "output": "10\n210\n252\n"}, {"input": "3\n5 2\n19 6\n9 3", "output": "10\n27132\n84\n"}, {"input": "3\n5 2\n19 9\n9 3", "output": "10\n92378\n84\n"}, {"input": "3\n9 1\n2 5\n20 12", "output": "9\n0\n125970\n"}, {"input": "3\n8 1\n2 9\n20 12", "output": "8\n0\n125970\n"}, {"input": "3\n...
code_stdio
[ { "content": "For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique.\n\n* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.\n* find($x$): Report the number of $x$ in $S$ (0 or 1).\n* delete($x$): Delete $x...
[{"input": "8\n0 1\n0 10\n0 4\n0 2\n1 0\n0 7\n0 3\n0 2", "output": "1\n2\n3\n4\n0\n5\n6\n6\n"}, {"input": "8\n0 1\n0 7\n0 4\n0 2\n1 0\n0 7\n0 3\n0 2", "output": "1\n2\n3\n4\n0\n4\n5\n5\n"}, {"input": "8\n0 0\n0 0\n0 4\n1 2\n1 1\n1 2\n1 0\n1 2", "output": "1\n1\n2\n0\n0\n0\n1\n0\n"}, {"input": "8\n0 2\n0 3\n0 2\n2 4\n1 ...
code_stdio
[ { "content": "George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. \n\nHelp George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the curr...
[{"input": "05:50\n05:44\n", "output": "00:06\n"}, {"input": "00:00\n01:00\n", "output": "23:00\n"}, {"input": "00:01\n00:00\n", "output": "00:01\n"}, {"input": "23:59\n23:59\n", "output": "00:00\n"}, {"input": "23:44\n23:55\n", "output": "23:49\n"}, {"input": "00:00\n13:12\n", "output": "10:48\n"}, {"input": "12:00\n2...
code_stdio
[ { "content": "You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}.\n\nYou can apply the following operation to this permutation, any number of times (possibly zero):\n\n* Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, swap the values of P_i and P_j.\n\n\n\nA...
[{"input": "8 2\n4 5 7 8 3 1 2 6", "output": "1\n2\n3\n6\n5\n4\n7\n8\n"}, {"input": "8 6\n4 5 7 8 3 1 2 6", "output": "4\n5\n7\n8\n3\n1\n2\n6\n"}, {"input": "8 5\n4 5 7 8 3 1 2 6", "output": "4\n5\n6\n8\n3\n1\n2\n7\n"}, {"input": "8 1\n4 5 7 8 3 1 2 6", "output": "1\n2\n3\n4\n5\n6\n7\n8\n"}, {"input": "8 4\n4 5 7 8 3 1...
code_stdio
[ { "content": "Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked $n$ of them how much effort they needed to reach red.\n\n\"Oh, I just spent $x_i$ hours solving problems\", said the $i$-th of them. \n\n...
[{"input": "15\n5318008\n379009\n06\n79153975193751375917591379919397337913333535330\n791539751937513759175913799193973379133301353533\n123456789023487138475693874561834576138495713485673485364857638475673465873457346581495713641\n7915397519375137511917591379919397337913333535330\n3155355553535353532535535833353535\n13...
code_stdio
[ { "content": "Galya is playing one-dimensional Sea Battle on a 1 Γ— n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.\n\nGalya doesn't know the ships location. She can shoot to some ce...
[{"input": "100 2 1 11\n0100000100000000000000001000000000010001100000000000101000000000000000000000001000001000010000000000\n", "output": "88\n1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 31 32 33 34 35 37 38 39 42 43 44 45 46 47 48 49 50 51 52 54 56 57 58 59 60 61 62 63 64 65 66 67 68 69 ...
code_stdio
[ { "content": "Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the bala...
[{"input": "1000000000000000000\n", "output": "3760\n"}, {"input": "822981260158260822\n", "output": "3740\n"}, {"input": "779547116602436626\n", "output": "3735\n"}, {"input": "578223540024980345\n", "output": "3705\n"}, {"input": "335408917861649372\n", "output": "3650\n"}, {"input": "974755271730884810\n", "output":...
code_stdio
[ { "content": "It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be w_{i}, then 0 < w_1 ≀ w_2 ≀ ... ≀ w_{k} holds.\n\nPolar bears Alice and Bob each have ...
[{"input": "100 50 10\n7 8 7 1 6 7 9 2 4 6 7 7 3 9 4 5 1 7 8 10 4 1 3 6 8 10 4 6 6 1 6 12 7 4 10 3 10 1 3 2 10 6 9 9 5 2 9 2 9 8 10 2 10 3 3 2 3 8 6 2 7 10 7 2 7 2 8 9 6 2 5 4 4 5 3 3 9 10 9 4 9 3 9 5 3 6 6 1 3 6 10 3 10 2 6 10 10 10 4 8\n3 3 2 9 4 4 10 2 7 3 3 2 6 3 3 4 7 4 1 2 3 8 1 6 7 7 2 10 1 1 1 5 7 7 5 1 6 8 7 5...
code_stdio
[ { "content": "Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).\nConsider a sequence A satisfying the following conditions:\n - A is a sequence of N positive integers.\n - 1 \\leq A_1 \\leq A_2 \\le \\cdots \\leq A_N \\leq M.\nLet us define a score of this sequence as ...
[{"input": "10 10 50\n9 10 0 100000\n4 8 5 100000\n1 3 1 100000\n2 6 3 100000\n9 10 1 84\n2 9 4 72167\n5 9 6 100000\n6 8 2 100000\n1 5 2 100000\n3 6 3 100000\n1 9 8 100000\n2 4 0 100000\n3 5 1 100000\n4 8 7 7354\n3 4 0 100000\n5 10 6 100000\n1 6 4 100000\n7 10 3 100000\n8 10 2 100000\n4 6 3 100000\n1 4 1 100000\n6 9 4 ...
code_stdio
[ { "content": "There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is \"R\", \"G\", or \"B\", the color of the corresponding stone is red, green, or blue...
[{"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n", "output": "15\n"}, {"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR\n", "output": "16\n"}, {"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGR...
code_stdio
[ { "content": "Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands \"ping a\" and \"ping b\". Each ping command sends exactly ten packets to the server specified in the argument of the comma...
[{"input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3\n", "output": "DEAD\nDEAD\n"}, {"input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3\n", "output": "DEAD\nDEAD\n"}, {"input": "14\n1 5 3\n1 0 10\...
code_stdio
[ { "content": "DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number x_{i}, DZY will put it into the bucket numbered h(x_{i}), where h(x) is the hash function. In this problem we will assume, that h(x) = ...
[{"input": "101 15\n139988797\n524419455\n1205904463\n153341038\n146759898\n171753194\n163710849\n42060733\n1382862835\n979451110\n1200809750\n37821717\n446728232\n850870259\n221398500\n", "output": "12\n"}, {"input": "101 15\n139988797\n524419455\n1205904463\n153341038\n146759898\n198834293\n163710849\n42060733\n13828...
code_stdio
[ { "content": "Problem\n\nA graph is given in which N vertices, each numbered from 1 to N, are connected by N-1 undirected edges. For each vertex, output the shortest number of steps to start from that vertex and visit all vertices.\n\nHowever, one step is to follow one side from one vertex and move to another v...
[{"input": "6\n1 2\n2 3\n3 4\n3 5\n5 6", "output": "6\n7\n8\n7\n7\n6\n"}, {"input": "6\n1 2\n2 3\n6 4\n3 5\n5 6", "output": "5\n6\n7\n5\n7\n6\n"}, {"input": "6\n1 2\n2 3\n6 4\n3 4\n5 6", "output": "5\n6\n7\n7\n5\n6\n"}, {"input": "6\n1 2\n2 3\n3 4\n3 5\n1 6", "output": "7\n8\n7\n6\n6\n6\n"}, {"input": "6\n1 2\n1 3\n3 4...
code_stdio
[ { "content": "A number is called 2050-number if it is $2050$, $20500$, ..., ($2050 \\cdot 10^k$ for integer $k \\ge 0$).\n\nGiven a number $n$, you are asked to represent $n$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.\n\n\n-----Input...
[{"input": "9\n204926935685243951\n999999999999999000\n1000000000000000000\n204999999999997950\n983999999999997950\n205\n1266\n50\n20\n", "output": "-1\n81\n-1\n126\n128\n-1\n-1\n-1\n-1\n"}, {"input": "9\n375241037050488412\n999999999999999000\n1000000000000000000\n204999999999997950\n1691361554995086523\n205\n2255\n50...
code_stdio
[ { "content": "You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≀ n) holds ci ≀ ci - 1. \n\nLet's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer f...
[{"input": "4\n40 40 24 5\n56 14 59 76 92 34 43 96 33 44 72 37 81 27 42 5 7 95 22 4 60 18 61 103 74 84 93 55 3 62 70 82 77 51 86 102 29 67 91 9\n71 53 21 64 17 45 46 101 97 30 109 100 57 16 80 87 28 12 94 23 39 98 32 52 54 10 19 41 90 11 66 65 99 89 40 36 58 20 78 108\n35 88 73 75 104 63 79 31 1 26 2 50 24 83 15 49 106...
code_stdio
[ { "content": "Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1, p_2, ..., p_{n}.\n\nWe'll call ...
[{"input": "1000 500\n", "output": "979041279\n"}, {"input": "1000 700\n", "output": "642759746\n"}, {"input": "1000 900\n", "output": "301804159\n"}, {"input": "1000 998\n", "output": "583666213\n"}, {"input": "1000 900\n", "output": "301804159\n"}, {"input": "1000 998\n", "output": "583666213\n"}, {"input": "1000 700...
code_stdio