info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"3 2\\n2 6\\n4 3\\n1 5\", \"3 4\\n1 4 7 10\\n2 5 8 11\\n3 6 9 12\", \"3 2\\n2 5\\n4 3\\n1 5\", \"3 2\\n2 6\\n4 3\\n2 5\", \"3 2\\n1 6\\n4 3\\n2 5\", \"3 2\\n1 6\\n4 4\\n2 5\", \"3 4\\n1 4 7 10\\n2 6 8 11\\n3 6 9 12\", \"3 2\\n2 5\\n3 3\\n1 5\", \"3 2\\n2 6\\n4 3\\n2 6\", \"3 2\\n1 6\\n4 3\\n2 ...
We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}. You need to rearrange these numbers as follows: 1. First, for each of the N rows, rearrange the number...
0
{"tests": "{\"inputs\": [\"2 3 1\", \"1 3 2\", \"1 3 1\", \"7 1 1\", \"2 3 3\", \"15 8 5\", \"4 3 1\", \"1 2 2\", \"1 5 1\", \"16 8 5\", \"4 6 1\", \"1 9 1\", \"16 8 3\", \"8 6 1\", \"1 9 2\", \"15 8 3\", \"9 6 1\", \"0 9 2\", \"2 6 1\", \"2 7 1\", \"1 7 1\", \"2 7 2\", \"2 6 2\", \"2 2 2\", \"16 8 7\", \"3 6 1\", \"16...
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical l...
0.25
{"tests": "{\"inputs\": [\"3\\n80 0 30\\n50 5 25\\n90 27 50\\n3\\n80 0 30\\n70 5 25\\n71 30 50\\n0\", \"3\\n80 0 30\\n50 5 25\\n90 27 50\\n3\\n80 0 30\\n70 5 25\\n71 30 84\\n0\", \"3\\n80 0 15\\n64 5 25\\n149 27 50\\n3\\n80 0 10\\n70 10 25\\n22 30 84\\n0\", \"3\\n80 0 30\\n50 5 25\\n90 27 50\\n3\\n80 0 30\\n70 5 25\\n7...
In Aizuwakamatsu Village, which is located far north of Aizuwakamatsu City, a bridge called "Yabashi" is the only way to move to the surrounding villages. Despite the large number of passers-by, the bridge is so old that it is almost broken. <image> Yabashi is strong enough to withstand up to 150 [kg]. For example,...
0.875
{"tests": "{\"inputs\": [\"4 3\", \"4 2\", \"6 3\", \"1 2\", \"6 4\", \"8 2\", \"6 1\", \"2 2\", \"6 5\", \"13 2\", \"10 1\", \"14 1\", \"5 2\", \"27 1\", \"4 1\", \"9 3\", \"10 4\", \"8 1\", \"13 4\", \"6 2\", \"16 1\", \"10 2\", \"13 1\", \"3 1\", \"15 4\", \"7 3\", \"12 6\", \"19 2\", \"9 1\", \"11 4\", \"30 2\", \"...
Alice is spending his time on an independent study to apply to the Nationwide Mathematics Contest. This year’s theme is "Beautiful Sequence." As Alice is interested in the working of computers, she wants to create a beautiful sequence using only 0 and 1. She defines a "Beautiful" sequence of length $N$ that consists on...
0.75
{"tests": "{\"inputs\": [\"2\\n10 100\\n100 270\\n2\\n10 100\\n100 280\\n3\\n100 150\\n10 360\\n40 450\\n3\\n100 150\\n10 360\\n40 440\\n2\\n100 10\\n50 200\\n2\\n100 100\\n50 110\\n1\\n15 10\\n4\\n1 10\\n2 20\\n3 100\\n90 200\\n0\", \"2\\n10 100\\n100 270\\n2\\n10 100\\n100 280\\n3\\n100 150\\n10 360\\n40 450\\n3\\n10...
"Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to mov...
0
{"tests": "{\"inputs\": [\"6 3\\n1\\n1\\n2\\n3\\n3\\nQ 5\\nM 3\\nQ 5\\n0 0\", \"6 3\\n2\\n1\\n2\\n3\\n3\\nQ 5\\nM 3\\nQ 5\\n0 0\", \"6 3\\n1\\n1\\n2\\n3\\n3\\nQ 5\\nM 4\\nQ 5\\n0 0\", \"6 3\\n0\\n1\\n2\\n3\\n3\\nQ 5\\nM 5\\nQ 5\\n0 0\", \"6 3\\n0\\n1\\n2\\n3\\n1\\nQ 5\\nM 4\\nQ 4\\n0 0\", \"6 3\\n1\\n2\\n2\\n6\\n3\\nQ ...
You are given a tree T that consists of N nodes. Each node is numbered from 1 to N, and node 1 is always the root node of T. Consider the following two operations on T: * M v: (Mark) Mark node v. * Q v: (Query) Print the index of the nearest marked ancestor of node v which is nearest to it. Initially, only the root no...
0
{"tests": "{\"inputs\": [\"3\\n0 ( 10\\n10 ) 20\\n0 ( 10\", \"3\\n0 ( 10\\n10 ) 5\\n10 ) 5\", \"3\\n0 ) 10\\n10 ( 5\\n10 ( 5\", \"3\\n0 ( 10\\n10 ) 5\\n10 ( 5\", \"3\\n-1 ( 10\\n10 ) 5\\n10 ) 5\", \"3\\n-1 ( 9\\n10 ) 9\\n20 ( 4\", \"3\\n-1 ) 0\\n8 ( 19\\n4 ' 2\", \"3\\n-2 ) 0\\n7 ) 0\\n4 ( 11\", \"3\\n-1 ( 0\\n10 ) 4\\...
International Carpenters Professionals Company (ICPC) is a top construction company with a lot of expert carpenters. What makes ICPC a top company is their original language. The syntax of the language is simply given in CFG as follows: S -> SS | (S) | )S( | ε In other words, a right parenthesis can be closed by a...
0.625
{"tests": "{\"inputs\": [\"1 3\\n0\\n1\", \"1 6\\n0\\n1\", \"2 3\\n0\\n1\", \"1 6\\n1\\n1\", \"2 3\\n0\\n0\", \"1 3\\n1\\n1\", \"1 11\\n0\\n1\", \"1 15\\n0\\n1\", \"1 5\\n2\\n1\", \"1 8\\n0\\n1\", \"1 13\\n0\\n1\", \"1 8\\n1\\n1\", \"1 11\\n1\\n1\", \"1 15\\n1\\n1\", \"1 5\\n1\\n1\", \"1 9\\n0\\n1\", \"1 28\\n1\\n1\", ...
Problem statement N-winged rabbit is on a balance beam of length L-1. The initial position of the i-th rabbit is the integer x_i, which satisfies 0 ≤ x_ {i} \ lt x_ {i + 1} ≤ L−1. The coordinates increase as you move to the right. Any i-th rabbit can jump to the right (ie, move from x_i to x_i + a_i) any number of tim...
0
{"tests": "{\"inputs\": [\"4\\n2 4\\n4 3\\n3 0\\n1 3\\n\", \"3\\n0 0\\n0 2\\n2 0\\n\", \"3\\n97972354 -510322\\n97972814 -510361\\n97972410 -510528\\n\", \"12\\n-83240790 -33942371\\n-83240805 -33942145\\n-83240821 -33941752\\n-83240424 -33941833\\n-83240107 -33942105\\n-83239958 -33942314\\n-83239777 -33942699\\n-8323...
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order. We define the distance between two points p_1 = (x_1...
0
{"tests": "{\"inputs\": [\"5\\n4 3 1 5 3\\n\", \"5\\n0 1 2 3 4\\n\", \"7\\n7 2 7 3 3 1 4\\n\", \"5\\n1 1 2 1 2\\n\", \"12\\n12 8 1 3 7 5 9 6 4 10 11 2\\n\", \"6\\n5 1 4 2 6 3\\n\", \"8\\n0 9 7 5 8 6 9 3\\n\", \"1\\n1337\\n\", \"9\\n5 1 3 6 8 2 9 0 10\\n\", \"7\\n3 2 0 1 0 1 2\\n\", \"1\\n0\\n\", \"7\\n1 2 3 3 3 3 4\\n\...
Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing. Strictly increasing sequence is a sequence of integers [x_1 < x_2 < ... < x_k]. And strictly decreasing sequence is a sequence of integers [y_1 > y_2 > ... > y_l]. Note that the empty sequence and th...
0.375
{"tests": "{\"inputs\": [\"3\\n110\\n011\\n100\\n100\\n011\\n100\\n100\\n\", \"2\\n11\\n11\\n00\\n01\\n11\\n\", \"2\\n10\\n00\\n00\\n00\\n10\\n\", \"2\\n10\\n10\\n01\\n01\\n10\\n\", \"3\\n100\\n100\\n111\\n000\\n000\\n000\\n101\\n\", \"2\\n10\\n11\\n00\\n00\\n11\\n\", \"3\\n110\\n010\\n100\\n100\\n011\\n100\\n100\\n\",...
For her birthday Alice received an interesting gift from her friends – The Light Square. The Light Square game is played on an N × N lightbulbs square board with a magical lightbulb bar of size N × 1 that has magical properties. At the start of the game some lights on the square board and magical bar are turned on. The...
0.375
{"tests": "{\"inputs\": [\"5\\n3 4 2 1 2\\n4 2 1 5 4\\n5 3 2 1 1\\n1 2\\n3 2\\n4 3\\n5 3\\n\", \"5\\n3 4 2 1 2\\n4 2 1 5 4\\n5 3 2 1 1\\n1 2\\n3 2\\n4 3\\n5 4\\n\", \"3\\n3 2 3\\n4 3 2\\n3 1 3\\n1 2\\n2 3\\n\", \"7\\n1 8 3 2 6 3 2\\n2 6 6 5 4 1 9\\n6 4 7 1 5 5 2\\n2 6\\n1 6\\n6 4\\n3 4\\n2 5\\n7 1\\n\", \"4\\n2 3 5 2\\...
You are given a tree consisting of n vertices. A tree is an undirected connected acyclic graph. <image> Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color. You have to paint the vertices so that any path consisting of exactly th...
0.125
{"tests": "{\"inputs\": [\"3 3\\n101\\n001\\n110\\n\", \"7 15\\n000100001010010\\n100111010110001\\n101101111100100\\n010000111111010\\n111010010100001\\n000011001111101\\n111111011010011\\n\", \"2 58\\n1100001110010010100001000000000110110001101001100010101110\\n11101100101011110011100100011000100010101000111111101101...
A binary matrix is called good if every even length square sub-matrix has an odd number of ones. Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all. All the terms above have their...
0.125
{"tests": "{\"inputs\": [\"3 6 1 4\\n\", \"1 1 4 4\\n\", \"4 7 12 15\\n\", \"1 463129088 536870913 1000000000\\n\", \"1 4 4 7\\n\", \"1 2 3 3\\n\", \"1 1 2 1000000000\\n\", \"8136 12821 10573 15189\\n\", \"169720415 312105195 670978284 671296539\\n\", \"654444727 988815385 77276659 644738371\\n\", \"26733 47464 19138 4...
Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm: * On the first step the string consists of a single character "a". * On the k-th step Polycarpus concatenates two copies of the string obtained on the (k - 1)-th step, while inserting the k-th character of ...
0
{"tests": "{\"inputs\": [\"BBC\\n1 10 1\\n1 10 1\\n21\\n\", \"BSC\\n1 1 1\\n1 1 3\\n1000000000000\\n\", \"BBBSSC\\n6 4 1\\n1 2 3\\n4\\n\", \"B\\n100 100 100\\n1 1 1\\n1\\n\", \"SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\\n94 16 85\\n14 18 91\\n836590091442\\n\",...
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
0.375
{"tests": "{\"inputs\": [\"5\\n2 2 2 2 2\\n\", \"4\\n3 4 8 9\\n\", \"12\\n2 3 4 5 6 7 8 9 10 11 12 13\\n\", \"24\\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\\n\", \"15\\n3 3 3 3 3 3 3 4 2 4 2 2 2 4 2\\n\", \"152\\n29 23 17 25 13 29 29 29 25 23 25 29 19 25 13 25 13 23 21 27 15 29 29 25 27 17 17 19 ...
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 2. Each table has at least 3 foxes sitting around it. 3...
0
{"tests": "{\"inputs\": [\"5\\n1 1 2 3 3\\n\", \"4\\n0 1 2 3\\n\", \"2\\n95745 95745\\n\", \"100\\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 730...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
0.25
{"tests": "{\"inputs\": [\"A232726\\n\", \"A223635\\n\", \"A221033\\n\", \"A222222\\n\", \"A101010\\n\", \"A999999\\n\", \"A910224\\n\", \"A232232\\n\", \"A767653\\n\", \"A458922\\n\", \"A764598\\n\", \"A987654\\n\", \"A332567\\n\", \"A638495\\n\", \"A234567\\n\", \"A292992\\n\", \"A102222\\n\", \"A710210\\n\", \"A9876...
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 Input A232726 Outpu...
0
{"tests": "{\"inputs\": [\"5\\n2 1 6\\n0 4 1\\n2 -1 3\\n1 -2 1\\n4 -1 1\\n\", \"8\\n0 0 1\\n0 0 2\\n0 0 3\\n0 0 4\\n0 0 5\\n0 0 6\\n0 0 7\\n0 0 8\\n\", \"2\\n281573 0 281573\\n706546 0 706546\\n\", \"1\\n72989 14397 49999\\n\", \"20\\n-961747 0 961747\\n-957138 0 957138\\n-921232 0 921232\\n-887450 0 887450\\n-859109 0...
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which i...
0
{"tests": "{\"inputs\": [\"12 23 3\\n\", \"1 10 2\\n\", \"6 19 5\\n\", \"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\", ...
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\": [\"4 3\\n1 1 1 0\\n0 1\\n0 2\\n3 0\\n\", \"4 3\\n0 1 0 1\\n0 1\\n1 2\\n2 3\\n\", \"2 1\\n0 1\\n0 1\\n\", \"10 14\\n1 1 0 0 1 0 1 0 1 1\\n0 1\\n0 2\\n0 4\\n0 9\\n1 3\\n2 5\\n3 4\\n3 6\\n3 8\\n4 9\\n5 6\\n6 7\\n7 8\\n7 9\\n\", \"10 19\\n0 0 0 0 0 0 0 0 1 1\\n0 1\\n0 3\\n0 4\\n1 2\\n1 3\\n1 4\\n1 5...
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular dependencies between tasks. A task can only be executed if all tasks it depen...
0
{"tests": "{\"inputs\": [\"5 1\\n1 999999997 999999998 999999999 1000000000\", \"16 10\\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408\", \"2 100\\n1 10\", \"10 8851025\\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746\", \"5 1\\n1 1856513539 999999998 999999999 100...
Snuke has decided to use a robot to clean his room. There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0. For the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \leq 10^{9} holds. The robot is initi...
0
{"tests": "{\"inputs\": [\"2006\\n1111\", \"2006\\n1101\", \"2006\\n0101\", \"2006\\n0100\", \"2006\\n1100\", \"2006\\n1000\", \"2006\\n1001\", \"2006\\n1011\", \"2006\\n1010\", \"2006\\n0010\", \"2006\\n0011\", \"2006\\n0001\", \"2006\\n0000\", \"2006\\n0110\", \"2006\\n0111\", \"2006\\n1110\", \"2006\\n1101\", \"2006...
<image> At the request of a friend who started learning abacus, you decided to create a program to display the abacus beads. Create a program that takes a certain number as input and outputs a row of abacus beads. However, the number of digits of the abacus to be displayed is 5 digits, and the arrangement of beads fr...
0
{"tests": "{\"inputs\": [\"0100\\n0101\\n10100\\n01000\\n0101011\\n0011\\n011111\\n#\", \"0100\\n0101\\n10100\\n01000\\n0101011\\n0011\\n011110\\n#\", \"0100\\n1101\\n10100\\n11000\\n0001011\\n0011\\n011110\\n#\", \"0100\\n1101\\n10000\\n10000\\n0001011\\n0011\\n011110\\n#\", \"0100\\n0101\\n10100\\n10001\\n0011011\\n1...
Aka Beko, trying to escape from 40 bandits, got lost in the city of A. Aka Beko wants to go to City B, where the new hideout is, but the map has been stolen by a bandit. Kobborg, one of the thieves, sympathized with Aka Beko and felt sorry for him. So I secretly told Aka Beko, "I want to help you go to City B, but I w...
0
{"tests": "{\"inputs\": [\"2 5\\n0 1 0 1 0\\n1 0 0 0 1\\n3 6\\n1 0 0 0 1 0\\n1 1 1 0 1 0\\n1 0 1 1 0 1\\n0 0\", \"2 5\\n0 1 0 1 0\\n1 0 0 0 1\\n3 6\\n1 0 1 0 1 0\\n1 1 1 0 1 0\\n1 0 1 1 0 1\\n0 0\", \"2 5\\n0 1 1 1 0\\n1 0 0 0 1\\n3 6\\n1 0 0 0 1 0\\n1 1 1 0 1 0\\n1 0 1 1 0 1\\n0 0\", \"2 5\\n0 1 0 1 0\\n1 0 0 0 1\\n3 ...
problem At IOI Confectionery, rice crackers are baked using the traditional method since the company was founded. This traditional method is to bake the front side for a certain period of time with charcoal, turn it over when the front side is baked, and bake the back side for a certain period of time with charcoal. W...
0.25
{"tests": "{\"inputs\": [\"3\\n4.0 4.0 3.0\\n5.0 6.0 3.0\\n5.5 4.5 1.0\\n2\\n3.0 3.0 3.0\\n1.5 1.5 1.0\\n0\", \"3\\n4.0 4.0 3.0\\n5.0 6.0 3.0\\n5.5 4.5 1.0\\n2\\n3.0 3.0 3.0\\n1.5 2.4837552710328548 1.0\\n0\", \"3\\n4.0 4.919471432458173 3.0\\n5.0 6.0 3.0\\n5.5 5.446740750188785 1.0\\n2\\n3.0 3.0 3.0\\n2.02017185775911...
A mobile phone company ACMICPC (Advanced Cellular, Mobile, and Internet-Connected Phone Corporation) is planning to set up a collection of antennas for mobile phones in a city called Maxnorm. The company ACMICPC has several collections for locations of antennas as their candidate plans, and now they want to know which ...
0
{"tests": "{\"inputs\": [\"3 6\\nR 1\\nL 2\\nL 5\\n1 10\\nR 1\\n2 10\\nR 5\\nL 7\\n2 10\\nR 3\\nL 8\\n2 99\\nR 1\\nL 98\\n4 10\\nL 1\\nR 2\\nL 8\\nR 9\\n6 10\\nR 2\\nR 3\\nL 4\\nR 6\\nL 7\\nL 8\\n0 0\", \"3 6\\nR 1\\nL 2\\nL 5\\n1 20\\nR 1\\n2 10\\nR 5\\nL 7\\n2 10\\nR 3\\nL 8\\n2 99\\nR 1\\nL 98\\n4 10\\nL 1\\nR 2\\nL...
A straight tunnel without branches is crowded with busy ants coming and going. Some ants walk left to right and others right to left. All ants walk at a constant speed of 1 cm/s. When two ants meet, they try to pass each other. However, some sections of the tunnel are narrow and two ants cannot pass each other. When tw...
0
{"tests": "{\"inputs\": [\"4\\n1.0 0.0 0.0\\n1.5 0.0 3.0\\n2.0 4.0 0.0\\n1.0 3.0 4.0\\n0\", \"4\\n1.0 0.0 0.0\\n1.5 0.0 3.0\\n2.4193437752467455 4.0 0.0\\n1.0 3.0 4.0\\n0\", \"4\\n1.0 0.0 0.5226161732400485\\n1.5 0.0 3.0\\n2.4193437752467455 4.0 0.0\\n1.0 3.0 4.0\\n0\", \"4\\n1.0 0.0 1.3084678474472202\\n1.5 0.0 3.0\\n...
You are given N non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of the largest circle is not double longer than that of the smallest. <image> Figure 1: The Sample Input The distance between two circles C1 and C2 is given by the usual formula <image> where (xi, yi ) is the coor...
0.375
{"tests": "{\"inputs\": [\"2 2\\n2 2\\n3 3\", \"2 2\\n2 1\\n3 3\", \"2 2\\n1 2\\n3 3\", \"1 2\\n2 1\\n3 3\", \"2 4\\n2 2\\n3 3\", \"2 3\\n2 2\\n2 2\", \"1 2\\n3 -1\\n3 2\", \"2 2\\n2 2\\n6 3\", \"2 4\\n2 2\\n6 4\", \"1 2\\n1 2\\n3 1\", \"2 2\\n2 2\\n2 3\", \"2 0\\n2 2\\n2 3\", \"2 0\\n0 2\\n2 3\", \"3 2\\n2 2\\n2 3\", ...
problem AOR Co., Ltd. (Association Of Return home) has $ N $ employees. Employee $ i $ wants to use the elevator to go down to the $ 1 $ floor and arrives in front of the elevator on the $ F_i $ floor at time $ t_i $. You decide to remotely control an elevator that has only $ 1 $ on the $ 1 $ floor at time $ 0 $ and ...
0
{"tests": "{\"inputs\": [\"4\\n4\\n7\\n435\\n479\\n7\\n8\\n1675475\\n9756417\", \"4\\n4\\n7\\n707\\n479\\n7\\n8\\n1675475\\n9756417\", \"4\\n4\\n7\\n707\\n479\\n7\\n8\\n1675475\\n18691566\", \"4\\n4\\n7\\n707\\n479\\n7\\n8\\n1675475\\n9140046\", \"4\\n4\\n7\\n300\\n479\\n5\\n8\\n1675475\\n9140046\", \"4\\n4\\n11\\n551\...
The Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings "47", "744", "4" are lucky while "5", "17", "467" are not. The Little Elephant has the strings A and B of digits. These strings are of equal lengths, t...
0
{"tests": "{\"inputs\": [\"5 3 100\\n11 80\\n14 90\\n23 70\\n80 30\\n153 70\\n\", \"5 6 100\\n11 80\\n14 90\\n23 70\\n80 30\\n153 70\\n\", \"1 3 20\\n20 20\\n\", \"1 7 10\\n40 40\\n\", \"1 4 30\\n10 20\\n\", \"8 1 9999\\n1 0\\n1 0\\n1 0\\n1 0\\n1 0\\n1 0\\n1 0\\n1 0\\n\", \"2 4 345\\n323 40\\n234 20\\n\", \"8 7 1\\n1 9...
Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed. The Dark Assembly consists of n senators. Each of...
0
{"tests": "{\"inputs\": [\"3 3 0\\n\", \"3 2 1\\n\", \"1859 96 1471\\n\", \"555 1594 412\\n\", \"1987 237 1286\\n\", \"1 1 0\\n\", \"3 3 2\\n\", \"369 511 235\\n\", \"918 1704 848\\n\", \"1 534 0\\n\", \"1939 407 1072\\n\", \"22 1481 21\\n\", \"289 393 19\\n\", \"1446 1030 111\\n\", \"1969 30 744\\n\", \"50 2000 40\\n\...
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was s...
0.125
{"tests": "{\"inputs\": [\"3 1\\n\", \"100 100\\n\", \"6 1\\n\", \"94 9\\n\", \"4 35\\n\", \"93 67\\n\", \"45 52\\n\", \"63 1\\n\", \"4 2\\n\", \"8 3\\n\", \"25 2\\n\", \"10 25\\n\", \"5 6\\n\", \"100 1\\n\", \"16 9\\n\", \"84 7\\n\", \"10 5\\n\", \"4 9\\n\", \"4 90\\n\", \"33 3\\n\", \"13 13\\n\", \"15 5\\n\", \"83 1\...
NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles: <image> It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar pi...
0.5
{"tests": "{\"inputs\": [\"5 7\\n2 4\\n5 1\\n2 3\\n3 4\\n4 1\\n5 3\\n3 5\\n\", \"2 3\\n1 2\\n1 2\\n1 2\\n\", \"3 1\\n3 1\\n\", \"3 2\\n2 1\\n2 3\\n\", \"50 20\\n4 18\\n39 33\\n49 32\\n7 32\\n38 1\\n46 11\\n8 1\\n3 31\\n30 47\\n24 16\\n33 5\\n5 21\\n3 48\\n13 23\\n49 50\\n18 47\\n40 32\\n9 23\\n19 39\\n25 12\\n\", \"10 ...
This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled. Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at...
0
{"tests": "{\"inputs\": [\"4\\n4\\n1227\\n1\\n0\\n6\\n177013\\n24\\n222373204424185217171912\\n\", \"36\\n6\\n165310\\n6\\n177978\\n6\\n211759\\n6\\n212643\\n6\\n229540\\n6\\n250029\\n6\\n211519\\n6\\n256097\\n6\\n163478\\n5\\n91505\\n5\\n79280\\n6\\n260629\\n6\\n128051\\n6\\n121972\\n6\\n261633\\n6\\n172044\\n6\\n1190...
Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by 2 but the number itself is not divisible by 2. For example, 13, 1227, 185217 are ebne numbers, while 12, 2, 177013, 265918 are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clar...
0
{"tests": "{\"inputs\": [\"3\\n1 3 2\\n\", \"3\\n1000000000 1000000000 1000000000\\n\", \"3\\n377 9052790 230\\n\", \"5\\n1 1 912380429 929219321 1000000000\\n\", \"3\\n1 912387428 4\\n\", \"16\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
Let's call a list of positive integers a_0, a_1, ..., a_{n-1} a power sequence if there is a positive integer c, so that for every 0 ≤ i ≤ n-1 then a_i = c^i. Given a list of n positive integers a_0, a_1, ..., a_{n-1}, you are allowed to: * Reorder the list (i.e. pick a permutation p of \{0,1,...,n - 1\} and change...
0.625
{"tests": "{\"inputs\": [\"3\\n3 1\\n1 3 2\\n1 2\\n2 2\\n1 2\\n1 2\\n1 2\\n7 5\\n1 2 5 4 3 6 7\\n1 2\\n6 7\\n3 4\\n1 2\\n2 3\\n\", \"5\\n2 0\\n1 2\\n2 1\\n1 2\\n1 2\\n2 1\\n2 1\\n1 2\\n3 9\\n1 2 3\\n1 2\\n1 3\\n2 3\\n1 2\\n1 3\\n2 3\\n1 2\\n1 3\\n2 3\\n3 0\\n3 2 1\\n\", \"3\\n3 1\\n1 3 2\\n1 2\\n2 2\\n1 2\\n1 2\\n1 2\\...
This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in the wild pikachu herd. But it has become known recently that infamous team R...
0.75
{"tests": "{\"inputs\": [\"3\\n5 9 4\\n1 2\\n1 3\\n1 4\\n1 5\\n2 3\\n2 4\\n2 5\\n3 4\\n3 5\\n10 15 3\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n1 7\\n2 8\\n3 9\\n4 10\\n5 6\\n7 10\\n10 8\\n8 6\\n6 9\\n9 7\\n4 5 4\\n1 2\\n2 3\\n3 4\\n4 1\\n1 3\\n\", \"1\\n15 17 4\\n1 4\\n1 3\\n1 2\\n2 3\\n2 4\\n3 4\\n1 15\\n1 14\\n1 13\\n1 12\\n1 ...
You are given an undirected graph with n vertices and m edges. Also, you are given an integer k. Find either a clique of size k or a non-empty subset of vertices such that each vertex of this subset has at least k neighbors in the subset. If there are no such cliques and subsets report about it. A subset of vertices ...
0
{"tests": "{\"inputs\": [\"2 3 3\\n\", \"2 2 2\\n\", \"1 2 5\\n\", \"1000000000000000000 1000000000000000000 1000000000000000000\\n\", \"135645 1 365333453\\n\", \"1 12 1728\\n\", \"110 1000 998\\n\", \"1 5 5\\n\", \"1 3 6561\\n\", \"563236 135645 356563\\n\", \"1 10 999999999999999999\\n\", \"5 5 4\\n\", \"1 999999999...
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) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial. Vasya has made a bet with his friends that h...
0
{"tests": "{\"inputs\": [\"7 2\\n1 2\\n1 3\\n1 4\\n3 5\\n3 6\\n3 7\\n2 7\\n\", \"6 4\\n1 2\\n2 3\\n2 4\\n4 5\\n4 6\\n2 4 5 6\\n\", \"10 3\\n10 5\\n3 2\\n6 8\\n1 5\\n10 4\\n6 1\\n9 8\\n2 9\\n7 3\\n3 9 1\\n\", \"16 8\\n16 12\\n16 15\\n15 9\\n15 13\\n16 3\\n15 2\\n15 10\\n1 2\\n6 16\\n5 15\\n2 7\\n15 4\\n14 15\\n11 16\\n8...
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go ...
0
{"tests": "{\"inputs\": [\"4 5\\n1 2 R\\n1 3 R\\n2 3 B\\n3 4 B\\n1 4 B\\n\", \"6 5\\n1 3 R\\n2 3 R\\n3 4 B\\n4 5 R\\n4 6 R\\n\", \"3 3\\n1 2 B\\n3 1 R\\n3 2 B\\n\", \"6 6\\n1 2 R\\n1 3 R\\n2 3 R\\n4 5 B\\n4 6 B\\n5 6 B\\n\", \"2 1\\n1 2 B\\n\", \"3 3\\n1 2 R\\n1 3 R\\n2 3 R\\n\", \"11 7\\n1 2 B\\n1 3 R\\n3 2 R\\n4 5 R\...
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edge...
0
{"tests": "{\"inputs\": [\"6 10\\n7 4 7\\n5 8 8\\n12 5 8\\n6 11 6\\n3 3 7\\n5 9 6\\n\", \"3 12\\n3 5 7\\n4 6 7\\n5 9 5\\n\", \"25 6\\n1 10 5\\n1 8 4\\n1 8 2\\n4 8 9\\n3 2 8\\n1 9 5\\n2 10 10\\n3 9 6\\n3 5 4\\n2 7 8\\n2 3 2\\n2 6 8\\n3 7 8\\n4 3 7\\n1 8 1\\n3 6 4\\n3 2 8\\n2 2 1\\n4 8 8\\n4 8 4\\n3 10 2\\n3 6 6\\n2 2 5\...
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices. It is known that the i-th contestant will eat si slices of pizza, and gain ai ...
0
{"tests": "{\"inputs\": [\"5\\n10 R\\n14 B\\n16 B\\n21 R\\n32 R\\n\", \"4\\n-5 R\\n0 P\\n3 P\\n7 B\\n\", \"2\\n1 R\\n2 R\\n\", \"6\\n0 B\\n3 P\\n7 B\\n9 B\\n11 P\\n13 B\\n\", \"9\\n-105 R\\n-81 B\\n-47 P\\n-25 R\\n-23 B\\n55 P\\n57 R\\n67 B\\n76 P\\n\", \"2\\n-1000000000 P\\n1000000000 P\\n\", \"6\\n-8401 R\\n-5558 P\\...
The cities of Byteland and Berland are located on the axis Ox. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line Ox there are three types of cities: * the cities of Byteland, * the cities of Berland, * disputed cities. Recent...
0
{"tests": "{\"inputs\": [\"2\", \"1000000\", \"10\", \"4\", \"1100000\", \"8\", \"0100000\", \"14\", \"0110000\", \"0110010\", \"6\", \"1100010\", \"0100100\", \"12\", \"0110100\", \"16\", \"1110010\", \"0110110\", \"0\", \"1000010\", \"0000010\", \"0100010\", \"0000100\", \"24\", \"1001000\", \"20\", \"1100100\", \"18...
Given is a positive even number N. Find the number of strings s of length N consisting of `A`, `B`, and `C` that satisfy the following condition: * s can be converted to the empty string by repeating the following operation: * Choose two consecutive characters in s and erase them. However, choosing `AB` or `BA` is no...
0
{"tests": "{\"inputs\": [\"1 1 1\\n1 1\", \"4 7 3\\n3 2\\n4 3\\n2 1\\n4 4\", \"21 77 68\\n16 73\\n16 99\\n19 66\\n2 87\\n2 16\\n7 17\\n10 36\\n10 68\\n2 38\\n10 74\\n13 55\\n21 21\\n3 7\\n12 41\\n13 88\\n18 6\\n2 12\\n13 87\\n1 9\\n2 27\\n13 15\", \"4 7 3\\n3 1\\n4 3\\n2 1\\n4 4\", \"21 77 68\\n16 73\\n16 99\\n19 66\\n...
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i. He can rearrange the balls by performing the following two operations any number of times, in any order: * Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the po...
0
{"tests": "{\"inputs\": [\"1 3 3\", \"1000 100 100\", \"2 1 0\", \"1 6 3\", \"1000 100 000\", \"2 1 -1\", \"1 6 5\", \"1010 100 000\", \"3 1 0\", \"2 6 5\", \"1010 000 000\", \"6 1 0\", \"2 0 5\", \"1010 010 000\", \"1 1 0\", \"2 0 10\", \"1110 010 000\", \"2 0 -1\", \"2 0 20\", \"1110 011 000\", \"2 1 20\", \"1110 001...
There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq ...
0
{"tests": "{\"inputs\": [\"5\\n7\\n127\", \"5\\n7\\n135\", \"5\\n8\\n135\", \"5\\n5\\n135\", \"5\\n4\\n135\", \"5\\n4\\n218\", \"5\\n2\\n218\", \"5\\n2\\n143\", \"5\\n2\\n167\", \"5\\n2\\n89\", \"5\\n3\\n89\", \"5\\n1\\n89\", \"5\\n1\\n155\", \"5\\n2\\n155\", \"5\\n4\\n155\", \"5\\n4\\n233\", \"5\\n2\\n233\", \"5\\n2\\...
<image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in gr...
0
{"tests": "{\"inputs\": [\"4 10\\n1 0 1\\n1 0 2\\n3 1 2\\n2 0 1\\n1 2 3\\n3 0 1\\n1 0 1\\n2 0 2\\n1 1 3\\n3 0 2\", \"4 10\\n1 0 1\\n1 0 2\\n3 1 2\\n2 0 1\\n1 3 3\\n3 0 1\\n1 0 1\\n2 0 2\\n1 1 3\\n3 0 2\", \"4 10\\n1 0 1\\n1 0 2\\n3 1 2\\n2 0 1\\n1 3 3\\n3 0 2\\n1 0 1\\n2 0 2\\n1 1 3\\n3 0 2\", \"4 10\\n1 0 1\\n1 0 2\\n...
There are n rabbits, one in each of the huts numbered 0 through n − 1. At one point, information came to the rabbits that a secret organization would be constructing an underground passage. The underground passage would allow the rabbits to visit other rabbits' huts. I'm happy. The passages can go in both directions,...
0.25
{"tests": "{\"inputs\": [\"1 5\\n2 3 8\", \"1 5\\n2 0 8\", \"1 5\\n1 -1 8\", \"1 5\\n1 -1 6\", \"1 1\\n2 1 1\", \"1 0\\n2 1 1\", \"1 0\\n4 -2 5\", \"1 2\\n1 0 11\", \"1 0\\n0 -2 7\", \"1 1\\n1 0 13\", \"1 5\\n3 3 8\", \"0 5\\n1 0 6\", \"1 2\\n1 0 18\", \"1 0\\n0 -3 14\", \"1 1\\n2 0 4\", \"1 9\\n2 -1 13\", \"1 2\\n-1 0...
D: Anipero 2012 Anipero Summer Live, commonly known as Anipero, is the largest anime song live event in Japan where various anime song artists gather. 2D, who loves anime songs, decided to go to Anipero this year as well as last year. He has already purchased m of psyllium to enjoy Anipero. Psyllium is a stick that g...
0.625
{"tests": "{\"inputs\": [\"4\\n10 9 2\\n20 33 1\\n30 115 1\\n5 3 2\\n\", \"3\\n40 1 2\\n1000 1100 5\\n300 2 1\\n\", \"1\\n10 4 44\\n\", \"8\\n58 29 4\\n40 74 5\\n54 27 1\\n18 74 4\\n5 8 1\\n25 18 3\\n90 28 3\\n3 7 5\\n\", \"1\\n10 3 44\\n\", \"8\\n58 29 4\\n40 74 5\\n54 27 1\\n18 74 4\\n5 8 1\\n25 18 3\\n90 28 3\\n1 7 ...
Vasya wants to buy himself a nice new car. Unfortunately, he lacks some money. Currently he has exactly 0 burles. However, the local bank has n credit offers. Each offer can be described with three numbers a_i, b_i and k_i. Offers are numbered from 1 to n. If Vasya takes the i-th offer, then the bank gives him a_i bur...
0
{"tests": "{\"inputs\": [\"2 2\\n1 2\\n3 4\\n\", \"2 3\\n1 2 1\\n2 1 2\\n\", \"2 1\\n179\\n179\\n\", \"1 2\\n57 57\\n\", \"2 2\\n17 56\\n12 8\\n\", \"1 4\\n1 5 4 3\\n\", \"2 2\\n1 2\\n3 1\\n\", \"2 2\\n1 1\\n1 1\\n\", \"4 3\\n1 2 3\\n10 11 4\\n9 12 5\\n8 7 6\\n\", \"5 5\\n1 2 10 1 1\\n2 1 20 2 1\\n11 13 14 15 16\\n2 5 ...
Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, this city has nm intersections. At any intersection of i-th Eastern street and j-th Southern street there is a monument...
0
{"tests": "{\"inputs\": [\"3 5\\n3 12 18\\n2 6 5 3 3\\n\", \"4 2\\n1 5 17 19\\n2 1\\n\", \"4 2\\n1 5 17 19\\n4 5\\n\", \"2 1\\n500000000000000000 1000000000000000000\\n700000000\\n\", \"2 1\\n1 999999998000000002\\n999999999\\n\", \"5 3\\n6 24 25 31 121\\n6 5 9\\n\", \"2 2\\n1 1000000000000000000\\n1000000000000000000 ...
Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes x_1, x_2, ..., x_n, so he will be awak...
0.625
{"tests": "{\"inputs\": [\"5\\nvasya 100\\nvasya 200\\nartem 100\\nkolya 200\\nigor 250\\n\", \"3\\nvasya 200\\nkolya 1000\\nvasya 1000\\n\", \"10\\nj 10\\ni 9\\nh 8\\ng 7\\nf 6\\ne 5\\nd 4\\nc 3\\nb 2\\na 1\\n\", \"5\\nvasya 1000\\nvasya 100\\nkolya 200\\npetya 300\\noleg 400\\n\", \"1\\nvasya 1000\\n\", \"1\\ntest 0\...
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He ha...
0.125
{"tests": "{\"inputs\": [\"2 2\\n\", \"4 3\\n\", \"9 6\\n\", \"3 4\\n\", \"6 6\\n\", \"85 48\\n\", \"1 5\\n\", \"30 40\\n\", \"88 88\\n\", \"100 11\\n\", \"10 6\\n\", \"6 4\\n\", \"21 21\\n\", \"10 100\\n\", \"80 91\\n\", \"77 77\\n\", \"96 96\\n\", \"5 100\\n\", \"3 19\\n\", \"5 5\\n\", \"16 55\\n\", \"2 10\\n\", \"13...
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all poi...
0
{"tests": "{\"inputs\": [\"7\\n2 3 5 7 11 4 8\\n2\\n8 10\\n2 123\\n\", \"6\\n5 5 7 10 14 15\\n3\\n2 11\\n3 12\\n4 4\\n\", \"1\\n6\\n1\\n2 3\\n\", \"9\\n9999991 9999943 9999883 4658161 4657997 2315407 2315263 1000003 1000033\\n13\\n9999991 9999991\\n9999943 9999943\\n9999883 9999883\\n4658161 4658161\\n4657997 4657997\\...
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answe...
0.625
{"tests": "{\"inputs\": [\"1\\n1\\n\", \"3\\n1 4 5\\n\", \"4\\n1 2 999999 1000000\\n\", \"6\\n1 10 100 1000 10000 1000000\\n\", \"9\\n1 2 3 100 500000 500001 999901 999997 999999\\n\", \"10\\n1 100000 199999 299998 399997 499996 599995 699994 799993 899992\\n\", \"3\\n1 2 3\\n\", \"3\\n5 345435 999996\\n\", \"3\\n1 4 5...
Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them bac...
0
{"tests": "{\"inputs\": [\"10 5\\n9 4 3 8 8\\n\", \"4 6\\n1 2 3 4 3 2\\n\", \"10 10\\n8 8 8 7 7 7 6 1 1 1\\n\", \"100000 50\\n43104 45692 17950 43454 99127 33540 80887 7990 116 79790 66870 61322 5479 24876 7182 99165 81535 3498 54340 7460 43666 921 1905 68827 79308 59965 8437 13422 40523 59605 39474 22019 65794 40905 3...
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory. Though Ryouko is forgetful, she is also bo...
0
{"tests": "{\"inputs\": [\"6\\n1 5\\n3 3\\n4 4\\n9 2\\n10 1\\n12 1\\n4\\n1 2\\n2 4\\n2 5\\n2 6\\n\", \"3\\n1 1000000000\\n999999999 1000000000\\n1000000000 1000000000\\n4\\n1 2\\n1 2\\n2 3\\n1 3\\n\", \"2\\n304 54\\n88203 83\\n1\\n1 2\\n\", \"20\\n4524 38\\n14370 10\\n22402 37\\n34650 78\\n50164 57\\n51744 30\\n55372 5...
Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos User ainta, who lives in a 2D world, is going to post a video as well. There are n dominoes on a 2D Cartesian plane. i-th domino (1 ≤ i ≤ n) can be represented a...
0.125
{"tests": "{\"inputs\": [\"10 3 5 2 3\\n\", \"922784684 566833132 755777509 3 4\\n\", \"907995862 367493085 293994468 5 4\\n\", \"100000001 3 100000000 3 100000001\\n\", \"1000000000 1000 999 100 1000000000\\n\", \"3 100 101 2 3\\n\", \"947904756 540408420 270204210 4 2\\n\", \"970423020 540551739 540551739 4 4\\n\", \...
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? <image> One day, when he came to his friend Evan, Om Nom didn't find him at h...
0
{"tests": "{\"inputs\": [\"5 3\\n1 0 0 4 1\\n\", \"3 2\\n2 0 2\\n\", \"3 2\\n2 1 1\\n\", \"3 3\\n2 1 2\\n\", \"7 1\\n4 4 6 6 6 6 5\\n\", \"3 2\\n2 0 1\\n\", \"3 1\\n2 1 1\\n\", \"3 1\\n0 1 2\\n\", \"10 6\\n3 0 0 0 0 0 0 1 0 0\\n\", \"5 5\\n0 1 1 0 0\\n\", \"3 2\\n2 2 1\\n\", \"5 1\\n0 0 1 3 4\\n\", \"2 1\\n1 1\\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\": [\"4 9\\n2 3 5 8\\n0 1 3 6\\n\", \"2 4\\n1 3\\n1 2\\n\", \"3 8\\n2 4 6\\n1 5 7\\n\", \"5 10\\n0 1 3 5 7\\n0 1 2 4 7\\n\", \"30 63\\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58...
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you...
0.625
{"tests": "{\"inputs\": [\"10\\n\", \"2\\n\", \"20289\\n\", \"31775\\n\", \"1\\n\", \"82801\\n\", \"32866\\n\", \"99996\\n\", \"99997\\n\", \"43670\\n\", \"79227\\n\", \"3\\n\", \"86539\\n\", \"5188\\n\", \"99998\\n\", \"100000\\n\", \"4\\n\", \"99999\\n\", \"31809\\n\", \"77859\\n\", \"53022\\n\", \"4217\\n\", \"60397...
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j co...
0.75
{"tests": "{\"inputs\": [\"2\\n\", \"10\\n\", \"1\\n\", \"7\\n\", \"292\\n\", \"100000000\\n\", \"2000\\n\", \"8\\n\", \"198\\n\", \"116\\n\", \"5000\\n\", \"100\\n\", \"9\\n\", \"55\\n\", \"83\\n\", \"14\\n\", \"9999999\\n\", \"500000000\\n\", \"709000900\\n\", \"111199\\n\", \"244\\n\", \"20\\n\", \"1200\\n\", \"4\\n...
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as...
0
{"tests": "{\"inputs\": [\"3\\ni will win\\nwill i\\ntoday or tomorrow\\ntoday or tomorrow and yesterday\\ni dare you\\nbad day\\n\\nSAMPLE\", \"3\\ni will win\\nwill i\\ntoday or tomorrow\\nyadot or tomorrow and yesterday\\ni dare you\\nbad day\\n\\nSAMPLE\", \"3\\nh will win\\nwill i\\ntoday ro tomorrow\\nyadot or tn...
Alice and Bob are fighting over who is a superior debater. However they wish to decide this in a dignified manner. So they decide to fight in the Battle of Words. In each game both get to speak a sentence. Because this is a dignified battle, they do not fight physically, the alphabets in their words do so for them. ...
0.75
{"tests": "{\"inputs\": [\"5 1 6\\n\\nSAMPLE\", \"123461 123460 998998998\", \"4 2 1000000000\", \"123461 96628 998998998\", \"5 1 6\\n\\nELPMAS\", \"2 1 8\\n\\nMAEPLS\", \"5 1 15\\n\\nELPMAS\", \"2 1 10\\n\\nSLPEAM\", \"2 1 16\\n\\nSLPEAM\", \"5 1 25\\n\\nELPM@S\", \"5 1 41\\n\\nELPM@S\", \"5 2 41\\n\\nELPM@S\", \"123...
Alice is climbing stairs. There are total N stairs. She climbs A stairs upwards in day and she comes downstairs in night by B stairs. Find number of days she will take to reach the top of staircase. Input: First and only line contains three space separated integers denoting A, B, N. Output: Print only one line o...
0.875
{"tests": "{\"inputs\": [\"3 1\", \"3 2\", \"8 4\", \"9999999 4999\", \"14 4\", \"5 1\", \"3 0\", \"9479599 4999\", \"23 4\", \"8 1\", \"23 6\", \"4 1\", \"34 6\", \"7 6\", \"8 2\", \"14 8\", \"5 2\", \"45 4\", \"2 1\", \"25 6\", \"59 6\", \"9 6\", \"14 2\", \"24 8\", \"6 1\", \"32 6\", \"86 6\", \"8 6\", \"6 2\", \"32...
We have N lamps numbered 1 to N, and N buttons numbered 1 to N. Initially, Lamp 1, 2, \cdots, A are on, and the other lamps are off. Snuke and Ringo will play the following game. * First, Ringo generates a permutation (p_1,p_2,\cdots,p_N) of (1,2,\cdots,N). The permutation is chosen from all N! possible permutations ...
0
{"tests": "{\"inputs\": [\"2 3 3\\n2 2\\nRRL\\nLUD\", \"4 3 5\\n2 2\\nUDRRR\\nLLDUD\", \"5 6 11\\n2 1\\nRLDRRUDDLRL\\nURRDRLLDLRD\", \"2 3 3\\n2 2\\nRLR\\nLUD\", \"4 3 5\\n2 2\\nUDRRR\\nLLDTD\", \"2 6 11\\n2 1\\nRLDRRUDDLRL\\nURRDRLLDLRD\", \"2 6 3\\n2 2\\nRLR\\nLUD\", \"4 1 5\\n2 2\\nUDRRR\\nLLDTD\", \"4 1 5\\n0 2\\nU...
We have a rectangular grid of squares 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. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a st...
0.25
{"tests": "{\"inputs\": [\"4000 500 2000\", \"4000 2000 500\", \"1000000000000000000 2 1\", \"5856 500 2000\", \"4000 2000 312\", \"1000000000000000000 2 0\", \"1100000000000000000 2 0\", \"5856 883 583\", \"1100000000000000000 4 0\", \"6439 2000 572\", \"1100000000100000000 4 0\", \"6439 987 572\", \"11010000001000000...
ButCoder Inc. runs a programming competition site called ButCoder. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is 0, and a user whose rating reaches K or higher is called Ka...
0.375
{"tests": "{\"inputs\": [\"3\\n6\\n-1\", \"3\\n2\\n-1\", \"3\\n3\\n-1\", \"3\\n1\\n-1\", \"3\\n5\\n-1\", \"3\\n4\\n-1\", \"3\\n-1\\n-1\", \"3\\n8\\n-1\", \"3\\n11\\n-1\", \"3\\n21\\n-1\", \"3\\n39\\n-1\", \"3\\n47\\n-1\", \"3\\n41\\n-1\", \"3\\n74\\n-1\", \"3\\n140\\n-1\", \"3\\n19\\n-1\", \"3\\n13\\n-1\", \"3\\n9\\n-1...
As I was cleaning up the warehouse, I found an old document that describes how to get to the treasures of my ancestors. The following was written in this ancient document. 1. First, stand 1m east of the well on the outskirts of the town and turn straight toward the well. 2. Turn clockwise 90 degrees, go straight for ...
0
{"tests": "{\"inputs\": [\"3 2\\n1 1 0\\n0 0 1\", \"2 2\\n0 0\\n1 1\", \"3 3\\n1 1 0\\n0 0 1\", \"3 4\\n1 1 0\\n0 0 1\", \"3 5\\n1 1 0\\n0 0 1\", \"3 5\\n1 1 0\\n1 0 1\", \"3 5\\n1 1 0\\n1 -1 1\", \"3 3\\n1 1 -1\\n0 0 1\", \"3 4\\n1 1 0\\n0 1 1\", \"3 5\\n1 0 0\\n1 0 1\", \"3 5\\n1 1 -1\\n1 0 1\", \"3 4\\n1 1 0\\n0 1 0...
You have a cross-section paper with W x H squares, and each of them is painted either in white or black. You want to re-arrange the squares into a neat checkered pattern, in which black and white squares are arranged alternately both in horizontal and vertical directions (the figure shown below is a checkered patter wi...
0
{"tests": "{\"inputs\": [\"4\\n####\\n##.#..#\\n##..#.#\\n##.#....#\", \"4\\n####\\n#..#.##\\n##..#.#\\n##.#....#\", \"4\\n####\\n#..#.##\\n#.#..##\\n##.#....#\", \"4\\n####\\n##.#..#\\n#.#..##\\n##.#....#\", \"4\\n####\\n##.#..#\\n#.#..##\\n#....#.##\", \"4\\n####\\n#..#.##\\n#.#..##\\n#....#.##\", \"4\\n####\\n##.#.....
Digory Kirke and Polly Plummer are two kids living next door to each other. The attics of the two houses are connected to each other through a passage. Digory's Uncle Andrew has been secretly doing strange things in the attic of his house, and he always ensures that the room is locked. Being curious, Digory suspects th...
0
{"tests": "{\"inputs\": [\"2 3 7\\n100\\n101\\n4 12 5 17\\n5 4 9 4\\n1 4 13 18\\n12 1 14 9\\n3 10 7 18\\n3 15 12 17\\n8 6 8 12\\n\", \"2 2 5\\n10\\n11\\n1 1 8 8\\n2 4 5 6\\n1 2 7 8\\n3 3 6 8\\n5 6 7 8\\n\", \"1 2 10\\n01\\n4 1 5 2\\n1 2 1 4\\n3 4 3 5\\n1 3 1 5\\n4 3 5 5\\n1 1 3 3\\n1 3 4 5\\n3 2 3 4\\n3 1 5 2\\n3 1 3 5...
Vus the Cossack has a field with dimensions n × m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: 1. He takes the current field and finds a new inverted field. In other words, the new field will contain "1" only there, where "0" was in the current field...
0
{"tests": "{\"inputs\": [\"12\\n)(()(()())()\\n\", \"10\\n()()())(()\\n\", \"6\\n)))(()\\n\", \"10\\n(()(()))()\\n\", \"10\\n))))((((()\\n\", \"50\\n(((((((((((((((((((((((()))))))))))))))))))))))))(\\n\", \"4\\n))((\\n\", \"10\\n(())())()(\\n\", \"1\\n(\\n\", \"4\\n)()(\\n\", \"100\\n))()()(())()()(()()())((()()())())...
This is a harder version of the problem. In this version, n ≤ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya beli...
0
{"tests": "{\"inputs\": [\"OOOWWW\\n\", \"BBWBB\\n\", \"BBWWBB\\n\", \"BWWB\\n\", \"WWWOOOOOOWWW\\n\", \"AA\\n\", \"A\\n\", \"ABCDEF\\n\", \"BA\\n\", \"CC\\n\", \"B\\n\", \"FEDCBA\\n\", \"CBWBB\\n\", \"BBWBWB\\n\", \"BVWB\\n\", \"WWWOONOOOWWW\\n\", \"AB\\n\", \"C\\n\", \"EEDCBA\\n\", \"BBWBC\\n\", \"BBWBWA\\n\", \"BVXB...
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls). When the ball is inserted the following happens repeatedly: if so...
0.25
{"tests": "{\"inputs\": [\"6 5\\n5 0 3 1 2\\n1 8 9 1 3\\n1 2 3 4 5\\n9 1 0 3 7\\n2 3 0 6 3\\n6 4 1 7 0\\n\", \"1 4\\n93 85 23 13\\n\", \"1 2\\n0 0\\n\", \"2 2\\n1 0\\n0 0\\n\", \"3 3\\n99 99 99\\n100 100 100\\n100 100 100\\n\", \"1 7\\n67 78 37 36 41 0 14\\n\", \"1 1\\n0\\n\", \"3 3\\n1000 1000 1000\\n1 1 1\\n2 2 2\\n\...
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ...
0
{"tests": "{\"inputs\": [\"0\\n1\\n-2\\n-3\\n-4\\n-5\\n-6\\n-7\\n-8\\n-9\\n10\\n\", \"0\\n1\\n-2\\n-3\\n-4\\n-5\\n-6\\n-2\\n-8\\n-9\\n10\\n\", \"0\\n2\\n-2\\n-3\\n-4\\n-5\\n-6\\n-2\\n-8\\n-9\\n10\\n\", \"0\\n2\\n-2\\n-3\\n-4\\n-5\\n-2\\n-2\\n-8\\n-9\\n10\\n\", \"0\\n2\\n-2\\n-3\\n-4\\n-5\\n-2\\n-2\\n-8\\n-9\\n11\\n\", ...
per nextum in unam tum XI conscribementis fac sic vestibulo perlegementum da varo. morde varo. seqis cumula varum. cis per nextum in unam tum XI conscribementis fac sic seqis decumulamenta da varo. varum privamentum fodementum da aresulto. ...
0
{"tests": "{\"inputs\": [\"4\\n1\\n8\\n6\\n1000000000000000000\\n\", \"4\\n1\\n8\\n1\\n1000000000000000000\\n\", \"4\\n1\\n3\\n1\\n1000000100000000000\\n\", \"4\\n1\\n8\\n10\\n1100000000000000100\\n\", \"4\\n1\\n4\\n10\\n1110000000000000100\\n\", \"4\\n1\\n4\\n10\\n0111000000000000100\\n\", \"4\\n1\\n8\\n10\\n011110000...
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases. A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase ha...
0
{"tests": "{\"inputs\": [\"4\\n2 1 1 2\\n+*\\n\", \"3\\n2 2 0\\n+-*\\n\", \"4\\n2 1 1 5\\n+*-\\n\", \"10\\n1 1 0 1 1 1 1 0 0 0\\n*-+\\n\", \"10\\n0 2 2 2 0 0 0 2 0 0\\n-*+\\n\", \"100\\n1 2 2 2 1 1 2 2 0 2 2 0 1 0 0 0 0 1 0 0 0 1 1 2 1 1 2 2 0 2 0 2 1 1 0 2 1 0 1 2 1 2 2 1 1 1 2 1 1 1 0 1 1 0 0 2 2 1 2 2 1 0 1 0 0 2 1 ...
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, …, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers ...
0
{"tests": "{\"inputs\": [\"10 11\\n1 2\\n2 3\\n3 4\\n1 4\\n3 5\\n5 6\\n8 6\\n8 7\\n7 6\\n7 9\\n9 10\\n6\\n1 2\\n3 5\\n6 9\\n9 2\\n9 3\\n9 10\\n\", \"2 1\\n1 2\\n3\\n1 2\\n1 2\\n2 1\\n\", \"5 4\\n1 3\\n2 3\\n4 3\\n1 5\\n3\\n1 3\\n2 4\\n5 2\\n\", \"6 6\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 1\\n4\\n1 2\\n1 6\\n6 5\\n4 3\\n\",...
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle. A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1, and also exists an ed...
0
{"tests": "{\"inputs\": [\"3\\n3 3 5\\n\", \"4\\n1 2 3 5\\n\", \"42\\n2 2 2 3 6 8 14 22 37 70 128 232 330 472 473 784 1481 2008 3076 4031 7504 8070 8167 11954 17832 24889 27113 41190 48727 92327 148544 186992 247329 370301 547840 621571 868209 1158781 1725242 3027208 4788036 5166155\\n\", \"44\\n4 6 8 14 28 36 43 76 78...
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n). Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge...
0
{"tests": "{\"inputs\": [\"AHA\\n\", \"Z\\n\", \"XO\\n\", \"HNCMEEMCNH\\n\", \"AABAA\\n\", \"NNN\\n\", \"WWS\\n\", \"X\\n\", \"D\\n\", \"AAAKTAAA\\n\", \"QOQ\\n\", \"G\\n\", \"AHHA\\n\", \"WYYW\\n\", \"SSS\\n\", \"JL\\n\", \"H\\n\", \"ZZ\\n\", \"VO\\n\", \"VIYMAXXAVM\\n\", \"C\\n\", \"AZA\\n\", \"L\\n\", \"BAB\\n\", \"...
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
0.75
{"tests": "{\"inputs\": [\"3\\n?\\n18\\n1?\\n\", \"2\\n??\\n?\\n\", \"5\\n12224\\n12??5\\n12226\\n?0000\\n?00000\\n\", \"98\\n?\\n?0\\n2?\\n6?\\n6?\\n69\\n??\\n??\\n96\\n1?2\\n??3\\n104\\n??4\\n1?9\\n??2\\n18?\\n?01\\n205\\n?19\\n244\\n??8\\n?5?\\n?5?\\n276\\n??3\\n???\\n???\\n?28\\n?3?\\n3??\\n??8\\n355\\n4?0\\n4??\\n...
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit. Restore the the original sequence knowing digits remaining on the board. Inpu...
0.5
{"tests": "{\"inputs\": [\"3 3\\n1 2 3\\n\", \"2 1\\n2 2\\n\", \"39 93585\\n2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"97 78153\\n2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1...
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to di. The Sith Lord loves counting the number of nodes in the tree that are at a distance at most...
0.125
{"tests": "{\"inputs\": [\"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\", \"5 3\\n3-a 2-b 4-c 3-a 2-c\\n2-a 2-b 1-c\\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\", \"9 2\\n1-a 2-b 1-o 1-k 1-l 1-m 1-a 3-b 3-z\\n1-a 2-b\\n\", \"2 2\\n1-a 1-b\\n2-a 1...
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.75
{"tests": "{\"inputs\": [\"2 7\\n\", \"9 36\\n\", \"100 199\\n\", \"10 10\\n\", \"10 39\\n\", \"1 1\\n\", \"100 1\\n\", \"100 200\\n\", \"77 13\\n\", \"100 103\\n\", \"10 40\\n\", \"3 9\\n\", \"100 399\\n\", \"1 4\\n\", \"77 280\\n\", \"77 1\\n\", \"100 13\\n\", \"10 1\\n\", \"100 201\\n\", \"100 400\\n\", \"100 77\\n\...
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n. Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order...
0.375
{"tests": "{\"inputs\": [\"3 4\\n\", \"3 3\\n\", \"8 50\\n\", \"302237 618749\\n\", \"999999 1000000\\n\", \"893011 315181\\n\", \"4449 1336\\n\", \"871866 348747\\n\", \"999 999\\n\", \"2311 7771\\n\", \"429181 515017\\n\", \"21 15\\n\", \"201439 635463\\n\", \"977965 896468\\n\", \"1000000 1000000\\n\", \"384 187\\n\...
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving. More formally, first one of four diagonal directions is chosen and the billiard ball moves ...
0.5
{"tests": "{\"inputs\": [\"4\\n-1 20 40 77 119\\n30 10 73 50 107\\n21 29 -1 64 98\\n117 65 -1 -1 -1\\n\", \"5\\n119 119 119 119 119\\n0 0 0 0 -1\\n20 65 12 73 77\\n78 112 22 23 11\\n1 78 60 111 62\\n\", \"2\\n5 15 40 70 115\\n50 45 40 30 15\\n\", \"3\\n55 80 10 -1 -1\\n15 -1 79 60 -1\\n42 -1 13 -1 -1\\n\", \"2\\n33 15 ...
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends...
0
{"tests": "{\"inputs\": [\"12 17 9 40\\n\", \"3 3 2 3\\n\", \"20 78 8 997\\n\", \"88888 99999 77777 1\\n\", \"9199 8137 4561 82660\\n\", \"100000 100000 1000 100000\\n\", \"20 59 2 88\\n\", \"2 20 1 14\\n\", \"1 1 1 1\\n\", \"90706 97197 90706 96593\\n\", \"51133 7737 2779 83291\\n\", \"90755 85790 85790 98432\\n\", \"...
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gift bundle also includes a square scoop of size r × r, designed for fishing....
0
{"tests": "{\"inputs\": [\"46 2\\n\", \"2018 214\\n\", \"9 3\\n\", \"3 2\\n\", \"1000000000000000000 2000\\n\", \"10 3\\n\", \"20180214 5\\n\", \"998244353998244353 2000\\n\", \"8 3\\n\", \"1562 862\\n\", \"7 2\\n\", \"5 3\\n\", \"6 3\\n\", \"1000000000000000000 2\\n\", \"250 1958\\n\", \"7 3\\n\", \"1314 520\\n\", \"3...
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients stric...
0.5
{"tests": "{\"inputs\": [\"3 3\", \"150 300\", \"300 150\", \"3 5\", \"21 300\", \"300 280\", \"5 5\", \"13 300\", \"5 6\", \"13 146\", \"2 146\", \"1 8\", \"62 300\", \"13 178\", \"3 6\", \"4 146\", \"3 146\", \"4 6\", \"2 8\", \"2 13\", \"2 5\", \"62 108\", \"13 214\", \"2 3\", \"3 289\", \"2 14\", \"2 18\", \"2 6\",...
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N. Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he...
0
{"tests": "{\"inputs\": [\"56,65\\n97,54\\n64,-4\\n55,76\\n42,-27\\n43,80\\n87,-86\\n55,-6\\n89,34\\n95,5\\n0,0\", \"56,65\\n97,54\\n64,-4\\n55,76\\n42,-27\\n43,80\\n87,-86\\n55,-6\\n89,34\\n5,59\\n0,0\", \"56,65\\n97,54\\n64,-4\\n55,76\\n42,-27\\n43,80\\n77,-86\\n55,-6\\n89,34\\n95,5\\n0,0\", \"56,65\\n97,54\\n64,-4\\...
When a boy was cleaning up after his grand father passing, he found an old paper: <image> In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing ...
0
{"tests": "{\"inputs\": [\"12 3\\n2 3 6\\n12 4\\n1 2 3 6\\n0 0\", \"12 3\\n2 3 6\\n13 4\\n1 2 3 6\\n0 0\", \"12 3\\n2 3 6\\n12 4\\n2 2 3 6\\n0 0\", \"12 3\\n1 4 11\\n13 4\\n1 2 3 6\\n0 0\", \"7 3\\n4 1 29\\n13 4\\n2 2 6 6\\n0 0\", \"17 3\\n2 4 11\\n13 4\\n1 2 3 6\\n0 0\", \"15 3\\n2 6 11\\n13 4\\n1 2 3 6\\n0 0\", \"21 ...
She is an apprentice wizard. She first learned the magic of manipulating time. And she decided to open a liquor store to earn a living. It has to do with the fact that all the inhabitants of the country where she lives love alcohol. Residents especially like sake that has been aged for many years, and its value increas...
0
{"tests": "{\"inputs\": [\"10\\n6 6 6 3 6 1000000000 3 3 6 6\\n\", \"3\\n1337 1337 1337\\n\", \"18\\n2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10\\n\", \"55\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3\\n\", \"3\\n1 2 3\\n\", \"2\\n1 1\\n\", \"1\\n10000...
Polycarp has prepared n competitive programming problems. The topic of the i-th problem is a_i, and some problems' topics may coincide. Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and all contests should have pairwise distinct topics. He may not use all the ...
0
{"tests": "{\"inputs\": [\"5\\n1 2 2 2 2\\n\", \"3\\n1 1 1\\n\", \"3\\n3 3 3\\n\", \"1\\n963837006\\n\", \"57\\n28 57 82 64 59 54 23 13 19 67 77 46 100 73 59 21 72 81 53 73 92 86 14 100 9 17 77 96 46 41 24 29 60 100 89 47 8 25 24 64 3 32 14 53 80 70 87 1 99 77 41 60 8 95 2 1 78\\n\", \"5\\n1 3 3 5 3\\n\", \"3\\n1 2 2\\...
Pavel has several sticks with lengths equal to powers of two. He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be ...
0
{"tests": "{\"inputs\": [\"3\\n011\\n101\\n110\\n7\\n1 2 3 1 3 2 1\\n\", \"4\\n0110\\n0001\\n0001\\n1000\\n3\\n1 2 4\\n\", \"4\\n0110\\n0010\\n1001\\n1000\\n20\\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\\n\", \"4\\n0110\\n0010\\n0001\\n1000\\n4\\n1 2 3 4\\n\", \"16\\n0100001011000101\\n0001010100010111\\n110001011111011...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequence p_1, p_2, …, p_m of m vertexes; for each 1 ≤ i < m there is an arc from p_i to p_{i+1}. Define the sequence v_1, v_2, …, v...
0
{"tests": "{\"inputs\": [\"4\\n29 34 19 38\\n\", \"4\\n29 34 18 38\\n\", \"4\\n29 13 19 38\\n\", \"4\\n29 13 19 57\\n\", \"4\\n49 13 19 57\\n\", \"4\\n29 34 19 30\\n\", \"4\\n26 34 19 30\\n\", \"4\\n29 34 0 38\\n\", \"4\\n49 13 19 66\\n\", \"4\\n29 68 25 38\\n\", \"4\\n29 68 25 32\\n\", \"4\\n0 34 18 38\\n\", \"4\\n29 ...
Bob is playing with 6-sided dice. A net of such standard cube is shown below. <image> He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice. Fo...
0.875
{"tests": "{\"inputs\": [\"3\\n2 0\\n0 2\\n2 0\\n\", \"5\\n0 1\\n1 3\\n2 1\\n3 0\\n2 0\\n\", \"3\\n2 0\\n0 2\\n2 0\\n\", \"3\\n2 1\\n0 0\\n1 1\\n\", \"2\\n0 1\\n1 0\\n\", \"3\\n3 1\\n1 0\\n0 1\\n\", \"2\\n2 1\\n0 1\\n\", \"1\\n0 0\\n\", \"3\\n0 0\\n1 0\\n1 0\\n\", \"3\\n0 1\\n3 0\\n1 0\\n\", \"5\\n0 1\\n1 3\\n2 1\\n3 0...
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculated c_i — the number of vertices j in the subtree of vertex i, such that a_j < a_i. <image>Illustration for the second example, the first...
0
{"tests": "{\"inputs\": [\"5 4 2\\n2 4\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"5 5 3\\n1 3 5\\n1 2\\n2 3\\n3 4\\n3 5\\n2 4\\n\", \"5 4 2\\n3 4\\n2 1\\n2 3\\n1 4\\n4 5\\n\", \"4 3 2\\n3 4\\n1 2\\n2 3\\n1 4\\n\", \"16 15 3\\n12 14 16\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 10\\n10 11\\n11 12\\n1 13\\n13 14\\n14 15\\n...
Bessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the day. The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has k special fields and he h...
0
{"tests": "{\"inputs\": [\"5\\n5 3\\n1 5 2 6 1\\n1 6\\n6\\n3 2\\n1 2 3\\n4 3\\n3 1 2 3\\n10 3\\n1 2 3 4 5 6 7 8 9 10\\n\", \"1\\n7 2\\n5 5 1 1 2 1 1\\n\", \"1\\n26 2\\n2 1 1 1 3 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1\\n\", \"1\\n17 15\\n3 5 4 6 10 2 16 10 18 8 5 1 2 7 15 14 8\\n\", \"1\\n10 10\\n10 1 1 1 1 1 1 11 1...
Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}. In this problem, for the integer multiset s, the median of s is equal to th...
0
{"tests": "{\"inputs\": [\"codeforces\\nforceofcode\\n\", \"aa\\naa\\n\", \"bbabb\\nbababbbbab\\n\", \"ab\\nbbbba\\n\", \"xzzxxxzxzzzxzzzxxzzxzzxzxzxxzxxzxxzxzzxxzxxzxxxzxzxzxxzzxxxxzxzzzxxxzxzxxxzzxxzxxzxxzzxxzxxzxzxzzzxzzzzxzxxzzxzxxzxxzzxzxzx\\nzzx\\n\", \"a\\nb\\n\", \"zxzxzxzxzxzxzx\\nd\\n\", \"pfdempfohomnpgbeegi...
One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the s...
0.625