info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"6\\naabaac\\n\", \"8\\n0rTrT022\\n\", \"2\\naA\\n\", \"1\\ns\\n\", \"10\\n6IIC6CCIIC\\n\", \"20\\nqqqoqqoqMoqMMMqqMMqM\\n\", \"45\\nf3409ufEFU32rfsFJSKDFJ234234ASkjffjsdfsdfsj33\\n\", \"30\\n8M8MMMMMlrMlMMrMMllMMrllMMrMrl\\n\", \"40\\nTddTddddTddddddTdddTdddddddddddddddddddd\\n\", \"45\\nRRNR...
Kolya has a string s of length n consisting of lowercase and uppercase Latin letters and digits. He wants to rearrange the symbols in s and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forward, s...
0
{"tests": "{\"inputs\": [\"5 1 1\\n1 0 0 0 4\\n\", \"6 1 2\\n3 8 0 1 0 0\\n\", \"5 1 1\\n1 1 0 3 0\\n\", \"5 1 1\\n4 0 0 1 0\\n\", \"2 1 1\\n0 2\\n\", \"100 66 30\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 27 15 53 29 56 30 24 50 39 39 46 4 14 44 16 55 48 15 5...
Instructors of Some Informatics School make students go to bed. The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially,...
0
{"tests": "{\"inputs\": [\"3\\n2 1 4\\n\", \"4\\n3 1 4 4\\n\", \"4\\n3 1 4 1\\n\", \"5\\n3 1 4 1 5\\n\", \"11\\n5000 5000 5000 5000 5000 5000 0 1 0 1 0\\n\", \"1\\n0\\n\", \"1\\n1\\n\", \"4\\n0 1 1 0\\n\", \"17\\n1 9 2 8 4 5 7 3 8 4 6 2 8 4 1 0 5\\n\", \"4\\n57 918 827 953\\n\", \"51\\n17 26 14 0 41 18 40 14 29 25 5 23...
Æsir - CHAOS Æsir - V. "Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect. The time right now...... 00:01:12...... It's time." The emotion samples are now sufficient. After almost 3 years, it's time for Ivy to awake her bonded sister, Vanessa. The system inside A.R.C....
0
{"tests": "{\"inputs\": [\"2\\n3\\n1 2 3 5 6 E 7\\n8 9 10 4 11 12 13\\n11\\n34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1\\nE 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3\\n\", \"1\\n9\\n36 21 27 E 24 22 16 6 3 9 34 8 32 23 31 28 10 26 17\\n25 12 7 30 29 13 15 4 33 2 14 11 5 19 37 35 ...
You are an intergalactic surgeon and you have an alien patient. For the purposes of this problem, we can and we will model this patient's body using a $2 \times (2k + 1)$ rectangular grid. The alien has $4k + 1$ distinct organs, numbered $1$ to $4k + 1$. In healthy such aliens, the organs are arranged in a particular ...
0
{"tests": "{\"inputs\": [\"3 2\\n3 2 1\\n\", \"5 1\\n1000000000 1000000000 1000000000 1000000000 1000000000\\n\", \"3 2\\n1 0 1\\n\", \"4 4\\n2 8 4 1\\n\", \"1 1\\n0\\n\", \"1 1\\n1\\n\", \"4 5\\n5 5 5 5\\n\", \"5 2\\n3 1 0 3 1\\n\", \"3 2\\n1 0 0\\n\", \"3 2\\n0 0 1\\n\", \"161 5\\n17 0 3 8 4 8 8 14 15 7 5 17 2 5 7 1 ...
Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it. For each of next $n$ days Vasya knows $a_i$ — number of units of garbage he will produce on the $i$-th day. Each unit of garbage must ...
0
{"tests": "{\"inputs\": [\"4\\n1 4 2 2\\n\", \"6\\n1 2 4 4 4 9\\n\", \"7\\n1 2 4 4 4 9 4\\n\", \"10\\n2 1 1 1 2 2 2 1 1 2\\n\", \"50\\n4 10 4 4 4 10 10 10 4 10 4 4 10 10 4 10 10 4 10 10 4 4 10 4 4 10 4 10 4 10 10 4 4 10 10 10 4 4 10 10 10 10 10 4 4 10 10 4 10 4\\n\", \"100\\n50 50 51 50 51 51 51 51 51 50 50 50 50 50 50...
You have a set of $n$ weights. You know that their masses are $a_1$, $a_2$, ..., $a_n$ grams, but you don't know which of them has which mass. You can't distinguish the weights. However, your friend does know the mass of each weight. You can ask your friend to give you exactly $k$ weights with the total mass $m$ (both...
0
{"tests": "{\"inputs\": [\"2\\n1 2\\n\", \"3\\n1 2\\n2 3\\n\", \"5\\n1 2\\n1 3\\n1 4\\n2 5\\n\", \"6\\n1 2\\n1 3\\n1 4\\n2 5\\n2 6\\n\", \"4\\n2 4\\n2 3\\n2 1\\n\", \"5\\n5 1\\n5 2\\n5 3\\n5 4\\n\", \"20\\n19 16\\n19 18\\n20 7\\n9 4\\n6 17\\n14 2\\n9 15\\n2 13\\n5 11\\n19 12\\n12 20\\n16 9\\n11 8\\n19 5\\n3 1\\n19 14\\...
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with $n$ nodes. In the beginning, $0$ is written on all edges. In one operation, you can choose any $2$ distinct leaves $u$, $v$ and any real number $x$ and add $x$ to values...
0
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n\", \"2\\n2 6\\n\", \"10\\n71 36 100 39 27 41 58 74 4 85\\n\", \"10\\n849301699267836160 67229601484054264 784845291827189290 183826569640257406 460280890246109263 872157111020252352 67769527483940854 637993450461522066 967701547330585333 32506720713898043\\n\", \"1\\n930163663730...
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else! Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer...
0
{"tests": "{\"inputs\": [\"10 2\\n4 1 5 10\\n1 4 10 5\\n\", \"7 6\\n2 1 2 1\\n4 2 4 3\\n2 5 2 5\\n2 3 5 3\\n1 2 1 2\\n3 2 5 3\\n\", \"1 0\\n\", \"200 13\\n84 113 191 187\\n52 68 74 83\\n63 46 158 68\\n38 15 170 81\\n38 81 164 183\\n109 52 141 156\\n117 151 126 155\\n21 25 128 197\\n111 30 163 59\\n138 62 154 73\\n83 16...
There is a square grid of size $n \times n$. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs $\min(h, w)$ to color a rectangle of size $h \times w$. You are to make all cells white for minimum total cost. The sq...
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\", \"2\\n1 1\\n1000000000\\n3 1000000000\\n1000000000 996 251\\n\", \"1\\n7 2\\n5 5 1 1 2 1 1\\n\", \"1\\n10 2\\n1 1 2 1 1 1 1 5 1 5\\n\", \"1\\n10 10\\n10 1 1 1 1 1 1 11 1 11\\n\", \"1\\n9 3\\n3 1 1 ...
Slime has a sequence of positive integers $a_1, a_2, \ldots, a_n$. In one operation Orac can choose an arbitrary subsegment $[l \ldots r]$ of this sequence and replace all values $a_l, a_{l + 1}, \ldots, a_r$ to the value of median of $\{a_l, a_{l + 1}, \ldots, a_r\}$. In this problem, for the integer multiset $s$, t...
0
{"tests": "{\"inputs\": [\"3 3\\n1 0 1\\n2 1 3\\n2 1 2\\n2 2 3\\n\", \"3 3\\n1 0 1\\n3 1 2 3\\n1 2\\n2 1 3\\n\", \"3 3\\n1 0 1\\n3 1 2 3\\n2 1 2\\n1 3\\n\", \"11 10\\n0 0 1 0 0 0 0 1 1 0 1\\n3 2 3 11\\n1 3\\n2 6 7\\n1 5\\n1 11\\n1 10\\n5 4 6 8 9 10\\n2 1 5\\n1 7\\n5 1 2 4 8 9\\n\", \"10 9\\n1 0 1 1 0 1 0 0 1 0\\n4 2 3 ...
Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. Each switch control doors of some rooms, but each door is controlled by...
0.375
{"tests": "{\"inputs\": [\"4 0\\n\", \"0 4\\n\", \"8 6\\n\", \"1 1\\n\", \"38 5\\n\", \"2 122\\n\", \"4 2\\n\", \"4 9\\n\", \"8 10\\n\", \"206 209\\n\", \"5 17\\n\", \"1 2\\n\", \"2 1\\n\", \"1 1\\n\", \"1 0\\n\", \"0 1\\n\", \"2 2\\n\", \"4 1\\n\", \"4 2\\n\", \"4 3\\n\", \"4 4\\n\", \"4 5\\n\", \"4 6\\n\", \"4 7\\n\"...
User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below. At first, the score is 0. For each block of contiguous "o"s with length x the score increases by x^2. For each block ...
0
{"tests": "{\"inputs\": [\"1 1 1\\n\", \"4 2 2\\n\", \"1000 1000 1000\\n\", \"1 2 5\\n\", \"1 1000 1000\\n\", \"999 998 997\\n\", \"50 50 328\\n\", \"1000 12 17\\n\", \"1 10 100\\n\", \"787 554 337\\n\", \"143 679 749\\n\", \"1000 33 1000\\n\", \"1000 1000 52\\n\", \"300000 300000 300000\\n\", \"123321 287789 256654\\n...
Alice, Bob and Charlie are playing Card Game for Three, as below: - At first, each of the three players has a deck consisting of some number of cards. Alice's deck has N cards, Bob's deck has M cards, and Charlie's deck has K cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks c...
0
{"tests": "{\"inputs\": [\"2 3\\n1 2 1\\n2 1 2\\n\", \"2 2\\n1 2\\n3 4\\n\", \"1 1\\n1543\\n\", \"2 1\\n179\\n1329\\n\", \"1 2\\n66 699\\n\", \"2 2\\n2 2\\n2 2\\n\", \"2 2\\n1 1000000000\\n1 1000000000\\n\", \"1 4\\n1 5 4 3\\n\", \"3 1\\n1\\n7\\n9\\n\", \"2 1\\n179\\n179\\n\", \"1 2\\n57 57\\n\", \"2 2\\n1 2\\n3 1\\n\"...
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 ...
0
{"tests": "{\"inputs\": [\"2 1\\n0 1\\n2 1\\n\", \"1 2\\n1\\n1\\n\", \"3 3\\n0 1 1\\n4 3 5\\n\", \"5 5\\n0 1 0 0 1\\n2 4 1 2 1\\n\", \"20 20\\n0 1 0 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0\\n109 1 24 122 136 42 25 112 110 15 26 48 35 10 86 13 41 6 24 15\\n\", \"20 30\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n1 1 3 2 1 3 2 ...
The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes $n$ pictures. When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal pro...
0
{"tests": "{\"inputs\": [\"5\\n3 1 5 2 6\\n\", \"5\\n1 2 3 4 5\\n\", \"5\\n1 100 101 100 1\\n\", \"10\\n96 66 8 18 30 48 34 11 37 42\\n\", \"1\\n87\\n\", \"2\\n93 51\\n\", \"3\\n31 19 5\\n\", \"4\\n86 21 58 60\\n\", \"5\\n21 6 54 69 32\\n\", \"6\\n46 30 38 9 65 23\\n\", \"7\\n82 60 92 4 2 13 15\\n\", \"8\\n77 84 26 34 ...
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
0
{"tests": "{\"inputs\": [\"14 2\\n1 4\\n2 4\\n3 4\\n4 13\\n10 5\\n11 5\\n12 5\\n14 5\\n5 13\\n6 7\\n8 6\\n13 6\\n9 6\\n\", \"3 1\\n1 3\\n2 3\\n\", \"16 2\\n1 12\\n2 12\\n3 12\\n4 13\\n5 13\\n6 13\\n7 14\\n8 14\\n9 15\\n10 15\\n11 15\\n12 16\\n13 16\\n14 16\\n15 16\\n\", \"13 2\\n7 5\\n10 11\\n5 12\\n1 2\\n10 7\\n2 6\\n...
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least $3$ (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself $k$-multihedgehog. Let us define $k$-multihedgehog ...
0
{"tests": "{\"inputs\": [\"3 3\\n.#.\\n###\\n##.\\n\", \"4 2\\n##\\n.#\\n.#\\n##\\n\", \"4 5\\n....#\\n####.\\n.###.\\n.#...\\n\", \"2 1\\n.\\n#\\n\", \"3 5\\n.....\\n.....\\n.....\\n\", \"4 4\\n..##\\n..#.\\n##..\\n##..\\n\", \"1 1\\n#\\n\", \"10 10\\n.........#\\n........##\\n#####.....\\n####......\\n#.........\\n#....
A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an $n\times m$ grid. Initially, you may place some north magnets and some south magnets into the cells. You are...
0
{"tests": "{\"inputs\": [\"4 3\\n1 0 2 3\\n\", \"3 10\\n10 10 10\\n\", \"5 6\\n6 5 6 2 2\\n\", \"3 5\\n0 0 0\\n\", \"100 100\\n19 67 31 66 29 23 62 17 63 93 71 87 82 62 38 49 77 35 61 36 32 18 93 7 31 73 17 3 15 82 80 19 26 87 38 57 30 86 31 8 21 22 93 52 41 3 92 29 45 18 93 18 80 9 5 52 9 65 85 79 33 50 5 11 49 14 64 ...
Initially there was an array $a$ consisting of $n$ integers. Positions in it are numbered from $1$ to $n$. Exactly $q$ queries were performed on the array. During the $i$-th query some segment $(l_i, r_i)$ $(1 \le l_i \le r_i \le n)$ was selected and values of elements on positions from $l_i$ to $r_i$ inclusive got ch...
0
{"tests": "{\"inputs\": [\"4\\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\\n\", \"1\\n42\\n\", \"2\\n1 1 1 1\\n\", \"2\\n54748096 1 641009859 1\\n\", \"3\\n1 7 923264237 374288891 7 524125987 1 1 1\\n\", \"4\\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1\\n\", \"5\\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1...
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula $g_{ij} = \operatorname{gcd}(a_{i}, a_{j})$ Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as $\operato...
0
{"tests": "{\"inputs\": [\"3\\n1 1\\n1 2\\n1 3\\n\", \"3\\n1 1\\n2 1\\n3 1\\n\", \"4\\n2 1\\n2 2\\n3 1\\n3 2\\n\", \"5\\n3 6\\n5 10\\n4 3\\n2 1\\n1 3\\n\", \"1\\n1000000000 1000000000\\n\", \"4\\n1 1\\n1 1000000000\\n1000000000 1\\n1000000000 1000000000\\n\", \"5\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n\", \"7\\n1 1\\n1 4\\n1 ...
There are $n$ points on the plane, the $i$-th of which is at $(x_i, y_i)$. Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area. The strange area is enclosed by three lines, $x = l$, $y = a$ and $x = r$, as its left side, its bottom side and its right side respectively, where $l$, $...
0
{"tests": "{\"inputs\": [\"3\\n.E.\\nE.E\\n.E.\\n\", \"3\\nEEE\\nE..\\nE.E\\n\", \"5\\nEE.EE\\nE.EE.\\nE...E\\n.EE.E\\nEE.EE\\n\", \"3\\nEEE\\nEEE\\n...\\n\", \"3\\n.EE\\n.EE\\n.EE\\n\", \"5\\nEE.EE\\nEE..E\\nEEE..\\nEE..E\\nEE.EE\\n\", \"1\\nE\\n\", \"8\\nE.EEE..E\\nEEE.E.E.\\nEEE.E.E.\\nEE.E.E..\\nE...EE..\\nE.EE.......
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the ro...
0
{"tests": "{\"inputs\": [\"10 2\\n10 -1 2 2 2 2 2 2 -1 10\\n\", \"5 10\\n-1 -1 -1 -1 -1\\n\", \"18 1\\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466\\n\", \"29 6\\n-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7\...
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: $f(a, l, r) = \sum_{i = l}^{r} a [ i ] ; m(a) = \operatorname{max}_{1 \leq l \leq r \leq n} f(a, l, r)$ A swap operation is the following sequence of actions: choose two indexes i, j (i ≠ j); perform assignme...
0
{"tests": "{\"inputs\": [\"3 1 2\\n1 1 1\\n\", \"4 2 3\\n1 2 4 8\\n\", \"2 1 2\\n12 9\\n\", \"2 1 2\\n12 7\\n\", \"3 1 3\\n3 2 0\\n\", \"5 10 8\\n1000000000 1000000000 1000000000 1000000000 1000000000\\n\", \"1 2 3\\n612635770\\n\", \"3 2 5\\n0 2 3\\n\", \"2 1 8\\n18 17\\n\", \"5 10 8\\n0 0 0 0 0\\n\", \"1 1 2\\n1\\n\"...
You are given n numbers a_1, a_2, ..., a_{n}. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make [Image] as large as possible, where $1$ denotes the bitwise OR. Find the maximum possible value of [Image] after performing at most k operations optimally. ...
0.375
{"tests": "{\"inputs\": [\"0010100\\n\", \"111\\n\", \"0\\n\", \"1\\n\", \"0101010101\\n\", \"010100001\\n\", \"000111000\\n\", \"0101001000\\n\", \"0000001000\\n\", \"0101\\n\", \"000101110\\n\", \"010101010\\n\", \"0101001010\\n\", \"0100101100\\n\", \"0110100000\\n\", \"0000000000\\n\", \"1111111111\\n\", \"00101011...
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o...
0
{"tests": "{\"inputs\": [\"2\\n1 2\\n\", \"4\\n1 1 2 3\\n\", \"5\\n1 1 1 1 1\\n\", \"7\\n1 2 1 3 1 2 1\\n\", \"1\\n1\\n\", \"3\\n1 1 3\\n\", \"10\\n1 1 3 2 2 1 3 4 7 5\\n\", \"20\\n1 2 2 2 2 1 4 7 8 6 5 3 5 3 8 11 5 10 16 10\\n\", \"32\\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\\n\", \"10\\n1 1 3...
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (...
0
{"tests": "{\"inputs\": [\"1\\n\\n4\\n2\\n\", \"2\\n1\\n4 4\\n2\\n\", \"3\\n3 3\\n10 10 10\\n17\\n\", \"2\\n2\\n200000 100000\\n34567\\n\", \"20\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 299981\\n1234567890\\n\", \"20\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n299981 1 1 1 1 1 1 1 1...
There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k + 1 and k equals a_{k}. It is known that for each x there are at most 20 coin ty...
0
{"tests": "{\"inputs\": [\"3 3 3 100\\n1 1 1\\n\", \"3 6 5 1000000007\\n1 2 3\\n\", \"3 5 6 11\\n1 2 1\\n\", \"2 3 3 1000\\n1 2\\n\", \"3 10 10 150691913\\n8 7 10\\n\", \"100 500 500 895583345\\n20 39 5 5 41 47 36 33 34 22 21 33 7 4 15 35 16 37 39 46 27 4 12 35 43 26 23 40 16 50 27 7 49 28 17 28 16 22 18 12 25 34 28 24...
Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly a_{i} bugs in every line of code that he writes. Let's call a sequence of non-negative integers v_1, v_2, ..., v_{n} a plan, if v_1 + v_2 + .....
0
{"tests": "{\"inputs\": [\"10\\nAND 9 4\\nIN 1\\nIN 1\\nXOR 6 5\\nAND 3 7\\nIN 0\\nNOT 10\\nIN 1\\nIN 1\\nAND 2 8\\n\", \"3\\nAND 2 3\\nIN 0\\nIN 0\\n\", \"3\\nAND 2 3\\nIN 1\\nIN 0\\n\", \"3\\nAND 2 3\\nIN 0\\nIN 1\\n\", \"3\\nAND 2 3\\nIN 1\\nIN 1\\n\", \"3\\nOR 2 3\\nIN 0\\nIN 0\\n\", \"3\\nOR 2 3\\nIN 1\\nIN 0\\n\"...
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $1$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, w...
0.375
{"tests": "{\"inputs\": [\"4 1 2\\n1 3\\n1 2\\n\", \"3 3 1\\n2\\n1 2\\n1 3\\n2 3\\n\", \"10 3 2\\n1 10\\n1 2\\n1 3\\n4 5\\n\", \"1 0 1\\n1\\n\", \"1000 0 1\\n72\\n\", \"24 38 2\\n4 13\\n7 1\\n24 1\\n2 8\\n17 2\\n2 18\\n22 2\\n23 3\\n5 9\\n21 5\\n6 7\\n6 19\\n6 20\\n11 7\\n7 20\\n13 8\\n16 8\\n9 10\\n14 9\\n21 9\\n12 10...
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world. There is at most one...
0
{"tests": "{\"inputs\": [\"4 3\\n1 2\\n1 1\\n3 1 3 2\\n2 1 1\\n\", \"6 5\\n2 1 2\\n2 1 2\\n3 1 2 3\\n2 1 5\\n2 4 4\\n2 4 4\\n\", \"4 3\\n4 3 2 2 1\\n3 1 1 3\\n3 2 3 3\\n2 3 1\\n\", \"4 4\\n3 3 4 1\\n4 3 4 2 2\\n4 2 1 2 3\\n3 4 2 2\\n\", \"3 5\\n2 1 2\\n2 1 5\\n2 4 4\\n\", \"2 1\\n10 1 1 1 1 1 1 1 1 1 1\\n25 1 1 1 1 1 1...
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve...
0
{"tests": "{\"inputs\": [\"3 4\\n0 0\\n0 2\\n2 0\\n0 2\\n2 2\\n2 0\\n1 1\\n\", \"3 4\\n0 0\\n0 2\\n2 0\\n0 2\\n2 2\\n2 0\\n0 0\\n\", \"8 8\\n53212775 61830464\\n32047271 31958754\\n46845363 47341547\\n46097536 79640734\\n25559819 90360169\\n5442822 40309249\\n57656501 31139219\\n1191345 7784770\\n61052639 71686018\\n53...
After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has $n$ power sources, and the second one has $m$ power sources. A power source can be described as a point $(x_i, y_i)$ on a 2-...
0
{"tests": "{\"inputs\": [\"3\\n1\\n1\\n1\\n\", \"5\\n1\\n0\\n1\\n0\\n1\\n\", \"9\\n1\\n1\\n0\\n0\\n0\\n1\\n1\\n0\\n1\\n\", \"1\\n1\\n\", \"1\\n0\\n\", \"3\\n0\\n0\\n0\\n\", \"15\\n1\\n0\\n0\\n1\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n0\\n0\\n\", \"20\\n1\\n1\\n0\\n0\\n1\\n1\\n0\\n0\\n1\\n1\\n0\\n0\\n1\\n1\\n0\\n0\\n1\\n1...
In Morse code, an letter of English alphabet is represented as a string of some length from $1$ to $4$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1". Because there are $2^1+2^2+2^3+2^4 = 30$ strings w...
0
{"tests": "{\"inputs\": [\"4\\n1 2 1 2\\n\", \"10\\n1 1 2 2 2 1 1 2 2 1\\n\", \"200\\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 ...
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th...
0
{"tests": "{\"inputs\": [\"2 2 1\\n1 1 2\\n2 2 1\\n\", \"6 6 3\\n2 2 6\\n1 4 5\\n2 3 4\\n1 4 1\\n1 3 1\\n2 2 3\\n\", \"5 5 5\\n2 5 3\\n1 2 3\\n1 4 5\\n2 5 2\\n1 2 1\\n\", \"13 18 9\\n2 3 10\\n1 12 10\\n1 11 4\\n2 2 8\\n1 5 1\\n1 7 12\\n1 5 13\\n1 9 7\\n1 10 11\\n2 3 12\\n1 9 2\\n1 3 9\\n1 8 12\\n2 11 3\\n1 3 1\\n1 8 4\...
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans: to orient each undirected edge in one of two possible directions to maximize nu...
0
{"tests": "{\"inputs\": [\"1689\\n\", \"18906\\n\", \"2419323689\\n\", \"8589157262\\n\", \"2717172350336955863014903670481525170997949309274087058935108848979319747543008692128164875210350026\\n\", \"9825995656040286793128006047268547610068699214477842995873286607346639816314908021369221299622234988\\n\", \"1000000006...
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resultin...
0
{"tests": "{\"inputs\": [\"4 2\\n1 3\\n3 4\\n\", \"4 6\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n3 4\\n\", \"5 5\\n4 2\\n3 5\\n4 5\\n5 1\\n1 2\\n\", \"5 4\\n1 2\\n3 2\\n3 4\\n5 4\\n\", \"3 1\\n1 2\\n\", \"2 1\\n1 2\\n\", \"2 0\\n\", \"20 0\\n\", \"381 0\\n\", \"3 3\\n1 2\\n2 3\\n3 1\\n\", \"3 0\\n\", \"3 1\\n1 3\\n\", \"3 2\\n2 ...
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one r...
0
{"tests": "{\"inputs\": [\"3\\n101\\n3 3\\n3 2\\n3 1\\n\", \"4\\n1111\\n3 4\\n5 2\\n3 1\\n3 2\\n\", \"6\\n011100\\n5 3\\n5 5\\n2 4\\n3 5\\n4 2\\n1 5\\n\", \"1\\n0\\n1 5\\n\", \"20\\n00101101001100000010\\n1 1\\n5 3\\n3 3\\n4 5\\n1 4\\n5 2\\n4 2\\n4 4\\n5 1\\n1 1\\n5 3\\n2 4\\n2 4\\n1 2\\n2 3\\n1 4\\n1 5\\n1 3\\n3 4\\n4...
It is a holiday season, and Koala is decorating his house with cool lights! He owns $n$ lights, all of which flash periodically. After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters $a_i$ and $b_i$. Light with parameters $a_i$ and $b_i$ will toggle (on to off...
0
{"tests": "{\"inputs\": [\"4 4\\n\", \"5 3\\n\", \"7 3\\n\", \"1 1\\n\", \"100 80\\n\", \"2 2\\n\", \"3 3\\n\", \"3 1\\n\", \"4 2\\n\", \"5 5\\n\", \"5 1\\n\", \"6 6\\n\", \"6 4\\n\", \"6 2\\n\", \"30 22\\n\", \"79 61\\n\", \"87 43\\n\", \"81 1\\n\", \"101 3\\n\", \"11 3\\n\"], \"outputs\": [\"1111\", \"01010\", \"0010...
Let $s$ be some string consisting of symbols "0" or "1". Let's call a string $t$ a substring of string $s$, if there exists such number $1 \leq l \leq |s| - |t| + 1$ that $t = s_l s_{l+1} \ldots s_{l + |t| - 1}$. Let's call a substring $t$ of string $s$ unique, if there exist only one such $l$. For example, let $s = ...
0
{"tests": "{\"inputs\": [\"5\\n2 5 1 4 6\\n1 7\\n1 1\\n3 5\\n3 6\\n\", \"5\\n9 7 8 6 5\\n1 1\\n2 1\\n3 1\\n4 1\\n\", \"1\\n1\\n\", \"2\\n1 1\\n1 1\\n\", \"10\\n40 77 65 14 86 16 2 51 62 79\\n1 75\\n10 86\\n3 52\\n6 51\\n10 8\\n3 61\\n3 53\\n5 98\\n2 7\\n\", \"10\\n52 1 84 16 59 26 56 74 52 97\\n5 7\\n7 13\\n3 98\\n7 22...
Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote a_{i}. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges). Let's define dist(v, u) as the sum of the i...
0
{"tests": "{\"inputs\": [\"5\\n4 5 1 7 4\\n\", \"2\\n1 2\\n\", \"3\\n1 1 1\\n\", \"10\\n6 8 7 6 8 7 6 7 8 7\\n\", \"5\\n4 4 4 7 3\\n\", \"5\\n4 7 5 2 2\\n\", \"6\\n5 4 2 4 3 2\\n\", \"7\\n7 8 2 7 10 11 5\\n\", \"10\\n2 3 3 3 2 6 2 5 3 5\\n\", \"2\\n62 64\\n\", \"2\\n71 70\\n\", \"5\\n4 5 4 3 3\\n\", \"6\\n4 2 3 2 2 2\\...
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is r_{i}. The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team cons...
0
{"tests": "{\"inputs\": [\"8\\n1 2\\n2 3\\n3 4\\n4 5\\n4 6\\n3 7\\n3 8\\n\", \"5\\n3 2\\n3 5\\n2 4\\n1 3\\n\", \"4\\n1 2\\n2 3\\n3 4\\n\", \"6\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n\", \"4\\n4 3\\n3 1\\n1 2\\n\", \"3\\n1 2\\n1 3\\n\", \"3\\n1 2\\n1 3\\n\", \"3\\n3 1\\n1 2\\n\", \"3\\n1 3\\n1 2\\n\", \"3\\n1 2\\n1 3\\n\", \"3...
You are given an unweighted tree with $n$ vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices $a, b, c$ on this tree such that the number of edges which belong to at least one of the simple paths between $a$ and $b$, $b$ and $c$, or $a$ and $c$ is...
0
{"tests": "{\"inputs\": [\"5\\n1 2 4 3 2\\n\", \"7\\n1 3 5 6 5 4 2\\n\", \"3\\n2 2 2\\n\", \"4\\n1 2 4 3\\n\", \"15\\n37504 79054 80071 95721 135743 164345 189260 190810 191657 196168 200000 200000 190810 190018 185437\\n\", \"4\\n1 2 3 4\\n\", \"6\\n1 2 3 4 2 3\\n\", \"4\\n2 2 2 3\\n\", \"4\\n1 3 2 2\\n\", \"12\\n2 3 ...
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence $a$ consisting of $n$ integers. You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or...
0
{"tests": "{\"inputs\": [\"5\\n5 0 0 2 4\\n\", \"7\\n7 0 0 1 4 0 6\\n\", \"7\\n7 4 0 3 0 5 1\\n\", \"5\\n2 1 0 0 0\\n\", \"2\\n0 0\\n\", \"3\\n3 0 0\\n\", \"3\\n0 0 1\\n\", \"5\\n2 0 1 0 3\\n\", \"5\\n0 4 0 2 1\\n\", \"7\\n0 1 2 3 0 4 6\\n\", \"5\\n0 0 5 3 1\\n\", \"5\\n0 0 0 1 2\\n\", \"4\\n0 1 0 2\\n\", \"10\\n6 3 0 ...
There are $n$ friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself. For each friend the value $f_i$ is known: it is either $f_i = 0$ if the $i$-th friend doesn't know whom he wants to give the gi...
0
{"tests": "{\"inputs\": [\"8\\n1 2 3\\n123 321 456\\n5 10 15\\n15 18 21\\n100 100 101\\n1 22 29\\n3 19 38\\n6 30 46\\n\", \"1\\n137 10000 10000\\n\", \"1\\n1 137 10000\\n\", \"1\\n73 10000 10000\\n\", \"1\\n1667 3334 10000\\n\", \"1\\n256 4096 10000\\n\", \"1\\n1 1667 10000\\n\", \"2\\n1 137 10000\\n1 1429 10000\\n\", ...
You are given three integers $a \le b \le c$. In one move, you can add $+1$ or $-1$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make n...
0
{"tests": "{\"inputs\": [\"5 2\\n1 3 1\\n1 5 1\\n\", \"3 2\\n1 3 1\\n1 2 1\\n\", \"10 3\\n4 7 2\\n1 10 3\\n8 9 1\\n\", \"2 1\\n1 2 1\\n\", \"3 1\\n1 2 2\\n\", \"3 1\\n1 3 2\\n\", \"100 1\\n1 100 99\\n\", \"100 1\\n1 100 100\\n\", \"100 1\\n1 100 98\\n\", \"100 2\\n1 100 49\\n1 99 49\\n\", \"10 2\\n3 7 4\\n6 10 1\\n\", ...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ — the day, when questions for the $i$-th exam will be published, $d_...
0.125
{"tests": "{\"inputs\": [\"4 5 1\\n1 2\\n1 3\\n1 4\\n2 3\\n3 4\\n\", \"4 5 3\\n1 2\\n1 3\\n1 4\\n2 3\\n3 4\\n\", \"4 4 3\\n1 2\\n1 4\\n2 3\\n3 4\\n\", \"2 1 1\\n1 2\\n\", \"3 2 1\\n1 2\\n3 1\\n\", \"3 3 1\\n2 3\\n1 2\\n3 1\\n\", \"4 3 2\\n1 2\\n1 3\\n1 4\\n\", \"4 4 1\\n4 1\\n4 3\\n4 2\\n1 3\\n\", \"4 5 2\\n4 1\\n2 4\\...
You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to find any spanning tree of this graph such that the degree of the first vertex (vertex with label $1$ on it) is equal to $D...
0
{"tests": "{\"inputs\": [\"5\\n2 1 1 2 5\\n\", \"3\\n4 5 3\\n\", \"2\\n10 10\\n\", \"4\\n1 2 2 1\\n\", \"6\\n3 2 3 3 2 3\\n\", \"1\\n1\\n\", \"14\\n7 7 7 4 3 3 4 5 4 4 5 7 7 7\\n\", \"10\\n1 9 7 6 2 4 7 8 1 3\\n\", \"6\\n1 1 1 1 2 1\\n\", \"7\\n1 1 2 2 3 3 1\\n\", \"4\\n2 2 2 3\\n\", \"7\\n4 1 1 2 4 3 3\\n\", \"4\\n3 1...
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a sequence $a$ of $n$ integers, with $a_i$ being the height of the $i...
0
{"tests": "{\"inputs\": [\"6\\n3 4\\n1 2\\n5 6\\n5 7\\n7 4\\n8 9\\n9 8\\n2 5\\n1 1\\n1 1\\n2 2\\n2 2\\n1 100\\n10 10\\n10 10\\n1 2\\n4 5\\n8 4\\n2 2\\n1 1\\n1 1\\n1 2\\n3 4\\n1 2\\n1 1\\n1 1\\n\", \"1\\n2 2\\n1 2\\n3 4\\n1 3\\n2 4\\n\", \"1\\n2 10\\n1 2\\n3 4\\n1 3\\n2 4\\n\", \"1\\n1 2\\n2 5\\n5 3\\n\", \"1\\n1 2\\n1 ...
Masha has $n$ types of tiles of size $2 \times 2$. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type. Masha decides to construct the square of size $m \times m$ consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal matrix, a...
0.25
{"tests": "{\"inputs\": [\"26 6\\n\", \"8 3\\n\", \"1 1\\n\", \"9 4\\n\", \"7 2\\n\", \"1000000000 100000\\n\", \"999961559 44720\\n\", \"800019998 40000\\n\", \"813491792 78123\\n\", \"4 2\\n\", \"1 2\\n\", \"1 3\\n\", \"1 4\\n\", \"2 1\\n\", \"2 2\\n\", \"2 3\\n\", \"2 4\\n\", \"3 1\\n\", \"3 2\\n\", \"3 3\\n\", \"3 ...
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training! Polycarp doesn't want to procrastinate, so he wants ...
0
{"tests": "{\"inputs\": [\"3 4\\n4 6\\n10 -2\\n8 -1\\n\", \"5 20\\n45 -6\\n34 -15\\n10 34\\n1 27\\n40 -45\\n\", \"3 2\\n300 -300\\n1 299\\n1 123\\n\", \"20 15000\\n57 -299\\n354 -298\\n156 -298\\n102 -298\\n862 -300\\n134 -300\\n1446 -289\\n23 -298\\n1012 -298\\n901 -300\\n97 -300\\n172 -297\\n108 -265\\n209 -294\\n307...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
0
{"tests": "{\"inputs\": [\"4\\n1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1\\n\", \"3\\n1 1 1 1 1 3 3 3 3\\n\", \"4\\n1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1\\n\", \"1\\n10\\n\", \"2\\n3 3 3 3\\n\", \"7\\n5 9 5 4 1 9 8 4 5 1 4 10 7 7 8 4 2 4 4 5 4 4 10 3 4 6 8 1 9 9 5 6 8 7 1 8 6 6 7 5 3 1 1 4 7 2 3 3 8\\n\", \"7\\n1 8 9 6 4 7 4 3 5 5 4 2 ...
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: $\left[ \begin{array}{l l l}{1} & {3} & {1} \\{3} & {1} & {3} \\{1} & {3...
0
{"tests": "{\"inputs\": [\"7 3 2\\n1 2 1\\n\", \"10 1 11\\n1\\n\", \"10 1 5\\n2\\n\", \"1000 3 9\\n106 118 99\\n\", \"1000 20 8\\n3 6 3 4 3 5 3 5 5 5 3 1 3 8 2 4 4 5 3 2\\n\", \"1000 16 2\\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\\n\", \"5 1 2\\n1\\n\", \"1 1 1\\n1\\n\", \"2 1 1\\n1\\n\", \"4 1 2\\n1\\n\", \"15 ...
There is a river of width $n$. The left bank of the river is cell $0$ and the right bank is cell $n + 1$ (more formally, the river can be represented as a sequence of $n + 2$ cells numbered from $0$ to $n + 1$). There are also $m$ wooden platforms on a river, the $i$-th platform has length $c_i$ (so the $i$-th platform...
0
{"tests": "{\"inputs\": [\"1.200000\\n\", \"2.572479\\n\", \"4.024922\\n\", \"0.447214\\n\", \"0.493197\\n\", \"0.496139\\n\", \"0.498273\\n\", \"0.499026\\n\", \"0.499230\\n\", \"0.499376\\n\", \"0.832050\\n\", \"0.894427\\n\", \"0.948683\\n\", \"0.976187\\n\", \"0.986394\\n\", \"0.989949\\n\", \"0.993884\\n\", \"1.40...
$\text{A}$ -----Input----- The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5). -----Output----- Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for a...
0
{"tests": "{\"inputs\": [\"6 3 3\\n\", \"6 2 3\\n\", \"10 4 3\\n\", \"8 5 3\\n\", \"8 3 3\\n\", \"5 4 2\\n\", \"5 4 3\\n\", \"5 5 2\\n\", \"5 5 3\\n\", \"6 4 2\\n\", \"6 4 3\\n\", \"6 5 2\\n\", \"6 5 3\\n\", \"7 4 2\\n\", \"7 4 3\\n\", \"7 5 2\\n\", \"7 5 3\\n\", \"1 1 1\\n\", \"400000 400000 400000\\n\", \"200000 1000...
You are given three integers $n$, $d$ and $k$. Your task is to construct an undirected tree on $n$ vertices with diameter $d$ and degree of each vertex at most $k$, or say that it is impossible. An undirected tree is a connected undirected graph with $n - 1$ edges. Diameter of a tree is the maximum length of a simpl...
0
{"tests": "{\"inputs\": [\"2\\nab\\nbc\\n\", \"3\\naa\\nbc\\n\", \"1\\ncb\\nac\\n\", \"1\\nab\\ncb\\n\", \"3\\nbb\\ncb\\n\", \"4\\naa\\nbb\\n\", \"4\\naa\\nbc\\n\", \"4\\nbc\\nca\\n\", \"10\\naa\\naa\\n\", \"10\\nac\\nab\\n\", \"10\\nbb\\nbc\\n\", \"20\\nca\\nab\\n\", \"20\\ncc\\nac\\n\", \"20\\nab\\nbb\\n\", \"100\\na...
You are given two strings $s$ and $t$ both of length $2$ and both consisting only of characters 'a', 'b' and 'c'. Possible examples of strings $s$ and $t$: "ab", "ca", "bb". You have to find a string $res$ consisting of $3n$ characters, $n$ characters should be 'a', $n$ characters should be 'b' and $n$ characters sho...
0
{"tests": "{\"inputs\": [\"7\\n4 1 2 2 1 5 3\\n\", \"11\\n-5 -4 -3 -2 -1 0 1 2 3 4 5\\n\", \"4\\n1 1 1 1\\n\", \"1\\n100000\\n\", \"2\\n-100000 -100000\\n\", \"2\\n10000 99999\\n\", \"3\\n4 2 2\\n\", \"3\\n1 3 4\\n\", \"3\\n7 1 7\\n\", \"3\\n-2 -4 -4\\n\", \"29\\n-7 -8 -15 13 -5 -7 -4 -5 -8 29 -3 -2 7 -12 3 -2 -9 4 24 ...
This problem is given in two editions, which differ exclusively in the constraints on the number $n$. You are given an array of integers $a[1], a[2], \dots, a[n].$ A block is a sequence of contiguous (consecutive) elements $a[l], a[l+1], \dots, a[r]$ ($1 \le l \le r \le n$). Thus, a block is defined by a pair of indic...
0
{"tests": "{\"inputs\": [\"5\\nba\\na\\nabab\\na\\naba\\nbaba\\nab\\naba\\n\", \"3\\na\\naa\\naa\\na\\n\", \"2\\na\\nc\\n\", \"2\\nz\\nz\\n\", \"5\\nba\\na\\nbaba\\na\\naba\\nabab\\nab\\naba\\n\", \"5\\nb\\nb\\nba\\nab\\nbab\\nbab\\nabab\\nbaba\\n\", \"5\\nc\\ncd\\ncdc\\ncdcc\\nb\\ncb\\nccb\\ndccb\\n\", \"3\\nba\\nab\\...
Ivan wants to play a game with you. He picked some string $s$ of length $n$ consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $1$ to $n-1$), but he didn't tell you which strings are pre...
0.125
{"tests": "{\"inputs\": [\"2 4 6 8 10\\n\", \"50 27 17 31 89\\n\", \"50 87 29 81 21\\n\", \"74 21 36 68 80\\n\", \"75 82 48 95 12\\n\", \"41 85 14 43 23\\n\", \"94 28 3 29 9\\n\", \"94 21 36 89 20\\n\", \"60 92 82 71 53\\n\", \"46 68 3 0 51\\n\", \"12 39 3 50 84\\n\", \"12 31 47 31 84\\n\", \"79 2 93 92 16\\n\", \"65 4...
Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp:     I Aqua Fortis     I Aqua Regia     II Amalgama     VII Minium     IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci...
0
{"tests": "{\"inputs\": [\"4\\n2 5 3 1\\n\", \"2\\n1 5\\n\", \"1\\n8\\n\", \"6\\n1 1 1 3 2 9\\n\", \"5\\n8 9 3 1 9\\n\", \"6\\n1 5 2 1 7 11\\n\", \"8\\n1 6 11 8 5 10 7 8\\n\", \"3\\n4 9 6\\n\", \"2\\n4 8\\n\", \"3\\n1 1 5\\n\", \"5\\n4 5 5 2 11\\n\", \"6\\n1 7 2 8 8 2\\n\", \"5\\n3 9 3 2 3\\n\", \"7\\n6 6 1 1 1 2 3\\n\...
DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I M...
0
{"tests": "{\"inputs\": [\"5 4\\n1 4 5 60 4\\n\", \"3 1\\n1 1 1\\n\", \"15 2\\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3\\n\", \"1 1\\n1\\n\", \"2 1\\n1 2\\n\", \"2 1\\n2 1\\n\", \"2 2\\n1 2\\n\", \"2 2\\n2 1\\n\", \"3 1\\n1 2 3\\n\", \"3 1\\n1 3 2\\n\", \"3 1\\n2 1 3\\n\", \"3 1\\n2 3 1\\n\", \"3 1\\n3 1 2\\n\", \"3 1\\n3 2 1\\n\...
You are given an integer sequence $a_1, a_2, \dots, a_n$. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$. The median of a sequence is the value of an element which is in the middle of the sequence after s...
0.25
{"tests": "{\"inputs\": [\"5 4\\n2 -2 3 1 2\\n1 3\\n4 5\\n2 5\\n1 3\\n\", \"5 4\\n2 -2 3 1 4\\n3 5\\n3 4\\n2 4\\n2 5\\n\", \"1 0\\n1000000\\n\", \"1 0\\n-1\\n\", \"1 1\\n-10\\n1 1\\n\", \"1 2\\n-7\\n1 1\\n1 1\\n\", \"1 5\\n9\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n\", \"1 50\\n5\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\...
The only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$. You can...
0
{"tests": "{\"inputs\": [\"5 4\\n2 -2 3 1 2\\n1 3\\n4 5\\n2 5\\n1 3\\n\", \"5 4\\n2 -2 3 1 4\\n3 5\\n3 4\\n2 4\\n2 5\\n\", \"1 0\\n1000000\\n\", \"1 0\\n-1\\n\", \"1 1\\n-10\\n1 1\\n\", \"1 2\\n-7\\n1 1\\n1 1\\n\", \"1 5\\n9\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n\", \"1 50\\n5\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\...
The only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$. You can...
0
{"tests": "{\"inputs\": [\"5\\n2 1 5 4 3\\n\", \"7\\n1 3 5 6 7 4 2\\n\", \"3\\n1 2 3\\n\", \"4\\n1 2 4 3\\n\", \"10\\n1 2 5 9 10 8 7 6 4 3\\n\", \"100\\n2 3 4 6 7 8 9 12 13 14 15 16 17 19 20 21 24 25 27 28 31 32 34 40 42 43 45 46 47 49 54 55 58 59 60 61 62 63 68 71 74 75 80 81 82 85 86 87 88 89 91 92 95 96 98 99 100 97...
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence $a$ consisting of $n$ integers. All these integers are distinct, each value from $1$ to $n$ appears in the sequence exactly once. You are making ...
0.5
{"tests": "{\"inputs\": [\"4\\nabac\\n3\\n2 1 0\\nabc\\n1\\n0\\nabba\\n3\\n1 0 1\\necoosdcefr\\n10\\n38 13 24 14 11 5 3 24 17 0\\n\", \"1\\nabac\\n3\\n2 1 0\\n\", \"1\\ncbba\\n2\\n0 0\\n\", \"1\\nzbb\\n2\\n0 0\\n\", \"2\\naccccccc\\n1\\n0\\naaaaac\\n3\\n0 0 0\\n\", \"1\\naaad\\n3\\n0 0 0\\n\", \"1\\naaabb\\n3\\n0 0 0\\...
Polycarp wrote on the board a string $s$ containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string $s$, and he rewrote the remaining letters in any order. As a result, he got some new string $t$. You have to find it with s...
0
{"tests": "{\"inputs\": [\"8 3\\n5 4 2 6 5 1 9 2\\n\", \"5 1\\n1 1 1 1 1\\n\", \"4 2\\n1 2000 2000 2\\n\", \"1 1\\n2000\\n\", \"1 1\\n1234\\n\", \"3 2\\n1 1 1\\n\", \"4 2\\n3 5 1 1\\n\", \"5 3\\n5 5 6 7 1\\n\", \"6 4\\n1 1 1 1 2 2\\n\", \"5 3\\n5 5 6 6 4\\n\", \"16 15\\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12\\n\", \"1...
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann...
0
{"tests": "{\"inputs\": [\"4\\n1 -5 3 2\\n\", \"5\\n4 -2 3 -9 2\\n\", \"9\\n-1 1 -1 1 -1 1 1 -1 -1\\n\", \"8\\n16 -5 -11 -15 10 5 4 -4\\n\", \"2\\n1000000000 1000000000\\n\", \"2\\n-1000000000 -1000000000\\n\", \"2\\n1000000000 -1000000000\\n\", \"2\\n-1000000000 1000000000\\n\", \"3\\n1000000000 1000000000 1000000000\...
Kolya got an integer array $a_1, a_2, \dots, a_n$. The array can contain both positive and negative integers, but Kolya doesn't like $0$, so the array doesn't contain any zeros. Kolya doesn't like that the sum of some subsegments of his array can be $0$. The subsegment is some consecutive segment of elements of the ar...
0
{"tests": "{\"inputs\": [\"2 2\\n1 1\\n0 1\\n\", \"3 4\\n0 0 0 1\\n0 0 0 0\\n1 1 1 1\\n\", \"3 3\\n0 0 0\\n1 0 1\\n1 1 0\\n\", \"4 5\\n0 1 1 1 1\\n1 1 1 1 1\\n1 1 1 1 1\\n1 1 1 1 1\\n\", \"2 2\\n0 1\\n1 1\\n\", \"1 1\\n0\\n\", \"1 2\\n0 1\\n\", \"1 2\\n0 0\\n\", \"1 3\\n0 1 1\\n\", \"1 3\\n1 0 1\\n\", \"2 1\\n0\\n1\\n\...
You are given a binary matrix $a$ of size $n \times m$. A binary matrix is a matrix where each element is either $0$ or $1$. You may perform some (possibly zero) operations with this matrix. During each operation you can inverse the row of this matrix or a column of this matrix. Formally, inverting a row is changing a...
0.125
{"tests": "{\"inputs\": [\"8-7+6-5+4-3+2-1-0\\n\", \"2+2\\n\", \"112-37\\n\", \"255+255+255+255+255+255+255+255+255+255\\n\", \"0-255-255-255-255-255-255-255-255-255\\n\", \"0+0+0+0+0+0+0+0+0+0\\n\", \"0-0-0-0-0-0-0-0-0-0\\n\", \"0+100+100+100+100+100+100+100+100+100\\n\", \"255-100-100-100-100-100-100-100-100-100\\n\"...
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution... -----Input----- The only line of input data contain...
0
{"tests": "{\"inputs\": [\"4 3\\n\", \"10 4\\n\", \"13 4\\n\", \"2 2\\n\", \"3 2\\n\", \"4 2\\n\", \"3 3\\n\", \"6 3\\n\", \"7 3\\n\", \"5 5\\n\", \"6 5\\n\", \"10 5\\n\", \"20 5\\n\", \"21 5\\n\", \"10 10\\n\", \"11 10\\n\", \"20 10\\n\", \"90 10\\n\", \"91 10\\n\", \"9901 100\\n\", \"39801 200\\n\", \"199363 447\\n\"...
The king of Berland organizes a ball! $n$ pair are invited to the ball, they are numbered from $1$ to $n$. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from $1$ to $k$, inclusive. Let $b_i$ be the color o...
0
{"tests": "{\"inputs\": [\"5 2\\n00100\\n\", \"6 1\\n000000\\n\", \"4 1\\n0011\\n\", \"12 6\\n000010000100\\n\", \"5 1\\n01010\\n\", \"5 4\\n10000\\n\", \"9 2\\n010111110\\n\", \"10 1\\n0011100011\\n\", \"14 2\\n00001101011000\\n\", \"5 3\\n10011\\n\", \"15 3\\n111111101111111\\n\", \"18 11\\n110111111111111111\\n\", \...
You work as a system administrator in a dormitory, which has $n$ rooms one after another along a straight hallway. Rooms are numbered from $1$ to $n$. You have to connect all $n$ rooms to the Internet. You can connect each room to the Internet directly, the cost of such connection for the $i$-th room is $i$ coins. ...
0.75
{"tests": "{\"inputs\": [\"4 4 3\\n1 2\\n2 3\\n1 4\\n4 3\\n\", \"4 6 3\\n1 2\\n2 3\\n1 4\\n4 3\\n2 4\\n1 3\\n\", \"5 6 2\\n1 2\\n1 3\\n2 4\\n2 5\\n3 4\\n3 5\\n\", \"2 1 200000\\n2 1\\n\", \"3 2 100000\\n1 2\\n2 3\\n\", \"3 2 100000\\n1 2\\n1 3\\n\", \"3 3 1000\\n1 2\\n2 3\\n3 1\\n\", \"5 6 166666\\n1 2\\n1 3\\n2 4\\n2 ...
There are $n$ cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pair of cities. The cities are numbered from $1$ to $n$. It is known that, from the capital (the city with the number $1$), you can rea...
0
{"tests": "{\"inputs\": [\"5\\n2 1 1 2 5\\n\", \"3\\n4 5 3\\n\", \"2\\n10 10\\n\", \"3\\n1 2 3\\n\", \"10\\n1 9 7 6 2 4 7 8 1 3\\n\", \"1\\n1\\n\", \"1\\n2\\n\", \"3\\n2 1 2\\n\", \"2\\n1 2\\n\", \"5\\n1 2 2 1 2\\n\", \"5\\n5 2 5 2 6\\n\", \"4\\n3 3 3 4\\n\", \"3\\n1 1 1\\n\", \"5\\n2 1 1 2 1\\n\", \"2\\n99999999 99999...
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a sequence $a$ of $n$ integers, with $a_i$ being the height of the $i...
0
{"tests": "{\"inputs\": [\"7\\nABACABA\\n\", \"5\\nZZZAA\\n\", \"26\\nQWERTYUIOPASDFGHJKLZXCVBNM\\n\", \"2\\nQA\\n\", \"2\\nWW\\n\", \"11\\nGGRRAATTZZZ\\n\", \"50\\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA\\n\", \"100\\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNE...
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters...
0
{"tests": "{\"inputs\": [\"?(_-_/___*__):-___>__.\\n\", \"?(__-_+_/_____):-__>__,_____<__.\\n\", \"?(______________________/____+_______*__-_____*______-___):-__<___,___<____,____<_____,_____<______,______<_______.\\n\", \"?(__+___+__-___):-___>__.\\n\", \"?(__*___+_-____):-___>__,____<__.\\n\", \"?(__):-__>__.\\n\", \...
Golorps are mysterious creatures who feed on variables. Golorp's name is a program in some programming language. Some scientists believe that this language is Befunge; golorps are tantalizingly silent. Variables consumed by golorps can take values from 0 to 9, inclusive. For each golorp its daily diet is defined by it...
0
{"tests": "{\"inputs\": [\"2+3\\n\", \"9-7\\n\", \"1+1+1\\n\", \"1+11+111\\n\", \"111-11-1\\n\", \"1+1-1+1-1+1-1+1-1+1\\n\", \"9+1\\n\", \"10-1\\n\", \"31+49+49+71-51-61+59-111+51\\n\", \"255+255+255+255+255-255-255-255-255-255\\n\", \"100+100+10+10+10+10+10+5\\n\", \"255-255+255-255+255-255+255-255+255\\n\", \"0-255-2...
In this problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evalua...
0
{"tests": "{\"inputs\": [\"3\\n3 5 2 3 2 4\\n\", \"1\\n2750131 199999\\n\", \"1\\n3 6\\n\", \"1\\n3 2\\n\", \"1\\n815 1630\\n\", \"1\\n68914 137828\\n\", \"1\\n99917 199834\\n\", \"1\\n200000 100000\\n\", \"2\\n3 2 3 2\\n\", \"2\\n1327 1847 2654 283\\n\", \"2\\n1118003 93212 87037 186424\\n\", \"2\\n97908 66299 198897 ...
Authors guessed an array $a$ consisting of $n$ integers; each integer is not less than $2$ and not greater than $2 \cdot 10^5$. You don't know the array $a$, but you know the array $b$ which is formed from it with the following sequence of operations: Firstly, let the array $b$ be equal to the array $a$; Secondly, fo...
0
{"tests": "{\"inputs\": [\"5\\n1 2 1 2 3\\n\", \"2\\n100 1\\n\", \"4\\n1 3 3 7\\n\", \"100\\n23 39 85 46 97 72 41 70 37 18 8 40 33 61 12 79 51 78 61 66 85 97 78 14 70 47 100 40 15 40 61 52 19 30 14 91 82 56 10 6 68 24 97 61 31 78 18 45 88 6 37 38 51 86 37 42 58 30 79 56 50 14 61 18 13 20 57 3 93 15 24 74 32 21 71 93 2 ...
You are given an array $a$ consisting of $n$ integers. Let's denote monotonic renumeration of array $a$ as an array $b$ consisting of $n$ integers such that all of the following conditions are met: $b_1 = 0$; for every pair of indices $i$ and $j$ such that $1 \le i, j \le n$, if $a_i = a_j$, then $b_i = b_j$ (note ...
0
{"tests": "{\"inputs\": [\"6\\n3 5 4 7 10 12\\n\", \"5\\n-1 2 5 8 11\\n\", \"1\\n42\\n\", \"3\\n0 -536870912 536870912\\n\", \"2\\n536870912 -536870912\\n\", \"3\\n1 2 3\\n\", \"4\\n1 2 3 8\\n\", \"2\\n1 2\\n\", \"3\\n0 1 2\\n\", \"2\\n-3 -2\\n\", \"2\\n-4 -2\\n\", \"2\\n2 1\\n\", \"1\\n1\\n\", \"3\\n0 2 6\\n\", \"3\\n...
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any sub...
0.375
{"tests": "{\"inputs\": [\"6 5\\n1 2 2 4 2 3\\n\", \"7 5\\n3 3 2 1 1 1 3\\n\", \"1 1\\n1\\n\", \"1 1\\n1000000000\\n\", \"2 1\\n1 1\\n\", \"2 1\\n1 1000000000\\n\", \"2 1\\n1 2\\n\", \"2 2\\n1 1\\n\", \"2 2\\n1 123\\n\", \"8 6\\n4 5 1 2 3 5 3 3\\n\", \"8 6\\n893967334 893967335 893967331 893967332 893967333 893967335 8...
You are given the array $a$ consisting of $n$ elements and the integer $k \le n$. You want to obtain at least $k$ equal elements in the array $a$. In one move, you can make one of the following two operations: Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum...
0
{"tests": "{\"inputs\": [\"1\\n\", \"7\\n\", \"13\\n\", \"3\\n\", \"8\\n\", \"16\\n\", \"11\\n\", \"2\\n\", \"5\\n\", \"10\\n\", \"9\\n\", \"15\\n\", \"4\\n\", \"12\\n\", \"6\\n\", \"14\\n\"], \"outputs\": [\"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"1...
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts: Th...
0
{"tests": "{\"inputs\": [\"9\\nbrie soft\\ncamembert soft\\nfeta soft\\ngoat soft\\nmuenster soft\\nasiago hard\\ncheddar hard\\ngouda hard\\nswiss hard\\n\", \"6\\nparmesan hard\\nemmental hard\\nedam hard\\ncolby hard\\ngruyere hard\\nasiago hard\\n\", \"9\\ngorgonzola soft\\ncambozola soft\\nmascarpone soft\\nricott...
Not to be confused with chessboard. [Image] -----Input----- The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have. The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string...
0
{"tests": "{\"inputs\": [\"10\\ncodeforces\\ndodivthree\\n\", \"7\\nabaca?b\\nzabbbcc\\n\", \"9\\nbambarbia\\nhellocode\\n\", \"10\\ncode??????\\n??????test\\n\", \"1\\nz\\nz\\n\", \"1\\nz\\na\\n\", \"2\\naa\\naa\\n\", \"2\\nab\\naa\\n\", \"2\\nba\\naa\\n\", \"2\\naf\\nfa\\n\", \"2\\naf\\nfz\\n\", \"1\\n?\\nz\\n\", \"1...
There are $n$ left boots and $n$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $l$ and $r$, both of length $n$. The character $l_i$ stands for the color of the $i$-th left boot and the character $r_i$ stands for the color of the...
0
{"tests": "{\"inputs\": [\"7\\n4 1 2 2 1 5 3\\n\", \"11\\n-5 -4 -3 -2 -1 0 1 2 3 4 5\\n\", \"4\\n1 1 1 1\\n\", \"1\\n100000\\n\", \"2\\n-100000 -100000\\n\", \"2\\n10000 99999\\n\", \"3\\n4 2 2\\n\", \"3\\n1 3 4\\n\", \"3\\n7 1 7\\n\", \"3\\n-2 -4 -4\\n\", \"10\\n2 10 9 1 10 4 7 8 5 4\\n\", \"20\\n1 2 1 4 1 4 3 5 5 4 3...
This problem is given in two editions, which differ exclusively in the constraints on the number $n$. You are given an array of integers $a[1], a[2], \dots, a[n].$ A block is a sequence of contiguous (consecutive) elements $a[l], a[l+1], \dots, a[r]$ ($1 \le l \le r \le n$). Thus, a block is defined by a pair of indic...
0
{"tests": "{\"inputs\": [\"7 4\\n3 7 5 1 10 3 20\\n\", \"7 2\\n3 7 5 1 10 3 20\\n\", \"1 0\\n1\\n\", \"1 0\\n2\\n\", \"1 1\\n1000000000\\n\", \"3 0\\n3 3 3\\n\", \"3 0\\n2 2 3\\n\", \"5 0\\n3 4 5 6 7\\n\", \"4 0\\n2 3 4 5\\n\", \"2 2\\n1000000000 1000000000\\n\", \"7 2\\n2 7 5 1 10 2 20\\n\", \"2 1\\n1 1\\n\", \"5 3\\n...
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$. Note that the sequence can contain equal elements. If there is no suc...
0
{"tests": "{\"inputs\": [\"6 8\\n....*...\\n...**...\\n..*****.\\n...**...\\n....*...\\n........\\n\", \"5 5\\n.*...\\n****.\\n.****\\n..**.\\n.....\\n\", \"5 5\\n.*...\\n***..\\n.*...\\n.*...\\n.....\\n\", \"3 3\\n*.*\\n.*.\\n*.*\\n\", \"3 3\\n.*.\\n***\\n**.\\n\", \"3 3\\n.*.\\n***\\n.*.\\n\", \"3 3\\n**.\\n***\\n.*....
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consid...
0
{"tests": "{\"inputs\": [\"6 5\\n1 5\\n2 1\\n1 4\\n3 1\\n6 1\\n\", \"10 10\\n6 8\\n9 10\\n10 1\\n2 10\\n10 7\\n3 1\\n8 1\\n2 1\\n4 1\\n5 10\\n\", \"10 10\\n6 3\\n4 7\\n7 1\\n9 8\\n8 10\\n7 2\\n5 2\\n4 8\\n6 7\\n8 7\\n\", \"10 10\\n4 3\\n6 8\\n5 3\\n4 1\\n2 9\\n7 8\\n9 6\\n10 2\\n9 3\\n6 3\\n\", \"10 10\\n1 3\\n9 6\\n4 ...
You are given a connected undirected graph consisting of $n$ vertices and $m$ edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the ...
0
{"tests": "{\"inputs\": [\"8\\n-2.14 2.06\\n-1.14 2.04\\n-2.16 1.46\\n-2.14 0.70\\n-1.42 0.40\\n-0.94 -0.48\\n-1.42 -1.28\\n-2.16 -1.62\\n\", \"5\\n2.26 1.44\\n2.28 0.64\\n2.30 -0.30\\n1.58 0.66\\n3.24 0.66\\n\", \"8\\n6.98 2.06\\n6.40 1.12\\n5.98 0.24\\n5.54 -0.60\\n7.16 0.30\\n7.82 1.24\\n8.34 0.24\\n8.74 -0.76\\n\",...
-----Input----- The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane. Each of the next n lines contains two real coordinates x_{i} and y_{i} of the $i^{\text{th}}$ point, specified with exactly 2 fractional digits. All coordinates are between - 1000 and 1000, inclusive. -----...
0
{"tests": "{\"inputs\": [\"7 3\\n1 2 3 2 4 3 1\\n\", \"10 4\\n1 3 1 3 10 3 7 7 12 3\\n\", \"15 2\\n1 2 1 1 1 2 1 1 2 1 2 1 1 1 1\\n\", \"2 2\\n1 1\\n\", \"5 2\\n2 2 2 3 1\\n\", \"6 2\\n1 2 2 3 4 4\\n\", \"1 1\\n1\\n\", \"12 5\\n1 1 1 1 1 1 2 2 2 2 2 2\\n\", \"40 3\\n1 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...
You are given an array $s$ consisting of $n$ integers. You have to find any array $t$ of length $k$ such that you can cut out maximum number of copies of array $t$ from array $s$. Cutting out the copy of $t$ means that for each element $t_i$ of array $t$ you have to find $t_i$ in $s$ and remove it from $s$. If for so...
0
{"tests": "{\"inputs\": [\"4 2\\n9 9\\n10 8\\n5 3\\n4 3\\n\", \"2 4\\n1 2 3 4\\n10 3 7 3\\n\", \"6 1\\n3\\n6\\n2\\n5\\n1\\n4\\n\", \"1 2\\n11 21\\n\", \"3 2\\n85 6\\n64 71\\n1 83\\n\", \"2 3\\n63 26 69\\n24 23 30\\n\", \"3 3\\n51 64 90\\n98 38 80\\n91 7 54\\n\", \"16 1\\n1\\n1\\n100\\n100\\n100\\n1\\n100\\n100\\n1\\n10...
You are given a matrix $a$, consisting of $n$ rows and $m$ columns. Each cell contains an integer in it. You can change the order of rows arbitrarily (including leaving the initial order), but you can't change the order of cells in a row. After you pick some order of rows, you traverse the whole matrix the following w...
0
{"tests": "{\"inputs\": [\"6 2\\n1 4\\n4 3\\n3 5\\n3 6\\n5 2\\n\", \"4 2\\n3 1\\n1 4\\n1 2\\n\", \"10 2\\n10 3\\n1 2\\n1 3\\n1 4\\n2 5\\n2 6\\n2 7\\n3 8\\n3 9\\n\", \"2 0\\n2 1\\n\", \"2 1\\n1 2\\n\", \"3 0\\n1 2\\n1 3\\n\", \"3 1\\n3 2\\n2 1\\n\", \"3 2\\n2 1\\n1 3\\n\", \"4 0\\n2 3\\n2 4\\n3 1\\n\", \"4 1\\n4 2\\n2 1...
Treeland consists of $n$ cities and $n-1$ roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — the country's topology is an undirected tree. There are some private road companies in Treeland. The government decided to sell roads ...
0
{"tests": "{\"inputs\": [\"4\\n1 2 4 4\\n\", \"9\\n1 1 8 8 8 4 4 4 4\\n\", \"7\\n4 3 7 1 4 3 3\\n\", \"1\\n1\\n\", \"2\\n1 1\\n\", \"2\\n1 2\\n\", \"9\\n9 5 7 9 6 4 6 4 8\\n\", \"10\\n1 2 3 4 5 6 7 8 9 10\\n\", \"10\\n6 6 6 6 6 6 6 6 6 6\\n\", \"10\\n10 7 10 10 7 10 7 7 10 10\\n\", \"10\\n6 8 9 6 5 9 4 8 8 6\\n\", \"10...
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year... $n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coo...
0.25
{"tests": "{\"inputs\": [\"5\\n3 5\\n1 4\\n2 4\\n1 5\\n2 3\\n\", \"3\\n2 3\\n3 1\\n1 2\\n\", \"3\\n3 2\\n3 1\\n1 2\\n\", \"4\\n3 2\\n4 3\\n4 1\\n2 1\\n\", \"5\\n4 2\\n5 3\\n1 5\\n2 3\\n4 1\\n\", \"6\\n2 4\\n5 3\\n1 6\\n2 5\\n3 6\\n4 1\\n\", \"7\\n2 3\\n6 3\\n7 6\\n5 1\\n1 2\\n7 4\\n5 4\\n\", \"8\\n8 5\\n8 1\\n6 4\\n2 6...
There are $n$ kids, numbered from $1$ to $n$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $p_1$, $p_2$, ..., $p_n$ (all these numbers are from $1$ to $n$ and are distinct, so $p$ is a permutation). Let the next kid for a kid $p_i$ be kid $p_{i + 1}$ if $i < n$ and $p_...
0
{"tests": "{\"inputs\": [\"10 2 4\\n3 7\\n8 10\\n0 10\\n3 4\\n8 1\\n1 2\\n\", \"10 1 1\\n0 9\\n0 5\\n\", \"10 1 1\\n0 9\\n1 5\\n\", \"1 1 1\\n0 1\\n1 100000\\n\", \"1 1 1\\n0 1\\n0 100000\\n\", \"2000 1 1\\n0 1\\n2000 33303\\n\", \"2000 1 1\\n1999 2000\\n0 18898\\n\", \"100 50 1\\n1 2\\n3 4\\n5 6\\n7 8\\n9 10\\n11 12\\...
Polycarp lives on a coordinate line at the point $x = 0$. He goes to his friend that lives at the point $x = a$. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $n$ non-intersecting segments,...
0
{"tests": "{\"inputs\": [\"7\\n4 3 5 1 2 2 1\\n\", \"5\\n3 7 5 1 5\\n\", \"3\\n5 1 4\\n\", \"7\\n2 2 3 2 1 2 2\\n\", \"1\\n1\\n\", \"10\\n2 3 6 7 4 6 3 2 6 6\\n\", \"5\\n20 21 22 23 24\\n\", \"4\\n200000 200000 200000 200000\\n\", \"3\\n200000 200000 200000\\n\", \"2\\n200000 200000\\n\", \"1\\n200000\\n\"], \"outputs\...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
0
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n3 4\\n5 4\\n3 5\\n\", \"17 15\\n1 8\\n1 12\\n5 11\\n11 9\\n9 15\\n15 5\\n4 13\\n3 13\\n4 3\\n10 16\\n7 10\\n16 7\\n14 3\\n14 4\\n17 6\\n\", \"4 4\\n1 2\\n2 3\\n1 3\\n1 4\\n\", \"5 5\\n1 2\\n2 3\\n3 4\\n4 1\\n3 5\\n\", \"200000 0\\n\", \"1 0\\n\", \"5 10\\n1 2\\n2 3\\n3 4\\n4 5\\n5...
You are given an undirected graph consisting of $n$ vertices and $m$ edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of verti...
0.875
{"tests": "{\"inputs\": [\"5\\n2 0 0 1 2\\n1 2\\n2 3\\n2 4\\n2 5\\n\", \"5\\n1 0 0 0 2\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"3\\n1 1 2\\n2 3\\n1 3\\n\", \"2\\n2 1\\n1 2\\n\", \"2\\n1 2\\n1 2\\n\", \"3\\n1 2 1\\n1 3\\n2 3\\n\", \"5\\n1 2 2 0 2\\n1 2\\n1 5\\n3 5\\n4 5\\n\", \"6\\n1 2 1 2 1 0\\n1 5\\n2 3\\n3 5\\n3 6\\n4 5\\n\",...
You are given an undirected tree of $n$ vertices. Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex. You choose an edge and remove it from the tree. Tree falls apart into two connected components. ...
0.375
{"tests": "{\"inputs\": [\"9\\n5 1 3 6 8 2 9 0 10\\n\", \"5\\n1 2 4 0 2\\n\", \"8\\n3 2 0 1 0 1 2 3\\n\", \"7\\n3 2 0 1 0 1 2\\n\", \"1\\n1337\\n\", \"5\\n1 4 2 5 3\\n\", \"6\\n5 1 4 2 6 3\\n\", \"6\\n1 2 100 3 101 4\\n\", \"12\\n12 8 1 3 7 5 9 6 4 10 11 2\\n\", \"12\\n11 2 1 3 5 8 9 10 7 6 4 12\\n\"], \"outputs\": [\"...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
0
{"tests": "{\"inputs\": [\"5 6\\n1 2 0 2 0\\n2 4\\n3 3\\n1 5\\n1 2\\n1 5\\n2 3\\n\", \"5 3\\n4 2 1 3 2\\n3 5\\n4 2\\n2 5\\n\", \"78 36\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0\\n1 52\\n2 6\\n9 43\\n10 52...
The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions — and he won't start playing until he gets all of them. E...
0
{"tests": "{\"inputs\": [\"6 8\\n....*...\\n...**...\\n..*****.\\n...**...\\n....*...\\n........\\n\", \"5 5\\n.*...\\n****.\\n.****\\n..**.\\n.....\\n\", \"5 5\\n.*...\\n***..\\n.*...\\n.*...\\n.....\\n\", \"3 3\\n*.*\\n.*.\\n*.*\\n\", \"3 3\\n.*.\\n***\\n**.\\n\", \"3 3\\n.*.\\n***\\n.*.\\n\", \"3 3\\n**.\\n***\\n.*....
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consid...
0