info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"4\\n100 0\\n0 100\\n-100 0\\n0 -100\\n\", \"7\\n0 2\\n1 0\\n-3 0\\n0 -2\\n-1 -1\\n-1 -3\\n-2 -3\\n\", \"5\\n0 0\\n0 -1\\n3 0\\n-2 0\\n-2 1\\n\", \"5\\n0 0\\n2 0\\n0 -1\\n-2 0\\n-2 1\\n\", \"2\\n1000000000 1000000000\\n-1000000000 -1000000000\\n\", \"22\\n-1000000000 -379241\\n993438994 -99343...
There are $n$ detachments on the surface, numbered from $1$ to $n$, the $i$-th detachment is placed in a point with coordinates $(x_i, y_i)$. All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one det...
0
{"tests": "{\"inputs\": [\"6\\nLLRLLL\\n\", \"4\\nRRLL\\n\", \"4\\nLLRR\\n\", \"6\\nRLLRRL\\n\", \"8\\nLRLRLLLR\\n\", \"10\\nRLLRLRRRLL\\n\", \"12\\nLRRRRRLRRRRL\\n\", \"14\\nRLLRLLLLRLLLRL\\n\", \"16\\nLLLRRRLRRLLRRLLL\\n\", \"18\\nRRRLLLLRRRLRLRLLRL\\n\", \"20\\nRLRLLRLRRLLRRRRRRLRL\\n\", \"22\\nRLLLRLLLRRLRRRLRLLLLL...
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the $\frac{n}{2}$ desks, two people at each desk. Vasily quickly realized that number n is even. Like all true mathematicians, Vasily has all students numbered from 1 to n. But Vasily Petrov did not like the way ...
0.125
{"tests": "{\"inputs\": [\"4\\n4 2 2 3\\n\", \"6\\n1 1 1 1 1 3\\n\", \"1\\n3\\n\", \"7\\n5 3 3 5 5 4 4\\n\", \"8\\n3 3 3 3 3 3 3 1\\n\", \"15\\n4 4 4 3 2 1 5 3 5 3 4 1 2 4 4\\n\", \"20\\n4 5 3 4 5 4 2 4 2 1 5 3 3 1 4 1 2 4 4 3\\n\", \"28\\n1 3 4 4 4 3 1 4 5 1 3 5 3 2 5 1 4 4 5 3 4 2 5 4 2 5 3 2\\n\", \"30\\n1 5 5 5 5 5...
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more par...
0
{"tests": "{\"inputs\": [\"NEAT\\n\", \"WORD\\n\", \"CODER\\n\", \"APRILFOOL\\n\", \"AI\\n\", \"JUROR\\n\", \"YES\\n\", \"Q\\n\", \"PUG\\n\", \"SOURPUSS\\n\", \"CROUP\\n\", \"BURG\\n\", \"DODO\\n\", \"WET\\n\", \"MAYFLY\\n\", \"VITALIZE\\n\", \"KHAKI\\n\", \"WAXY\\n\", \"WEEVIL\\n\", \"THIAMINE\\n\", \"ALKALINITY\\n\",...
-----Input----- The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. -----Output----- Output "YES" or "NO". -----Examples----- Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI ...
0
{"tests": "{\"inputs\": [\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\", \"13\\n\", \"14\\n\", \"15\\n\", \"450\\n\", \"999\\n\", \"1000\\n\", \"16\\n\", \"17\\n\", \"18\\n\", \"19\\n\", \"20\\n\", \"21\\n\", \"22\\n\", \"23\\n\", \"24\\n\", \"2...
Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys... It took Neko an entire day to turn back to normal. Neko reported to Aki that he saw a lot of w...
0
{"tests": "{\"inputs\": [\"4\\n2 3\\n\", \"5\\n3 5\\n\", \"2\\n2 2\\n\", \"1000000000000000000\\n1000000000000000000 1000000000000000000\\n\", \"1000000000000000000\\n1 1\\n\", \"2\\n1 1\\n\", \"1234567890123456\\n1234567889969697 153760\\n\", \"12000000000000\\n123056 11999999876946\\n\", \"839105509657869903\\n591153...
On a chessboard with a width of $n$ and a height of $n$, rows are numbered from bottom to top from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. Therefore, for each cell of the chessboard, you can assign the coordinates $(r,c)$, where $r$ is the number of the row, and $c$ is the number of the col...
0.875
{"tests": "{\"inputs\": [\"4 3\\n-5 20 -3 0\\n\", \"4 2\\n-5 20 -3 0\\n\", \"10 6\\n2 -5 1 3 0 0 -4 -3 1 0\\n\", \"4 4\\n-5 20 -3 0\\n\", \"4 1\\n-5 20 -3 0\\n\", \"1 0\\n-13\\n\", \"2 0\\n-12 -13\\n\", \"3 1\\n9 -16 -7\\n\", \"5 5\\n-15 -10 -20 -19 -14\\n\", \"7 3\\n-2 -14 3 -17 -20 -13 -17\\n\", \"10 10\\n-9 4 -3 16 ...
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of win...
0
{"tests": "{\"inputs\": [\"5 5 1 2\\n1 2\\n3 1\\n4 3\\n3 4\\n1 4\\n\", \"3 3 5 2\\n3 1\\n4 0\\n5 1\\n\", \"3 3 2 4\\n0 1\\n2 1\\n1 2\\n\", \"3 3 1 1\\n0 0\\n1 1\\n0 2\\n\", \"9 10 5 2\\n22 5\\n25 0\\n29 0\\n31 2\\n32 5\\n31 8\\n29 10\\n25 10\\n23 8\\n\", \"10 10 2 4\\n-4 5\\n-3 2\\n-1 0\\n3 0\\n5 2\\n6 5\\n5 8\\n3 10\\...
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
0
{"tests": "{\"inputs\": [\"1\\n1\\n\", \"2\\n1 2\\n\", \"4\\n1 2 3 4\\n\", \"3\\n1 1 1\\n\", \"3\\n1 2 2\\n\", \"5\\n1 1 1 1 2\\n\", \"6\\n1 2 3 3 2 1\\n\", \"7\\n6 5 4 3 2 1 0\\n\", \"10\\n1 2 1 2 1 2 1 2 1 2\\n\", \"11\\n1 1 1 1 1 2 2 2 2 2 1\\n\", \"3\\n1 2 1\\n\", \"4\\n562617869 961148050 596819899 951133776\\n\",...
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct po...
0.125
{"tests": "{\"inputs\": [\"1 0\\n\", \"1 1\\n\", \"5 58\\n\", \"17 1000000000\\n\", \"17 262144\\n\", \"7 262143\\n\", \"17 262142\\n\", \"17 131072\\n\", \"17 131071\\n\", \"17 131070\\n\", \"17 65536\\n\", \"17 65535\\n\", \"17 65534\\n\", \"17 2\\n\", \"17 1\\n\", \"17 0\\n\", \"0 1000000000\\n\", \"0 2\\n\", \"0 1\...
Construct a sequence a = {a_1,\ a_2,\ ...,\ a_{2^{M + 1}}} of length 2^{M + 1} that satisfies the following conditions, if such a sequence exists. - Each integer between 0 and 2^M - 1 (inclusive) occurs twice in a. - For any i and j (i < j) such that a_i = a_j, the formula a_i \ xor \ a_{i + 1} \ xor \ ... \ xor \ a_...
0
{"tests": "{\"inputs\": [\"2 0 0 0 4\\n\", \"1 1 1 4 4\\n\", \"4 5 6 5 6\\n\", \"10 20 0 40 0\\n\", \"9 20 0 40 0\\n\", \"5 -1 -6 -5 1\\n\", \"99125 26876 -21414 14176 17443\\n\", \"8066 7339 19155 -90534 -60666\\n\", \"100000 -100000 -100000 100000 100000\\n\", \"10 20 0 41 0\\n\", \"25 -64 -6 -56 64\\n\", \"125 455 4...
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
0
{"tests": "{\"inputs\": [\"3\\n7 11\\n2 9 1 3 18 1 4\\n4 35\\n11 9 10 7\\n1 8\\n5\\n\", \"1\\n10 1000000000\\n5 6 7 4 1000000000 10 74 1000000000 1000000000 1000000000\\n\", \"1\\n24 1\\n2 1 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000...
New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus. Vasya's verse contains $n$ parts. It takes $a_i$ seconds to recite the $i$-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes $a_1$ seconds, secondly — the part wh...
0.5
{"tests": "{\"inputs\": [\"4\\n1 2 1 0\\n\", \"6\\n2 0 1 3 2 0\\n\", \"3\\n0 2 2\\n\", \"2\\n0 0\\n\", \"2\\n1 0\\n\", \"2\\n0 1\\n\", \"2\\n1 1\\n\", \"3\\n1 1 0\\n\", \"3\\n0 1 1\\n\", \"3\\n1 0 0\\n\", \"3\\n2 0 0\\n\", \"3\\n1 0 1\\n\", \"3\\n1 1 1\\n\", \"40\\n3 3 2 1 0 0 0 4 5 4 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 ...
Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!". Not all students are equally sociable. About each student you know the value a_{i} — the maximum number of messages which the i-th student is agree to send per da...
0
{"tests": "{\"inputs\": [\"4 4\\n5 2 4 1\\n\", \"3 20\\n199 41 299\\n\", \"5 10\\n47 100 49 2 56\\n\", \"5 1000\\n38361 75847 14913 11499 8297\\n\", \"10 10\\n48 33 96 77 67 59 35 15 14 86\\n\", \"10 1000\\n16140 63909 7177 99953 35627 40994 29288 7324 44476 36738\\n\", \"30 10\\n99 44 42 36 43 82 99 99 10 79 97 84 5 7...
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b_1, b_2, ..., b_{k} (1 ≤ b_1 < b_2 < ... < b_{k} ≤ n) in such a way that the value of $\sum_{i = 1}^{k} a_{b_{i}} \operatorname{mod} m$ is maximized. Chosen sequence can be empty. Print the ma...
0
{"tests": "{\"inputs\": [\"1 1 -3\\n0 3 3 0\\n\", \"3 1 -9\\n0 3 3 -1\\n\", \"-6 -9 -7\\n1 -8 -4 -3\\n\", \"407 -599 272\\n-382 -695 -978 -614\\n\", \"944189733 -942954006 219559971\\n-40794646 -818983912 915862872 -115357659\\n\", \"664808710 -309024147 997224520\\n-417682067 -256154660 -762795849 -292925742\\n\", \"3...
In this problem we consider a very simplified model of Barcelona city. Barcelona can be represented as a plane with streets of kind $x = c$ and $y = c$ for every integer $c$ (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Di...
0
{"tests": "{\"inputs\": [\"4\\nmail\\nai\\nlru\\ncf\\n\", \"3\\nkek\\npreceq\\ncheburek\\n\", \"1\\nz\\n\", \"2\\nab\\nba\\n\", \"2\\nac\\nbc\\n\", \"2\\ncd\\nce\\n\", \"2\\nca\\ncb\\n\", \"2\\ndc\\nec\\n\", \"26\\nhw\\nwb\\nba\\nax\\nxl\\nle\\neo\\nod\\ndj\\njt\\ntm\\nmq\\nqf\\nfk\\nkn\\nny\\nyz\\nzr\\nrg\\ngv\\nvc\\n...
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
0
{"tests": "{\"inputs\": [\"2\\n1\\n1\\n\", \"3\\n1\\n1\\n1\\n\", \"4\\n1\\n2\\n2\\n3\\n\", \"0\\n\", \"1\\n125\\n\", \"2\\n472\\n107\\n\", \"3\\n215\\n137\\n256\\n\", \"4\\n49\\n464\\n28\\n118\\n\", \"4\\n172\\n84\\n252\\n163\\n\", \"2\\n66\\n135\\n\", \"1\\n190\\n\", \"3\\n184\\n100\\n71\\n\", \"3\\n361\\n387\\n130\\n...
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x_1, x_2, x_3, x_4} (x_1 ≤ x_2 ≤ x_3 ≤ x_4) arithmetic mean is $\frac{x_{1} + x_{2} + x_{3} + x_{4}}{4}$, ...
0
{"tests": "{\"inputs\": [\"0 0\\n1 1\\n2 2\\n\", \"0 0\\n2 0\\n1 1\\n\", \"0 0\\n0 1\\n0 2\\n\", \"0 0\\n5 0\\n10 0\\n\", \"0 0\\n1 2\\n2 1\\n\", \"0 0\\n5 0\\n0 6\\n\", \"1 0\\n0 1\\n10 10\\n\", \"0 0\\n0 1\\n1 0\\n\", \"0 0\\n0 1\\n1 1\\n\", \"0 0\\n1 1\\n1 0\\n\", \"1 1\\n1 0\\n0 1\\n\", \"1 0\\n1 2\\n1 1\\n\", \"1 ...
The Squareland national forest is divided into equal $1 \times 1$ square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates $(x, y)$ of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land ...
0
{"tests": "{\"inputs\": [\"4 3 1 6\\n\", \"5 5 5 6\\n\", \"1 1 8 8\\n\", \"1 1 8 1\\n\", \"1 1 1 8\\n\", \"8 1 1 1\\n\", \"8 1 1 8\\n\", \"7 7 6 6\\n\", \"8 1 8 8\\n\", \"1 8 1 1\\n\", \"1 8 8 1\\n\", \"1 8 8 8\\n\", \"8 8 1 1\\n\", \"8 8 1 8\\n\", \"8 8 8 1\\n\", \"1 3 1 6\\n\", \"1 3 1 4\\n\", \"1 3 1 5\\n\", \"3 3 2...
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the co...
0.375
{"tests": "{\"inputs\": [\"3 4\\n2 5\\n7 9\\n10 11\\n\", \"5 10\\n5 7\\n11 12\\n16 20\\n25 26\\n30 33\\n\", \"1 1000000000\\n1 1000000000\\n\", \"1 1000000000\\n999999999 1000000000\\n\", \"5 10\\n3 4\\n10 11\\n12 13\\n14 16\\n18 20\\n\", \"5 10\\n2 4\\n5 6\\n7 9\\n16 18\\n19 20\\n\", \"5 10\\n2 4\\n7 9\\n11 12\\n16 17...
A plane is flying at a constant height of $h$ meters above the ground surface. Let's consider that it is flying from the point $(-10^9, h)$ to the point $(10^9, h)$ parallel with $Ox$ axis. A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may star...
0
{"tests": "{\"inputs\": [\"1 2\\n\", \"4 4\\n\", \"5 7\\n\", \"6 2\\n\", \"9 1\\n\", \"1 1\\n\", \"8 9\\n\", \"9 8\\n\", \"9 9\\n\", \"2 4\\n\", \"1 9\\n\", \"6 5\\n\", \"9 2\\n\", \"3 3\\n\", \"8 8\\n\", \"8 1\\n\", \"6 7\\n\", \"9 2\\n\", \"3 2\\n\", \"2 1\\n\", \"1 9\\n\", \"7 6\\n\", \"5 4\\n\", \"6 5\\n\", \"9 9\\...
Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation $a + 1 = b$ with positive integers $a$ and $b$, but Kolya forgot the numbers $a$ and $b$. He does, however, remember that the first (leftmost) digit of $a$ was $d_a$, and the first (leftmost) digit of $b$ was $d_b$...
0
{"tests": "{\"inputs\": [\"2\\n\", \"13\\n\", \"720\\n\", \"0\\n\", \"1\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"637\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"100\\n\", \"99\\n\", \"245\\n\", \"118\\n\", \"429\\n\", \"555\\n\", \"660\\n\", \"331\\n\", \"987\\n\", \"123456789\\n\", \"234567890\\...
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about ...
0
{"tests": "{\"inputs\": [\"5 5\\n\", \"3 6\\n\", \"3 0\\n\", \"1 0\\n\", \"3 3\\n\", \"32 32\\n\", \"32 31\\n\", \"1 1\\n\", \"2 0\\n\", \"3 1\\n\", \"3 2\\n\", \"3 5\\n\", \"3 4\\n\", \"3 10203\\n\", \"3 10100\\n\", \"5 0\\n\", \"5 1\\n\", \"5 2\\n\", \"5 3\\n\", \"5 4\\n\", \"5 6\\n\", \"5 7\\n\", \"5 8\\n\", \"5 9\\...
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to f...
0
{"tests": "{\"inputs\": [\"8 3\\n3 3 1 2 2 1 1 3\\n3 1 1\\n\", \"6 5\\n1 2 4 2 4 3\\n0 0 1 0 0\\n\", \"1 1\\n1\\n1\\n\", \"2 1\\n1 1\\n1\\n\", \"2 1\\n1 1\\n2\\n\", \"2 2\\n1 2\\n1 1\\n\", \"2 2\\n2 2\\n1 1\\n\", \"3 3\\n3 3 2\\n0 0 1\\n\", \"4 4\\n4 4 4 4\\n0 1 1 1\\n\", \"2 2\\n1 1\\n1 0\\n\", \"3 3\\n3 3 3\\n0 0 1\\...
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
0
{"tests": "{\"inputs\": [\"0 2\\n\", \"2 0\\n\", \"2 2\\n\", \"2000 2000\\n\", \"0 0\\n\", \"11 2\\n\", \"1 4\\n\", \"5 13\\n\", \"60 59\\n\", \"27 16\\n\", \"1134 1092\\n\", \"756 1061\\n\", \"953 1797\\n\", \"76 850\\n\", \"24 1508\\n\", \"1087 1050\\n\", \"149 821\\n\", \"983 666\\n\", \"45 1323\\n\", \"1994 1981\\n...
Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements are equal to $-1$. For each such array they counted its maximal pref...
0
{"tests": "{\"inputs\": [\"3 2\\n2 1\\n2 2\\n\", \"9 3\\n1 2 3\\n2 8\\n1 4 5\\n\", \"10 0\\n\", \"10 2\\n1 1 2\\n1 8 9\\n\", \"9 3\\n1 4 5\\n1 1 2\\n1 6 7\\n\", \"7 2\\n2 3\\n1 5 6\\n\", \"81 28\\n1 77 78\\n1 50 51\\n2 9\\n1 66 67\\n1 12 13\\n1 20 21\\n1 28 29\\n1 34 35\\n1 54 55\\n2 19\\n1 70 71\\n1 45 46\\n1 36 37\\n...
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot...
0
{"tests": "{\"inputs\": [\"3\\n#.#\\n...\\n#.#\\n\", \"4\\n##.#\\n#...\\n####\\n##.#\\n\", \"5\\n#.###\\n....#\\n#....\\n###.#\\n#####\\n\", \"5\\n#.###\\n....#\\n#....\\n....#\\n#..##\\n\", \"6\\n#.##.#\\n......\\n#.##.#\\n......\\n##.###\\n#...##\\n\", \"3\\n###\\n#.#\\n###\\n\", \"21\\n#########.###.#####.#\\n#.####...
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile: [Image] By the pieces lay a large square wooden board. The board is divided into $n^2$ cells arranged into ...
0.25
{"tests": "{\"inputs\": [\"4\\n2 1 6 4\\n3 4 4 2\\n\", \"4\\n10 5 6 4\\n1 11 4 2\\n\", \"3\\n10 1 10\\n1 10 1 1\\n\", \"4\\n2 1 6 4\\n4 2 3 5\\n\", \"3\\n20 3 20\\n1 20 1 1\\n\", \"2\\n10 1\\n1 3 2 1\\n\", \"20\\n3 1 9 9 6 1 3 4 5 6 7 3 1 9 9 1 9 1 5 7\\n17 7 19 5\\n\", \"20\\n81 90 11 68 23 18 78 75 45 86 58 37 21 15 ...
Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, b...
0
{"tests": "{\"inputs\": [\"7 11\\n2 4 7 3\\n\", \"1000 999\\n10 20 30 40\\n\", \"4 4\\n1 2 3 4\\n\", \"5 6\\n5 2 4 1\\n\", \"57 88\\n54 30 5 43\\n\", \"700 699\\n687 69 529 616\\n\", \"4 5\\n1 3 4 2\\n\", \"4 6\\n1 3 2 4\\n\", \"5 4\\n2 3 5 4\\n\", \"5 5\\n1 4 2 5\\n\", \"5 7\\n4 3 2 1\\n\", \"5 8\\n2 3 5 1\\n\", \"6 5...
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities. Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea...
0
{"tests": "{\"inputs\": [\"1\\n\", \"2\\n\", \"13\\n\", \"101\\n\", \"1023\\n\", \"9999\\n\", \"10000\\n\", \"2333\\n\", \"9139\\n\", \"9859\\n\", \"5987\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"7\\n\", \"9\\n\", \"10\\n\", \"15\\n\", \"51\\n\", \"99\\n\", \"138\\n\", \"233\\n\", \"666\\n\", \"1234\\n\", \"3567\\n\", \"44...
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. -----Input----- A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). -----Output----- A single number, deno...
0.25
{"tests": "{\"inputs\": [\"4\\n2 5 5 2\\n\", \"5\\n6 3 4 1 5\\n\", \"8\\n4 4 4 2 2 100 100 100\\n\", \"6\\n10 10 50 10 50 50\\n\", \"1\\n1\\n\", \"100\\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45...
Vasya has an array of integers of length n. Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat...
0.75
{"tests": "{\"inputs\": [\"5 6\\n3 3 3 3 3\\n\", \"3 5\\n1 2 4\\n\", \"5 5\\n2 3 1 4 4\\n\", \"1 1000\\n548\\n\", \"3 3\\n3 1 1\\n\", \"10 17\\n12 16 6 9 12 6 12 1 12 13\\n\", \"24 1\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n\", \"5 2\\n2 1 2 2 2\\n\", \"21 19\\n19 13 2 16 8 15 14 15 7 8 3 17 11 6 1 18 16 6 2...
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera ...
0
{"tests": "{\"inputs\": [\"3 2\\n\", \"3 3\\n\", \"4 0\\n\", \"1337 42\\n\", \"1 0\\n\", \"2 0\\n\", \"2 1\\n\", \"3 0\\n\", \"3 1\\n\", \"4 1\\n\", \"4 2\\n\", \"4 3\\n\", \"4 4\\n\", \"4 5\\n\", \"4 6\\n\", \"3000 0\\n\", \"3000 42\\n\", \"3000 1337\\n\", \"3000 3713\\n\", \"3000 2999\\n\", \"3000 3000\\n\", \"1500 1...
Calculate the number of ways to place $n$ rooks on $n \times n$ chessboard so that both following conditions are met: each empty cell is under attack; exactly $k$ pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. ...
0
{"tests": "{\"inputs\": [\"3\\nRBR\\n\", \"4\\nRBBR\\n\", \"5\\nRBBRR\\n\", \"5\\nRBRBR\\n\", \"10\\nRRBRRBBRRR\\n\", \"10\\nBRBRRRRRRR\\n\", \"10\\nBRRRRRRRRR\\n\", \"20\\nBRBRRRRRRRRRRRRRRRRR\\n\", \"30\\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB\\n\", \"50\\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\\n\", \"20\\nRRRBR...
User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. While the top ball inside the stack is red, pop the ball from the top of the stack. Then replace the blue ball on the top with a red ball. And finally push some blue balls to the...
0
{"tests": "{\"inputs\": [\"4\\n2 1 2 1\\n\", \"5\\n0 -1 -1 -1 -1\\n\", \"2\\n10 8\\n\", \"5\\n-14 -2 0 -19 -12\\n\", \"6\\n-15 2 -19 20 0 9\\n\", \"3\\n17 4 -1\\n\", \"4\\n20 3 -15 7\\n\", \"1\\n11\\n\", \"1\\n-10\\n\", \"7\\n-8 9 0 -10 -20 -8 3\\n\", \"9\\n2 4 -4 15 1 11 15 -7 -20\\n\", \"10\\n-20 0 3 -5 -18 15 -3 -9 ...
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears...
0
{"tests": "{\"inputs\": [\"ababa\\n\", \"zzcxx\\n\", \"yeee\\n\", \"a\\n\", \"bbab\\n\", \"abcd\\n\", \"abc\\n\", \"abcdaaaa\\n\", \"aaaaaaaaaaaaaaa\\n\", \"adb\\n\", \"dcccbad\\n\", \"bcbccccccca\\n\", \"abcdefgh\\n\", \"aabcdef\\n\", \"aabc\\n\", \"ssab\\n\", \"ccdd\\n\", \"abcc\\n\", \"ab\\n\", \"abcde\\n\", \"aa\\n...
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a gr...
0
{"tests": "{\"inputs\": [\"3 0\\n\", \"3 1\\n1 1 3 2\\n\", \"3 2\\n1 1 3 2\\n2 1 3 2\\n\", \"3 2\\n1 1 3 2\\n2 1 3 1\\n\", \"50 0\\n\", \"50 1\\n2 31 38 25\\n\", \"50 2\\n2 38 41 49\\n1 19 25 24\\n\", \"50 10\\n2 4 24 29\\n1 14 49 9\\n2 21 29 12\\n2 2 46 11\\n2 4 11 38\\n2 3 36 8\\n1 24 47 28\\n2 23 40 32\\n1 16 50 38\...
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less...
0
{"tests": "{\"inputs\": [\"3 0\\n\", \"3 1\\n2 > 3\\n\", \"4 1\\n3 = 6\\n\", \"5 2\\n1 < 2\\n9 > 10\\n\", \"35 0\\n\", \"10 5\\n17 <= 10\\n16 >= 18\\n9 > 18\\n8 = 8\\n6 >= 13\\n\", \"5 2\\n1 = 10\\n2 = 9\\n\", \"3 3\\n1 = 2\\n3 = 4\\n5 = 6\\n\", \"4 3\\n2 > 3\\n4 > 5\\n6 > 7\\n\", \"1 1\\n1 > 2\\n\", \"1 1\\n1 <= 2\\n\...
King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital. The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has th...
0
{"tests": "{\"inputs\": [\"0840\\n\", \"02\\n\", \"01\\n\", \"011\\n\", \"001\\n\", \"03\\n\", \"07\\n\", \"0\\n\", \"018473\\n\", \"0198473\\n\", \"01984783\\n\", \"01982373\\n\", \"0198499473\\n\", \"019847003\\n\", \"019258473\\n\", \"01984935\\n\", \"01828473\\n\", \"014039\\n\", \"000473\\n\", \"01992473\\n\", \"0...
Suppose you have a special $x$-$y$-counter. This counter can store some value as a decimal number; at first, the counter has value $0$. The counter performs the following algorithm: it prints its lowest digit and, after that, adds either $x$ or $y$ to its value. So all sequences this counter generates are starting fr...
0
{"tests": "{\"inputs\": [\"4\\n2 4 6 12\\n\", \"2\\n2 3\\n\", \"2\\n1 6\\n\", \"3\\n1 2 7\\n\", \"1\\n1\\n\", \"2\\n1 10\\n\", \"3\\n1 2 6\\n\", \"15\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\\n\", \"14\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14\\n\", \"5\\n2 5 6 7 11\\n\", \"11\\n3 4 5 6 7 8 9 10 11 12 13\\n\", \"3\\n4 9 11\\n\",...
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
0
{"tests": "{\"inputs\": [\"3 3 5\\n\", \"2 4 4\\n\", \"1 1 1\\n\", \"1 1000000000 1000000000\\n\", \"8 7 5\\n\", \"1000000000 1 1\\n\", \"1000000000 1000000000 1000000000\\n\", \"800000003 7 7\\n\", \"11 7 7\\n\", \"1000000000 1 1\\n\", \"100000 100 1000\\n\", \"1000000000 6000 1000000\\n\", \"1 1000000000 1000000000\\...
The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is,...
0
{"tests": "{\"inputs\": [\"A221033\\n\", \"A223635\\n\", \"A232726\\n\", \"A102210\\n\", \"A231010\\n\", \"A222222\\n\", \"A555555\\n\", \"A102222\\n\", \"A234567\\n\", \"A987654\\n\", \"A101010\\n\", \"A246810\\n\", \"A210210\\n\", \"A458922\\n\", \"A999999\\n\", \"A888888\\n\", \"A232232\\n\", \"A222210\\n\", \"A7102...
-----Input----- The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). -----Output----- Output a single integer. -----Examples----- Input A221033 Output 21 Input A223635 Output 22 I...
0
{"tests": "{\"inputs\": [\"6 1\\n5 6 7 8 10 2\\n3 5 6 7 1 10\\n\", \"4 0\\n5 3 2 2\\n13 8 5 1\\n\", \"5 0\\n1 1 1 1 1\\n10 10 10 10 10\\n\", \"5 1\\n1 1 1 1 1\\n10 10 10 10 10\\n\", \"4 2\\n1 1 1 1\\n10 10 10 10\\n\", \"4 2\\n1 2 4 8\\n1 5 3 5\\n\", \"4 2\\n1 2 4 8\\n5 1 3 5\\n\", \"4 2\\n1 2 4 8\\n5 3 1 5\\n\", \"4 2\...
Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it. There are $N$ atoms numbered from $1$ to $N$. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom $i$ req...
0
{"tests": "{\"inputs\": [\"5 10\\n-1 5 0 -5 3\\n\", \"3 4\\n-10 0 20\\n\", \"5 10\\n-5 0 10 -11 0\\n\", \"5 13756\\n-2 -9 -10 0 10\\n\", \"20 23036\\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1\\n\", \"12 82016\\n1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2\\n\", \"7 8555\\n-2 -3 -2 3 0 -2 0\\n\", \"16 76798\\n-1 11 -7 -4 0 -1...
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of i-th day a transaction a_{i} occurs. If a_{i} > 0, then a_{i} bourles are deposited to Luba's account. If a_{i} < 0, then a_{i} bourles are withdrawn. ...
0
{"tests": "{\"inputs\": [\"3\\n1 2 2 1 3 1\\n\", \"1\\n1 1\\n\", \"10\\n3 10 5 5 8 6 6 9 9 3 1 7 10 2 4 9 3 8 2 2\\n\", \"2\\n1 4 2 3\\n\", \"2\\n1 1 2 2\\n\", \"1\\n79808 79808\\n\", \"4\\n56 14 77 12 87 55 31 46\\n\", \"10\\n859983 998985 909455 4688 549610 325108 492856 2751 734117 162579 97740 703983 356830 17839 8...
You're given an array $a$ of length $2n$. Is it possible to reorder it in such way so that the sum of the first $n$ elements isn't equal to the sum of the last $n$ elements? -----Input----- The first line contains an integer $n$ ($1 \le n \le 1000$), where $2n$ is the number of elements in the array $a$. The second...
0
{"tests": "{\"inputs\": [\"3 4 2 1\\n1 2 3 59\\n\", \"3 4 3 3\\n4 4 0 5\\n\", \"1 1 1 1\\n1 3 4 7\\n\", \"1 10 1 4\\n11 12 17 29\\n\", \"3 3 1 2\\n23 8 4 37\\n\", \"10 10 5 5\\n478741118 470168785 859734009 999999937\\n\", \"10 15 7 3\\n680853366 753941356 522057812 999999937\\n\", \"3000 10 1 6\\n709202316 281605678 5...
Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size $n \times m$ cells on a map (rows of grid are numbered from $1$ to $n$ from north to south, and columns are numbered from $1$ to $m$ from west to east). After that he measured the average h...
0
{"tests": "{\"inputs\": [\"1 1 2\\n\", \"3 4 5\\n\", \"4 1 1\\n\", \"1 1 1\\n\", \"1000000 1000000 1000000\\n\", \"3 11 8\\n\", \"8 5 12\\n\", \"1000000 500000 1\\n\", \"1000000 500000 2\\n\", \"2 2 2\\n\", \"3 3 3\\n\", \"4 4 4\\n\", \"2 4 2\\n\", \"10 5 14\\n\", \"10 5 15\\n\", \"10 4 16\\n\", \"3 3 6\\n\", \"9 95 90...
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one...
0.875
{"tests": "{\"inputs\": [\"2\\n2 0\\n0 2\\n\", \"3\\n2 0\\n0 2\\n-2 2\\n\", \"4\\n2 0\\n0 2\\n-2 0\\n0 -2\\n\", \"2\\n2 1\\n1 2\\n\", \"1\\n1 1\\n\", \"10\\n9 7\\n10 7\\n6 5\\n6 10\\n7 6\\n5 10\\n6 7\\n10 9\\n5 5\\n5 8\\n\", \"10\\n-1 28\\n1 28\\n1 25\\n0 23\\n-1 24\\n-1 22\\n1 27\\n0 30\\n1 22\\n1 21\\n\", \"10\\n-5 9...
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a...
0
{"tests": "{\"inputs\": [\"3\\n1 3 2\\n\", \"5\\n1 4 3 1 2\\n\", \"51\\n45 37 1 8 4 41 35 15 17 2 7 48 20 42 41 5 26 25 37 1 19 43 3 49 33 2 45 43 39 14 1 21 22 17 18 8 49 24 35 26 22 43 45 1 3 17 1 16 35 33 5\\n\", \"100\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ...
In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today. You are given an array $a$ of length $n$. Lesha considers all the non-e...
0
{"tests": "{\"inputs\": [\"5 1 3 2\\n\", \"7 2 2 5\\n\", \"4 3 4 0\\n\", \"2 2 0 2\\n\", \"3 2 0 3\\n\", \"1 1 0 1\\n\", \"1 1 1 0\\n\", \"11 2 3 8\\n\", \"2 2 2 0\\n\", \"2 2 1 1\\n\", \"3 2 2 1\\n\", \"3 2 1 2\\n\", \"5 1 4 1\\n\", \"10 1 7 3\\n\", \"20 1 5 15\\n\", \"6 1 3 3\\n\", \"9 2 3 6\\n\", \"9 1 6 3\\n\", \"1...
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black. Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing...
0
{"tests": "{\"inputs\": [\"5\\n2 6 8 7 4\\n\", \"8\\n1 2 3 4 5 6 7 8\\n\", \"4\\n1 2 4 8\\n\", \"2\\n3 4\\n\", \"7\\n1 2 4 6 8 10 12\\n\", \"7\\n1 2 3 4 5 6 8\\n\", \"7\\n1 2 4 8 10 12 6\\n\", \"7\\n3 8 1 4 2 5 6\\n\", \"10\\n5 5 5 5 5 5 5 5 5 5\\n\", \"10\\n5 5 5 5 5 5 3 5 5 5\\n\", \"8\\n3 1 4 1 5 9 2 6\\n\", \"5\\n1...
A sequence $a_1, a_2, \dots, a_k$ is called an arithmetic progression if for each $i$ from $1$ to $k$ elements satisfy the condition $a_i = a_1 + c \cdot (i - 1)$ for some fixed $c$. For example, these five sequences are arithmetic progressions: $[5, 7, 9, 11]$, $[101]$, $[101, 100, 99]$, $[13, 97]$ and $[5, 5, 5, 5, ...
0
{"tests": "{\"inputs\": [\"abcdd\\n\", \"abbcdddeaaffdfouurtytwoo\\n\", \"g\\n\", \"tt\\n\", \"go\\n\", \"eefffffffkkkkxxxx\\n\", \"jjjjjjjjkkdddddiirg\\n\", \"nnnnnnwwwwwwxll\\n\", \"kkkkkccaaaaaqqqqqqqq\\n\", \"iiiiilleeeeeejjjjjjn\\n\", \"xxxxxxxxxxxxxxtttttt\\n\", \"iiiiiitttttyyyyyyyyp\\n\", \"arexjrujgilmbbao\\n\...
Some time ago Lesha found an entertaining string $s$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows. Lesha chooses an arbitrary (possibly zero) number of pairs on positions $(i, i + 1)$ in such a way that the ...
0
{"tests": "{\"inputs\": [\"3 2\\n2 0 2\\n\", \"5 3\\n1 0 0 4 1\\n\", \"1 1\\n0\\n\", \"2 1\\n0 0\\n\", \"2 1\\n0 1\\n\", \"2 1\\n1 0\\n\", \"2 1\\n1 1\\n\", \"2 2\\n0 0\\n\", \"2 2\\n0 1\\n\", \"9 1\\n0 1 1 1 1 1 6 7 8\\n\", \"9 1\\n0 1 1 1 1 5 6 7 8\\n\", \"6 1\\n0 1 2 2 0 0\\n\", \"2 2\\n1 1\\n\", \"2 2\\n1 0\\n\", \...
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate ...
0
{"tests": "{\"inputs\": [\"1\\n1\\n\", \"2\\n10\\n\", \"6\\n100011\\n\", \"4\\n0101\\n\", \"10\\n1101001100\\n\", \"44\\n10010000111011010000111011111010010100001101\\n\", \"80\\n01110111110010110111011110101000110110000111000100111000000101001011111000110011\\n\", \"100\\n0010110000001111110111101011100111101000110011...
After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem. Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa...
0
{"tests": "{\"inputs\": [\"4\\n1 2 2 4\\n\", \"3\\n2 3 3\\n\", \"3\\n2 3 1\\n\", \"1\\n1\\n\", \"16\\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10\\n\", \"20\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\\n\", \"20\\n11 14 2 10 17 5 9 6 18 3 17 7 4 15 17 1 4 14 10 11\\n\", \"100\\n46 7 63 48 75 82 85 90 65 23 36 96 96...
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function $g : \{1,2, \ldots, n \} \rightarrow \{1,2, \ldots, n \}$, that for any $x \in \{1,2, \ldots, n \}$ the formula g(g(x)) = g(x) holds. Let's denote as f^{(}k)(x) the function f applied k time...
0
{"tests": "{\"inputs\": [\"6 6\\nHSHSHS\\n\", \"14 100\\n...HHHSSS...SH\\n\", \"23 50\\nHHSS.......SSHHHHHHHHHH\\n\", \"34 44\\n.HHHSSS.........................HS\\n\", \"34 45\\n.HHHSSS.........................HS\\n\", \"34 34\\n.HHHSSS.........................HS\\n\", \"34 33\\n.HHHSSS.........................HS\\n\"...
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"Dr. Suess, How The Grinch Stole Christmas Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents...
0
{"tests": "{\"inputs\": [\"2\\n6\\n1\\n\", \"10\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"10\\n11\\n12\\n13\\n14\\n15\\n16\\n17\\n18\\n19\\n20\\n\", \"10\\n21\\n22\\n23\\n24\\n25\\n26\\n27\\n28\\n29\\n30\\n\", \"10\\n31\\n32\\n33\\n34\\n35\\n36\\n37\\n38\\n39\\n40\\n\", \"10\\n41\\n42\\n43\\n44\\n45\\n46\\n47\\n...
The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You are given an integer $n$. You have to find a sequence $s$ consisting of digits $\{1, 3, 7\}$ such that it has exactly $n$ subsequences equal to $1337$. For exam...
0
{"tests": "{\"inputs\": [\"4\\n100 10 1 0\\n\", \"3\\n2 70 3\\n\", \"39\\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\\n\", \"50\\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 8...
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d_1, d_2, ..., d_{k}. Vasya wants to choose some inte...
0
{"tests": "{\"inputs\": [\"10 2 1\\n1 1 1\\n1 1 1\\n1 1 1\\n2 2 2\\n2 2 2\\n2 2 2\\n\", \"8 1 1\\n2 2 1\\n3 3 1\\n3 1 3\\n1 1 1\\n2 1 1\\n1 2 3\\n\", \"5 1 1\\n1 2 2\\n2 2 2\\n2 2 2\\n1 2 2\\n2 2 2\\n2 2 2\\n\", \"1 1 1\\n3 3 1\\n1 1 1\\n3 2 2\\n2 2 2\\n1 3 1\\n3 3 2\\n\", \"1 3 1\\n1 3 3\\n2 3 2\\n2 1 3\\n1 3 2\\n3 3 ...
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". ...
0
{"tests": "{\"inputs\": [\"1\\n\", \"3\\n\", \"2\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\", \"13\\n\", \"14\\n\", \"15\\n\", \"16\\n\", \"17\\n\", \"18\\n\", \"19\\n\", \"20\\n\", \"99\\n\", \"100\\n\", \"9999\\n\", \"21736\\n\", \"873467\\n\", \"4124980\\n\", \"5...
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)? The ...
0
{"tests": "{\"inputs\": [\"5\\n2 1 3 0 1\\n\", \"9\\n0 2 3 4 1 1 0 2 2\\n\", \"4\\n0 2 1 1\\n\", \"5\\n1 0 2 1 0\\n\", \"1\\n0\\n\", \"5\\n3 0 4 1 2\\n\", \"3\\n1 0 0\\n\", \"7\\n3 0 0 4 2 2 1\\n\", \"10\\n1 0 2 3 3 0 4 4 2 5\\n\", \"7\\n2 4 3 5 1 6 0\\n\", \"10\\n6 2 8 1 4 5 7 3 9 3\\n\", \"5\\n2 0 3 1 1\\n\", \"7\\n2...
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
0
{"tests": "{\"inputs\": [\"1 1\\n\", \"2 2\\n\", \"100000 3\\n\", \"2344 5\\n\", \"999 10\\n\", \"6 1\\n\", \"43 4\\n\", \"3333 3\\n\", \"4444 4\\n\", \"100000 10\\n\", \"3134 9\\n\", \"9 9\\n\", \"32 9\\n\", \"33333 9\\n\", \"99999 1\\n\", \"99999 9\\n\", \"99999 7\\n\", \"4234 4\\n\", \"66666 6\\n\", \"66666 9\\n\", ...
One beautiful day Vasily the bear painted 2m circles of the same radius R on a coordinate plane. Circles with numbers from 1 to m had centers at points (2R - R, 0), (4R - R, 0), ..., (2Rm - R, 0), respectively. Circles with numbers from m + 1 to 2m had centers at points (2R - R, 2R), (4R - R, 2R), ..., (2Rm - R, 2R), r...
0
{"tests": "{\"inputs\": [\"2 6 2 2\\n\", \"1 9 1 2\\n\", \"1 10000 1 1\\n\", \"9999 10000 10000 10000\\n\", \"1023 2340 1029 3021\\n\", \"2173 2176 10000 9989\\n\", \"1 2 123 1\\n\", \"123 1242 12 312\\n\", \"2 9997 3 12\\n\", \"1 10000 10000 10000\\n\", \"3274 4728 888 4578\\n\", \"4600 9696 5634 8248\\n\", \"2255 790...
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other wi...
0.75
{"tests": "{\"inputs\": [\"4\\n2 3 4\\n*aba\\na*ab\\nba*b\\nabb*\\n\", \"4\\n2 3 4\\n*abc\\na*ab\\nba*b\\ncbb*\\n\", \"3\\n1 2 3\\n*aa\\na*a\\naa*\\n\", \"10\\n9 8 6\\n*abbbababb\\na*babbaaaa\\nbb*bbaabab\\nbab*bbbaab\\nbbbb*baaab\\nababb*baaa\\nbaabab*bba\\naabaaab*ab\\nbaaaaaba*a\\nbabbbaaba*\\n\", \"10\\n3 9 5\\n*aa...
You are playing the following game. There are n points on a plane. They are the vertices of a regular n-polygon. Points are labeled with integer numbers from 1 to n. Each pair of distinct points is connected by a diagonal, which is colored in one of 26 colors. Points are denoted by lowercase English letters. There are ...
0
{"tests": "{\"inputs\": [\"3\\n2 1 3\\n\", \"3\\n1 2 3\\n\", \"99\\n3 1 3 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2\\n\", \"100\\n3 1 3 1 2 1 2 3 1 2 3 2 3 2 3 2 3 1 2 1 ...
The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier. Future students will be asked just a single question. They are given a sequen...
0
{"tests": "{\"inputs\": [\"3\\n\", \"4\\n\", \"10\\n\", \"1\\n\", \"2\\n\", \"5\\n\", \"1248\\n\", \"1000000\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"11\\n\", \"12\\n\", \"13\\n\", \"14\\n\", \"15\\n\", \"16\\n\", \"17\\n\", \"18\\n\", \"19\\n\", \"20\\n\", \"623847\\n\", \"771623\\n\", \"324\\n\", \"98232\\n\",...
Let $n$ be an integer. Consider all permutations on integers $1$ to $n$ in lexicographic order, and concatenate them into one big sequence $p$. For example, if $n = 3$, then $p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]$. The length of this sequence will be $n \cdot n!$. Let $1 \leq i \leq j \leq n \cdot...
0
{"tests": "{\"inputs\": [\"winlose???winl???w??\\nwin\\n\", \"glo?yto?e??an?\\nor\\n\", \"??c?????\\nabcab\\n\", \"ddddd\\nd\\n\", \"ww?ww\\nw\\n\", \"?????\\nn\\n\", \"xznxr\\nxznxr\\n\", \"wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\\nbhghd\\n\", \"emnd?t??m?gd...
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible. H...
0
{"tests": "{\"inputs\": [\"2\\n2 1\\n\", \"3\\n1 2\\n3 2\\n\", \"6\\n1 5\\n3 4\\n6 1\\n3 2\\n3 1\\n\", \"4\\n4 3\\n4 1\\n4 2\\n\", \"5\\n4 1\\n4 5\\n1 2\\n1 3\\n\", \"7\\n5 7\\n2 5\\n2 1\\n1 6\\n3 6\\n4 1\\n\", \"8\\n8 6\\n7 4\\n8 5\\n2 7\\n3 2\\n5 2\\n1 2\\n\", \"9\\n3 1\\n2 7\\n9 2\\n2 1\\n6 9\\n8 9\\n9 5\\n2 4\\n\",...
Eric is the teacher of graph theory class. Today, Eric teaches independent set and edge-induced subgraph. Given a graph $G=(V,E)$, an independent set is a subset of vertices $V' \subset V$ such that for every pair $u,v \in V'$, $(u,v) \not \in E$ (i.e. no edge in $E$ connects two vertices from $V'$). An edge-induced ...
0
{"tests": "{\"inputs\": [\"527\\n\", \"4573\\n\", \"1357997531\\n\", \"444443\\n\", \"22227\\n\", \"24683\\n\", \"11\\n\", \"1435678543\\n\", \"4250769\\n\", \"4052769\\n\", \"5685341\\n\", \"1111111111111111231\\n\", \"333333332379\\n\", \"85\\n\", \"7700016673\\n\", \"3545151980584871227240436532285876424929993850510...
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
0.5
{"tests": "{\"inputs\": [\"4\\n4 2 1 3\\n3 2 4 1\\n\", \"1\\n1\\n1\\n\", \"2\\n1 2\\n1 2\\n\", \"3\\n3 2 1\\n1 3 2\\n\", \"6\\n4 5 2 6 3 1\\n1 5 2 4 6 3\\n\", \"7\\n7 4 6 2 5 1 3\\n7 5 6 1 3 2 4\\n\", \"10\\n5 1 6 2 8 3 4 10 9 7\\n5 1 6 2 8 3 4 10 9 7\\n\", \"9\\n1 6 4 5 9 8 7 3 2\\n2 3 7 8 9 5 4 6 1\\n\", \"8\\n5 8 3 ...
Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid games. Help them obtain the required permutation by paying as little money as possible. More formally, we have two permutations, p and s of numbers from 1 to n. We can swap p_{i} and p_{j}, ...
0
{"tests": "{\"inputs\": [\"1 4\\n2 1 3 2\\n1 2\\n1 3\\n3 4\\n\", \"0 3\\n1 2 3\\n1 2\\n2 3\\n\", \"4 8\\n7 8 7 5 4 6 4 10\\n1 6\\n1 2\\n5 8\\n1 3\\n3 5\\n6 7\\n3 4\\n\", \"7 25\\n113 106 118 108 106 102 106 104 107 120 114 120 112 100 113 118 112 118 113 102 110 105 118 114 101\\n13 16\\n16 23\\n10 19\\n6 9\\n17 20\\n8...
As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value a_{i} associated with it. We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other wo...
0
{"tests": "{\"inputs\": [\"10 5\\n\", \"-10 5\\n\", \"20 -10\\n\", \"-10 -1000000000\\n\", \"-1000000000 -1000000000\\n\", \"1000000000 1000000000\\n\", \"-123131 3123141\\n\", \"-23423 -243242423\\n\", \"123112 4560954\\n\", \"1321 -23131\\n\", \"1000000000 999999999\\n\", \"54543 432423\\n\", \"1 1\\n\", \"-1 -1\\n\"...
Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you t...
0
{"tests": "{\"inputs\": [\"banana\\n4\\n\", \"banana\\n3\\n\", \"banana\\n2\\n\", \"b\\n1\\n\", \"aba\\n2\\n\", \"aaa\\n2\\n\", \"aa\\n3\\n\", \"aaaaaaaabbbbbccccccccccccccccccccccccccccccc\\n7\\n\", \"aaaaa\\n10\\n\", \"baba\\n3\\n\", \"aan\\n5\\n\", \"banana\\n5\\n\", \"a\\n5\\n\", \"aaaaaaa\\n5\\n\", \"abc\\n100\\n\...
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
0
{"tests": "{\"inputs\": [\"5 2\\nIvanov 1 763\\nAndreev 2 800\\nPetrov 1 595\\nSidorov 1 790\\nSemenov 2 503\\n\", \"5 2\\nIvanov 1 800\\nAndreev 2 763\\nPetrov 1 800\\nSidorov 1 800\\nSemenov 2 503\\n\", \"10 2\\nSHiBIEz 2 628\\nXxwaAxB 1 190\\nXwR 2 290\\nRKjOf 2 551\\nTUP 1 333\\nFarsFvyH 1 208\\nCGDYnq 1 482\\nqaM ...
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m ...
0
{"tests": "{\"inputs\": [\"10\\n5 6 5 6\\n6 6 7 7\\n5 8 6 6\\n9 9 9 9\\n\", \"10\\n6 6 6 6\\n7 7 7 7\\n4 4 4 4\\n8 8 8 8\\n\", \"5\\n3 3 3 3\\n3 3 3 3\\n3 3 3 3\\n3 3 3 3\\n\", \"100000\\n100000 100000 100000 100000\\n100000 100000 100000 100000\\n100000 100000 100000 100000\\n100000 100000 100000 100000\\n\", \"5\\n3 ...
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b...
0
{"tests": "{\"inputs\": [\"0 2 5\\n1 3 5\\n\", \"0 1 3\\n2 3 6\\n\", \"0 1 5\\n2 4 5\\n\", \"1 8 10\\n0 7 9\\n\", \"11 13 18\\n4 6 12\\n\", \"7 13 18\\n2 6 12\\n\", \"372839920 992839201 1000000000\\n100293021 773829394 999999993\\n\", \"100293023 882738299 1000000000\\n0 445483940 500000000\\n\", \"339403920 743344311...
Bob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeating with some period. For example, for Alice days $[l_a; r_a]$ are lucky, then there are some unlucky days: $[r_a ...
0
{"tests": "{\"inputs\": [\"6\\n5 5 5\\n3 2 4\\n1 4 1\\n2 1 3\\n3 2 4\\n3 3 4\\n\", \"7\\n10 7 8\\n5 10 3\\n4 2 6\\n5 5 5\\n10 2 8\\n4 2 1\\n7 7 7\\n\", \"1\\n1 1 1\\n\", \"2\\n2 3 1\\n2 2 3\\n\", \"1\\n1000000000 1000000000 1000000000\\n\", \"3\\n100 100 100\\n25 63 11\\n63 15 11\\n\", \"2\\n999999999 1000000000 100000...
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangul...
0
{"tests": "{\"inputs\": [\"2 2\\n1 0\\n0 0\\n\", \"2 3\\n1 1 1\\n1 1 1\\n\", \"2 3\\n0 1 0\\n1 1 1\\n\", \"5 5\\n1 1 1 1 1\\n1 0 0 0 0\\n1 0 0 0 0\\n1 0 0 0 0\\n1 0 0 0 0\\n\", \"5 5\\n1 1 1 0 1\\n1 1 0 0 1\\n0 0 1 1 1\\n1 1 1 1 0\\n1 0 1 1 1\\n\", \"5 6\\n1 0 0 0 1 1\\n1 1 1 1 1 1\\n1 1 1 1 1 1\\n1 0 0 0 1 1\\n1 0 0 0...
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: $a_{1} OR a_{2} OR \ldots OR a_{k}$ where $a...
0.25
{"tests": "{\"inputs\": [\"3 3\\n\", \"9 12\\n\", \"8 2\\n\", \"9 13\\n\", \"0 0\\n\", \"2 1\\n\", \"0 15\\n\", \"1 14\\n\", \"2 13\\n\", \"4 11\\n\", \"5 10\\n\", \"6 9\\n\", \"7 8\\n\", \"660 6\\n\", \"3 12\\n\", \"8 7\\n\", \"9 6\\n\", \"10 5\\n\", \"11 4\\n\", \"12 3\\n\", \"13 2\\n\", \"14 1\\n\", \"15 0\\n\", \"9...
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely. Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tom...
0
{"tests": "{\"inputs\": [\"7 3\\n1 2 3\\n1 4 5\\n4 6 7\\n\", \"9 3\\n3 6 9\\n2 5 8\\n1 4 7\\n\", \"5 2\\n4 1 5\\n3 1 2\\n\", \"14 5\\n1 5 3\\n13 10 11\\n6 3 8\\n14 9 2\\n7 4 12\\n\", \"14 6\\n14 3 13\\n10 14 5\\n6 2 10\\n7 13 9\\n12 11 8\\n1 4 9\\n\", \"14 6\\n11 13 10\\n3 10 14\\n2 7 12\\n13 1 9\\n5 11 4\\n8 6 5\\n\",...
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: overall, there must be m dances; exactly three people must take part in each dance; each dance must...
0
{"tests": "{\"inputs\": [\"3\\n0 0 0\\n\", \"5\\n3 3 2 2 2\\n\", \"4\\n0 1 2 3\\n\", \"3\\n1 0 2\\n\", \"3\\n2 1 1\\n\", \"4\\n2 0 0 2\\n\", \"5\\n1 0 3 1 2\\n\", \"4\\n2 2 2 2\\n\", \"10\\n7 7 7 7 7 9 8 8 7 9\\n\", \"1\\n0\\n\", \"36\\n34 35 34 34 32 32 35 34 34 32 33 35 33 35 35 34 35 33 34 35 34 35 35 35 34 35 32 35...
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced. Chouti remembered that $n$ persons took part in that party. To make the party funnier, each person wore one hat among $n$ kinds...
0
{"tests": "{\"inputs\": [\"4\\n1 2\\n3 4\\n3 2\\n\", \"6\\n3 4\\n5 4\\n3 2\\n1 3\\n4 6\\n\", \"8\\n1 3\\n1 6\\n3 4\\n6 2\\n5 6\\n6 7\\n7 8\\n\", \"5\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"3\\n1 2\\n3 2\\n\", \"3\\n1 3\\n2 3\\n\", \"4\\n1 4\\n1 2\\n4 3\\n\", \"4\\n1 2\\n1 3\\n1 4\\n\", \"6\\n1 2...
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
0
{"tests": "{\"inputs\": [\"4\\n0 10 5 15\\n\", \"4\\n0 15 5 10\\n\", \"5\\n0 1000 2000 3000 1500\\n\", \"5\\n-724093 710736 -383722 -359011 439613\\n\", \"50\\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433...
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them...
0.5
{"tests": "{\"inputs\": [\"3 4\\n1**2\\na3*0\\nc4**\\n\", \"5 5\\n#*&#*\\n*a1c&\\n&q2w*\\n#a3c#\\n*&#*&\\n\", \"5 2\\n&l\\n*0\\n*9\\n*#\\n#o\\n\", \"25 16\\nvza**ooxkmd#*ywa\\ndip#*#&ef&z&&&pv\\nwggob&&72#*&&nku\\nrsb##*&jm&#u**te\\nzif#lu#t&2w#jbqb\\nwfo&#&***0xp#&hp\\njbw##h*###nkmkdn\\nqrn*&y#3cnf&d*rc\\nend*zg&0f*&...
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: There is at least one digit in the string, There is at least one lowercase (small) letter of the Latin alphabet in the string, There...
0.25
{"tests": "{\"inputs\": [\"5 6\\n2 1 1\\n5 2 6\\n2 3 2\\n3 4 3\\n4 5 5\\n1 5 4\\n\", \"5 7\\n2 1 5\\n3 2 3\\n1 3 3\\n2 4 1\\n4 3 5\\n5 4 1\\n1 5 3\\n\", \"10 45\\n5 6 8\\n9 4 8\\n7 1 1\\n9 7 1\\n7 2 1\\n1 4 2\\n5 7 7\\n10 5 7\\n7 8 8\\n8 5 4\\n4 7 3\\n1 8 7\\n3 1 9\\n9 1 3\\n10 2 7\\n6 2 7\\n2 5 7\\n5 4 7\\n6 7 6\\n4 2...
Andrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew's city are one-way, and people are not necessary able to travel from one part to another, but it pales in comparison to...
0
{"tests": "{\"inputs\": [\"4 26\\nbear\\n\", \"2 7\\naf\\n\", \"3 1000\\nhey\\n\", \"5 50\\nkzsij\\n\", \"5 500\\nvsdxg\\n\", \"1 0\\na\\n\", \"1 1\\ng\\n\", \"1 25\\nr\\n\", \"1 15\\no\\n\", \"10 100\\naddaiyssyp\\n\", \"50 100\\ntewducenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb\\n\", \"2 1\\nzz\\n\", \"8 8\\nabcdefg...
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only. The distance between two letters is defined as the difference between their positions in the alphabet. For example, $\operatorname{dist}(c, e) = \operatorname{dist}(e, c) = 2$, and $\operatorname{di...
0
{"tests": "{\"inputs\": [\"3 1 1000\\n011\\n\", \"4 4 100500\\n0110\\n1010\\n0101\\n1001\\n\", \"2 0 1000\\n\", \"2 1 1000\\n11\\n\", \"5 0 13\\n\", \"5 3 19\\n10001\\n10001\\n00110\\n\", \"3 0 100500\\n\", \"4 0 100500\\n\", \"5 0 100500\\n\", \"6 0 100500\\n\", \"3 1 100501\\n101\\n\", \"4 2 100501\\n1010\\n1010\\n\"...
An n × n square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2. You are given n and the first m rows of the matrix. Print the number of special n × n matrices, such that the first m rows coincide with the given ones. As the re...
0
{"tests": "{\"inputs\": [\"6\\n4 4 2 5 2 3\\n\", \"9\\n5 1 3 1 5 2 4 2 5\\n\", \"5\\n1558 4081 3591 1700 3232\\n\", \"10\\n3838 1368 4825 2068 4755 2048 1342 4909 2837 4854\\n\", \"10\\n4764 4867 2346 1449 1063 2002 2577 2089 1566 614\\n\", \"10\\n689 3996 3974 4778 1740 3481 2916 2744 294 1376\\n\", \"100\\n1628 4511 ...
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code a_{i} is k...
0.25
{"tests": "{\"inputs\": [\"5 1 2 5 5 2\\n\", \"4 4 2 6 4 2\\n\", \"1 3 1 3 3 1\\n\", \"2 4 1 4 1 4\\n\", \"7 2 7 2 7 3\\n\", \"1 10 6 10 3 10\\n\", \"20 1 20 1 18 20\\n\", \"2 1 3 1 2 2\\n\", \"1 2 2 4 3 2\\n\", \"7 4 3 3 4 3\\n\", \"2 1 9 10 1 8\\n\", \"20 4 8 16 12 16\\n\", \"100 100 100 100 100 100\\n\", \"1 100 100...
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no e...
0
{"tests": "{\"inputs\": [\"5\\n5 2 1 3 4\\n\", \"3\\n1 2 3\\n\", \"4\\n4 3 2 1\\n\", \"5\\n1 2 5 3 4\\n\", \"1\\n1\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"3\\n2 1 3\\n\", \"6\\n4 5 6 1 2 3\\n\", \"10\\n10 5 9 4 1 8 3 7 2 6\\n\", \"3\\n1 3 2\\n\", \"3\\n3 1 2\\n\", \"4\\n1 2 3 4\\n\", \"4\\n2 3 1 4\\n\", \"6\\n3 2 1 6 4...
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages. Recent actions shows a list of n different threads ordered by the time of the latest message in the thread....
0
{"tests": "{\"inputs\": [\"abc\\ncbaabc\\n\", \"aaabrytaaa\\nayrat\\n\", \"ami\\nno\\n\", \"r\\nr\\n\", \"r\\nb\\n\", \"randb\\nbandr\\n\", \"aaaaaa\\naaaaa\\n\", \"aaaaaa\\naaaaaaa\\n\", \"qwerty\\nywertyrewqqq\\n\", \"qwerty\\nytrewq\\n\", \"azaza\\nzazaz\\n\", \"mnbvcxzlkjhgfdsapoiuytrewq\\nqwertyuiopasdfghjklzxcvbn...
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the tra...
0
{"tests": "{\"inputs\": [\"6 6\\n..S...\\n..S.W.\\n.S....\\n..W...\\n...W..\\n......\\n\", \"1 2\\nSW\\n\", \"5 5\\n.S...\\n...S.\\nS....\\n...S.\\n.S...\\n\", \"10 10\\n....W.W.W.\\n.........S\\n.S.S...S..\\nW.......SS\\n.W..W.....\\n.W...W....\\nS..S...S.S\\n....W...S.\\n..S..S.S.S\\nSS.......S\\n\", \"10 10\\n....W....
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog...
0
{"tests": "{\"inputs\": [\"3\\nadd 1\\nremove\\nadd 2\\nadd 3\\nremove\\nremove\\n\", \"7\\nadd 3\\nadd 2\\nadd 1\\nremove\\nadd 4\\nremove\\nremove\\nremove\\nadd 6\\nadd 7\\nadd 5\\nremove\\nremove\\nremove\\n\", \"4\\nadd 1\\nadd 3\\nremove\\nadd 4\\nadd 2\\nremove\\nremove\\nremove\\n\", \"2\\nadd 1\\nremove\\nadd ...
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and thr...
0
{"tests": "{\"inputs\": [\"..-**-..\\n..-**-..\\n..-..-..\\n..-..-..\\n..-..-..\\n..-..-..\\n\", \"**-**-**\\n**-**-**\\n..-**-.*\\n**-**-**\\n..-..-..\\n..-**-..\\n\", \"**-**-*.\\n*.-*.-**\\n**-**-**\\n**-**-**\\n..-..-..\\n..-**-..\\n\", \"..-..-..\\n..-..-..\\n..-..-..\\n..-..-..\\n..-..-..\\n..-..-..\\n\", \"**-**...
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the p...
0
{"tests": "{\"inputs\": [\"4 5\\n3 1 7 5\\n\", \"3 10\\n100 100 100\\n\", \"10 9\\n4 5 5 7 5 4 5 2 4 3\\n\", \"3 3\\n7 12 8\\n\", \"70 3956\\n246 495 357 259 209 422 399 443 252 537 524 299 538 234 247 558 527 529 153 366 453 415 476 410 144 472 346 125 299 321 363 334 297 316 346 309 497 281 163 396 482 254 447 318 31...
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You may perform the following operation on this sequence: choose any element and either increase or decrease it by one. Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can ...
0
{"tests": "{\"inputs\": [\"2 2 3\\n000\\n000\\n\\n111\\n111\\n\", \"3 3 3\\n111\\n111\\n111\\n\\n111\\n111\\n111\\n\\n111\\n111\\n111\\n\", \"1 1 10\\n0101010101\\n\", \"1 1 1\\n0\\n\", \"1 1 1\\n1\\n\", \"3 1 1\\n1\\n\\n1\\n\\n1\\n\", \"3 1 1\\n1\\n\\n0\\n\\n1\\n\", \"1 3 1\\n1\\n1\\n1\\n\", \"1 3 1\\n1\\n0\\n1\\n\", ...
A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer nu...
0
{"tests": "{\"inputs\": [\"3 5\\n\", \"2 4\\n\", \"1 1\\n\", \"4 12\\n\", \"6 49\\n\", \"1 2\\n\", \"2 3\\n\", \"2 1\\n\", \"2 207745\\n\", \"3 6\\n\", \"3 4\\n\", \"3 26412\\n\", \"4 3\\n\", \"4 11\\n\", \"4 68366\\n\", \"5 13\\n\", \"5 4\\n\", \"5 241483\\n\", \"6 48\\n\", \"6 63\\n\", \"6 119733\\n\", \"7 105\\n\", ...
Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be maximized. A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be...
0
{"tests": "{\"inputs\": [\"3\\n2 4 8\\n\", \"4\\n1 -7 -2 3\\n\", \"10\\n35 11 35 28 48 25 2 43 23 10\\n\", \"100\\n437 89 481 95 29 326 10 304 97 414 52 46 106 181 385 173 337 148 437 133 52 136 86 250 289 61 480 314 166 69 275 486 117 129 353 412 382 469 290 479 388 231 7 462 247 432 488 146 466 422 369 336 148 460 41...
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them. The game they came up with has the following rules. In...
0
{"tests": "{\"inputs\": [\"3 3\\n0 0 0\\n0 1 0\\n0 0 0\\n\", \"4 3\\n0 0 0\\n0 0 1\\n1 0 0\\n0 0 0\\n\", \"50 4\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 1 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 ...
Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1...
0
{"tests": "{\"inputs\": [\"5\\n1 0 0 0 1\\n\", \"12\\n0 0 0 0 1 1 1 1 0 1 1 0\\n\", \"2\\n0 1\\n\", \"1\\n0\\n\", \"1\\n1\\n\", \"2\\n1 0\\n\", \"2\\n0 0\\n\", \"2\\n1 1\\n\", \"3\\n0 0 0\\n\", \"3\\n0 0 1\\n\", \"3\\n0 1 0\\n\", \"3\\n0 1 1\\n\", \"3\\n1 0 0\\n\", \"3\\n1 0 1\\n\", \"3\\n1 1 0\\n\", \"3\\n1 1 1\\n\", ...
A lighthouse keeper Peter commands an army of $n$ battle lemmings. He ordered his army to stand in a line and numbered the lemmings from $1$ to $n$ from left to right. Some of the lemmings hold shields. Each lemming cannot hold more than one shield. The more protected Peter's army is, the better. To calculate the prot...
0