info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"3 2\\n0 2 1\\n\", \"5 1\\n0 1 2 3 4\\n\", \"6 200000\\n0 1 2 3 4 5\\n\", \"7 6\\n3 2 4 1 0 5 6\\n\", \"1 1\\n0\\n\", \"1 200000\\n0\\n\", \"73 95\\n4 53 37 9 45 54 16 34 12 10 13 24 2 36 33 48 50 43 15 11 47 42 46 30 27 52 67 72 66 19 56 61 69 21 68 1 70 49 64 62 3 51 44 65 29 25 38 28 8 5 39...
Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length $n$ and having an alphabet size $k$, count the number of strings that produce such a suffix array. Let $s$ be a string of length $n$. Then the $i$-th suffix of $s$ is...
0
{"tests": "{\"inputs\": [\"3\\n0 0 1\\n2 0 1\\n4 0 1\\n\", \"3\\n0 0 2\\n3 0 2\\n6 0 2\\n\", \"3\\n0 0 2\\n2 0 2\\n1 1 2\\n\", \"1\\n0 0 10\\n\", \"2\\n-10 10 1\\n10 -10 1\\n\", \"2\\n-6 6 9\\n3 -6 6\\n\", \"2\\n-10 -10 10\\n10 10 10\\n\", \"3\\n-4 1 5\\n-7 7 10\\n-3 -4 8\\n\", \"3\\n-2 8 10\\n3 -2 5\\n3 1 3\\n\", \"3\...
Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circl...
0
{"tests": "{\"inputs\": [\"6\\n3 6 9 18 36 108\\n\", \"2\\n7 17\\n\", \"9\\n4 8 10 12 15 18 33 44 81\\n\", \"22\\n2 4 8 16 32 96 288 576 1728 3456 10368 20736 62208 186624 559872 1119744 3359232 10077696 30233088 90699264 181398528 544195584\\n\", \"14\\n122501 245002 367503 735006 1225010 4287535 8575070 21437675 4287...
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s...
0
{"tests": "{\"inputs\": [\"10\\n10\\n10\\n14\\n10\\n10\\n10\\n10\\n10\\n10\\n10\", \"2\\n3\\n5\", \"5\\n1\\n2\\n5\\n4\\n5\", \"10\\n6\\n10\\n14\\n10\\n10\\n10\\n10\\n10\\n10\\n10\", \"2\\n3\\n6\", \"5\\n2\\n2\\n5\\n4\\n5\", \"10\\n6\\n10\\n14\\n10\\n10\\n10\\n10\\n10\\n10\\n20\", \"2\\n3\\n4\", \"5\\n2\\n3\\n5\\n4\\n5\...
Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B. The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on the 2D grid. Each of the soldiers you lead has h_i health. Each so...
0
{"tests": "{\"inputs\": [\"4\\n8 2\\n()(())()\\n10 3\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n\", \"4\\n8 2\\n()(())()\\n10 1\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n\", \"4\\n8 2\\n()(())()\\n10 1\\n))()()()((\\n2 1\\n()\\n2 1\\n()\\n\", \"4\\n8 1\\n()(())()\\n10 1\\n))()()()((\\n2 1\\n()\\n2 1\\n()\\n\", \"4\\n8 2\\n()(())(...
You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s_{1}s_{2}... s_{n} of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choose any consecutive substring of s and reverse it. In other words,...
0.25
{"tests": "{\"inputs\": [\"3 20\\n5\\n11\\n3\", \"3 20\\n5\\n11\\n6\", \"3 20\\n1\\n11\\n6\", \"3 20\\n1\\n3\\n6\", \"3 20\\n1\\n3\\n3\", \"3 25\\n1\\n3\\n3\", \"3 35\\n1\\n3\\n3\", \"3 35\\n1\\n3\\n4\", \"3 55\\n1\\n3\\n4\", \"3 55\\n1\\n3\\n0\", \"3 55\\n1\\n4\\n0\", \"3 55\\n2\\n4\\n0\", \"3 20\\n7\\n7\\n3\", \"3 20...
Problem C Medical Checkup Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on. Students are now forming a long queue, waiting for the checkup to start. Students are also numbered 1, 2, 3, and so on, from the top of the queue. They have to under...
0
{"tests": "{\"inputs\": [\"1 2\\nSP.-SS.S-S.S\\n\", \"4 9\\nPP.-PPPS-S.S\\nPSP-PPSP-.S.\\n.S.-S..P-SS.\\nP.S-P.PP-PSP\\n\", \"3 7\\n.S.-SSSP-..S\\nS..-.SPP-S.P\\n.S.-PPPP-PSP\\n\", \"5 6\\nPP.-PS.P-P..\\nPPS-SP..-P.P\\nP.P-....-S..\\nSPP-.P.S-.S.\\nSP.-S.PS-PPP\\n\", \"1 1\\n..S-PS..-.PP\\n\", \"2 2\\nPP.-S.SS-.S.\\nSS...
В самолёте есть n рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа. Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ко...
0
{"tests": "{\"inputs\": [\"2 1\\n1 1\\n100 100\\n5\\n\", \"3 2\\n1000000000000000 1000000000000000\\n3000000000000000 4000000000000000\\n6000000000000000 7000000000000000\\n2000000000000000 4000000000000000\\n\", \"6 9\\n1 2\\n8 16\\n21 27\\n31 46\\n49 57\\n59 78\\n26 27 28 13 2 4 2 2 24\\n\", \"20 10\\n4 9\\n10 15\\n1...
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: ...
0.625
{"tests": "{\"inputs\": [\"2 2 2\\n\", \"2 3 3\\n\", \"1 1 1\\n\", \"3 5 10\\n\", \"2 3 1000000000000000000\\n\", \"7 8 9\\n\", \"8 10 11\\n\", \"5 30 930\\n\", \"3 3 3\\n\", \"1 5 5\\n\", \"1 2 2\\n\", \"1 2 5\\n\", \"1 2 4\\n\", \"1000000000000000000 1000000000000000000 1000000000000000000\\n\", \"1 125 15625\\n\", \...
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a_0 + a_1x^1 + ... + a_{n}x^{n}. Numbers a_{i} are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial. Vasya has made a bet with his fr...
0
{"tests": "{\"inputs\": [[\"ka\"], [\"a\"], [\"aa\"], [\"z\"], [\"Abbaa\"], [\"maintenance\"], [\"Woodie\"], [\"Incomprehensibilities\"]], \"outputs\": [[\"kaka\"], [\"kaa\"], [\"kaaa\"], [\"kaz\"], [\"kaAkabbaa\"], [\"kamaikantekanakance\"], [\"kaWookadie\"], [\"kaIkancokamprekahekansikabikalikatiekas\"]]}", "source":...
# Introduction Ka ka ka cypher is a cypher used by small children in some country. When a girl wants to pass something to the other girls and there are some boys nearby, she can use Ka cypher. So only the other girls are able to understand her. She speaks using KA, ie.: `ka thi ka s ka bo ka y ka i ka s ka u ka gly...
0
{"tests": "{\"inputs\": [\"5\\n72\\n72\\n30\\n75\\n11\\n\", \"5\\n79\\n149\\n136\\n194\\n124\\n\", \"6\\n885\\n419\\n821\\n635\\n63\\n480\\n\", \"1\\n1000000000\\n\", \"5\\n3\\n6\\n9\\n10\\n5\\n\", \"5\\n5\\n8\\n18\\n17\\n17\\n\", \"1\\n649580447\\n\", \"5\\n7\\n40\\n37\\n25\\n4\\n\", \"5\\n80\\n72\\n30\\n75\\n11\\n\",...
Let's assume that * v(n) is the largest prime number, that does not exceed n; * u(n) is the smallest prime number strictly greater than n. Find <image>. Input The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Each of the following t lines of the input contains integer n (2 ≤ n ≤ ...
0
{"tests": "{\"inputs\": [\"2 1 0\", \"2 0 0\", \"1 0 1\", \"2 2 0\", \"1 2 3\", \"1 3 2\", \"2 3 2\", \"2 0 2\", \"2 2 3\", \"2 3 1\", \"2 0 1\", \"1 1 0\", \"1 -2 -1\", \"1 -1 -2\", \"4 0 0\", \"7 0 0\", \"6 2 1\", \"1 0 0\", \"5 0 0\", \"5 2 1\", \"2 2 1\", \"1 1 1\", \"2 2 2\", \"0 1 1\", \"4 2 2\", \"-1 1 1\", \"10...
You are given integers N,\ A and B. Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists. * P_0=A * P_{2^N-1}=B * For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} ...
0
{"tests": "{\"inputs\": [\"3\\naab\\nccb\\n\", \"1\\nZ\\nZ\\n\", \"52\\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn\\n\", \"1\\nX\\nX\\n\", \"20\\nqqhhYOayyfmrooRKKWWZ\\nSSeeYOaNNfmrggRCCMMZ\\n\", \"30\\nqrwwcooUGDDIflZVVbbFaittmRKPPv\\nqrOOcQQUGHHIflZNNBB...
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors....
0
{"tests": "{\"inputs\": [\"1000 1000 1 1 10\\n1\\n2\\n1\\n1 900 1 1000\\n\", \"2 4 1 1 1\\n1\\n4\\n1\\n1 2 1 3\\n\", \"10 10 1 8 4\\n10\\n2 3 4 5 6 7 8 9\\n10\\n1 1 3 1\\n2 1 7 1\\n1 1 9 1\\n7 1 4 1\\n10 1 7 1\\n2 1 7 1\\n3 1 2 1\\n5 1 2 1\\n10 1 5 1\\n6 1 9 1\\n\", \"2 10 1 1 1\\n1\\n10\\n1\\n1 5 1 8\\n\", \"4 4 1 0 1...
In the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of them. The sections are enumerated from 1 to m along the corridor, and all sections with equal numbers on different floors are l...
0
{"tests": "{\"inputs\": [\"3\\ntameru\\ntameru\\nuremat\\ntameru\\nkougekida\\ntameru\", \"3\\ntameru\\ntameru\\nuremat\\ntameru\\nadikeguok\\ntameru\", \"3\\ntameru\\ntameru\\nuremat\\ntameru\\nadikeguok\\ntamdru\", \"3\\ntameru\\nuremat\\nuremat\\ntameru\\nadikeguok\\ntamdru\", \"3\\ntaremu\\nuremat\\nuremat\\ntameru...
A: Isono, let's do that! --Sendame - story Nakajima "Isono ~, let's do that!" Isono "What is that, Nakajima" Nakajima "Look, that's that. It's hard to explain because I have to express it in letters for some reason." Isono "No, it seems that you can put in figures and photos, right?" <image> Nakajima "It's true!...
0.125
{"tests": "{\"inputs\": [\"25 35\\n\", \"575 85\\n\", \"280 210\\n\", \"408 765\\n\", \"25 5\\n\", \"45 872\\n\", \"10 15\\n\", \"111 111\\n\", \"661 175\\n\", \"999 1000\\n\", \"5 25\\n\", \"90 120\\n\", \"5 1000\\n\", \"1000 5\\n\", \"600 175\\n\", \"105 140\\n\", \"130 312\\n\", \"440 330\\n\", \"30 40\\n\", \"15 15...
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the app...
0
{"tests": "{\"inputs\": [\"5 2 0\\n2 1\\n4 2\", \"100000 100000 1\\n50000 23836\", \"3 4 2\\n2 2\\n2 4\", \"100000 100000 1\\n50000 25003\", \"3 4 2\\n2 2\\n2 8\", \"5 4 2\\n2 1\\n4 2\", \"3 4 2\\n2 3\\n1 4\", \"5 5 4\\n3 1\\n3 5\\n1 3\\n4 3\", \"9 2 0\\n2 1\\n4 2\", \"100000 100000 1\\n50000 29731\", \"8 2 0\\n2 1\\n4...
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall squares, and the others are all empty squares. It is guaranteed that Squares (1, 1) and ...
0
{"tests": "{\"inputs\": [\"1 1 1\\n\", \"1 2 2\\n\", \"1 3 5\\n\", \"6 2 9\\n\", \"7 3 7\\n\", \"135 14 39\\n\", \"5000 5000 5000\\n\", \"2 1 1\\n\", \"1 1 3\\n\", \"1 2 3\\n\", \"4 1 2\\n\", \"5 9 4\\n\", \"4 2 5\\n\", \"9 4 10\\n\", \"16 8 29\\n\", \"17 46 45\\n\", \"28 47 1\\n\", \"94 87 10\\n\", \"84 29 61\\n\", \"...
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii-chan! With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands! There are three...
0.25
{"tests": "{\"inputs\": [\"4\\n800\\n700\\n1600\\n600\\n4\\n300\\n700\\n1600\\n30\\n4\\n300\\n700\\n1600\\n650\\n3\\n1000\\n2000\\n500\\n3\\n250\\n250\\n1000\\n4\\n1251\\n667\\n876\\n299\\n0\", \"4\\n800\\n700\\n1600\\n600\\n4\\n300\\n700\\n1600\\n30\\n4\\n300\\n700\\n1600\\n650\\n3\\n1000\\n2000\\n500\\n3\\n250\\n250\...
500-yen Saving "500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more than one million yen in your saving box in ten years. Some Japanese people...
0
{"tests": "{\"inputs\": [\"4 4\\n\", \"3 9\\n\", \"9 3\\n\", \"3 6\\n\", \"506 2708\\n\", \"11 24\\n\", \"92 91\\n\", \"58 53\\n\", \"39 97\\n\", \"47 96\\n\", \"49 39\\n\", \"76 100\\n\", \"97821761637600 97821761637600\\n\", \"65214507758400 97821761637600\\n\", \"97821761637600 65214507758400\\n\", \"10293281928930 ...
There is an infinite board of square tiles. Initially all tiles are white. Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should ...
0
{"tests": "{\"inputs\": [\"6 5 2\\n1 2 5\\n2 3 7\\n2 4 4\\n4 5 2\\n4 6 8\\n1 6\\n5 3\\n\", \"5 5 4\\n1 2 5\\n2 3 4\\n1 4 3\\n4 3 7\\n3 5 2\\n1 5\\n1 3\\n3 3\\n1 5\\n\", \"6 5 2\\n1 2 10\\n2 3 7\\n2 4 4\\n4 5 2\\n4 6 8\\n1 6\\n5 3\\n\", \"6 5 2\\n1 2 10\\n2 3 7\\n2 4 4\\n4 5 2\\n4 6 10\\n1 6\\n5 3\\n\", \"6 5 2\\n1 2 10...
You are a mayor of Berlyatov. There are $n$ districts and $m$ two-way roads between them. The $i$-th road connects districts $x_i$ and $y_i$. The cost of travelling along this road is $w_i$. There is some path between each pair of districts, so the city is connected. There are $k$ delivery routes in Berlyatov. The $i$...
0
{"tests": "{\"inputs\": [\"4\\n5 5\\n1 2 3 4 5\\n7 4\\n-6 -5 -3 0\\n3 3\\n2 3 4\\n3 2\\n3 4\\n\", \"1\\n2 2\\n0 -1\\n\", \"1\\n7 4\\n-6 -7 -8 -9\\n\", \"1\\n3 2\\n-4 -6\\n\", \"1\\n4 2\\n-7 -9\\n\", \"1\\n3 2\\n-10 -12\\n\", \"1\\n3 2\\n-8 -12\\n\", \"1\\n5 1\\n-10\\n\", \"1\\n4 3\\n-3 -4 -4\\n\", \"1\\n5 1\\n-4\\n\", ...
Suppose $a_1, a_2, \dots, a_n$ is a sorted integer sequence of length $n$ such that $a_1 \leq a_2 \leq \dots \leq a_n$. For every $1 \leq i \leq n$, the prefix sum $s_i$ of the first $i$ terms $a_1, a_2, \dots, a_i$ is defined by $$ s_i = \sum_{k=1}^i a_k = a_1 + a_2 + \dots + a_i. $$ Now you are given the last $k$ t...
0
{"tests": "{\"inputs\": [\"3\\n1\\n2\\n3\\n\", \"3\\n3\\n2\\n1\\n\", \"10\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n1\\n\", \"10\\n8\\n8\\n5\\n1\\n2\\n7\\n3\\n8\\n9\\n4\\n\", \"10\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"100\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n2\\n3\\n4\\n5...
Vasya had a strictly increasing sequence of positive integers a_1, ..., a_{n}. Vasya used it to build a new sequence b_1, ..., b_{n}, where b_{i} is the sum of digits of a_{i}'s decimal representation. Then sequence a_{i} got lost and all that remained is sequence b_{i}. Vasya wonders what the numbers a_{i} could be l...
0
{"tests": "{\"inputs\": [\"3\\n2 2\\n2 3\", \"6\\n1 2\\n2 1\\n2 4\\n4 6\\n5 6\", \"7\\n1 7\\n7 1\\n3 4\\n7 5\\n6 3\\n2 1\", \"6\\n1 2\\n2 3\\n2 4\\n6 6\\n5 6\", \"6\\n1 2\\n2 1\\n2 4\\n4 6\\n4 6\", \"7\\n1 7\\n7 1\\n3 4\\n2 5\\n6 3\\n2 1\", \"6\\n1 3\\n2 3\\n2 4\\n6 6\\n5 6\", \"7\\n1 7\\n7 1\\n3 7\\n2 5\\n6 3\\n2 1\",...
Takahashi and Aoki will play a game on a tree. The tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i. At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki will alternately perform the following operation: * Choose a vertex ...
0
{"tests": "{\"inputs\": [\"1\\n7 3\\nRGGRGRG\", \"1\\n7 2\\nRGGRGRG\", \"1\\n7 2\\nGRGRGGR\", \"1\\n7 0\\nRGGRGRG\", \"1\\n7 3\\nGRGRGGR\", \"1\\n7 2\\nGHGRRGR\", \"1\\n7 1\\nGRGQGGS\", \"1\\n7 0\\nQGGQGSH\", \"1\\n7 4\\nGRGRGGR\", \"1\\n7 -1\\nRGGRGRG\", \"1\\n7 2\\nGRGRHGR\", \"1\\n7 3\\nQGGRGRG\", \"1\\n7 2\\nRGGRHR...
Read problems statements in Mandarin Chinese and Russian as well. John's barn has a fence consisting of N consecutive parts numbered from left to right starting from 1 to N. Each part is initially painted in one of two colors: red or green, whose information is provided you by a string C. The color of i-th part C_{i}...
0
{"tests": "{\"inputs\": [[\"GTCTTAGTGTAGCTATGCATGC\", \"GCATGCATAGCTACACTACGAC\"], [\"ATGCTACG\", \"CGTAGCAT\"], [\"AGTCTGTATGCATCGTACCC\", \"GGGTACGATGCATACAGACT\"], [\"TGCTACGTACGATCGACGATCCACGAC\", \"GTCGTGGATCGTCGATCGTACGTAGCA\"], [\"ATGCCTACGGCCATATATATTTAG\", \"CTAAATATGTATGGCCGTAGGCAT\"], [\"GTCACCGA\", \"TCGGCT...
DNA is a biomolecule that carries genetic information. It is composed of four different building blocks, called nucleotides: adenine (A), thymine (T), cytosine (C) and guanine (G). Two DNA strands join to form a double helix, whereby the nucleotides of one strand bond to the nucleotides of the other strand at the corre...
0
{"tests": "{\"inputs\": [[12], [6], [50], [44], [625], [5], [7100], [123456], [1234567], [7654321], [4], [7654322]], \"outputs\": [[[1, 2, 3, 7, 9]], [null], [[1, 3, 5, 8, 49]], [[2, 3, 5, 7, 43]], [[2, 5, 8, 34, 624]], [[3, 4]], [[2, 3, 5, 119, 7099]], [[1, 2, 7, 29, 496, 123455]], [[2, 8, 32, 1571, 1234566]], [[6, 10...
My little sister came back home from school with the following task: given a squared sheet of paper she has to cut it in pieces which, when assembled, give squares the sides of which form an increasing sequence of numbers. At the beginning it was lot of fun but little by little we were tired of seeing the pile of torn ...
0
{"tests": "{\"inputs\": [\"999996270\\n\", \"34\\n\", \"999002449\\n\", \"134534550\\n\", \"999999999\\n\", \"6\\n\", \"999999937\\n\", \"2\\n\", \"4\\n\", \"222953472\\n\", \"9\\n\", \"48\\n\", \"998244352\\n\", \"999161856\\n\", \"999751680\\n\", \"18\\n\", \"3\\n\", \"36\\n\", \"13\\n\", \"14\\n\", \"33\\n\", \"9999...
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. ...
0.75
{"tests": "{\"inputs\": [\"2 10\\n1 2 9\\n1 2 9\\n2 1 9\\n1 2 8\\n2 1 9\\n1 2 9\\n1 2 9\\n1 2 11\\n1 2 9\\n1 2 9\\n\", \"4 4\\n1 3 1953\\n3 2 2844\\n1 3 2377\\n3 2 2037\\n\", \"2 1\\n2 2 44\\n\", \"4 8\\n1 2 4824\\n3 1 436\\n2 2 3087\\n2 4 2955\\n2 4 2676\\n4 3 2971\\n3 4 3185\\n3 1 3671\\n\", \"15 14\\n1 2 1\\n2 3 1\\...
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself). Input The first line of the input contains two integer...
0
{"tests": "{\"inputs\": [\"2\\n3 2\\n1 3 5\\n4 1\\n5 2 3 5\\n\", \"1\\n3 1383\\n1 2 3\\n\", \"1\\n3 3\\n1 2 3\\n\", \"1\\n3 1383\\n1 2 3\\n\", \"1\\n3 3\\n1 2 3\\n\", \"1\\n2 1383\\n1 2 3\\n\", \"2\\n3 2\\n1 3 5\\n4 1\\n5 4 3 5\\n\", \"2\\n3 2\\n1 1 5\\n4 1\\n5 4 3 5\\n\", \"2\\n3 2\\n0 1 5\\n4 1\\n5 2 3 5\\n\", \"1\\n...
Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters. The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let'...
0
{"tests": "{\"inputs\": [[[24, 20, 14, 19, 18, 9]], [[1, 7, 6, 17, 12, 16]], [[12, 14, 13, 9, 10, 6]], [[18, 16, 17, 15, 13, 14]], [[1, 25, 24, 2, 3, 16]], [[1, 1, 1, 1, 1, 1]], [[2, 3, 8, 9, 10, 13]]], \"outputs\": [[true], [false], [false], [true], [false], [false], [true]]}", "source": "taco"}
# Task The function `fold_cube(number_list)` should return a boolean based on a net (given as a number list), if the net can fold into a cube. Your code must be effecient and complete the tests within 500ms. ## Input Imagine a net such as the one below. ``` @ @ @ @ @ @ ``` Then, put it on the table with each ...
0
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n1 2\\n\", \"3 3\\n3 1 2\\n1 2\\n3 1\\n3 2\\n\", \"5 2\\n3 1 5 4 2\\n5 2\\n5 4\\n\", \"5 11\\n5 1 3 4 2\\n5 1\\n5 2\\n1 5\\n2 1\\n1 2\\n1 4\\n2 5\\n1 3\\n5 4\\n5 3\\n3 1\\n\", \"10 23\\n6 9 8 10 4 3 7 1 5 2\\n7 2\\n3 2\\n2 4\\n2 3\\n7 5\\n6 4\\n10 7\\n7 1\\n6 8\\n6 2\\n8 10\\n3 5\\...
At the big break Nastya came to the school dining room. There are $n$ pupils in the school, numbered from $1$ to $n$. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going...
0
{"tests": "{\"inputs\": [[[1, 2]], [[1, 3]], [[1, 5]], [[0]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]], [[-42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -...
Some integral numbers are odd. All are more odd, or less odd, than others. Even numbers satisfy `n = 2m` ( with `m` also integral ) and we will ( completely arbitrarily ) think of odd numbers as `n = 2m + 1`. Now, some odd numbers can be more odd than others: when for some `n`, `m` is more odd than for another's. Re...
0
{"tests": "{\"inputs\": [[[3, 5, 8, 1, 14, 3]], [[3, 5, 8, 9, 14, 23]], [[3, 5, 8, 8, 14, 14]], [[14, 9, 8, 5, 3, 1]], [[14, 14, 8, 8, 5, 3]], [[8, 8, 8, 8, 8, 8]], [[8, 9]], [[8, 8, 8, 8, 8, 9]], [[9, 8]], [[9, 9, 9, 8, 8, 8]], [[3, 5, 8, 1, 14, 2]]], \"outputs\": [[0], [1], [2], [3], [4], [5], [1], [2], [3], [4], [0]...
A series or sequence of numbers is usually the product of a function and can either be infinite or finite. In this kata we will only consider finite series and you are required to return a code according to the type of sequence: |Code|Type|Example| |-|-|-| |`0`|`unordered`|`[3,5,8,1,14,3]`| |`1`|`strictly increasing`...
0.25
{"tests": "{\"inputs\": [\"5 3\\n1 1 5 4 5\\n1 2\\n2 5\\n5 4\", \"10 10\\n8 7 2 9 10 6 6 5 5 4\\n8 1\\n6 3\\n6 2\\n7 10\\n9 7\\n9 9\\n2 4\\n8 2\\n1 8\\n7 7\", \"5 3\\n1 1 3 1 5\\n1 2\\n2 5\\n5 4\", \"4 4\\n4 4 4 4\\n4 0\\n3 1\\n1 1\\n2 1\", \"10 10\\n8 7 2 9 10 6 6 5 5 4\\n8 1\\n6 3\\n6 2\\n7 10\\n9 7\\n9 9\\n2 4\\n10 ...
There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it. When Snuke cast a spell, the following happens: * Let the current number of balls be k. All the balls with k written on them disappear at the same time. Snuke's objective is to vanish all the balls by casting the ...
0
{"tests": "{\"inputs\": [\"xxxxxxxxxxfxxxxxxxxxxxxxxxxxxxxxxxxxxxrxtxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxexxxxmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoxxxxxxxxxxexxxxxxxxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxtxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxuxxxxxxxxxxxxx...
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1...
0
{"tests": "{\"inputs\": [\"666660666\\n62238520449600706121638\\n20202202000333003330333\", \"666660666\\n62238520449600706121638\\n20470251257982382367886\", \"666660666\\n79768964391256325078385\\n20470251257982382367886\", \"666660666\\n79768964391256325078385\\n25978567800744130697792\", \"666660666\\n5599997477344...
She loves e-mail so much! She sends e-mails by her cellular phone to her friends when she has breakfast, she talks with other friends, and even when she works in the library! Her cellular phone has somewhat simple layout (Figure 1). Pushing button 1 once displays a character (’), pushing <image> it twice in series di...
0
{"tests": "{\"inputs\": [\"2 0 0 2\\n\", \"0 2 0 1\\n\", \"13118 79593 32785 22736\\n\", \"0 2 2 0\\n\", \"10 0 0 10\\n\", \"9 0 8 0\\n\", \"34750 34886 34751 44842\\n\", \"50042 34493 84536 17892\\n\", \"0 1 1 0\\n\", \"4 5 5 5\\n\", \"2 2 1 2\\n\", \"67949 70623 71979 70623\\n\", \"43308 1372 53325 1370\\n\", \"4075 ...
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: ...
0
{"tests": "{\"inputs\": [[\"foo\"], [\"foobar001\"], [\"foobar1\"], [\"foobar00\"], [\"foobar99\"], [\"\"], [\"foobar000\"], [\"foobar999\"], [\"foobar00999\"], [\"1\"], [\"009\"]], \"outputs\": [[\"foo1\"], [\"foobar002\"], [\"foobar2\"], [\"foobar01\"], [\"foobar100\"], [\"1\"], [\"foobar001\"], [\"foobar1000\"], [\"...
Your job is to write a function which increments a string, to create a new string. - If the string already ends with a number, the number should be incremented by 1. - If the string does not end with a number. the number 1 should be appended to the new string. Examples: `foo -> foo1` `foobar23 -> foobar24` `foo004...
0
{"tests": "{\"inputs\": [\"14\\n\", \"20\\n\", \"8192\\n\", \"1000000\\n\", \"959806\\n\", \"1452\\n\", \"4\\n\", \"6\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"12\\n\", \"15\\n\", \"16\\n\", \"110880\\n\", \"166320\\n\", \"221760\\n\", \"277200\\n\", \"332640\\n\", \"498960\\n\", \"554400\\n\", \"665280\\n\", \"720720\\n\...
Alice and Bob begin their day with a quick game. They first choose a starting number X_0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and ann...
0
{"tests": "{\"inputs\": [\"4\\n4\\n1 2 3\\n1 2 3\\n5\\n1 2 3 4\\n1 1 1 1\\n6\\n1 2 1 1 2\\n1 2 1 2 2\\n7\\n1 1 3 4 4 5\\n1 2 1 4 2 5\\n\", \"4\\n4\\n1 2 3\\n1 2 3\\n5\\n1 2 3 4\\n1 1 1 1\\n6\\n1 2 1 1 2\\n1 2 1 2 2\\n7\\n1 1 3 4 4 5\\n1 2 1 4 4 5\\n\", \"4\\n4\\n1 2 3\\n1 2 3\\n5\\n1 4 3 4\\n1 1 1 1\\n6\\n1 1 1 1 2\\n1...
Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memorial graph o...
0
{"tests": "{\"inputs\": [\"4\\n3 4\\n1 4\\n3 4\\n\", \"3\\n1 3\\n1 3\\n\", \"3\\n1 2\\n2 3\\n\", \"15\\n10 15\\n12 15\\n6 15\\n8 15\\n2 15\\n3 15\\n10 15\\n13 15\\n5 15\\n7 15\\n11 15\\n4 14\\n1 15\\n14 15\\n\", \"15\\n9 15\\n6 15\\n12 15\\n3 14\\n14 15\\n11 15\\n6 15\\n7 15\\n10 15\\n4 15\\n1 15\\n13 15\\n2 15\\n9 15\...
Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from $1$ to $n$. For every edge $e$ of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge $e$ (and only this ...
0.25
{"tests": "{\"inputs\": [\"6 6\\n2 4\\n6 2\\n0 0 0 0 1 0\\n0 1 1 0 0 0\\n0 1 0 0 0 0\\n0 0 0 1 0 0\\n0 0 0 0 0 1\\n0 0 0 0 0 0\\n3 3\\n1 1\\n3 3\\n0 0 0\\n0 1 0\\n0 0 0\\n0 0\", \"6 6\\n2 4\\n6 2\\n0 0 0 0 1 0\\n0 1 1 0 0 0\\n0 1 0 0 0 0\\n0 0 0 1 1 0\\n0 0 0 0 0 1\\n0 0 0 0 0 0\\n3 3\\n1 2\\n3 3\\n0 0 0\\n0 1 0\\n0 0 ...
Takayuki and Kazuyuki are good twins, but their behavior is exactly the opposite. For example, if Takayuki goes west, Kazuyuki goes east, and if Kazuyuki goes north, Takayuki goes south. Currently the two are in a department store and are in different locations. How can two people who move in the opposite direction mee...
0
{"tests": "{\"inputs\": [\"1707 1117\\n\", \"1766 1038\\n\", \"217 3\\n\", \"1229 1315\\n\", \"634 1825\\n\", \"1903 1612\\n\", \"1887 1729\\n\", \"1472 854\\n\", \"43 1640\\n\", \"56 48\\n\", \"675 741\\n\", \"1610 774\\n\", \"436 1302\\n\", \"1153 1823\\n\", \"1544 1794\\n\", \"1895 753\\n\", \"1415 562\\n\", \"1722 ...
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
0
{"tests": "{\"inputs\": [\"5\\n8\\n-8 2 -6 -5 -4 3 3 2\\n7\\n1 1 4 1 0 -2 -1\\n7\\n6 12 8 6 2 6 10\\n6\\n5 1 2 3 6 7\\n5\\n1 3 4 3 0\\n\", \"5\\n4\\n6 2 2 3\\n1\\n4\\n5\\n4 -8 5 6 -7\\n2\\n3 3\\n4\\n2 1 2 3\\n\", \"5\\n8\\n-8 2 -6 -5 -4 3 3 2\\n7\\n1 1 4 1 0 -2 -1\\n7\\n6 12 8 6 2 6 4\\n6\\n5 1 2 2 6 7\\n5\\n1 2 4 3 0\...
Uh oh! Ray lost his array yet again! However, Omkar might be able to help because he thinks he has found the OmkArray of Ray's array. The OmkArray of an array a with elements a_1, a_2, …, a_{2k-1}, is the array b with elements b_1, b_2, …, b_{k} such that b_i is equal to the median of a_1, a_2, …, a_{2i-1} for all i. O...
0
{"tests": "{\"inputs\": [\"10\\n5 8 1 10 3 6 2 9 7 4\\n4 2 6 3 1 9 10 5 8 7\\n\", \"20\\n1 12 9 6 11 13 2 8 20 7 16 19 4 18 3 15 10 17 14 5\\n5 14 17 10 15 3 18 4 19 16 7 20 8 2 13 11 6 9 12 1\\n\", \"10\\n1 6 10 3 4 9 2 5 8 7\\n7 5 1 6 10 3 4 8 9 2\\n\", \"10\\n2 1 10 3 7 8 5 6 9 4\\n6 9 2 4 1 10 3 7 8 5\\n\", \"10\\n...
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the perm...
0
{"tests": "{\"inputs\": [\"9\\n3 3 5 4 1 2 4 2 1\", \"9\\n21 18 28 18 28 45 90 45 23\", \"9\\n2 3 7 4 1 2 4 2 1\", \"9\\n21 18 3 18 28 45 90 45 23\", \"9\\n2 3 4 4 1 2 4 2 1\", \"9\\n21 18 3 18 46 45 90 45 23\", \"9\\n2 3 2 4 1 2 4 2 1\", \"9\\n21 18 3 17 46 45 90 45 23\", \"9\\n2 3 2 4 1 2 4 2 2\", \"9\\n21 18 1 17 46...
Let us consider a grid of squares with 10^9 rows and N columns. Let (i, j) be the square at the i-th column (1 \leq i \leq N) from the left and j-th row (1 \leq j \leq 10^9) from the bottom. Snuke has cut out some part of the grid so that, for each i = 1, 2, ..., N, the bottom-most h_i squares are remaining in the i-t...
0
{"tests": "{\"inputs\": [\"7\\n3\\n007\\n4\\n1000\\n5\\n00000\\n3\\n103\\n4\\n2020\\n9\\n123456789\\n30\\n001678294039710047203946100020\\n\", \"7\\n3\\n007\\n4\\n1000\\n5\\n00000\\n3\\n103\\n4\\n1247\\n9\\n123456789\\n30\\n001678294039710047203946100020\\n\", \"7\\n3\\n007\\n4\\n1000\\n5\\n00000\\n3\\n153\\n4\\n1247\\...
You are given a digital clock with $n$ digits. Each digit shows an integer from $0$ to $9$, so the whole clock shows an integer from $0$ to $10^n-1$. The clock will show leading zeroes if the number is smaller than $10^{n-1}$. You want the clock to show $0$ with as few operations as possible. In an operation, you can ...
0
{"tests": "{\"inputs\": [\"1 1\\n-1 -1\\n2\\n0 1 0\\n1 0 0\\n\", \"1 1\\n-1 -1\\n3\\n1 0 0\\n0 1 0\\n1 1 -3\\n\", \"841746 527518\\n595261 331297\\n10\\n-946901 129987 670374\\n-140388 -684770 309555\\n-302589 415564 -387435\\n-565799 -72069 -395358\\n-523453 -511446 854898\\n-846967 -749453 -341866\\n-622388 434663 26...
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation a_{i}x + b_{i}y + c_{i} = 0, where a_{i} and b_{i} are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an interse...
0.5
{"tests": "{\"inputs\": [\"7 2\\n-10 0 ? 1 ? 2 10\\n\", \"1 1\\n0\\n\", \"5 1\\n-3 -2 -1 0 1\\n\", \"7 1\\n-4 ? ? ? ? ? 2\\n\", \"17 1\\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100\\n\", \"3 1\\n-5 ? 0\\n\", \"7 2\\n-10 0 ? 1 6 2 ?\\n\", \"3 1\\n-3 ? -2\\n\", \"6 1\\n-1 ? 1 2 3 4\\n\", \"1 1\\n?\\n\", \"9 2\\n-10 0 ? 1 ? 2...
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n. This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (a1 + a2 ... + ak, ...
0
{"tests": "{\"inputs\": [\"5 3\\n3-a 2-b 4-c 3-a 2-c\\n2-a 2-b 1-c\\n\", \"6 1\\n3-a 6-b 7-a 4-c 8-e 2-a\\n3-a\\n\", \"5 5\\n1-h 1-e 1-l 1-l 1-o\\n1-w 1-o 1-r 1-l 1-d\\n\", \"9 3\\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\\n2-l 1-o 1-w\\n\", \"5 3\\n1-m 1-i 2-r 1-o 1-r\\n1-m 1-i 1-r\\n\", \"9 2\\n1-a 2-b 1-o 1-k 1-l 1-m 1-a...
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature ...
0.625
{"tests": "{\"inputs\": [[[[\"apple\", \"orange\"], [\"orange\", \"pear\"], [\"apple\", \"pear\"]], \"apple\"], [[[\"orange\", \"apple\"], [\"orange\", \"pear\"], [\"pear\", \"apple\"]], \"apple\"], [[[\"apple\", \"orange\"], [\"pear\", \"orange\"], [\"apple\", \"pear\"]], \"apple\"], [[[\"orange\", \"apple\"], [\"pear...
You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell. You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should return a string of 3 actions. if you have harvested apples, you woul...
0
{"tests": "{\"inputs\": [\"abb\", \"aaa\", \"baa\", \"bacba\", \"bba\", \"badba\", \"aa`\", \"aab\", \"cadba\", \"`aa\", \"bca\", \"dadba\", \"`ab\", \"acb\", \"ddaba\", \"``b\", \"aca\", \"dd`ba\", \"`_b\", \"bb`\", \"dd`b`\", \"b_`\", \"`bb\", \"ddb``\", \"c_`\", \"`cb\", \"ddba`\", \"`_c\", \"`bc\", \"ddaa`\", \"_`c...
There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot b...
0
{"tests": "{\"inputs\": [[[], 1], [[5], 1], [[2], 5], [[1, 2, 3, 4, 5], 1], [[1, 2, 3, 4, 5], 100], [[2, 2, 3, 3, 4, 4], 2]], \"outputs\": [[0], [5], [2], [15], [5], [9]]}", "source": "taco"}
There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out! ### input ```if-not:c * customers: an array of positive integers representing the queue. Each integer represents a customer, and its value is the amoun...
0
{"tests": "{\"inputs\": [\"2\\n3\\n1 2 3\\n1\\n9\", \"2\\n3\\n2 2 3\\n1\\n9\", \"2\\n3\\n2 1 3\\n1\\n9\", \"2\\n3\\n3 1 3\\n1\\n9\", \"2\\n3\\n3 4 3\\n1\\n9\", \"2\\n3\\n1 2 6\\n1\\n9\", \"2\\n3\\n3 1 3\\n1\\n6\", \"2\\n3\\n3 2 3\\n1\\n13\", \"2\\n3\\n3 4 3\\n1\\n4\", \"2\\n3\\n0 2 6\\n1\\n9\", \"2\\n3\\n2 1 3\\n0\\n11...
Chef likes cooking. But more than that, he likes to give gifts. And now he wants to give his girlfriend an unforgettable gift. But unfortunately he forgot the password to the safe where the money he saved for the gift is kept. But he knows how to hack the safe. To do this, you need to correctly answer questions asked ...
0.125
{"tests": "{\"inputs\": [[\"This is a string exemplification!\", 0], [\"String for test: incommensurability\", 1], [\"Ohh Man God Damn\", 7], [\"Ohh Man God Damnn\", 19], [\"I like it!\", 1234], [\"codingisfornerdsyounerd\", 10101010], [\"this_test_will_hurt_you\", 12345678987654321]], \"outputs\": [[\"This is a string...
This kata is blatantly copied from inspired by This Kata Welcome this is the second in the series of the string iterations kata! Here we go! --------------------------------------------------------------------------------- We have a string s Let's say you start with this: "String" The first thing you do is reve...
0
{"tests": "{\"inputs\": [\"1 2000000000 10007\\n\", \"19431 20000000 17\\n\", \"1570000 800000000 30011\\n\", \"1000 2000000000 211\\n\", \"1999999000 2000000000 23\\n\", \"1 2000000000 23\\n\", \"44711 44711 44711\\n\", \"1 2000000000 44711\\n\", \"300303 600000 503\\n\", \"1000000000 2000000000 4001\\n\", \"5002230 1...
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ...
0
{"tests": "{\"inputs\": [\"7\\n3 4 2 3 4 2 2\\n\", \"5\\n20 1 14 10 2\\n\", \"13\\n5 5 4 4 3 5 7 6 5 4 4 6 5\\n\", \"10\\n13 13 13 13 13 13 13 9 9 13\\n\", \"100\\n11 16 16 11 16 11 16 16 11 16 16 16 16 16 16 16 16 16 11 16 16 16 16 16 16 11 16 11 16 11 16 16 16 11 5 16 16 11 16 16 16 16 16 11 16 11 5 16 16 16 16 5 16 ...
Monocarp has arranged $n$ colored marbles in a row. The color of the $i$-th marble is $a_i$. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color). In other words, Monocarp wants to ...
0.125
{"tests": "{\"inputs\": [\"3\\n1 1\\n2 1\\n1 7\\n\", \"12\\n1 1\\n2 1\\n1 7\\n1 1\\n2 1\\n1 7\\n1 1\\n2 1\\n1 7\\n1 1\\n2 1\\n1 7\\n\", \"1\\n99999 100000\\n\", \"1\\n99899 100000\\n\", \"1\\n99899 99899\\n\", \"3\\n1 1\\n2 1\\n96342 7\\n\", \"1\\n8627 2007\\n\", \"1\\n1000000 1000000\\n\", \"1\\n1000000 1\\n\", \"2\\n...
Alice and Bob play ping-pong with simplified rules. During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return. The one ...
0
{"tests": "{\"inputs\": [\"2\\n4 2\\nR 1 1\\nB 1 5\\n\", \"2\\n4 2\\nR 3 3\\nB 1 5\\n\", \"5\\n-1 1\\nR -10 10\\nQ -9 9\\nQ -2 -8\\nB -6 10\\nB -10 1\\n\", \"20\\n-321 454\\nQ 967 -89\\nR -811 454\\nQ -404 454\\nR -734 454\\nQ -804 454\\nQ -316 77\\nQ -802 454\\nB -499 454\\nQ 401 -663\\nQ -601 454\\nQ -974 454\\nB 710...
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check whether the king is in check. Anton doesn't know how to implement thi...
0
{"tests": "{\"inputs\": [\"1 3\\n0 0\", \"5 21600\\n2 14\\n3 22\\n1 3\\n0 10\\n1 9\", \"7 57\\n0 25\\n3 10\\n2 4\\n5 15\\n3 22\\n2 14\\n1 9\", \"1 0\\n1 -1\", \"7 149\\n0 25\\n3 10\\n2 4\\n2 20\\n3 22\\n2 23\\n1 2\", \"7 28\\n0 25\\n3 10\\n2 4\\n5 20\\n3 22\\n2 14\\n1 9\", \"7 149\\n0 25\\n3 10\\n0 4\\n0 8\\n3 23\\n1 2...
There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores. It takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores. If Takahashi reaches Store i at time t, he can do shopping the...
0
{"tests": "{\"inputs\": [\"3\\n1 1 3\", \"5\\n3 4 3 4 3\", \"5\\n3 4 3 3 3\", \"3\\n0 2 2\", \"4\\n2 4 2 2\", \"3\\n4 2 2\", \"3\\n1 0 3\", \"3\\n0 2 4\", \"4\\n2 4 4 2\", \"3\\n4 0 2\", \"3\\n1 -1 3\", \"3\\n0 2 8\", \"4\\n2 4 3 2\", \"3\\n0 0 2\", \"3\\n2 -1 3\", \"3\\n0 1 8\", \"4\\n3 4 3 2\", \"3\\n2 -1 2\", \"3\\n...
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats. Constraints * 2 ≤ N ...
0.125
{"tests": "{\"inputs\": [[2, 3], [1, 30], [3, 3], [2, 2], [5, 2], [40, 40]], \"outputs\": [[8], [0], [48], [0], [40], [92400]]}", "source": "taco"}
# Task Consider a `bishop`, a `knight` and a `rook` on an `n × m` chessboard. They are said to form a `triangle` if each piece attacks exactly one other piece and is attacked by exactly one piece. Calculate the number of ways to choose positions of the pieces to form a triangle. Note that the bishop attacks piec...
0
{"tests": "{\"inputs\": [\"20\\n9 2 12 10 2 9 13 14 11 16 9 1 9 13 5 11 12 19 20 1\\n\", \"7\\n1 2 3 3 3 2 1\\n\", \"100\\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 10 10 10 10 10 10 10 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 17 17 17 17 17 17 17 17 17 17 17 17 17 12 17 1 1 1 1 1 1 1 1 1 1 1 2...
This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved. You are given an array [a_1, a_2, ..., a_n]. Your goal is to find the length of the longest subarray of this array such that the...
0.875
{"tests": "{\"inputs\": [\"12\\n12 3\\nzazasqzqsasq\\n1 1\\nz\\n1 1\\na\\n15 4\\nabccbaabccbazaa\\n16 8\\ncadjfdsljfdkljds\\n6 2\\nbaazaa\\n6 3\\nbosszb\\n6 1\\nqwerty\\n7 7\\ndaaaaaa\\n14 2\\nacabcbdeffewzd\\n18 6\\nzzzzzzzzzzzzyyyyyz\\n9 4\\naabaabbbc\\n\", \"12\\n12 3\\nzazasqzqsasq\\n1 1\\nz\\n1 1\\na\\n15 6\\nabcc...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
0
{"tests": "{\"inputs\": [\"10\\n77 16 42 68 100 38 40 99 75 67\\n0 1 0 2 1 1 0 0 0\\n1\\n43\\n\", \"30\\n45 63 41 0 9 11 50 83 33 74 62 85 42 29 17 26 4 0 33 85 16 11 46 98 87 81 70 50 0 22\\n1 3 0 1 2 2 0 1 2 1 3 2 0 1 1 2 0 0 2 1 0 2 0 1 3 1 0 3 1\\n1\\n19\\n\", \"20\\n79 33 19 90 72 83 79 78 81 59 33 91 13 76 81 28 ...
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each operat...
0
{"tests": "{\"inputs\": [\"5 6\\n1 2 6 8 10\\n1 4\\n1 9\\n0 6\\n0 10\\n1 100\\n1 50\\n\", \"5 8\\n5 1 2 4 3\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n1 1000000000\\n1 1\\n1 500000000\\n\", \"5 6\\n1 2 6 8 10\\n1 4\\n1 9\\n0 6\\n0 10\\n1 100\\n1 5\\n\", \"5 6\\n1 2 6 5 10\\n1 4\\n1 9\\n0 6\\n0 10\\n1 100\\n1 50\\n\", \"5 4\\n5 1 ...
Vova decided to clean his room. The room can be represented as the coordinate axis $OX$. There are $n$ piles of trash in the room, coordinate of the $i$-th pile is the integer $p_i$. All piles have different coordinates. Let's define a total cleanup as the following process. The goal of this process is to collect all ...
0.125
{"tests": "{\"inputs\": [\"5 0\\n3 7 3 7 3\\n\", \"10 0\\n1 2 1 2 3 1 1 1 50 1\\n\", \"6 0\\n6 6 3 3 4 4\\n\", \"7 0\\n3 3 1 3 2 1 2\\n\", \"5 0\\n1 2 1 2 1\\n\", \"5 0\\n2 3 2 3 3\\n\", \"100 0\\n6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62...
This is an easier version of the next problem. In this version, $q = 0$. A sequence of integers is called nice if its elements are arranged in blocks like in $[3, 3, 3, 4, 1, 1]$. Formally, if two elements are equal, everything in between must also be equal. Let's define difficulty of a sequence as a minimum possible...
0
{"tests": "{\"inputs\": [\"2 2\\n49 100\\n\", \"4 2\\n32 100 33 1\\n\", \"14 5\\n48 19 6 9 50 20 3 42 38 43 36 21 44 6\\n\", \"2 2\\n50 100\\n\", \"18 6\\n22 8 11 27 37 19 18 49 47 18 15 25 8 3 5 11 32 47\\n\", \"11 4\\n28 31 12 19 3 26 15 25 47 19 6\\n\", \"19 3\\n43 47 64 91 51 88 22 66 48 48 92 91 16 1 2 38 38 91 91...
Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab. There are $n$ solutions, the $i$-th of them should be tested on $a_i$ tests, testing one solution on one test takes $1$ second. The solutions are judged in the order from $1$ to $n$. There are...
0.5
{"tests": "{\"inputs\": [[\"Dermatoglyphics\"], [\"isogram\"], [\"moose\"], [\"isIsogram\"], [\"aba\"], [\"moOse\"], [\"thumbscrewjapingly\"], [\"abcdefghijklmnopqrstuvwxyz\"], [\"abcdefghijklmnopqrstuwwxyz\"], [\"\"]], \"outputs\": [[true], [true], [false], [false], [false], [false], [true], [true], [false], [true]]}"...
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. ```python is_isogram("Dermatoglyphics" ) == true is_isogram("aba" ) == false is_...
0
{"tests": "{\"inputs\": [\"4\\n6 -3 0 4\\n\", \"3\\n-2 0 2\\n\", \"2\\n1 2\\n\", \"2\\n1000000000 -1000000000\\n\", \"5\\n-979619606 -979619602 -979619604 -979619605 -979619603\\n\", \"5\\n-799147771 -799147773 -799147764 -799147774 -799147770\\n\", \"20\\n553280626 553280623 553280627 553280624 553280625 553280618 553...
There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a_1, a_2, ..., a_{n}. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided t...
0.875
{"tests": "{\"inputs\": [\"10 2 4\\n3 7\\n8 10\\n0 10\\n3 4\\n8 1\\n1 2\\n\", \"10 1 1\\n0 9\\n0 5\\n\", \"10 1 1\\n0 9\\n1 5\\n\", \"1 1 1\\n0 1\\n1 100000\\n\", \"1 1 1\\n0 1\\n0 100000\\n\", \"2000 1 1\\n0 1\\n2000 33303\\n\", \"2000 1 1\\n1999 2000\\n0 18898\\n\", \"100 50 1\\n1 2\\n3 4\\n5 6\\n7 8\\n9 10\\n11 12\\...
Polycarp lives on a coordinate line at the point $x = 0$. He goes to his friend that lives at the point $x = a$. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $n$ non-intersecting segments,...
0
{"tests": "{\"inputs\": [\"4\\n1 2 3 4\\n4\\n1 2 3 1\\n5\\n5 1 2 3 6\\n14\\n8 7 1 4 3 5 4 1 6 8 10 4 6 5\\n5\\n1 3 5 2 3\\n0\", \"4\\n1 2 3 2\\n4\\n1 2 3 1\\n5\\n2 1 2 3 6\\n14\\n8 7 1 4 3 5 4 2 6 8 10 4 6 5\\n5\\n1 3 5 2 3\\n0\", \"4\\n1 0 3 2\\n4\\n1 2 3 1\\n5\\n2 1 2 3 6\\n14\\n8 7 1 4 3 5 4 2 6 8 10 4 1 5\\n5\\n1 3...
Daruma Otoshi You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)". At the start of a game, several wooden blocks of the same size but with varying weights are stacked on top of each other, forming a tower. Another block symbolizing Dharma is placed atop. You have a wooden hammer with it...
0
{"tests": "{\"inputs\": [\"4\\nhello\\nhello\\nhello\\nhelloo\\nhello\\nhlllloo\\nhello\\nhelo\\n\", \"5\\naa\\nbb\\ncodeforces\\ncodeforce\\npolycarp\\npoolycarpp\\naaaa\\naaaab\\nabcdefghijklmnopqrstuvwxyz\\nzabcdefghijklmnopqrstuvwxyz\\n\", \"10\\naaaa\\naaaab\\naaaa\\nbaaaa\\na\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol). For example, as a result of typing the word "hello", the follo...
0
{"tests": "{\"inputs\": [\"2\\n0 2\", \"2\\n0 4\", \"2\\n0 5\", \"2\\n0 9\", \"2\\n0 18\", \"2\\n0 12\", \"2\\n0 17\", \"2\\n1 17\", \"2\\n1 21\", \"2\\n2 21\", \"2\\n2 27\", \"2\\n2 8\", \"2\\n0 8\", \"2\\n0 3\", \"2\\n1 3\", \"2\\n0 34\", \"2\\n2 17\", \"2\\n0 10\", \"2\\n2 14\", \"2\\n3 21\", \"2\\n2 7\", \"2\\n2 1\...
We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path u-v. It is expected that one of the vertices will be invaded by ...
0
{"tests": "{\"inputs\": [\"01011\\n0110\\n\", \"0011\\n1110\\n\", \"11111\\n111111\\n\", \"0110011\\n01100110\\n\", \"10000100\\n011110\\n\", \"1\\n0\\n\", \"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to...
0
{"tests": "{\"inputs\": [[\"Jeong-Ho Aristotelis\"], [\"Abishai Charalampos\"], [\"Idwal Augustin\"], [\"Hadufuns John\", 20], [\"Zoroaster Donnchadh\"], [\"Claude Miljenko\"], [\"Werner Vigi\", 15], [\"Anani Fridumar\"], [\"Paolo Oli\"], [\"Hjalmar Liupold\", 40], [\"Simon Eadwulf\"]], \"outputs\": [[600], [570], [420...
You can print your name on a billboard ad. Find out how much it will cost you. Each letter has a default price of £30, but that can be different if you are given 2 parameters instead of 1. You can not use multiplier "*" operator. If your name would be Jeong-Ho Aristotelis, ad would cost £600. 20 leters * 30 = 600 (Sp...
0
{"tests": "{\"inputs\": [\"1 2\\n8 8\\n0 0\\n0 1\\n3 3\\n1 2 5\\n2 8 3\\n0 1 2\\n0 0\\n2 2\\n3 3\\n1 2 5\\n2 8 6\\n0 1 2\\n0 0\\n1 2\\n2 2\\n1 2\\n3 4\\n0 0\\n0 1\\n2 3\\n1 2 3\\n4 5 6\\n0 0\\n1 2\\n0 0\", \"1 2\\n8 8\\n0 0\\n0 1\\n3 3\\n1 3 5\\n2 13 1\\n0 1 2\\n0 0\\n2 2\\n3 3\\n1 2 4\\n2 8 6\\n0 1 2\\n0 0\\n1 2\\n2 2...
The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear of delight. Now they are enthusiastically playing a game with the dic...
0
{"tests": "{\"inputs\": [\"3 5\\n\", \"15 6\\n\", \"1 1\\n\", \"100000000 1\\n\", \"1 100000000\\n\", \"96865066 63740710\\n\", \"58064619 65614207\\n\", \"31115339 39163052\\n\", \"14231467 12711896\\n\", \"92314891 81228036\\n\", \"75431019 54776881\\n\", \"48481739 28325725\\n\", \"99784030 7525\\n\", \"72834750 947...
Petya is having a party soon, and he has decided to invite his $n$ friends. He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one ...
0
{"tests": "{\"inputs\": [\"1\\n\", \"8\\n\", \"10\\n\", \"27\\n\", \"28206\\n\", \"32\\n\", \"115\\n\", \"81258\\n\", \"116003\\n\", \"149344197\\n\", \"57857854\\n\", \"999999999999999\\n\", \"181023403153\\n\", \"196071196742\\n\", \"49729446417673\\n\", \"14821870173923\\n\", \"29031595887308\\n\", \"195980601490039...
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous o...
0.5
{"tests": "{\"inputs\": [\"3\\n0 0 0\\n2 3 1\\n\", \"12\\n0 0 1 0 3 0 0 4 0 0 0 2\\n7 0 9 8 6 12 0 5 11 10 0 0\\n\", \"5\\n0 0 0 0 0\\n1 2 3 5 4\\n\", \"5\\n0 0 3 0 0\\n1 2 0 4 5\\n\", \"19\\n0 0 0 0 0 0 0 0 0 18 17 16 15 14 13 12 11 10 9\\n0 0 0 0 0 0 0 19 0 0 0 1 2 3 4 5 6 7 8\\n\", \"7\\n0 0 1 2 3 4 6\\n0 5 0 0 7 0 ...
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n...
0
{"tests": "{\"inputs\": [\"5 5 20 100\\n464 757 53 708 262\\n753 769 189 38 796\\n394 60 381 384 935\\n882 877 501 615 464\\n433 798 504 301 301\\n\", \"10 10 50 80\\n529 349 889 455 946 983 482 179 590 907\\n436 940 407 631 26 963 181 789 461 437\\n367 505 888 521 449 741 900 994 342 847\\n605 374 112 829 212 184 295 ...
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations. Each modification is one of the following: 1. Pick some row of the matrix and decrease each element of the row by p. This operation brings to DZY the v...
0
{"tests": "{\"inputs\": [\"AbC\\nDCbA\\n\", \"ABC\\nabc\\n\", \"abacaba\\nAbaCaBA\\n\", \"zzzzz\\nZZZZZ\\n\", \"zzzZZZ\\nZZZzzZ\\n\", \"abcdefghijklmnopqrstuvwxyz\\nABCDEFGHIJKLMNOPQRSTUVWXYZ\\n\", \"abcdefghijklmnopqrstuvwxyz\\nqrsimtabuvzhnwcdefgjklxyop\\n\", \"l\\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM\\n\", \"ncM...
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The...
0
{"tests": "{\"inputs\": [[9, 7], [15, 15], [18, 21], [19, 17], [24, 24], [25, 25], [26, 26], [27, 27], [56, 64]], \"outputs\": [[[0, 0]], [[1, 1]], [[1, 1]], [[1, 1]], [[2, 2]], [[2, 2]], [[2, 2]], [[2, 2]], [[10, 10]]]}", "source": "taco"}
This is related to my other Kata about cats and dogs. # Kata Task I have a cat and a dog which I got as kitten / puppy. I forget when that was, but I do know their current ages as `catYears` and `dogYears`. Find how long I have owned each of my pets and return as a list [`ownedCat`, `ownedDog`] NOTES: * Results ar...
0
{"tests": "{\"inputs\": [\"4\\n2\\n1 1\\n3\\n1 31 12\\n3\\n12345 67 84\\n9\\n1 2 3 4 5 6 7 8 9\\n\", \"4\\n2\\n1 1\\n3\\n1 31 12\\n3\\n12345 67 98\\n9\\n1 2 3 4 5 6 7 8 9\\n\", \"4\\n2\\n1 1\\n3\\n1 31 12\\n3\\n12345 67 98\\n9\\n1 2 3 4 4 6 7 8 9\\n\", \"4\\n2\\n1 1\\n3\\n1 31 12\\n3\\n21646 67 98\\n9\\n1 2 3 4 4 6 7 8...
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number a_{i} written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a nu...
0
{"tests": "{\"inputs\": [[\"4\", \"1 0 0 0\", \"1\", \"1 0 0 0\", \"3\", \"0 1 0 0\", \"2\", \"2 3 1 4\", \"10\"], \"4\\n1 0 0 0\\n1\\n1 0 0 0\\n3\\n0 1 0 0\\n2\\n2 3 1 4\\n12\", \"4\\n1 0 0 0\\n1\\n1 0 0 0\\n3\\n0 1 0 0\\n2\\n3 3 1 4\\n10\", \"4\\n2 0 0 0\\n1\\n1 0 0 0\\n3\\n0 1 0 0\\n2\\n2 3 1 4\\n12\", \"4\\n2 0 1 0...
-----Problem Statement----- Chef studies combinatorics. He tries to group objects by their rang (a positive integer associated with each object). He also gives the formula for calculating the number of different objects with rang N as following: the number of different objects with rang N = F(N) = A0 + A1 * N + A2 * N...
0
{"tests": "{\"inputs\": [\"7 0\", \"1001000000 1000000000\", \"6 5\", \"1001000000 1100000000\", \"3 5\", \"1001000010 1100000000\", \"3 6\", \"1001000010 1100100000\", \"1001000011 1100100000\", \"3 1\", \"9 -1\", \"1001000011 1000100000\", \"3 2\", \"1001000011 1000000000\", \"4 2\", \"1001000111 1000000000\", \"4 3\...
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the to...
0
{"tests": "{\"inputs\": [\"2\\n1 4\\n5 3\", \"2\\n0 4\\n5 3\", \"2\\n0 4\\n5 2\", \"2\\n1 4\\n6 3\", \"2\\n1 0\\n5 3\", \"2\\n2 4\\n6 3\", \"2\\n0 0\\n5 1\", \"2\\n3 0\\n5 5\", \"2\\n0 4\\n4 3\", \"2\\n2 0\\n5 5\", \"2\\n0 0\\n4 1\", \"2\\n6 0\\n5 3\", \"2\\n0 0\\n4 2\", \"2\\n2 2\\n0 3\", \"2\\n0 1\\n4 3\", \"2\\n0 5\...
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure. <image> For a given chess board where $k$ queens are already placed, find ...
0
{"tests": "{\"inputs\": [\"4\\n\", \"124356983594583453458888889\\n\", \"2\\n\", \"7854\\n\", \"584660\\n\", \"464\\n\", \"192329\\n\", \"85447\\n\", \"956\\n\", \"83\\n\", \"33\\n\", \"64\\n\", \"971836\\n\", \"578487\\n\", \"71752\\n\", \"2563\\n\", \"51494\\n\", \"247\\n\", \"52577\\n\", \"13\\n\", \"26232\\n\", \"0...
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:(1^{n} + 2^{n} + 3^{n} + 4^{n}) mod 5 for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language). --...
0.75
{"tests": "{\"inputs\": [\"4 5\\nabcde\\nabcde\\nabcde\\nabcde\\n1 1 1 1 1\\n1 1 1 1 1\\n1 1 1 1 1\\n1 1 1 1 1\\n\", \"4 3\\nabc\\naba\\nadc\\nada\\n10 10 10\\n10 1 10\\n10 10 10\\n10 1 10\\n\", \"3 3\\nabc\\nada\\nssa\\n1 1 1\\n1 1 1\\n1 1 1\\n\", \"5 2\\naa\\naa\\nab\\nbb\\nbb\\n1 100\\n100 100\\n1 1\\n100 100\\n100 ...
You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English alphabet, such that this string is the only string in the multiset that has letter c in position i....
0
{"tests": "{\"inputs\": [\"3\\n21\\n0\\n1\\n\", \"1\\n420441920\\n\", \"1\\n4\\n\", \"1\\n297540\\n\", \"1\\n9\\n\", \"1\\n144\\n\", \"1\\n16\\n\", \"1\\n25\\n\", \"1\\n999944\\n\", \"1\\n6\\n\", \"1\\n14\\n\", \"1\\n81\\n\", \"1\\n2\\n\", \"1\\n36\\n\", \"1\\n2925\\n\", \"1\\n5704\\n\", \"1\\n4104\\n\", \"1\\n1980\\n\...
Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero. Consider the following problem: You are given two integers n and m. You have to construct an m-free square matrix of size n × n such that...
0
{"tests": "{\"inputs\": [\"1593 4311\\n4321 2155\\n1256 6421\\n5310 1455\\n2152 5421\\n1549 3386\\n4528 1578\\n1234 4321\\n3330 3109\\n2739 2199\\n0 0\", \"1593 4311\\n4321 2155\\n1256 6421\\n5310 1455\\n2152 5421\\n1549 3288\\n4528 3719\\n1234 4321\\n3330 3109\\n2739 2199\\n0 0\", \"1593 4311\\n4321 2155\\n1256 6421\\...
In Aizuwakamatsu City, there is a first city called "Tokaichi" on January 10th every year. This Tokaichi has a history of about 600 years and is the largest first city in the Aizu region. It is also well known that Okiagari-koboshi, a familiar lucky charm, is sold in the Aizu region. Okiagari-koboshi is a papier-mâché ...
0
{"tests": "{\"inputs\": [\"119107271329329921\", \"27\", \"5\", \"9\", \"7\", \"8\", \"11\", \"6\", \"10\", \"12\", \"20\", \"33213408621377322\", \"45\", \"26939847318901699\", \"12809773843701327\", \"15368855316243065\", \"15\", \"5452054052106793\", \"18\", \"4107947535538903\", \"14\", \"5955896644305351\", \"7789...
There are N people (with different names) and K clubs. For each club you know the list of members (so you have K unordered lists). Each person can be a member of many clubs (and also 0 clubs) and two different clubs might have exactly the same members. The value of the number K is the minimum possible such that the fol...
0
{"tests": "{\"inputs\": [\"8\\n5 2\\nWLWLL\\n6 5\\nLLLWWL\\n7 1\\nLWLWLWL\\n15 5\\nWWWLLLWWWLLLWWW\\n40 7\\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\\n1 0\\nL\\n1 1\\nL\\n6 1\\nWLLWLW\\n\", \"8\\n5 2\\nWLWLL\\n6 5\\nLLLWWL\\n7 2\\nLWLWLWL\\n15 5\\nWWWLLLWWWLLLWWW\\n40 7\\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\\n1 0\...
You like playing chess tournaments online. In your last tournament you played $n$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $0$ points. When you win you get $1$ or $2$ points: if you have won also the previous game you get $2$ points, otherwise ...
0
{"tests": "{\"inputs\": [\"4\\n4 4 4\\n\", \"5\\n2 3 5 5\\n\", \"2\\n2\\n\", \"10\\n2 10 8 7 8 8 10 9 10\\n\", \"3\\n3 3\\n\", \"4\\n3 3 4\\n\", \"5\\n4 4 4 5\\n\", \"6\\n3 3 6 6 6\\n\", \"7\\n7 3 4 6 6 7\\n\", \"8\\n3 7 7 8 8 7 8\\n\", \"9\\n2 9 7 6 9 7 8 9\\n\", \"7\\n7 3 4 6 6 7\\n\", \"4\\n3 3 4\\n\", \"6\\n3 3 6 6...
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to a_{i} inclusive. No tickets are sold at the last station. Let ρ_{i}, j be the minimum number of tickets one needs to buy in order to get from stations i to stat...
0.25
{"tests": "{\"inputs\": [\"3 3 10\\n10 9 6\\n14 7 3\\n7 5 1\", \"3 3 10\\n10 8 13\\n14 3 4\\n5 5 1\", \"3 3 10\\n10 8 13\\n14 3 4\\n5 4 1\", \"1 2 5\\n4\\n10000\", \"2 3 5\\n4 5\\n6 3\\n8 6\", \"2 2 6\\n3 2\\n5 4\", \"3 3 10\\n10 9 6\\n11 7 3\\n7 5 1\", \"3 3 10\\n10 4 6\\n14 7 3\\n7 5 1\", \"3 3 10\\n10 8 11\\n1 7 3\\...
After many years of research, Ikta has acquired the ability to predict the future! The time and money he spent on this research was enormous, but it's finally time to be rewarded. To get the money back, Ikta decided to start investing in stocks. Ikta does not currently own any shares, but owns x yen. He has invested i...
0
{"tests": "{\"inputs\": [[2000, 3], [2000, 4], [2000, 7], [3000, 7], [4000, 4], [5000, 2], [5000, 3], [5000, 4], [5000, 5], [5000, 6], [5000, 7], [5000, 8], [5000, 9]], \"outputs\": [[[11, 1110, 12555]], [[21, 1120, 23665]], [[85, 1200, 99986]], [[141, 1600, 220756]], [[35, 2000, 58331]], [[5, 1100, 6111]], [[15, 1200,...
We want to find the numbers higher or equal than 1000 that the sum of every four consecutives digits cannot be higher than a certain given value. If the number is ``` num = d1d2d3d4d5d6 ```, and the maximum sum of 4 contiguous digits is ```maxSum```, then: ```python d1 + d2 + d3 + d4 <= maxSum d2 + d3 + d4 + d5 <= maxS...
0
{"tests": "{\"inputs\": [\"10 100000\\n1 49856 954208\\n98389 98970 222740\\n78151 99991 323776\\n63089 100000 263298\\n19955 99994 342017\\n27228 99998 310177\\n13398 98500 187599\\n95925 99993 643614\\n36475 99999 556166\\n1224 98485 55420\\n\", \"4 10\\n6 10 4\\n1 5 7\\n2 6 5\\n5 9 8\\n\", \"7 10\\n1 4 13\\n5 6 10\\...
You are given n segments on a number line, numbered from 1 to n. The i-th segments covers all integer points from l_i to r_i and has a value w_i. You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it's possible to travel between two integer points if there exists a...
0
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n6 5 4\\n\", \"3\\n1 1000 10000\\n10 100 100000\\n\", \"6\\n12 8 12 17 20 5\\n17 4 8 8 8 4\\n\", \"6\\n16 20 18 7 14 2\\n17 12 4 10 7 4\\n\", \"6\\n4 1 12 9 3 11\\n12 20 19 12 19 11\\n\", \"1\\n7\\n5\\n\", \"2\\n1 2\\n1 1\\n\", \"1\\n1\\n1\\n\", \"6\\n12 8 12 17 20 5\\n17 4 8 8 8 4...
Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends...
0
{"tests": "{\"inputs\": [[\"a1\", \"g5\"], [\"a3\", \"e4\"], [\"f3\", \"f2\"], [\"b7\", \"a8\"], [\"f7\", \"d3\"], [\"g2\", \"c3\"], [\"f3\", \"c1\"], [\"d4\", \"h8\"], [\"h6\", \"a7\"], [\"a6\", \"g3\"], [\"e1\", \"b4\"], [\"f4\", \"c4\"], [\"c3\", \"e8\"], [\"b5\", \"e5\"], [\"c8\", \"g8\"], [\"a6\", \"b5\"], [\"b3\"...
# Task An `amazon` (also known as a queen+knight compound) is an imaginary chess piece that can move like a `queen` or a `knight` (or, equivalently, like a `rook`, `bishop`, or `knight`). The diagram below shows all squares which the amazon attacks from e4 (circles represent knight-like moves while crosses correspond ...
0