info stringlengths 120 50k | question stringlengths 504 10.4k | avg@8_qwen3_4b_instruct_2507 float64 0 0.88 |
|---|---|---|
{"tests": "{\"inputs\": [\"2\\n\", \"3\\n\", \"4\\n\", \"6\\n\", \"10\\n\", \"15\\n\", \"100\\n\", \"5\\n\"], \"outputs\": [\"3\\n2 1 2 \", \"4\\n2 1 3 2 \", \"6\\n2 4 1 3 2 4 \", \"9\\n2 4 6 1 3 5 2 4 6 \", \"15\\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 \", \"22\\n2 4 6 8 10 12 14 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 \", \"150... | Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1 Γ n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies ... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 1\\n5 5\\n00001\\n11111\\n00111\\n00110\\n00110\\n\", \"3\\n1 3\\n3 1\\n010\\n101\\n010\\n\", \"1\\n1 1\\n1 1\\n0\\n\", \"5\\n4 5\\n1 1\\n01111\\n11111\\n11110\\n11010\\n11000\\n\", \"7\\n4 5\\n1 2\\n0001000\\n0111110\\n0110110\\n1100011\\n0110110\\n0111110\\n0001000\\n\", \"10\\n2 2\\n... | Alice lives on a flat planet that can be modeled as a square grid of size $n \times n$, with rows and columns enumerated from $1$ to $n$. We represent the cell at the intersection of row $r$ and column $c$ with ordered pair $(r, c)$. Each cell in the grid is either land or water.
[Image] An example planet with $n = 5... | 0.75 |
{"tests": "{\"inputs\": [\"6\\n6 3 1 0 0 0\\n\", \"4\\n4 0 0 0\\n\", \"1\\n1\\n\", \"5\\n5 0 0 0 0\\n\", \"10\\n10 8 7 6 5 4 3 2 1 0\\n\", \"20\\n20 16 12 8 5 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"99\\n99 26 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 ... | Stepan had a favorite string s which consisted of the lowercase letters of the Latin alphabet.
After graduation, he decided to remember it, but it was a long time ago, so he can't now remember it. But Stepan remembers some information about the string, namely the sequence of integers c_1, c_2, ..., c_{n}, where n equ... | 0 |
{"tests": "{\"inputs\": [\"3 3 2\\n1 2\\n2 1\\n3 3\\n3 2\\n\", \"5 4 3\\n3 4\\n3 1\\n3 3\\n5 3\\n1 3\\n1 4\\n\", \"1 1 10\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n1 1\\n\", \"10 10 20\\n7 5\\n4 5\\n5 4\\n7 4\\n1 5\\n6 7\\n9 5\\n8 4\\n1 4\\n2 10\... | Petya has a rectangular Board of size $n \times m$. Initially, $k$ chips are placed on the board, $i$-th chip is located in the cell at the intersection of $sx_i$-th row and $sy_i$-th column.
In one action, Petya can move all the chips to the left, right, down or up by $1$ cell.
If the chip was in the $(x, y)$ cell, ... | 0 |
{"tests": "{\"inputs\": [\"4 6 3\\n1 1 2 3\\n2 6 1 2\\n2 6 2 4\\n\", \"2 3 5\\n2 3 1 2\\n2 3 2 3\\n1 1 1 1\\n1 2 1 2\\n2 1 2 1\\n\", \"1 1 10\\n1 1 1 1\\n1 1 1 1\\n1 1 2 1\\n1 1 1 1\\n2 1 2 1\\n2 1 1 1\\n1 1 2 1\\n1 1 2 1\\n2 1 1 1\\n2 1 1 1\\n\", \"999999937 999999929 1\\n2 501178581 1 294328591\\n\", \"999999929 9999... | Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by $n$ sectors, and the outer area is equally divided by $m$ sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. ... | 0 |
{"tests": "{\"inputs\": [\"4 4 3\\n1 2\\n2 3\\n3 4\\n4 1\\n\", \"4 5 3\\n1 2\\n2 3\\n3 4\\n4 1\\n2 4\\n\", \"4 6 3\\n1 2\\n2 3\\n3 4\\n4 1\\n1 3\\n2 4\\n\", \"5 4 5\\n1 2\\n1 3\\n2 4\\n2 5\\n\", \"3 3 3\\n1 2\\n2 3\\n3 1\\n\", \"6 6 6\\n4 2\\n2 5\\n5 3\\n3 6\\n6 1\\n1 4\\n\", \"6 6 5\\n3 6\\n6 5\\n5 4\\n4 2\\n2 1\\n1 3... | Given a connected undirected graph with $n$ vertices and an integer $k$, you have to either: either find an independent set that has exactly $\lceil\frac{k}{2}\rceil$ vertices. or find a simple cycle of length at most $k$.
An independent set is a set of vertices such that no two of them are connected by an edge. A s... | 0 |
{"tests": "{\"inputs\": [\"4\\n1 1 4 9\\n\", \"4\\n4 3 2 1\\n\", \"3\\n4 2 1\\n\", \"8\\n42 1337 13 37 420 666 616 97\\n\", \"10\\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\\n\", \"2\\n1 1\\n\", \"2\\n500000000 1000000000\\n\", \"2\\n500000001 1000000000\\n\"], ... | $n$ fishermen have just returned from a fishing vacation. The $i$-th fisherman has caught a fish of weight $a_i$.
Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show their fish (each fisherman shows his fish exactly once, so, formally, the order... | 0 |
{"tests": "{\"inputs\": [\"4 3\\n1 2\\n1 3\\n1 4\\n\", \"6 1\\n2 1\\n2 3\\n2 5\\n5 4\\n5 6\\n\", \"5 5\\n1 2\\n2 3\\n3 4\\n3 5\\n\", \"3 1000000000\\n3 2\\n2 1\\n\", \"2 1000000000\\n2 1\\n\", \"2 1\\n2 1\\n\", \"4 1\\n1 3\\n1 4\\n2 1\\n\", \"4 1\\n4 1\\n2 4\\n3 1\\n\"], \"outputs\": [\"2.000000000000000000\", \"0.5000... | You are given a tree (an undirected connected graph without cycles) and an integer $s$.
Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and their sum is $s$. At the same time, he wants to make the diameter of the tree as small as possible.
Let's define the diamete... | 0.125 |
{"tests": "{\"inputs\": [\"2\\n0.25 0.75\\n0.75 0.25\\n\", \"3\\n0.125 0.25 0.625\\n0.625 0.25 0.125\\n\", \"10\\n0.01 0.01 0.01 0.01 0.01 0.1 0.2 0.2 0.4 0.05\\n1.0 0 0 0 0 0 0 0 0 0\\n\", \"10\\n0 0 0 0 0 0 0 0 0 1.0\\n1.0 0 0 0 0 0 0 0 0 0\\n\", \"1\\n1.0\\n1.0\\n\", \"2\\n0.00001 0.99999\\n0.5 0.5\\n\", \"3\\n0.1 0... | Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and dif... | 0 |
{"tests": "{\"inputs\": [\"4 3 7\\n7 4 17\\n3 0 8\\n11 2 0\\n13 3 5\\n3 1\\n2 1\\n4 3\\n\", \"4 3 7\\n7 4 17\\n3 0 8\\n11 2 0\\n13 3 5\\n3 1\\n2 1\\n4 1\\n\", \"4 3 7\\n7 4 17\\n3 0 8\\n11 2 0\\n14 3 5\\n3 1\\n2 1\\n4 3\\n\", \"10 10 2\\n2 1 1615\\n2 1 1326\\n0 0 3880\\n2 0 1596\\n1 2 4118\\n0 0 4795\\n0 1 814\\n0 0 45... | You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer $n$ castles of your opponent.
Let's describe the game process in detail. Initially you control an army of $k$ warriors. Your enemy controls $n$ castles; to conquer the $i$-th c... | 0 |
{"tests": "{\"inputs\": [\"4 3 2\\n1 3\\n4 2\\n5 1\\n4 1\\n\", \"3 100 100\\n0 0\\n0 0\\n100 200\\n\", \"7 10 12\\n5 6\\n20 23\\n15 4\\n16 5\\n4 54\\n12 1\\n4 15\\n\", \"1 100 100\\n50 70\\n\", \"1 100 100\\n101 100\\n\", \"2 1000000000 100000\\n1000000000 1000000\\n1000000000 10000\\n\", \"3 2 2\\n2 4\\n2 1\\n3 6\\n\"... | The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.
The main school of the capital is located in $(s_x,... | 0 |
{"tests": "{\"inputs\": [\"3 3 2 2\\n\", \"3 4 2 2\\n\", \"4 4 2 3\\n\", \"4 3 3 2\\n\", \"4 3 2 2\\n\", \"4 4 3 2\\n\", \"4 4 2 2\\n\", \"4 4 3 3\\n\"], \"outputs\": [\"2 2\\n1 2\\n1 1\\n1 3\\n2 3\\n2 1\\n3 1\\n3 2\\n3 3\\n\", \"2 2\\n1 2\\n1 1\\n1 3\\n1 4\\n2 4\\n2 3\\n2 1\\n3 1\\n3 2\\n3 3\\n3 4\\n\", \"2 3\\n1 3\\n... | Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a $n\times m$ grid (rows are numbered from $1$ to $n$, and col... | 0 |
{"tests": "{\"inputs\": [\"3 11\\n2 3 1 2 2 2 3 2 2 3 1\\n\", \"4 8\\n4 1 3 3 2 3 3 3\\n\", \"5 20\\n1 4 4 2 1 1 3 5 4 2 2 4 5 2 3 3 4 5 1 4\\n\", \"1 1\\n1\\n\", \"1 20\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n\", \"10 1\\n1\\n\", \"10000 10\\n10000 9999 9998 9997 9996 9995 9994 9993 9992 9991\\n\", \"5 2\\n3 3\\n\... | Arkady coordinates rounds on some not really famous competitive programming platform. Each round features $n$ problems of distinct difficulty, the difficulties are numbered from $1$ to $n$.
To hold a round Arkady needs $n$ new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the ... | 0.75 |
{"tests": "{\"inputs\": [\"2\\n2 1\\n\", \"4\\n3 4 1 2\\n\", \"6\\n2 5 3 1 4 6\\n\", \"10\\n7 2 9 6 5 8 1 3 10 4\\n\", \"2\\n1 2\\n\", \"10\\n6 1 2 9 3 5 4 10 7 8\\n\", \"10\\n10 9 8 7 6 5 4 3 2 1\\n\", \"50\\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14... | You are given a permutation $p$ of integers from $1$ to $n$, where $n$ is an even number.
Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type: take two indices $i$ and $j$ such that $2 \cdot |i - j| \geq n$ and swap $p_i$ and $p_j$.
There is no need to min... | 0 |
{"tests": "{\"inputs\": [\"3\\n1\\n2\\n3\\n\", \"3\\n3\\n2\\n1\\n\", \"10\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n1\\n\", \"10\\n8\\n8\\n5\\n1\\n2\\n7\\n3\\n8\\n9\\n4\\n\", \"10\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"100\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n2\\n3\\n4\\n5... | Vasya had a strictly increasing sequence of positive integers a_1, ..., a_{n}. Vasya used it to build a new sequence b_1, ..., b_{n}, where b_{i} is the sum of digits of a_{i}'s decimal representation. Then sequence a_{i} got lost and all that remained is sequence b_{i}.
Vasya wonders what the numbers a_{i} could be l... | 0 |
{"tests": "{\"inputs\": [\"3\\n10 20 10\\n6\\n1 1\\n2 1\\n2 2\\n3 1\\n3 2\\n3 3\\n\", \"7\\n1 2 1 3 1 2 1\\n9\\n2 1\\n2 2\\n3 1\\n3 2\\n3 3\\n1 1\\n7 1\\n7 7\\n7 4\\n\", \"1\\n1\\n3\\n1 1\\n1 1\\n1 1\\n\", \"1\\n1000000000\\n1\\n1 1\\n\", \"2\\n1 10\\n3\\n2 2\\n2 1\\n1 1\\n\", \"2\\n3922 3922\\n3\\n2 2\\n2 1\\n1 1\\n\"... | This is the harder version of the problem. In this version, $1 \le n, m \le 2\cdot10^5$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems.
You are given a sequence of integers $a=[a_1,a_2,\dots,a_n]$ of length $n$. Its subsequence is obtained by removin... | 0.5 |
{"tests": "{\"inputs\": [\"3\\n3 1 2\\n\", \"5\\n4 5 1 2 3\\n\", \"1\\n1\\n\", \"2\\n1 2\\n\", \"10\\n5 1 6 2 8 3 4 10 9 7\\n\", \"30\\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7\\n\", \"100\\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95... | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be ... | 0 |
{"tests": "{\"inputs\": [\"1 1\\n\", \"2 2\\n\", \"7 7\\n\", \"13 7\\n\", \"15 27\\n\", \"19 21\\n\", \"1 100\\n\", \"1 10\\n\"], \"outputs\": [\"5\\n1 3 4 5\\n\", \"22\\n2 6 8 10\\n14 18 20 22\\n\", \"287\\n7 21 28 35\\n49 63 70 77\\n91 105 112 119\\n133 147 154 161\\n175 189 196 203\\n217 231 238 245\\n259 273 280 28... | Dreamoon likes to play with sets, integers and $gcd$. $\operatorname{gcd}(a, b)$ is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements s_{i}, s_{j} from S, $\opera... | 0 |
{"tests": "{\"inputs\": [\"5\\n5 4 3 2 1\\n4\\n1 1 1 1\\n\", \"5\\n1 2 3 4 5\\n1\\n15\\n\", \"5\\n1 2 3 4 5\\n4\\n1 2 3 4\\n\", \"1\\n-42\\n1\\n-86\\n\", \"1\\n-21\\n10\\n-43 6 -46 79 -21 93 -36 -38 -67 1\\n\", \"10\\n87 -92 -67 -100 -88 80 -82 -59 81 -72\\n10\\n-50 30 30 77 65 92 -60 -76 -29 -15\\n\", \"6\\n1 2 3 4 5 ... | Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a s_{a} as close as possible to the sum of the elements in the array b s_{b}. So he wants to minimize the value v = |s_{a} - s_{b}|.
In one operation professor can swap some element from the array a and so... | 0 |
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 3\\n1 2 1\\n\", \"4 2\\n1 2\\n3 4\\n1 2 3 3\\n\", \"1 0\\n1\\n\", \"2 1\\n2 1\\n2 2\\n\", \"2 1\\n2 1\\n1 2\\n\", \"4 3\\n1 2\\n2 3\\n3 4\\n1 1 3 2\\n\", \"4 3\\n4 3\\n3 2\\n2 1\\n3 4 4 4\\n\", \"4 3\\n1 2\\n2 3\\n3 4\\n1 1 1 2\\n\"], \"outputs\": [\"-1\", \"3\\n2\\n1\\n3\\n\", ... | Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n.
Each man has at most one father but may have arbitrary number of sons.
Man number A is considered to b... | 0 |
{"tests": "{\"inputs\": [\"4\\nabcd\\ngg\\ncodeforces\\nabaca\\n\", \"1\\nddb\\n\", \"1\\nheaghhcgfb\\n\", \"1\\neefbhgeabache\\n\", \"1\\ndgeegbeabh\\n\", \"1\\nzcbacx\\n\", \"1\\nxyxzz\\n\", \"1\\nzyy\\n\"], \"outputs\": [\"bdac\\ngg\\ndfrcceeoos\\nNo answer\\n\", \"bdd\\n\", \"bfhhhacegg\\n\", \"bbfhhaaceeeeg\\n\", ... | You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neig... | 0 |
{"tests": "{\"inputs\": [\"2 3\\n6\\n8\\n1 5 6\\n1 9 4\\n2 4 2\\n\", \"1 3\\n4\\n1 5 3\\n1 9 4\\n4 6 6\\n\", \"0 2\\n1 1000000000 4\\n1 1000000000 2\\n\", \"0 0\\n\", \"2 3\\n4\\n6\\n1 4 3\\n1 5 2\\n1 6 5\\n\", \"0 5\\n1 96762320 50510976\\n243235878 312125306 50510976\\n326016273 338641867 50510976\\n385105810 4452248... | On a chessboard with a width of $10^9$ and a height of $10^9$, the rows are numbered from bottom to top from $1$ to $10^9$, and the columns are numbered from left to right from $1$ to $10^9$. Therefore, for each cell of the chessboard you can assign the coordinates $(x,y)$, where $x$ is the column number and $y$ is the... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n6 5 4\\n\", \"3\\n1 1000 10000\\n10 100 100000\\n\", \"6\\n12 8 12 17 20 5\\n17 4 8 8 8 4\\n\", \"6\\n16 20 18 7 14 2\\n17 12 4 10 7 4\\n\", \"6\\n4 1 12 9 3 11\\n12 20 19 12 19 11\\n\", \"1\\n7\\n5\\n\", \"2\\n1 2\\n1 1\\n\", \"1\\n1\\n1\\n\"], \"outputs\": [\"70\\n\", \"543210\\... | Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends... | 0 |
{"tests": "{\"inputs\": [\"4 1\\n(\\n\", \"4 4\\n(())\\n\", \"4 3\\n(((\\n\", \"875 50\\n)))((())()))((()(())))))())))((((((()))))))()(((((\\n\", \"1980 464\\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))(()))))))(())((())))()())()((())())()())))(())()(()))(()())()((((()))())()(())))))(()()(()(((((()(()()))((... | As Famil Doorβs birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings!
The sequence of round brackets is called valid if and only if: the... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n1 2\\n2 3\\n3 1\\n2 1 3\\n\", \"3 3\\n1 2\\n2 3\\n3 1\\n1 1 1\\n\", \"5 3\\n1 2\\n2 3\\n4 5\\n2 1 2 2 1\\n\", \"1 0\\n1\\n\", \"10 20\\n8 9\\n2 1\\n8 4\\n3 4\\n4 6\\n10 3\\n7 8\\n2 3\\n10 7\\n10 9\\n3 6\\n3 5\\n9 1\\n10 2\\n5 8\\n8 3\\n8 1\\n7 5\\n9 2\\n6 8\\n2 4 3 2 2 4 3 1 3 1\\n\", \... | Today Johnny wants to increase his contribution. His plan assumes writing $n$ blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the reader... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n2 3 1000000\\n4 0 4\\n3 0 1000000\\n4 0 1\\n2 0 5\\n3 1 1000000\\n\", \"0 1\\n242110 453990 1000000\\n\", \"1 1\\n500000 1 1000000\\n500000 0 999999\\n\", \"3 0\\n3 1 1000000\\n1 1 1000000\\n2 1 1000000\\n\", \"1 1\\n999999 999999 1000000\\n999999 0 999999\\n\", \"0 0\\n\", \"1 1\\n2314... | There is a square of size $10^6 \times 10^6$ on the coordinate plane with four points $(0, 0)$, $(0, 10^6)$, $(10^6, 0)$, and $(10^6, 10^6)$ as its vertices.
You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect with at least one side of the square.
Now you are wond... | 0 |
{"tests": "{\"inputs\": [\"1 1 2.000000\\n1\\n1\\n1\\n\", \"11 4 1.250000\\n9 11 7 5 15 6 6 6 6 6 6\\n8\\n4 5 6 7 8 9 10 11\\n\", \"13 4 1.250000\\n3 3 3 3 3 20 3 3 3 3 3 3 3\\n10\\n4 5 6 7 8 9 10 11 12 13\\n\", \"1 1 2.000000\\n4\\n1\\n1\\n\", \"1 1 2.000000\\n1121\\n1\\n1\\n\", \"1 1 2.000000\\n758432\\n1\\n1\\n\", \... | In this problem you will have to deal with a real algorithm that is used in the VK social network.
As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a cer... | 0.75 |
{"tests": "{\"inputs\": [\"3\\n2 1 3\\n\", \"3\\n3 1 4\\n\", \"1\\n1\\n\", \"4\\n7 7 1 1\\n\", \"2\\n3 4\\n\", \"10\\n582366931603099761 314858607473442114 530263190370309150 871012489649491233 877068367969362781 671646356752418008 390155369686708364 958695211216189893 919124874293325142 196726357117434998\\n\", \"20\\... | Ridhiman challenged Ashish to find the maximum valued subsequence of an array $a$ of size $n$ consisting of positive integers.
The value of a non-empty subsequence of $k$ elements of $a$ is defined as $\sum 2^i$ over all integers $i \ge 0$ such that at least $\max(1, k - 2)$ elements of the subsequence have the $i$-t... | 0.125 |
{"tests": "{\"inputs\": [\"5\\na\\nabcdfdcecba\\nabbaxyzyx\\ncodeforces\\nacbba\\n\", \"10\\nu\\nxqpczgnzazxyrvx\\ncfjgfhxmzqmjgzzjthziuomldylspyfuxvjlgdc\\nooydbldio\\nyvaamavy\\nrzjjebcgotjffuzr\\nhtfkwvihzuwxczopzqujdnaorgxibjfcmlzntskawxhyoymwynitukttewfpajuph\\nfactnjajntcaf\\nywowyovhrgradhtrqkgurkjpudnrrqhmmwiaq... | This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string $s$, consisting of lowercase English letters. Find the longest string, $t$, which satisfies the... | 0 |
{"tests": "{\"inputs\": [\"5 6 4 14\\n1 2 3 4 5\\n1 5 2\\n1 2 5\\n2 3 5\\n3 5 3\\n\", \"3 2 5 3\\n5 2 10\\n1 2 3\\n1 1 9\\n1 1 2\\n2 2 4\\n1 2 9\\n\", \"1 1 1 4\\n2\\n1 1 5\\n\", \"5 12 2 13\\n2 4 7 19 100\\n1 4 6\\n9 11 8\\n\", \"53 1 27 3\\n44 28 48 60 29 42 59 32 9 58 3 11 7 53 4 19 37 41 36 52 29 9 24 8 31 39 52 41... | You are playing a computer game, where you lead a party of $m$ soldiers. Each soldier is characterised by his agility $a_i$.
The level you are trying to get through can be represented as a straight line segment from point $0$ (where you and your squad is initially located) to point $n + 1$ (where the boss is located).... | 0 |
{"tests": "{\"inputs\": [\"4\\n3 4\\n1 4\\n3 4\\n\", \"3\\n1 3\\n1 3\\n\", \"3\\n1 2\\n2 3\\n\", \"15\\n10 15\\n12 15\\n6 15\\n8 15\\n2 15\\n3 15\\n10 15\\n13 15\\n5 15\\n7 15\\n11 15\\n4 14\\n1 15\\n14 15\\n\", \"15\\n9 15\\n6 15\\n12 15\\n3 14\\n14 15\\n11 15\\n6 15\\n7 15\\n10 15\\n4 15\\n1 15\\n13 15\\n2 15\\n9 15\... | Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from $1$ to $n$. For every edge $e$ of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge $e$ (and only this ... | 0 |
{"tests": "{\"inputs\": [\"4 2 10\\n17:05:53\\n17:05:58\\n17:06:01\\n22:39:47\\n\", \"1 2 86400\\n00:00:00\\n\", \"5 2 40000\\n06:30:57\\n07:27:25\\n09:10:21\\n11:05:03\\n12:42:37\\n\", \"7 4 30000\\n05:08:54\\n05:35:53\\n06:03:20\\n06:17:50\\n09:29:46\\n11:35:29\\n14:49:02\\n\", \"10 3 30000\\n00:06:54\\n00:42:06\\n03... | Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarp... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n\", \"4\\n0 0 0 2\\n\", \"3\\n1 1 3\\n\", \"7\\n0 0 2 2 5 5 6\\n\", \"10\\n1 2 3 4 4 4 7 7 7 10\\n\", \"1\\n1\\n\", \"1\\n0\\n\"], \"outputs\": [\"0 1 2 \", \"1 3 4 0 \", \"0 2 1 \", \"1 3 0 4 2 7 5 \", \"0 1 2 3 5 6 4 8 9 7 \", \"0 \", \"1 \"]}", "source": "primeintellect"} | Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that:
for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$.
The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
-----In... | 0 |
{"tests": "{\"inputs\": [\"4 6\\n1 2 5 2\\n2 3 3 4\\n\", \"2 3\\n5 6\\n5 5\\n\", \"24 3\\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\\n\", \"43 5\\n6 7 15 12 15 7 22 33 38 15 7 23 31 21 26 41 25 14 26 33 5 28 22 6 35 17 19 32 41 27 20 25 5 32 37 1... | There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c_1, c_2, ..., c_{n}. The Old Peykan wants to travel from city c_1 to c_{n} using roads. There are (n - 1) one way roads, the i-th road goes from city c_{i} to city c_{i} + ... | 0 |
{"tests": "{\"inputs\": [\"6 3\\n2 2 2\\n3 1\\n5 4\\n2 5\\n\", \"5 9\\n0 2 3\\n1 2\\n1 3\\n1 5\\n2 3\\n2 4\\n2 5\\n3 4\\n3 5\\n4 5\\n\", \"10 3\\n3 4 3\\n1 3\\n3 7\\n7 1\\n\", \"5000 5\\n1000 1000 3000\\n4 11\\n11 7\\n7 127\\n127 999\\n999 4\\n\", \"5000 1\\n1000 0 4000\\n444 789\\n\", \"1 0\\n1 0 0\\n\", \"1 0\\n0 1 0... | You are given an undirected graph without self-loops or multiple edges which consists of $n$ vertices and $m$ edges. Also you are given three integers $n_1$, $n_2$ and $n_3$.
Can you label each vertex with one of three numbers 1, 2 or 3 in such way, that: Each vertex should be labeled by exactly one number 1, 2 or 3... | 0.125 |
{"tests": "{\"inputs\": [\"3\\n-1 2 0\\n\", \"4\\n-1 -2 -3 0\\n\", \"5\\n-1 -2 1 2 0\\n\", \"5\\n-1 -2 -3 -4 0\\n\", \"3\\n-101 101 0\\n\", \"21\\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000\\n\", \"4\\n0 -1 -2 -3\\n\"], \"outputs\": [\"1 -1\\n1 2\\n1 0\\n\", \"1 -1\\n2... | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
The product of all numbers in the first set is less than zero ( < 0). The product of all numbers in the second set is greater than zero ( > 0). The product of all numbers in... | 0 |
{"tests": "{\"inputs\": [\"2 24 60 15\\n16 0\\n17 15\\n\", \"2 24 60 16\\n16 0\\n17 15\\n\", \"10 24 60 8\\n10 59\\n21 56\\n0 42\\n21 27\\n5 24\\n5 53\\n16 5\\n5 22\\n10 11\\n10 46\\n\", \"9 3 24 9\\n1 15\\n0 6\\n0 22\\n2 22\\n2 7\\n1 7\\n1 23\\n2 14\\n0 14\\n\", \"9 24 60 21\\n1 36\\n2 35\\n2 16\\n2 55\\n1 16\\n0 35\\... | There are many freight trains departing from Kirnes planet every day. One day on that planet consists of $h$ hours, and each hour consists of $m$ minutes, where $m$ is an even number. Currently, there are $n$ freight trains, and they depart every day at the same time: $i$-th train departs at $h_i$ hours and $m_i$ minut... | 0 |
{"tests": "{\"inputs\": [\"6 5\\n3 4 U\\n6 1 L\\n2 5 L\\n1 6 U\\n4 3 U\\n\", \"10 6\\n2 9 U\\n10 1 U\\n1 10 U\\n8 3 L\\n10 1 L\\n6 5 U\\n\", \"1 2\\n1 1 L\\n1 1 U\\n\", \"1000000000 1\\n117117117 882882884 U\\n\", \"10 10\\n5 6 U\\n4 7 U\\n8 3 L\\n8 3 L\\n1 10 U\\n9 2 U\\n10 1 L\\n10 1 L\\n8 3 U\\n8 3 U\\n\", \"15 7\\n... | Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.
A bar of chocolate can be presented as an n Γ n table, where each cell represents one piece of chocolate. The columns of the table are numbered from 1 to n from left to right and the rows are ... | 0 |
{"tests": "{\"inputs\": [\"5 2\\n5 2 3\\n3 1 4 5 2\\n3 5\\n\", \"4 4\\n5 1 4\\n4 3 1 2\\n2 4 3 1\\n\", \"4 4\\n2 1 11\\n1 3 2 4\\n1 3 2 4\\n\", \"23 5\\n10 3 3\\n2 1 4 11 8 10 5 6 7 9 12 3 14 13 16 18 21 15 17 19 20 23 22\\n4 6 3 18 23\\n\", \"23 5\\n10 3 4\\n2 1 4 11 8 10 5 6 7 9 12 3 14 13 16 18 21 15 17 19 20 23 22\... | There are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct.
You have two types of spells which you may cast: Fireball: you spend $x$ mana and destroy exactly $k$ consecutive warriors; Berserk: you spend $y$ mana, choose two consecutive warriors, and the warrior with ... | 0 |
{"tests": "{\"inputs\": [\"1\\n\", \"4\\n\", \"2\\n\", \"3\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\"], \"outputs\": [\"-1\", \"1 2 3 4 \\n13 15 11 5 \\n12 9 10 6 \\n16 14 8 7 \\n\", \"-1\", \"1 7 9 \\n3 2 5 \\n4 8 6 \\n\", \"1 2 3 4 5 \\n10 9 8 7 6 \\n11 16 17 23 25 \\n12 1... | Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, i... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2\\n2 3\\n\", \"4\\n1 2\\n3 2\\n4 2\\n\", \"19\\n2 19\\n7 15\\n8 10\\n16 1\\n12 5\\n11 5\\n6 18\\n12 14\\n14 15\\n2 6\\n9 14\\n4 17\\n16 10\\n4 2\\n7 18\\n3 2\\n9 13\\n11 10\\n\", \"20\\n12 10\\n5 19\\n12 18\\n4 2\\n3 16\\n11 8\\n3 2\\n17 4\\n14 7\\n6 5\\n10 20\\n14 9\\n16 12\\n9 13\\n1... | The Resistance is trying to take control over as many planets of a particular solar system as possible. Princess Heidi is in charge of the fleet, and she must send ships to some planets in order to maximize the number of controlled planets.
The Galaxy contains N planets, connected by bidirectional hyperspace tunnels i... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n\", \"4 1\\n\", \"5 6\\n\", \"100 100\\n\", \"10000 20001\\n\", \"10000 30001\\n\", \"10 17\\n\"], \"outputs\": [\"2 1 3 \", \"1 2 3 4 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"3 1 4 6 2 8 5 9 7 10 \"]}", "source": "primeintellect"} | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array a with indices from [l, r) can be implemented as follows: If the segment [l, r) is already sorted in non-descending order (that is, for any i such that l β€ i < r - 1 a[i] β€ a[i + 1]), then end the function call; Let $\ope... | 0 |
{"tests": "{\"inputs\": [\"5\\n3 4 3 2 4\\n\", \"3\\n4 4 4\\n\", \"99\\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 ... | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height h_{i}. The goal of the game is to reach n-th py... | 0 |
{"tests": "{\"inputs\": [\"4 3\\naaa\\nbbb\\nccb\\nddd\\n\", \"6 1\\na\\na\\nb\\nb\\nc\\nc\\n\", \"1 1\\na\\n\", \"10 10\\naaaaarpppp\\nbbbbsssssu\\ncciiiiiiqq\\nddmmgggggg\\neeebbbbbbb\\nfffffqoooo\\ngxxxxrrrrr\\nhhfuuuuuuu\\niiillqqqqq\\njjjjjppwww\\n\", \"10 10\\naaaaaaaaaa\\nbbbbbbbbbb\\ncccccccccc\\ndddddddddd\\ne... | Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns.
The colored pieces attracted Innokenty's attention so he immediately came up... | 0 |
{"tests": "{\"inputs\": [\"2\\n5 5\\n2 1\\n4 5\\n2 3\\n1 3\\n3 5\\n7 2\\n3 7\\n4 2\\n\", \"4\\n9 17\\n3 6\\n2 6\\n6 9\\n4 1\\n2 8\\n1 9\\n7 9\\n8 5\\n1 7\\n4 9\\n6 7\\n3 4\\n9 3\\n8 4\\n2 1\\n3 8\\n2 7\\n5 6\\n2 5\\n3 4\\n1 3\\n4 5\\n5 3\\n2 3\\n12 8\\n10 2\\n9 2\\n6 9\\n10 6\\n8 2\\n4 10\\n11 2\\n4 11\\n19 10\\n6 2\\n... | There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads.
... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n\", \"6\\n4 7 7 12 31 61\\n\", \"1\\n4\\n\", \"2\\n531 108\\n\", \"5\\n3 1 1 7 1\\n\", \"10\\n10 1 1 1 1 1 3 6 7 3\\n\", \"31\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 7 7 7 7 15 15 31\\n\"], \"outputs\": [\"No\\n\", \"Yes\\n4 12 7 31 7 61 \\n\", \"Yes\\n4 \\n\", \"Yes\\n1... | Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence $a_1, \ldots, a_n$. In order to not reveal the secret earlier than needed, Vitya encrypted the answer and obtained the sequence $b_1, \ldots, b_n$ using the foll... | 0.125 |
{"tests": "{\"inputs\": [\"4\\n1 2\\n2 3\\n3 4\\n\", \"6\\n1 2\\n2 3\\n3 4\\n2 5\\n3 6\\n\", \"5\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"2\\n1 2\\n\", \"8\\n1 2\\n1 3\\n1 4\\n1 8\\n7 8\\n6 8\\n5 8\\n\", \"9\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n6 7\\n7 8\\n7 9\\n\", \"3\\n2 3\\n1 2\\n\"], \"outputs\": [\"Yes\\n1\\n1 4\\n\", \"No\\n\... | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa... | 0.5 |
{"tests": "{\"inputs\": [\"11\\n1 100\\n3 70\\n4\\n2\\n3 120\\n5\\n3 120\\n6\\n1 150\\n4\\n3 300\\n\", \"5\\n1 100\\n3 200\\n2\\n4\\n5\\n\", \"7\\n1 20\\n2\\n6\\n4\\n6\\n6\\n2\\n\", \"1\\n1 100\\n\", \"2\\n1 100\\n2\\n\", \"10\\n1 37\\n6\\n5\\n2\\n5\\n6\\n5\\n2\\n4\\n2\\n\", \"10\\n1 5\\n4\\n5\\n4\\n1 21\\n6\\n1 10\\n1... | Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.
speed limit: this sign comes with a positive integer number β maximal speed of the car after the sign (cancel the action of the previous sign of this type); overtake is allowed: this sign means that aft... | 0 |
{"tests": "{\"inputs\": [\"11\\n0 0 0 1 1 0 1 0 0 1 1\\n1 2\\n1 3\\n2 4\\n2 5\\n5 6\\n5 7\\n3 8\\n3 9\\n3 10\\n9 11\\n\", \"4\\n0 0 0 0\\n1 2\\n2 3\\n3 4\\n\", \"15\\n0 1 0 0 1 1 0 1 1 1 1 1 0 1 0\\n10 7\\n10 3\\n10 8\\n5 7\\n13 14\\n8 13\\n15 4\\n15 13\\n5 2\\n9 3\\n11 15\\n13 6\\n1 12\\n9 1\\n\", \"42\\n1 0 0 1 0 1 1... | Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.
There are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored trees, so he wants to change the tree such that all vertices have the same color (black or white).
To c... | 0 |
{"tests": "{\"inputs\": [\"4\\n3 2 3 6\\n2 8 5 10\\n\", \"3\\n1 2 3\\n1 2 3\\n\", \"1\\n0\\n1\\n\", \"2\\n0 0\\n69 6969\\n\", \"10\\n3 3 5 5 6 6 1 2 4 7\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10\\n206158430208 206162624513 68719476737 137506062337 206162624513 4194305 68719476737 206225539072 137443147777 68719476736\\n20224389... | Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two intege... | 0 |
{"tests": "{\"inputs\": [\"5 8\\n....#..#\\n.#......\\n##.#....\\n##..#.##\\n........\\n4\\n1 1 2 3\\n4 1 4 1\\n1 2 4 5\\n2 5 5 8\\n\", \"7 39\\n.......................................\\n.###..###..#..###.....###..###..#..###.\\n...#..#.#..#..#.........#..#.#..#..#...\\n.###..#.#..#..###.....###..#.#..#..###.\\n.#....#... | They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Row... | 0.125 |
{"tests": "{\"inputs\": [\"3\\n4\\nS010\\n0001\\n1000\\n111F\\n3\\nS10\\n101\\n01F\\n5\\nS0101\\n00000\\n01111\\n11111\\n0001F\\n\", \"1\\n3\\nS11\\n011\\n01F\\n\", \"1\\n10\\nS000000000\\n0000000000\\n0000000000\\n0000000000\\n0000001000\\n0000000101\\n0000000000\\n0000000000\\n0000000000\\n000000000F\\n\", \"1\\n5\\n... | Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like walls, he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size $n\times n$ and he wants to traverse his grid from the upper left ($1,1$) corner to the... | 0 |
{"tests": "{\"inputs\": [\"5\\n4 5\\n10 8 6 4\\n1 2 3 4 5\\n1 1\\n3\\n3\\n1 1\\n3\\n2\\n5 3\\n1000 2 2 2 3\\n3 1 5\\n5 5\\n1 2 3 4 5\\n1 2 3 4 5\\n\", \"1\\n2 3\\n1 1\\n1 2 3\\n\", \"1\\n2 2\\n2 2\\n2 2\\n\", \"1\\n1 1\\n1000\\n1000\\n\", \"1\\n1 3\\n3\\n1 2 3\\n\", \"1\\n4 4\\n1 1 1 1\\n1 2 3 4\\n\", \"1\\n2 2\\n1 1\\... | You are given two arrays of integers $a_1,\ldots,a_n$ and $b_1,\ldots,b_m$.
Your task is to find a non-empty array $c_1,\ldots,c_k$ that is a subsequence of $a_1,\ldots,a_n$, and also a subsequence of $b_1,\ldots,b_m$. If there are multiple answers, find one of the smallest possible length. If there are still multiple... | 0.125 |
{"tests": "{\"inputs\": [\"2\\n1 2 2\\n1 2 2\\n1 2 2\\n1 2 2\\n2 1 1\\n2 1 1\\n2 1 1\\n2 1 1\\n\", \"3\\n1 2 3\\n1 1 1\\n1 1 1\\n1 1 1\\n2 1 3\\n2 2 2\\n2 2 2\\n2 2 2\\n3 1 2\\n3 3 3\\n3 3 3\\n3 3 3\\n\", \"3\\n1 2 3\\n2 3 1\\n3 1 2\\n2 3 3\\n3 1 1\\n1 2 2\\n1 2 1\\n2 3 2\\n3 1 3\\n1 3 1\\n2 1 2\\n3 2 3\\n\", \"1\\n1 1... | A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure.
As part of this task, we assume that the social network is... | 0 |
{"tests": "{\"inputs\": [\"6 2\\n5 5 6 8 3 12\\n\", \"1 1\\n5\\n\", \"5 300\\n939 465 129 611 532\\n\", \"5 1\\n416 387 336 116 81\\n\", \"3 10\\n1 100 1000\\n\", \"2 1\\n2 20\\n\", \"3 2\\n10 10 100\\n\"], \"outputs\": [\"2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\\n\", \"1\\n\", \"300 667.864105343... | Carol is currently curling.
She has n disks each with radius r on the 2D plane.
Initially she has all these disks above the line y = 10^100.
She then will slide the disks towards the line y = 0 one by one in order from 1 to n.
When she slides the i-th disk, she will place its center at the point (x_{i}, 10^100). ... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 3 1 4 5\\n\", \"4\\n4 2 2 4\\n\", \"2\\n1 1\\n\", \"5\\n100 1 100 1 100\\n\", \"4\\n2 3 4 2\\n\", \"4\\n2 1 3 3\\n\", \"5\\n1 5 5 1 4\\n\"], \"outputs\": [\"3\", \"1\", \"1\", \"2\", \"1\", \"2\", \"2\"]}", "source": "primeintellect"} | There are $n$ beautiful skyscrapers in New York, the height of the $i$-th one is $h_i$. Today some villains have set on fire first $n - 1$ of them, and now the only safety building is $n$-th skyscraper.
Let's call a jump from $i$-th skyscraper to $j$-th ($i < j$) discrete, if all skyscrapers between are strictly lower... | 0.875 |
{"tests": "{\"inputs\": [\"9\\n10 5 4 7 9 12 6 2 10\\n\", \"20\\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\\n\", \"20\\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19\\n\", \"100\\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 50... | You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you... | 0 |
{"tests": "{\"inputs\": [\"20\\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\\n\", \"18\\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\\n\", \"6\\n2 1 0 2 1 2\\n\", \"1\\n0\\n\", \"7\\n0 1 2 3 4 2 6\\n\", \"6\\n0 0 0 0 0 0\\n\", \"4\\n0 0 0 0\\n\"], \"outputs\": [\"4 5\\n2 2\\n\", \"3 6\\n2 3\\n\", \"-1\\n\", \"1 1\\n1 1\\n\", \"-1\... | Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ... | 0 |
{"tests": "{\"inputs\": [\"2\\nivan 1 00123\\nmasha 1 00123\\n\", \"3\\nkarl 2 612 12\\npetr 1 12\\nkatya 1 612\\n\", \"4\\nivan 3 123 123 456\\nivan 2 456 456\\nivan 8 789 3 23 6 56 9 89 2\\ndasha 2 23 789\\n\", \"20\\nnxj 6 7 6 6 7 7 7\\nnxj 10 8 5 1 7 6 1 0 7 0 6\\nnxj 2 6 5\\nnxj 10 6 7 6 6 5 8 3 6 6 8\\nnxj 10 6 1... | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given n strings β all entries from Vasya's phone books. Each entry starts with a fri... | 0 |
{"tests": "{\"inputs\": [\"5\\na\\nabcdfdcecba\\nabbaxyzyx\\ncodeforces\\nacbba\\n\", \"10\\nu\\nxqpczgnzazxyrvx\\ncfjgfhxmzqmjgzzjthziuomldylspyfuxvjlgdc\\nooydbldio\\nyvaamavy\\nrzjjebcgotjffuzr\\nhtfkwvihzuwxczopzqujdnaorgxibjfcmlzntskawxhyoymwynitukttewfpajuph\\nfactnjajntcaf\\nywowyovhrgradhtrqkgurkjpudnrrqhmmwiaq... | This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string $s$, consisting of lowercase English letters. Find the longest string, $t$, which satisfies the... | 0 |
{"tests": "{\"inputs\": [\"2 100\\n3 10\\n50 150\\n\", \"3 9\\n5 5 30\\n6 6 10\\n\", \"2 12\\n1 3\\n10 15\\n\", \"20 30\\n70 97 14 31 83 22 83 56 19 87 59 7 7 89 24 82 34 40 6 24\\n10 4 47 46 11 18 32 55 16 32 53 37 43 32 41 46 57 14 60 44\\n\", \"1 1\\n1000000\\n1\\n\", \"1 200\\n1000000\\n100\\n\", \"1 1000000\\n1000... | Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to a_{i} ml per second (this amount may be a real number). The water delivered by i-th tap has temperature t_{i}.
If for every $i \in [ 1, n ]$ you set i-th tap to deliver ex... | 0 |
{"tests": "{\"inputs\": [\"5\\n1 7\\n6 4\\n2 10\\n9 8\\n3 5\\n\", \"3\\n5 4\\n3 2\\n6 1\\n\", \"1\\n1 2\\n\", \"2\\n1 3\\n2 4\\n\", \"3\\n1 4\\n2 5\\n3 6\\n\", \"2\\n1 2\\n4 3\\n\"], \"outputs\": [\"3\\n5 3 1 \\n\", \"3\\n3 2 1 \\n\", \"1\\n1 \\n\", \"2\\n2 1 \\n\", \"3\\n3 2 1 \\n\", \"1\\n1 \\n\"]}", "source": "prime... | You are given $n$ pairs of integers $(a_1, b_1), (a_2, b_2), \ldots, (a_n, b_n)$. All of the integers in the pairs are distinct and are in the range from $1$ to $2 \cdot n$ inclusive.
Let's call a sequence of integers $x_1, x_2, \ldots, x_{2k}$ good if either $x_1 < x_2 > x_3 < \ldots < x_{2k-2} > x_{2k-1} < x_{2k}$... | 0 |
{"tests": "{\"inputs\": [\"3 4\\n1 2 0\\n1 3 1\\n2 3 0\\n2 3 1\\n\", \"4 8\\n1 1 0\\n1 3 0\\n1 3 1\\n3 2 0\\n2 1 0\\n3 4 1\\n2 4 0\\n2 4 1\\n\", \"5 10\\n1 2 0\\n1 3 1\\n1 4 0\\n2 3 0\\n2 3 1\\n2 5 0\\n3 4 0\\n3 4 1\\n4 2 1\\n4 5 0\\n\", \"10 40\\n9 9 1\\n4 10 0\\n4 1 1\\n6 4 1\\n9 9 1\\n6 4 1\\n2 7 1\\n3 7 1\\n5 9 1\\... | Egor is a famous Russian singer, rapper, actor and blogger, and finally he decided to give a concert in the sunny Republic of Dagestan.
There are $n$ cities in the republic, some of them are connected by $m$ directed roads without any additional conditions. In other words, road system of Dagestan represents an arbitra... | 0 |
{"tests": "{\"inputs\": [\"4\\n0 1 1 1\\n\", \"1\\n3\\n\", \"1\\n0\\n\", \"1\\n2000000000\\n\", \"1\\n1\\n\", \"26\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\\n\"], \"outputs\": [\"0\\n\", \"3\\n\", \"0\\n\", \"2000000000\\n\", \"1\\n\", \"5\\n\"]}", "source": "primeintellect"} | Ivan has got an array of n non-negative integers a_1, a_2, ..., a_{n}. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2^{a}_1, 2^{a}_2, ..., 2^{a}_{n} on a piece of paper. Now he wonders, what minimum number of integers of form 2^{b} (b β₯ 0) need to be added to the piece of p... | 0.125 |
{"tests": "{\"inputs\": [\"3 1\\n3 4 6 0\\n\", \"4 3\\n4 10 14 1\\n3 6 6 0\\n2 3 3 1\\n\", \"4 2\\n3 4 6 1\\n4 12 15 1\\n\", \"4 2\\n3 4 5 1\\n2 3 3 1\\n\", \"1 0\\n\", \"1 1\\n1 1 1 0\\n\"], \"outputs\": [\"7\", \"14\", \"Data not sufficient!\", \"Game cheated!\", \"1\", \"Game cheated!\"]}", "source": "primeintellect... | Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the nodes of the tree such tha... | 0 |
{"tests": "{\"inputs\": [\"2\\n4 3\\n5 0\\n1 4\\n2 2\\n\\n5 3\\n5 2\\n4 2\\n3 1\\n\", \"1\\n1 7\\n334569692 287790954\\n828776938 450248098\\n812787473 543828736\\n353202854 229469066\\n105035292 19740770\\n294918734 142174357\\n944609166 419900619\\n\", \"1\\n7 7\\n875211518 78149272\\n372527826 28528254\\n777595365 6... | Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly $n$ flowers.
Vladimir went to a flower shop, and he was amazed to see that there are $m$ types of flowers being sold there, and there is unlimited supply of flowers of each type. Vladimir wants to choose flow... | 0 |
{"tests": "{\"inputs\": [\"3\\n0 0 1\\n0 0 1\\n1 1 0\\n\", \"4\\n0 1 1 1\\n1 0 1 1\\n1 1 0 1\\n1 1 1 0\\n\", \"3\\n0 0 0\\n0 0 1\\n0 1 0\\n\", \"4\\n0 0 0 1\\n0 0 0 0\\n0 0 0 1\\n1 0 1 0\\n\", \"4\\n0 0 1 0\\n0 0 0 1\\n1 0 0 0\\n0 1 0 0\\n\", \"10\\n0 0 0 0 0 0 1 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 1 0 0 0 0 0 0\\n0 0 ... | There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with e... | 0 |
{"tests": "{\"inputs\": [\"1\\n3 1\\n2 1\\n3 1\\n\", \"1\\n3 2\\n1 2\\n1 3\\n\", \"10\\n6 4\\n3 2\\n1 6\\n4 6\\n6 5\\n1 3\\n6 4\\n3 5\\n1 2\\n6 5\\n4 1\\n6 1\\n6 3\\n6 2\\n3 1\\n4 6\\n1 6\\n3 5\\n5 5\\n4 5\\n4 2\\n3 5\\n4 1\\n4 1\\n1 3\\n2 1\\n4 1\\n4 2\\n1 2\\n3 2\\n4 1\\n6 6\\n3 4\\n5 6\\n1 3\\n6 2\\n3 5\\n3 1\\n1 2\... | Ayush and Ashish play a game on an unrooted tree consisting of $n$ nodes numbered $1$ to $n$. Players make the following move in turns: Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints. A leaf node is a node with degree less than or equal to $1$.
A tr... | 0 |
{"tests": "{\"inputs\": [\"1\\n\", \"3\\n\", \"5\\n\", \"7\\n\", \"9\\n\", \"11\\n\"], \"outputs\": [\"1\\n\", \"2 1 4\\n3 5 7\\n6 9 8\\n\", \"2 4 1 6 8\\n10 3 5 7 12\\n9 11 13 15 17\\n14 19 21 23 16\\n18 20 25 22 24\\n\", \"2 4 6 1 8 10 12\\n14 16 3 5 7 18 20\\n22 9 11 13 15 17 24\\n19 21 23 25 27 29 31\\n26 33 35 37 ... | Find an n Γ n matrix with different numbers from 1 to n^2, so the sum in each row, column and both main diagonals are odd.
-----Input-----
The only line contains odd integer n (1 β€ n β€ 49).
-----Output-----
Print n lines with n integers. All the integers should be different and from 1 to n^2. The sum in each row,... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n101\\n001\\n110\\n\", \"7 15\\n000100001010010\\n100111010110001\\n101101111100100\\n010000111111010\\n111010010100001\\n000011001111101\\n111111011010011\\n\", \"1 1\\n0\\n\", \"1 1\\n1\\n\", \"2 58\\n1100001110010010100001000000000110110001101001100010101110\\n111011001010111100111001... | 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... | 0 |
{"tests": "{\"inputs\": [\"3 3 3\\n\", \"2 3 1\\n\", \"2 3 1\\n\", \"2 2 2\\n\", \"2 3 3\\n\", \"3 3 4\\n\", \"5 5 12\\n\", \"7 5 17\\n\", \"2 15 3\\n\", \"5 5 3\\n\", \"2 4 3\\n\"], \"outputs\": [\"3 1 1 1 2 1 3\\n3 2 1 2 2 2 3\\n3 3 1 3 2 3 3\\n\", \"6 1 1 1 2 1 3 2 3 2 2 2 1\\n\", \"6 1 1 1 2 1 3 2 3 2 2 2 1\\n\", \... | Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place... | 0 |
{"tests": "{\"inputs\": [\"12\\n3\\n4 4\\n12 1\\n3 4\\n\", \"1\\n1\\n1 1\\n\", \"288807105787200\\n4\\n46 482955026400\\n12556830686400 897\\n414 12556830686400\\n4443186242880 325\\n\", \"2\\n4\\n1 1\\n1 2\\n2 1\\n2 2\\n\", \"18\\n36\\n1 1\\n1 2\\n1 3\\n1 6\\n1 9\\n1 18\\n2 1\\n2 2\\n2 3\\n2 6\\n2 9\\n2 18\\n3 1\\n3 2... | You are given a positive integer $D$. Let's build the following graph from it: each vertex is a divisor of $D$ (not necessarily prime, $1$ and $D$ itself are also included); two vertices $x$ and $y$ ($x > y$) have an undirected edge between them if $x$ is divisible by $y$ and $\frac x y$ is a prime; the weight of a... | 0 |
{"tests": "{\"inputs\": [\"3 3\\n1 2 3\\n\", \"2 1\\n7 12\\n\", \"1 1\\n1000\\n\", \"5 8\\n10 3 8 31 20\\n\", \"5 15\\n1 2 3 4 5\\n\", \"8 25\\n6 8 3 7 2 1 4 9\\n\", \"10 9\\n5 10 2 14 15 6 3 11 4 1\\n\", \"10 27\\n17 53 94 95 57 36 47 68 48 16\\n\", \"6 5\\n17 35 15 11 33 39\\n\", \"10 27\\n17 53 94 95 57 36 47 68 48 ... | General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value... | 0 |
{"tests": "{\"inputs\": [\"0 0\\n4 6\\n3\\nUUU\\n\", \"0 3\\n0 0\\n3\\nUDD\\n\", \"0 0\\n0 1\\n1\\nL\\n\", \"0 0\\n0 1\\n2\\nLU\\n\", \"0 0\\n1000000000 1000000000\\n2\\nDR\\n\", \"0 1\\n2 1\\n1\\nR\\n\"], \"outputs\": [\"5\\n\", \"3\\n\", \"-1\\n\", \"2\\n\", \"2000000000\\n\", \"1\\n\"]}", "source": "primeintellect"} | You a captain of a ship. Initially you are standing in a point $(x_1, y_1)$ (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point $(x_2, y_2)$.
You know the weather forecast β the string $s$ of length $n$, consisting only of letters U, D, L and R. The letter corre... | 0.125 |
{"tests": "{\"inputs\": [\"6\\n1 0 1 1 0 1\\n1 2 2 2 2\\n\", \"5\\n1 0 1 0 1\\n1 1 1 1\\n\", \"8\\n1 0 0 1 0 1 1 0\\n1 1 2 2 3 3 3\\n\", \"9\\n1 1 0 0 1 0 1 0 1\\n1 1 2 2 3 3 4 4\\n\", \"100\\n0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 0 1 0 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0... | Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | 0 |
{"tests": "{\"inputs\": [\"6 2 3\\n1 2\\n1 5\\n2 3\\n3 4\\n4 5\\n5 6\\n\", \"2 2 1\\n2 1\\n1 2\\n\", \"50 2 5\\n9 14\\n46 34\\n40 35\\n44 30\\n32 16\\n1 38\\n48 2\\n17 14\\n50 25\\n6 1\\n45 19\\n21 15\\n22 11\\n15 33\\n8 28\\n2 32\\n10 22\\n37 3\\n43 39\\n25 16\\n9 19\\n16 3\\n28 32\\n20 45\\n24 32\\n4 18\\n49 39\\n13 ... | Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r... | 0.875 |
{"tests": "{\"inputs\": [\"7 8 25\\n1 2 1\\n2 3 10\\n3 4 2\\n1 5 2\\n5 6 7\\n6 4 15\\n5 3 1\\n1 7 3\\n\", \"2 1 5\\n1 2 4\\n\", \"15 15 23\\n13 10 12\\n11 14 12\\n2 15 5\\n4 10 8\\n10 2 4\\n10 7 5\\n3 10 1\\n5 6 11\\n1 13 8\\n9 15 4\\n4 2 9\\n11 15 1\\n11 12 14\\n10 8 12\\n3 6 11\\n\", \"5 10 10000000\\n2 4 798\\n1 5 8... | You are given a simple weighted connected undirected graph, consisting of $n$ vertices and $m$ edges.
A path in the graph of length $k$ is a sequence of $k+1$ vertices $v_1, v_2, \dots, v_{k+1}$ such that for each $i$ $(1 \le i \le k)$ the edge $(v_i, v_{i+1})$ is present in the graph. A path from some vertex $v$ also... | 0.125 |
{"tests": "{\"inputs\": [\"3\\n4\\n7 2 2 7\\n8\\n2 8 1 4 8 2 1 5\\n5\\n5 5 5 5 5\\n\", \"1\\n4\\n1 1 10000 10000\\n\", \"10\\n5\\n10 4 10 4 4\\n4\\n7 14 14 7\\n6\\n13 3 13 3 5 5\\n5\\n8 6 8 17 6\\n6\\n6 13 6 6 6 13\\n7\\n12 11 5 5 11 12 12\\n16\\n5 12 2 5 2 5 8 5 8 2 2 8 12 5 2 8\\n17\\n3 9 9 1 1 1 1 15 15 1 1 1 1 1 1 ... | You have $n$ sticks of the given lengths.
Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be formed by a single stick. No stick can be chosen multiple times. It is guaranteed that it is always possible to choose s... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2 3\", \"2\\n2 3\", \"4\\n1 2 3 4\", \"2\\n2 4\", \"1\\n20\", \"1\\n1\"], \"outputs\": [\"2\\n0 1 3 2\", \"2\\n0 2 1 3\", \"3\\n0 1 3 2 6 7 5 4\", \"0\\n0\", \"0\\n0\", \"1\\n0 1\"]}", "source": "primeintellect"} | Kuro has just learned about permutations and he is really excited to create a new permutation type. He has chosen $n$ distinct positive integers and put all of them in a set $S$. Now he defines a magical permutation to be: A permutation of integers from $0$ to $2^x - 1$, where $x$ is a non-negative integer. The bitwis... | 0 |
{"tests": "{\"inputs\": [\"4\\n2\\n13\\n37\\n100\\n\", \"99\\n17\\n38\\n56\\n16\\n7\\n36\\n29\\n95\\n50\\n28\\n64\\n98\\n46\\n42\\n3\\n93\\n10\\n74\\n80\\n9\\n55\\n31\\n51\\n34\\n35\\n82\\n96\\n69\\n54\\n77\\n76\\n92\\n58\\n70\\n20\\n73\\n72\\n86\\n41\\n12\\n4\\n24\\n89\\n67\\n13\\n49\\n78\\n65\\n66\\n37\\n61\\n84\\n39... | Mishka got a six-faced dice. It has integer numbers from $2$ to $7$ written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly $x$ points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the r... | 0 |
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n\", \"3 3\\n1 2\\n2 3\\n3 1\\n\", \"10 45\\n10 5\\n10 7\\n6 1\\n5 8\\n3 5\\n6 5\\n1 2\\n6 10\\n2 9\\n9 5\\n4 1\\n7 5\\n1 8\\n6 8\\n10 9\\n7 2\\n7 9\\n4 10\\n7 3\\n4 8\\n10 3\\n10 8\\n2 10\\n8 2\\n4 2\\n5 2\\n9 1\\n4 5\\n1 3\\n9 6\\n3 8\\n5 1\\n6 4\\n4 7\\n8 7\\n7 1\\n9 3\\n3 4\\n6... | The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.
Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ... | 0 |
{"tests": "{\"inputs\": [\"5\\n4\\nRLRL\\n6\\nLRRRRL\\n8\\nRLLRRRLL\\n12\\nLLLLRRLRRRLL\\n5\\nRRRRR\\n\", \"1\\n27\\nLLLLRRLRLRRRRLRLLLLLLLLLLLL\\n\", \"1\\n31\\nLLLLRRLRLRRRRLRLLLLLLRRRRLLLLLL\\n\", \"1\\n27\\nLLLLRRLRRLRLLLLLLRRRRLLLLLL\\n\", \"1\\n28\\nLLLLLLLLLLLLLLLRRRRLRRLLRLRL\\n\"], \"outputs\": [\"0\\n1\\n1\\n... | Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$... | 0 |
{"tests": "{\"inputs\": [\"3\\n6 7 14\\n\", \"4\\n1 2 1 16\\n\", \"1\\n4\\n\", \"1\\n15\\n\", \"5\\n1000000000000000000 352839520853234088 175235832528365792 753467583475385837 895062156280564685\\n\"], \"outputs\": [\"2\\n\", \"4\\n\", \"0\\n\", \"0\\n\", \"3\\n\"]}", "source": "primeintellect"} | Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$ $(\dots 00000000110_2)$ into $3$ $(\dots 00000000011_2)$, $12$ $(... | 0 |
{"tests": "{\"inputs\": [\"3\\n3 1 2\\n\", \"4\\n1 8 1 6\\n\", \"5\\n1 1 1 2 2\\n\", \"5\\n3 4 3 1 2\\n\", \"1\\n1\\n\"], \"outputs\": [\"2\\n1 3\\n1 2\\n\", \"2\\n2 4\\n2 3\\n\", \"0\\n\", \"7\\n1 5\\n3 5\\n2 5\\n1 4\\n3 4\\n2 4\\n2 3\\n\", \"0\\n\"]}", "source": "primeintellect"} | Madeline has an array $a$ of $n$ integers. A pair $(u, v)$ of integers forms an inversion in $a$ if:
$1 \le u < v \le n$. $a_u > a_v$.
Madeline recently found a magical paper, which allows her to write two indices $u$ and $v$ and swap the values $a_u$ and $a_v$. Being bored, she decided to write a list of pairs $... | 0 |
{"tests": "{\"inputs\": [\"6 2 4\\n1 6\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n\", \"6 3 2\\n1 5 6\\n1 2\\n1 3\\n1 4\\n1 5\\n5 6\\n\", \"10 1 5\\n5\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 10\\n\", \"11 1 5\\n6\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 10\\n10 11\\n\", \"2 1 1\\n1\\n1 2\\n\"], \"outputs\":... | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos... | 0 |
{"tests": "{\"inputs\": [\"6\\n1 1 1 2 1 1\\n6\\n+ 2\\n+ 1\\n- 1\\n+ 2\\n- 1\\n+ 2\\n\", \"10\\n5 1 5 1 4 4 2 2 4 4\\n15\\n- 1\\n- 4\\n+ 2\\n+ 2\\n- 5\\n- 5\\n- 4\\n- 4\\n+ 10\\n+ 10\\n+ 10\\n+ 10\\n- 2\\n+ 1\\n- 4\\n\", \"1\\n1\\n34\\n- 1\\n+ 1\\n+ 1\\n+ 1\\n+ 1\\n+ 1\\n+ 1\\n+ 1\\n+ 1\\n+ 1\\n- 1\\n- 1\\n- 1\\n- 1\\n... | This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).
A... | 0.125 |
{"tests": "{\"inputs\": [\"6 11\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n2 4\\n2 5\\n2 6\\n3 4\\n3 5\\n3 6\\n\", \"4 6\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n3 4\\n\", \"3 0\\n\", \"3 3\\n1 2\\n2 3\\n1 3\\n\", \"6 9\\n1 4\\n1 5\\n1 6\\n2 4\\n2 5\\n2 6\\n3 4\\n3 5\\n3 6\\n\"], \"outputs\": [\"1 2 2 3 3 3 \", \"-1\\n\", \"-1\\n\", \"1 2... | You have a simple undirected graph consisting of $n$ vertices and $m$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
Let's make a definition.
Let $v_1$ and $v_2$ be two some nonempty subsets of vertices that do not intersect. Let... | 0.125 |
{"tests": "{\"inputs\": [\"7\\n1101001\\n3 4 9 100 1 2 3\\n\", \"5\\n10101\\n3 10 15 15 15\\n\", \"1\\n1\\n1337\\n\", \"30\\n010010010010010010010010010010\\n1 1 1000000000 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\", \"99\\n10101010101010101010101010101010101010101010101010101010101010101010101010101010... | Vasya has a string $s$ of length $n$ consisting only of digits 0 and 1. Also he has an array $a$ of length $n$.
Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue together the remaining parts (any of them can ... | 0 |
{"tests": "{\"inputs\": [\"2\\n5 26 2\\n3 9 1\\n\", \"1\\n1 1 100000000000000\\n\", \"1\\n100000000000000 100000000000000 100000000000000\\n\", \"1\\n1 100000000000000 100000000000000\\n\", \"10\\n55 112 1\\n13 1047113 2\\n81 1130992 1\\n1 1350 3\\n51 449093 5\\n17 79 4\\n79 1697922 2\\n28 1874623 5\\n11 1709 3\\n51 10... | Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$.
You will be given $q$ queries consi... | 0 |
{"tests": "{\"inputs\": [\"2\\n\", \"1\\n\", \"3\\n\", \"4\\n\", \"10\\n\"], \"outputs\": [\"1 1 2 2\\n\", \"1 1\\n\", \"1 3 1 2 2 3\\n\", \"1 3 3 1 2 4 2 4\\n\", \"1 3 5 7 9 9 7 5 3 1 2 4 6 8 10 8 6 4 2 10\\n\"]}", "source": "primeintellect"} | You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.
Let number i be in positions x_{i}, y_{i} (x_{i} < y_{i}) in the permuted array a. Let's define the value d_{i} = y_{i} - x_{i} β the distance between the positions of the number i. Permute the numbers in array a... | 0 |
{"tests": "{\"inputs\": [\"8 4\\n3 8 7 9 9 4 6 8\\n2 5 9 4 3 8 9 1\\n\", \"10 6\\n60 8 63 72 1 100 23 59 71 59\\n81 27 66 53 46 64 86 27 41 82\\n\", \"13 13\\n93 19 58 34 96 7 35 46 60 5 36 40 41\\n57 3 42 68 26 85 25 45 50 21 60 23 79\\n\", \"12 1\\n49 49 4 16 79 20 86 94 43 55 45 17\\n15 36 51 20 83 6 83 80 72 22 66 ... | The marmots need to prepare k problems for HC^2 over n days. Each problem, once prepared, also has to be printed.
The preparation of a problem on day i (at most one per day) costs a_{i} CHF, and the printing of a problem on day i (also at most one per day) costs b_{i} CHF. Of course, a problem cannot be printed before... | 0 |
{"tests": "{\"inputs\": [\"14 8\\n1 2\\n2 7\\n3 4\\n6 3\\n5 7\\n3 8\\n6 8\\n11 12\\n\", \"200000 3\\n7 9\\n9 8\\n4 5\\n\", \"3 1\\n1 3\\n\", \"200000 1\\n1 200000\\n\", \"500 5\\n100 300\\n200 400\\n420 440\\n430 450\\n435 460\\n\"], \"outputs\": [\"1\\n\", \"0\\n\", \"1\\n\", \"199998\\n\", \"335\\n\"]}", "source": "p... | You're given an undirected graph with $n$ nodes and $m$ edges. Nodes are numbered from $1$ to $n$.
The graph is considered harmonious if and only if the following property holds: For every triple of integers $(l, m, r)$ such that $1 \le l < m < r \le n$, if there exists a path going from node $l$ to node $r$, then th... | 0 |
{"tests": "{\"inputs\": [\"5\\n2\\n1 2\\n2 1\\n3\\n1 2 3\\n1 2 3\\n3\\n1 2 4\\n1 3 4\\n4\\n1 2 3 2\\n3 1 2 2\\n3\\n1 2 3\\n1 3 2\\n\", \"1\\n1\\n1\\n1\\n\", \"2\\n2\\n2 1\\n1 2\\n2\\n2 1\\n2 1\\n\", \"6\\n3\\n3 2 1\\n1 2 3\\n3\\n3 2 1\\n1 3 2\\n3\\n3 2 1\\n2 1 3\\n3\\n3 2 1\\n2 3 1\\n3\\n3 2 1\\n3 1 2\\n3\\n3 2 1\\n3 2... | Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid.
Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr... | 0 |
{"tests": "{\"inputs\": [\"2 5\\n3 1 2 3\\n3 3 4 5\\n\", \"10 10\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n\", \"3 10\\n4 6 10 1 9\\n9 6 1 8 10 4 9 5 7 2\\n8 3 10 6 8 2 4 5 1\\n\", \"10 100\\n4 51 22 73 78\\n1 52\\n5 49 74 100 14 80\\n1 6\\n2 98 65\\n5 79 13 47 24 77\\n6 47 57 35 24 59 94\\n9 89 11... | Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?
There are $n$ stores numbered from $1$ to $n$ in Nlogonia. The $i$-th of these stores offers a positive integer $a_i$.
Each day among the last $m$ days Dora bought a single in... | 0 |
{"tests": "{\"inputs\": [\"3 4\\n0 0\\n2 0\\n2 2\\n1 1 2\\n2 1\\n2 2\\n2 3\\n\", \"3 2\\n-1 1\\n0 0\\n1 1\\n1 1 2\\n2 1\\n\", \"10 10\\n0 -100000000\\n1 -100000000\\n1566 -99999999\\n2088 -99999997\\n2610 -99999994\\n3132 -99999990\\n3654 -99999985\\n4176 -99999979\\n4698 -99999972\\n5220 -99999964\\n1 2 5\\n2 1\\n1 1 ... | Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.
Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and othe... | 0 |
{"tests": "{\"inputs\": [\"7\\n1 3 2 2 4 5 4\\n\", \"1\\n1\\n\", \"2\\n1000000000 1000000000\\n\", \"5\\n1 2 2 4 5\\n\", \"4\\n1 1 2 4\\n\"], \"outputs\": [\"3\\n3 1 4 2 4 2 5 \", \"0\\n1 \", \"0\\n1000000000 1000000000 \", \"2\\n2 1 4 2 5 \", \"1\\n2 1 4 1 \"]}", "source": "primeintellect"} | This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ... | 0 |
{"tests": "{\"inputs\": [\"2\\n2 3\\n5\\n2 1 1\\n2 2 1\\n1 1 1\\n2 1 2\\n2 2 0\\n\", \"2\\n4 4\\n9\\n1 1 1\\n1 2 1\\n1 3 1\\n2 1 2\\n2 2 2\\n2 3 2\\n2 3 1\\n2 2 1\\n2 1 1\\n\", \"3\\n2 1 1\\n4\\n1 1 1\\n1 1 2\\n1 1 3\\n1 1 0\\n\", \"3\\n3 1 1\\n6\\n1 1 1\\n1 2 1\\n1 2 2\\n1 1 2\\n1 1 3\\n1 2 3\\n\", \"1\\n30\\n1\\n1 26... | Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are $n$ types of resources, numbered $1$ through $n$. Bob needs at least $a_i$ pieces of the $i$-th resource to build the spaceship.... | 0 |
{"tests": "{\"inputs\": [\"1\\n100\\n30\\n\", \"2\\n60 50\\n34 38\\n\", \"3\\n12 14 2\\n6 2 7\\n\", \"1\\n9\\n10\\n\", \"10\\n64 55 27 35 76 119 7 18 49 100\\n29 19 31 39 27 48 41 87 55 70\\n\"], \"outputs\": [\"2100.000000000000000\\n\", \"2632.000000000000000\\n\", \"76.000000000000000\\n\", \"20.250000000000000000\\... | In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.
In the plan developed by the president Takahashi, the trains will run as follows:
- A train will run for (t_1 + t_2 + t_3 + ... + t_N) seconds.
- In the first t_1 seconds, a train must ru... | 0 |
{"tests": "{\"inputs\": [\"6 2\\n1 2\\n1 3\\n2 4\\n2 5\\n4 6\\n\", \"13 3\\n1 2\\n3 2\\n4 2\\n5 2\\n3 6\\n10 6\\n6 7\\n6 13\\n5 8\\n5 9\\n9 11\\n11 12\\n\", \"3 5\\n2 1\\n3 1\\n\", \"2 1\\n1 2\\n\", \"2 5\\n2 1\\n\", \"15 1\\n12 9\\n13 7\\n1 3\\n10 4\\n9 2\\n2 15\\n11 4\\n2 14\\n10 8\\n6 7\\n12 5\\n8 7\\n3 10\\n10 2\\n... | A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.
Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.
Limak recently learned how to jump. He can jump from a vertex to any verte... | 0.75 |
{"tests": "{\"inputs\": [\"GENIUS\\n\", \"DOCTOR\\n\", \"IRENE\\n\", \"MARY\\n\", \"SMARTPHONE\\n\", \"REVOLVER\\n\", \"HOLMES\\n\", \"WATSON\\n\"], \"outputs\": [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"]}", "source": "primeintellect"} | -----Input-----
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
-----Output-----
Output "YES" or "NO".
-----Examples-----
Input
GENIUS
Output
YES
Input
DOCTOR
Output
NO
Input
IRENE
Output
YES
Input
MARY
Output
NO
Input
SMA... | 0.25 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.