Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
19
19
problem
stringlengths
445
3.52k
tests
stringlengths
41
746
cf-7523ff0de46ffb62
You are given two integers $x$ and $y$. Output two integers: the minimum of $x$ and $y$, followed by the maximum of $x$ and $y$. Input Format: The first line contains a single integer $t$ ($1 \leq t \leq 100$) โ€” the number of test cases. The only line of each test case contains two space-separated integers $x$ and ...
[{"input": "10\n1 9\n8 4\n1 4\n3 4\n2 0\n2 4\n6 9\n3 3\n0 0\n9 9", "output": "1 9\n4 8\n1 4\n3 4\n0 2\n2 4\n6 9\n3 3\n0 0\n9 9"}]
cf-c02443ec23f88353
You are given a string $s$ consisting of lowercase English letters. Rearrange the characters of $s$ to form a new string $r$ that is not equal to $s$, or report that it's impossible. Input Format: The first line contains a single integer $t$ ($1 \leq t \leq 1000$) โ€” the number of test cases. The only line of each t...
[{"input": "8\ncodeforces\naaaaa\nxxxxy\nco\nd\nnutdealer\nmwistht\nhhhhhhhhhh", "output": "YES\nforcodesec\nNO\nYES\nxxyxx\nYES\noc\nNO\nYES\nundertale\nYES\nthtsiwm\nNO"}]
cf-7ac66687aa5eab54
There is a clock labeled with the numbers $1$ through $12$ in clockwise order, as shown below. ![](CDN_BASE_URL/d18290022594db5fbc2eb2c94222b5d4) In this example, $(a,b,c,d)=(2,9,10,6)$, and the strings intersect. Alice and Bob have four distinct integers $a$, $b$, $c$, $d$ not more than $12$. Alice ties a red stri...
[{"input": "15\n2 9 10 6\n3 8 9 1\n1 2 3 4\n5 3 4 12\n1 8 2 10\n3 12 11 8\n9 10 12 1\n12 1 10 2\n3 12 6 9\n1 9 8 4\n6 7 9 12\n7 12 9 6\n10 12 11 1\n3 9 6 12\n1 4 3 5", "output": "YES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES"}]
cf-e76762ee2f865346
You are given a binary string$^{\dagger}$. Please find the minimum number of pieces you need to cut it into, so that the resulting pieces can be rearranged into a sorted binary string. ![](CDN_BASE_URL/f49d41e3510eec9591123a65ee9389ab) Note that: * each character must lie in exactly one of the pieces; * the pi...
[{"input": "6\n11010\n00000000\n1\n10\n0001111\n0110", "output": "3\n1\n1\n2\n1\n2"}]
cf-8a7b37d147fff9f2
Timur is in a car traveling on the number line from point $0$ to point $n$. The car starts moving from point $0$ at minute $0$. There are $k+1$ signs on the line at points $0, a_1, a_2, \dots, a_k$, and Timur knows that the car will arrive there at minutes $0, b_1, b_2, \dots, b_k$, respectively. The sequences $a$ an...
[{"input": "4\n10 1 3\n10\n10\n0\n6\n7\n10 2 4\n4 10\n4 7\n6\n4\n2\n7\n1000000000 1 1\n1000000000\n1000000000\n99999999\n6 1 3\n6\n5\n2\n6\n5", "output": "0 6 7 \n5 4 2 5 \n99999999 \n1 5 4"}]
cf-d64ea36c259258bd
Given an integer $r$, find the number of lattice points that have a Euclidean distance from $(0, 0)$ greater than or equal to $r$ but strictly less than $r+1$. A lattice point is a point with integer coordinates. The Euclidean distance from $(0, 0)$ to the point $(x,y)$ is $\sqrt{x^2 + y^2}$. Input Format: The first...
[{"input": "6\n1\n2\n3\n4\n5\n1984", "output": "8\n16\n20\n24\n40\n12504"}]
cf-71cdab7c3ed2a9e3
You are given an array $a$ consisting of $n$ nonnegative integers. You can swap the elements at positions $i$ and $j$ if $a_i~\mathsf{XOR}~a_j < 4$, where $\mathsf{XOR}$ is the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Find the lexicographically smallest array that can be made wit...
[{"input": "4\n4\n1 0 3 2\n5\n2 7 1 5 6\n8\n1 2 1 2 1 2 1 2\n4\n16 4 1 64", "output": "0 1 2 3 \n1 5 2 6 7 \n1 1 1 1 2 2 2 2 \n16 4 1 64"}]
cf-d5bc0040e507c601
Bob has a grid with $3$ rows and $n$ columns, each of which contains either $a_i$ or $-a_i$ for some integer $1 \leq i \leq n$. For example, one possible grid for $n=4$ is shown below: $$\begin{bmatrix} a_1 & -a_2 & -a_3 & -a_2 \\\ -a_4 & a_4 & -a_1 & -a_3 \\\ a_1 & a_2 & -a_2 & a_4 \end{bmatrix}$$ Alice and Bob pla...
[{"input": "4\n4\n1 -2 -3 -2\n-4 4 -1 -3\n1 2 -2 4\n2\n1 2\n-1 -2\n2 -2\n5\n1 2 3 4 5\n-2 3 -4 -5 -1\n3 -5 1 2 2\n6\n1 3 -6 2 5 2\n1 3 -2 -3 -6 -5\n-2 -1 -3 2 3 1", "output": "YES\nNO\nYES\nNO"}]
cf-c9dc2fe6951af63c
A contest contains $n$ problems and the difficulty of the $i$-th problem is expected to be at most $b_i$. There are already $n$ problem proposals and the difficulty of the $i$-th problem is $a_i$. Initially, both $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$ are sorted in non-decreasing order. Some of the probl...
[{"input": "2\n6\n1000 1400 2000 2000 2200 2700\n800 1200 1500 1800 2200 3000\n6\n4 5 6 7 8 9\n1 2 3 4 5 6", "output": "2\n3"}]
cf-f022f97a83aecd81
There are $n$ coins on the table forming a circle, and each coin is either facing up or facing down. Alice and Bob take turns to play the following game, and Alice goes first. In each operation, the player chooses a facing-up coin, removes the coin, and flips the two coins that are adjacent to it. If (before the oper...
[{"input": "3\n5\nUUDUD\n5\nUDDUD\n2\nUU", "output": "YES\nNO\nNO"}]
cf-03989708ba80f434
You have some cards. An integer between $1$ and $n$ is written on each card: specifically, for each $i$ from $1$ to $n$, you have $a_i$ cards which have the number $i$ written on them. There is also a shop which contains unlimited cards of each type. You have $k$ coins, so you can buy $k$ new cards in total, and the ...
[{"input": "8\n1 10\n1\n2 4\n8 4\n3 4\n6 1 8\n3 9\n7 6 2\n5 3\n6 6 7 4 6\n9 7\n7 6 1 7 6 2 4 3 3\n10 10\n1 3 1 2 1 9 3 5 7 5\n9 8\n5 8 7 5 1 3 2 9 8", "output": "11\n15\n15\n22\n28\n32\n28\n36"}]
cf-6b96f12da81e3aa6
The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved. You are given two positive integers $n$, $m$. Calculate the number of ordered pairs $(a, b)$ satisfying the following conditions: * $1\le a\le n$, $1\le b\le m$; * $a+b$ is a multip...
[{"input": "6\n1 1\n2 3\n3 5\n10 8\n100 1233\n1000000 1145141", "output": "1\n3\n4\n14\n153\n1643498"}]
cf-27257141f88d7919
The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved. You are given two positive integers $n$, $m$. Calculate the number of ordered pairs $(a, b)$ satisfying the following conditions: * $1\le a\le n$, $1\le b\le m$; * $b \cdot \gcd(a,b...
[{"input": "6\n1 1\n2 3\n3 5\n10 8\n100 1233\n1000000 1145141", "output": "0\n1\n1\n6\n423\n5933961"}]
cf-0c54c4db17b4a002
Let $\operatorname{lowbit}(x)$ denote the value of the lowest binary bit of $x$, e.g. $\operatorname{lowbit}(12)=4$, $\operatorname{lowbit}(8)=8$. For an array $a$ of length $n$, if an array $s$ of length $n$ satisfies $s_k=\left(\sum\limits_{i=k-\operatorname{lowbit}(k)+1}^{k}a_i\right)\bmod 998\,244\,353$ for all $...
[{"input": "2\n8 1\n1 2 1 4 1 2 1 8\n6 2\n1 4 3 17 5 16", "output": "1 1 1 1 1 1 1 1\n1 2 3 4 5 6"}]
cf-d269d3c95353659a
Little R is a magician who likes non-decreasing arrays. She has an array of length $n$, initially as $a_1, \ldots, a_n$, in which each element is an integer between $[1, m]$. She wants it to be non-decreasing, i.e., $a_1 \leq a_2 \leq \ldots \leq a_n$. To do this, she can perform several magic tricks. Little R has a ...
[{"input": "3\n5 8\n1 6 3 7 1\n2 3 5 8 7 1 5 6\n3 3\n1 3 2\n2 1 3\n10 10\n2 8 5 4 8 4 1 5 10 10\n6 7 2 6 3 4 1 1 3 5", "output": "3\n-1\n3"}]
cf-2846ab5c0f8efc0a
Three friends gathered to play a few games of chess together. In every game, two of them play against each other. The winner gets $2$ points while the loser gets $0$, and in case of a draw, both players get $1$ point each. Note that the same pair of players could have played any non-negative number of times (possibly...
[{"input": "7\n0 0 0\n0 1 1\n1 1 1\n1 1 2\n3 3 3\n3 4 5\n1 1 10", "output": "0\n1\n-1\n2\n-1\n6\n2"}]
cf-7ae26c5706fd4fd1
Today, Cat and Fox found an array $a$ consisting of $n$ non-negative integers. Define the loneliness of $a$ as the smallest positive integer $k$ ($1 \le k \le n$) such that for any two positive integers $i$ and $j$ ($1 \leq i, j \leq n - k +1$), the following holds: $$a_i | a_{i+1} | \ldots | a_{i+k-1} = a_j | a_{j+1...
[{"input": "7\n1\n0\n3\n2 2 2\n3\n1 0 2\n5\n3 0 1 4 2\n5\n2 0 4 0 2\n7\n0 0 0 0 1 2 4\n8\n0 1 3 2 2 1 0 3", "output": "1\n1\n3\n4\n4\n7\n3"}]
cf-3a92d2c8dbf1ac59
Fox loves permutations! She came up with the following problem and asked Cat to solve it: You are given an even positive integer $n$ and a permutation$^\dagger$ $p$ of length $n$. The score of another permutation $q$ of length $n$ is the number of local maximums in the array $a$ of length $n$, where $a_i = p_i + q_i...
[{"input": "4\n4\n1 2 3 4\n4\n4 3 1 2\n6\n6 5 1 4 2 3\n8\n1 2 4 5 7 6 8 3", "output": "2 4 1 3\n3 1 4 2\n2 5 1 4 3 6\n5 4 8 2 7 1 6 3"}]
cf-d894a01fb8ac77eb
This is an interactive problem. Fox gave Cat two positive integers $n$ and $k$. She has a hidden array $a_1, \ldots , a_n$ of length $n$, such that $1 \leq a_i \leq n$ for every $i$. Now they are going to play the following game: For any two integers $l, r$ such that $1 \leq l \leq r \leq n$, define $f(l, r) = (r - ...
[{"input": "3\n1 1\n\n1\n2 2\n\n1\n\n3\n\n1\n6 3\n\n7\n\n2\n\n3\n\n6\n\n1", "output": "! 1\n\n\n? 1 1\n\n? 2 1\n\n! -1\n\n\n? 1 9\n\n? 1 6\n\n? 3 6\n\n? 4 6\n\n! 6"}]
cf-6d4279adcb1fad9f
Fox has found an array $p_1, p_2, \ldots, p_n$, that is a permutation of length $n^\dagger$ of the numbers $1, 2, \ldots, n$. She wants to sort the elements in increasing order. Cat wants to help her โ€” he is able to swap any two numbers $x$ and $y$ in the array, but only if $l \leq x + y \leq r$ (note that the constra...
[{"input": "7\n2\n2 1\n3\n3 1 2\n4\n3 2 1 4\n5\n5 3 1 2 4\n5\n1 2 3 4 5\n6\n3 2 1 5 4 6\n6\n1 3 2 4 5 6", "output": "6\n11\n23\n29\n55\n46\n58"}]
cf-d0e6b6fcda95bed7
For $k$ positive integers $x_1, x_2, \ldots, x_k$, the value $\gcd(x_1, x_2, \ldots, x_k)$ is the greatest common divisor of the integers $x_1, x_2, \ldots, x_k$ โ€” the largest integer $z$ such that all the integers $x_1, x_2, \ldots, x_k$ are divisible by $z$. You are given three arrays $a_1, a_2, \ldots, a_n$, $b_1,...
[{"input": "3 4\n1 2 3\n4 5 6\n1 1 1\n0 1 2 3", "output": "2 3 3 3"}, {"input": "5 5\n3 4 6 8 4\n8 3 4 9 3\n10 20 30 40 50\n5 55 13 1000 113", "output": "2 7 3 7 7"}, {"input": "1 1\n3\n4\n5\n0", "output": "7"}]
cf-aa9efedb39810f70
Little Rosie has a phone with a desktop (or launcher, as it is also called). The desktop can consist of several screens. Each screen is represented as a grid of size $5 \times 3$, i.e., five rows and three columns. There are $x$ applications with an icon size of $1 \times 1$ cells; such an icon occupies only one cell...
[{"input": "11\n1 1\n7 2\n12 4\n0 3\n1 0\n8 1\n0 0\n2 0\n15 0\n8 2\n0 9", "output": "1\n1\n2\n2\n1\n1\n0\n1\n1\n2\n5"}]
cf-2900b66654b363c3
Polycarp has a string $s$, which consists of lowercase Latin letters. He encodes this string using the following algorithm: * first, he constructs a new auxiliary string $r$, which consists of all distinct letters of the string $s$, written in alphabetical order; * then the encoding happens as follows: each char...
[{"input": "5\n10\nserofedsoc\n3\nttf\n9\ntlrhgmaoi\n1\nw\n15\nhnndledmnhlttin", "output": "codeforces\nfft\nalgorithm\nw\nmeetinthemiddle"}]
cf-d3d645b73b59c21d
Polycarp was given an array $a$ of $n$ integers. He really likes triples of numbers, so for each $j$ ($1 \le j \le n - 2$) he wrote down a triple of elements $[a_j, a_{j + 1}, a_{j + 2}]$. Polycarp considers a pair of triples $b$ and $c$ beautiful if they differ in exactly one position, that is, one of the following ...
[{"input": "8\n5\n3 2 2 2 3\n5\n1 2 1 2 1\n8\n1 2 3 2 2 3 4 2\n4\n2 1 1 1\n8\n2 1 1 2 1 1 1 1\n7\n2 1 1 1 1 1 1\n6\n2 1 1 1 1 1\n5\n2 1 1 1 1", "output": "2\n0\n3\n1\n8\n4\n3\n2"}]
cf-5500d3fcb5e5722a
Let's imagine the surface of Mars as an infinite coordinate plane. Initially, the rover Perseverance-2 and the helicopter Ingenuity-2 are located at the point with coordinates $(0, 0)$. A set of instructions $s$ consisting of $n$ instructions of the following types was specially developed for them: * N: move one me...
[{"input": "10\n6\nNENSNE\n3\nWWW\n6\nNESSWS\n2\nSN\n2\nWE\n4\nSSNN\n4\nWESN\n2\nSS\n4\nEWNN\n4\nWEWE", "output": "RRHRRH\nNO\nHRRHRH\nNO\nNO\nRHRH\nRRHH\nRH\nRRRH\nRRHH"}]
cf-1aa2747d93916bb1
Being a physicist, Charlie likes to plan his life in simple and precise terms. For the next $m$ months, starting with no money, Charlie will work hard and earn $x$ pounds per month. For the $i$-th month $(1 \le i \le m)$, there'll be a single opportunity of paying cost $c_i$ pounds to obtain happiness $h_i$. Borrowi...
[{"input": "7\n1 10\n1 5\n2 80\n0 10\n200 100\n3 100\n70 100\n100 200\n150 150\n5 8\n3 1\n5 3\n3 4\n1 5\n5 3\n2 5\n1 5\n2 1\n5 3\n2 5\n2 4\n4 1\n5 1\n3 4\n5 2\n2 1\n1 2\n3 5\n3 2\n3 2", "output": "0\n10\n200\n15\n1\n9\n9"}]
cf-faae40af5e76d60b
Alice and Bob were playing a game again. They have a grid of size $a \times b$ ($1 \le a, b \le 10^9$), on which there are $n$ chips, with at most one chip in each cell. The cell at the intersection of the $x$-th row and the $y$-th column has coordinates $(x, y)$. Alice made the first move, and the players took turns...
[{"input": "6\n4 4 3 2\n4 1\n3 3\n2 4\nD 2\nR 1\n4 4 3 3\n4 1\n3 2\n2 3\nD 1\nL 1\nU 2\n3 5 3 2\n1 3\n2 2\n3 3\nR 2\nR 2\n6 4 4 2\n1 4\n2 3\n5 3\n1 1\nR 1\nU 1\n9 3 2 1\n6 1\n3 3\nD 8\n10 10 2 5\n7 5\n9 1\nR 1\nL 2\nD 1\nU 4\nD 1", "output": "2 1\n2 0\n0 3\n1 1\n2 0\n0 1"}]
cf-5bdc7b104350f60f
You can never buy enough happiness, so here we go again! In this version, you can only buy $h_i = 1$ unit of happiness each month, but the number of months is hugely increased. We are in the realm of quantum happiness and time dilation. Being a physicist, Charlie likes to plan his life in simple and precise terms. F...
[{"input": "6\n3 3\n2 2 2\n6 5\n2 2 8 2 6 8\n6 4\n4 10 3 8 6 10\n2 1\n1 1\n4 1\n4 1 3 1\n4 2\n1 3 4 3", "output": "2\n4\n3\n1\n2\n1"}]
cf-4dcb5afc4dd0896d
Mocha likes arrays, so before her departure, Bazoka gave her an array $a$ consisting of $n$ positive integers as a gift. Now Mocha wants to know whether array $a$ could become sorted in non- decreasing order after performing the following operation some (possibly, zero) times: * Split the array into two parts โ€” a ...
[{"input": "3\n6\n1 1 4 5 1 4\n5\n7 9 2 2 3\n3\n1 2 3", "output": "No\nYes\nYes"}]
cf-eb141c5086038eac
Mocha likes arrays, so before her departure, 378QAQ gave her an array $a$ consisting of $n$ positive integers as a gift. Mocha thinks that $a$ is beautiful if there exist two numbers $i$ and $j$ ($1\leq i,j\leq n$, $i\neq j$) such that for all $k$ ($1 \leq k \leq n$), $a_k$ is divisible$^\dagger$ by either $a_i$ or $...
[{"input": "4\n3\n7 3 8\n5\n7 1 9 3 5\n5\n4 12 2 6 3\n5\n7 49 9 3 1000000000", "output": "No\nYes\nYes\nNo"}]
cf-56bd4e1044a4fc5a
Mocha likes arrays, so before her departure, Chamo gave her an array $a$ consisting of $n$ positive integers as a gift. Mocha doesn't like arrays containing different numbers, so Mocha decides to use magic to change the array. Mocha can perform the following three-step operation some (possibly, zero) times: 1. Cho...
[{"input": "2\n2\n1 2\n5\n1 2 3 4 5", "output": "1\n4"}]
cf-241362537a821837
378QAQ has a tree with $n$ vertices. Initially, all vertices are white. There are two chess pieces called $P_A$ and $P_B$ on the tree. $P_A$ and $P_B$ are initially located on vertices $a$ and $b$ respectively. In one step, 378QAQ will do the following in order: 1. Move $P_A$ to a neighboring vertex. If the target...
[{"input": "3\n2\n1 2\n1 2\n5\n1 2\n1 2\n1 3\n1 4\n1 5\n8\n5 4\n7 1\n1 5\n1 8\n8 3\n7 2\n8 6\n3 4", "output": "2\n8\n13"}]
cf-2504211e2da6bf85
You are given a tree of $n$ vertices numbered from $1$ to $n$. Initially, all vertices are colored white or black. You are asked to perform $q$ queries: * "u" โ€” toggle the color of vertex $u$ (if it was white, change it to black and vice versa). After each query, you should answer whether all the black vertices ...
[{"input": "2\n2 1\n1 0\n1 2\n1\n5 4\n1 0 0 0 0\n1 2\n1 3\n1 5\n3 4\n4\n3\n2\n5", "output": "No\nNo\nYes\nYes\nNo"}, {"input": "4\n5 3\n1 1 1 1 1\n3 5\n2 5\n3 4\n1 5\n1\n1\n1\n4 4\n0 0 0 0\n1 2\n2 3\n1 4\n1\n2\n3\n2\n1 1\n1\n1\n1 1\n0\n1", "output": "Yes\nNo\nYes\nYes\nYes\nYes\nNo\nNo\nYes"}]
cf-fe72bd8119780ec8
Define the binary encoding of a finite set of natural numbers $T \subseteq \\{0,1,2,\ldots\\}$ as $f(T) = \sum\limits_{i \in T} 2^i$. For example, $f(\\{0,2\\}) = 2^0 + 2^2 = 5$ and $f(\\{\\}) = 0$. Notice that $f$ is a bijection from all such sets to all non-negative integers. As such, $f^{-1}$ is also defined. You ...
[{"input": "3\n15 15 15 15 15 15 12", "output": "4\n3\n5\n6\n7"}, {"input": "5\n63 63 63 63 6 63 63 63 63 63 63 5 63 63 63 63 63 63 8 63 63 63 63 2 63 63 63 63 63 63 63", "output": "1\n19"}]
cf-1ca08b48bd892578
One day, Zimpha casually came up with a problem. As a member of "Zimpha fan club", you decided to solve that problem. You are given two strings $s$ and $t$ of length $n$ and $m$, respectively. Both strings only consist of lowercase English letters, - and *. You need to replace all occurrences of * and -, observi...
[{"input": "10 10\njustmonika\nj-stsayori", "output": "No"}, {"input": "7 8\nttk-wxx\n*tt-l-xx", "output": "Yes"}, {"input": "13 11\nasoulwangziji\n-soulg*z-y-", "output": "No"}, {"input": "7 3\nabc*cba\na*c", "output": "No"}, {"input": "20 18\nbulijiojio-dibuliduo\n*li*ji-*ox*i*-du*-", "output": "Yes"}]
cf-7f5b6e4b96fcd311
378QAQ has a string $s$ of length $n$. Define the core of a string as the substring$^\dagger$ with maximum lexicographic$^\ddagger$ order. For example, the core of "$\mathtt{bazoka}$" is "$\mathtt{zoka}$", and the core of "$\mathtt{aaa}$" is "$\mathtt{aaa}$". 378QAQ wants to rearrange the string $s$ so that the core...
[{"input": "6\n3\nqaq\n4\ncccc\n6\nbazoka\n6\nzazzzz\n7\nababbbb\n7\nccbabcc", "output": "qaq\ncccc\nz\nzzz\nbbababb\ncbcacbc"}]
cf-79fa4a4184718719
This is the way it always was. This is the way it always will be. All will be forgotten again soon... Jellyfish is playing a one-player card game called "Slay the Spire". There are $n$ cards in total numbered from $1$ to $n$. The $i$-th card has power $c_i$. There is a binary string $s$ of length $n$. If $s_i = \t...
[{"input": "4\n5\n0 1 1 1 2\n00100\n3\n2 3 3\n000\n10\n0 0 0 0 0 0 0 1 1 1\n1111011111\n20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 3 3 4\n00000000001000101010", "output": "500000004\n0\n0\n675898154"}]
cf-11cfb743bc719098
Monocarp is working on his new site, and the current challenge is to make the users pick strong passwords. Monocarp decided that strong passwords should satisfy the following conditions: * password should consist only of lowercase Latin letters and digits; * there should be no digit that comes after a letter (s...
[{"input": "5\n4\n12ac\n5\n123wa\n9\nallllmost\n5\nac123\n6\n011679", "output": "YES\nNO\nYES\nNO\nYES"}]
cf-80c6887ef976a83f
You are given two integer arrays: array $a$ of length $n$ and array $b$ of length $n+1$. You can perform the following operations any number of times in any order: * choose any element of the array $a$ and increase it by $1$; * choose any element of the array $a$ and decrease it by $1$; * choose any element ...
[{"input": "3\n1\n2\n1 3\n2\n3 3\n3 3 3\n4\n4 2 1 2\n2 1 5 2 3", "output": "3\n1\n8"}]
cf-0ca0714ae890d497
Monocarp is opening his own IT company. He wants to hire $n$ programmers and $m$ testers. There are $n+m+1$ candidates, numbered from $1$ to $n+m+1$ in chronological order of their arriving time. The $i$-th candidate has programming skill $a_i$ and testing skill $b_i$ (a person's programming skill is different from t...
[{"input": "4\n1 0\n2 1\n1 2\n0 2\n4 5 5\n5 4 1\n1 2\n2 1 5 4\n5 2 3 1\n3 1\n4 3 3 4 1\n5 5 4 5 2", "output": "1 2 \n5 6 9 \n8 11 11 12 \n13 13 13 12 15"}]
cf-ee1166e86da8a5bc
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example: * bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)")...
[{"input": "4\n(())\n()\n()()()\n(()())(())", "output": "1\n0\n3\n13"}]
cf-01dda202b0218b62
Initially, we had one array, which was a permutation of size $n$ (an array of size $n$ where each integer from $1$ to $n$ appears exactly once). We performed $q$ operations. During the $i$-th operation, we did the following: * choose any array we have with at least $2$ elements; * split it into two non-empty ar...
[{"input": "6 3\n6 4 4\n5 5 2", "output": "30"}, {"input": "10 1\n10\n9", "output": "1814400"}, {"input": "4 1\n2\n4", "output": "8"}]
cf-94ba82d61a989906
You are given a rooted tree, consisting of $n$ vertices, numbered from $1$ to $n$. Vertex $1$ is the root. Additionally, the root only has one child. You are asked to add exactly $k$ edges to the tree (possibly, multiple edges and/or edges already existing in the tree). Recall that a bridge is such an edge that, aft...
[{"input": "4\n2\n1 2\n12\n4 10\n5 12\n12 11\n3 6\n9 6\n1 6\n12 7\n11 6\n2 11\n10 9\n10 8\n8\n1 2\n2 3\n2 4\n3 5\n3 6\n4 7\n4 8\n5\n1 2\n2 3\n3 4\n4 5", "output": "0 \n7 3 1 0 0 0 0 0 0 0 0 \n4 1 0 0 0 0 0 \n0 0 0 0"}]
cf-686973a2ba447968
The little boy Nikita was given some cubes as a present. He decided to build a tower out of them. Initially, the tower doesn't have any cubes. In one move, Nikita either puts exactly $1$ cube on top of the tower or removes exactly $1$ cube from the top of the tower. Is it possible that after $n$ moves, the resulting ...
[{"input": "3\n3 3\n2 4\n5 3", "output": "Yes\nNo\nYes"}]
cf-1087f5de081a27de
You are given a positive integer $x$. Find any array of integers $a_0, a_1, \ldots, a_{n-1}$ for which the following holds: * $1 \le n \le 32$, * $a_i$ is $1$, $0$, or $-1$ for all $0 \le i \le n - 1$, * $x = \displaystyle{\sum_{i=0}^{n - 1}{a_i \cdot 2^i}}$, * There does not exist an index $0 \le i \le n ...
[{"input": "7\n1\n14\n24\n15\n27\n11\n19", "output": "1\n1\n5\n0 -1 0 0 1\n6\n0 0 0 -1 0 1\n5\n-1 0 0 0 1\n6\n-1 0 -1 0 0 1\n5\n-1 0 -1 0 1\n5\n-1 0 1 0 1"}]
cf-bf629747f8647fbd
Nikita is a student passionate about number theory and algorithms. He faces an interesting problem related to an array of numbers. Suppose Nikita has an array of integers $a$ of length $n$. He will call a subsequence$^\dagger$ of the array special if its [least common multiple (LCM)](https://en.wikipedia.org/wiki/Lea...
[{"input": "6\n5\n1 2 4 8 16\n6\n3 2 10 20 60 1\n7\n2 3 4 6 12 100003 1200036\n9\n2 42 7 3 6 7 7 1 6\n8\n4 99 57 179 10203 2 11 40812\n1\n1", "output": "0\n4\n4\n5\n8\n0"}]
cf-200064be45810647
You are given a binary (consisting only of 0s and 1s) $n \times m$ matrix. You are also given a XORificator, using which you can invert all the values in a chosen row (i.e. replace 0 with 1 and 1 with 0). A column in the matrix is considered special if it contains exactly one 1. Your task is to find the maximum numbe...
[{"input": "5\n3 4\n1010\n0110\n0100\n1 1\n1\n1 1\n0\n2 5\n00101\n10110\n3 3\n101\n111\n000", "output": "3\n010\n1\n0\n1\n1\n3\n00\n2\n010"}]
cf-978389c1f63e8c56
This is an interactive problem. You are given an integer $n$. The jury has hidden from you a directed graph with $n$ vertices (numbered from $1$ to $n$) and some number of edges. You additionally know that: * The graph only contains edges of the form $i \leftarrow j$, where $1 \le i < j \le n$. * For any three...
[{"input": "2\n4\n\nYES\n\nYES\n\nYES\n\nNO\n\nNO\n\nNO\n\n5", "output": "? 1 2\n\n? 2 3\n\n? 1 3\n\n? 1 4\n\n? 2 4\n\n? 3 4\n\n! 0 0 0 1\n\n! 1 1 0 1 0"}]
cf-53bbfadfc69af54a
Alice has $n$ books. The $1$-st book contains $a_1$ pages, the $2$-nd book contains $a_2$ pages, $\ldots$, the $n$-th book contains $a_n$ pages. Alice does the following: * She divides all the books into two non-empty piles. Thus, each book ends up in exactly one of the two piles. * Alice reads one book with the ...
[{"input": "5\n2\n1 1\n4\n2 3 3 1\n5\n2 2 3 2 2\n2\n10 3\n3\n1 2 3", "output": "2\n4\n5\n13\n5"}]
cf-b15b42ca21d6498c
Bob decided to open a bakery. On the opening day, he baked $n$ buns that he can sell. The usual price of a bun is $a$ coins, but to attract customers, Bob organized the following promotion: * Bob chooses some integer $k$ ($0 \le k \le \min(n, b)$). * Bob sells the first $k$ buns at a modified price. In this case,...
[{"input": "7\n4 4 5\n5 5 9\n10 10 5\n5 5 11\n1000000000 1000000000 1000000000\n1000000000 1000000000 1\n1000 1 1000", "output": "17\n35\n100\n45\n1000000000000000000\n1000000000000000000\n500500"}]
cf-09d4b3eee7968b29
Let's call the Manhattan value of a permutation$^{\dagger}$ $p$ the value of the expression $|p_1 - 1| + |p_2 - 2| + \ldots + |p_n - n|$. For example, for the permutation $[1, 2, 3]$, the Manhattan value is $|1 - 1| + |2 - 2| + |3 - 3| = 0$, and for the permutation $[3, 1, 2]$, the Manhattan value is $|3 - 1| + |1 - ...
[{"input": "8\n3 4\n4 5\n7 0\n1 1000000000000\n8 14\n112 777\n5 12\n5 2", "output": "Yes\n3 1 2\nNo\nYes\n1 2 3 4 5 6 7\nNo\nYes\n8 2 3 4 5 6 1 7\nNo\nYes\n5 4 3 1 2\nYes\n2 1 3 4 5"}]
cf-97100ad837e06861
Elections are taking place in Berland. There are $n$ candidates participating in the elections, numbered from $1$ to $n$. The $i$-th candidate has $a_i$ fans who will vote for him. Additionally, there are $c$ people who are undecided about their favorite candidate, let's call them undecided. Undecided people will vote...
[{"input": "5\n3 1\n2 0 3\n2 3\n0 10\n5 3\n5 4 3 2 1\n4 5\n3 10 7 1\n6 0\n2 2 2 3 3 3", "output": "0 1 2\n1 0\n0 1 2 3 4\n1 0 2 3\n1 1 2 0 4 5"}]
cf-cc1dd97084442fd7
Sasha has two binary strings $s$ and $t$ of the same length $n$, consisting of the characters 0 and 1. There is also a computing machine that can perform two types of operations on binary strings $a$ and $b$ of the same length $k$: 1. If $a_{i} = a_{i + 2} =$ 0, then you can assign $b_{i + 1} :=$ 1 ($1 \le i \le k...
[{"input": "3\n4\n1111\n0000\n2\n1 2\n2 4\n4\n1010\n1101\n2\n1 3\n1 4\n6\n010101\n011010\n5\n2 3\n1 6\n2 5\n4 4\n3 6", "output": "2\n3\n2\n3\n1\n4\n3\n1\n2"}]
cf-61505319ac981d75
Given an array $a$ of length $n$. Let's construct a square matrix $b$ of size $n \times n$, in which the $i$-th row contains the array $a$ cyclically shifted to the right by $(i - 1)$. For example, for the array $a = [3, 4, 5]$, the obtained matrix is $$b = \begin{bmatrix} 3 & 4 & 5 \\\ 5 & 3 & 4 \\\ 4 & 5 & 3 \end{b...
[{"input": "6\n3 3\n3 4 5\n3 3\n3 4 9\n3 2\n3 4 9\n2 2\n2 8\n5 3\n8 27 5 4 3\n4 10\n2 2 2 2", "output": "3\n2\n3\n1\n4\n1"}]
cf-2e5b5d04f1d95a7f
Alice and Bob came up with a rather strange game. They have an array of integers $a_1, a_2,\ldots, a_n$. Alice chooses a certain integer $k$ and tells it to Bob, then the following happens: * Bob chooses two integers $i$ and $j$ ($1 \le i < j \le n$), and then finds the maximum among the integers $a_i, a_{i + 1},\l...
[{"input": "6\n4\n2 4 1 7\n5\n1 2 3 4 5\n2\n1 1\n3\n37 8 16\n5\n10 10 10 10 9\n10\n3 12 9 5 2 3 2 9 8 2", "output": "3\n1\n0\n15\n9\n2"}]
cf-336a44a84724d94f
You are given two distinct non-negative integers $x$ and $y$. Consider two infinite sequences $a_1, a_2, a_3, \ldots$ and $b_1, b_2, b_3, \ldots$, where * $a_n = n \oplus x$; * $b_n = n \oplus y$. Here, $x \oplus y$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation of int...
[{"input": "4\n0 1\n12 4\n57 37\n316560849 14570961", "output": "1\n8\n4\n33554432"}]
cf-1bc44fec8f5fbeb5
You have been offered to play a game. In this game, there are $n$ possible outcomes, and for each of them, you must bet a certain integer amount of coins. In the event that the $i$-th outcome turns out to be winning, you will receive back the amount of coins equal to your bet on that outcome, multiplied by $k_i$. Note...
[{"input": "6\n3\n3 2 7\n2\n3 3\n5\n5 5 5 5 5\n6\n7 9 3 17 9 13\n3\n6 3 2\n5\n9 4 6 8 3", "output": "27 41 12 \n1 1 \n-1\n1989 1547 4641 819 1547 1071 \n-1\n8 18 12 9 24"}]
cf-4857ca2b46ac76e5
You are given a binary string $s$ of length $n$, consisting of zeros and ones. You can perform the following operation exactly once: 1. Choose an integer $p$ ($1 \le p \le n$). 2. Reverse the substring $s_1 s_2 \ldots s_p$. After this step, the string $s_1 s_2 \ldots s_n$ will become $s_p s_{p-1} \ldots s_1 s_{p...
[{"input": "7\n8 4\n11100001\n4 2\n1110\n12 3\n111000100011\n5 5\n00000\n6 1\n101001\n8 4\n01110001\n12 2\n110001100110", "output": "3\n-1\n7\n5\n4\n-1\n3"}]
cf-83c9c92eee2f2fad
The Manhattan distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is defined as: $$|x_1 - x_2| + |y_1 - y_2|.$$ We call a Manhattan triangle three points on the plane, the Manhattan distances between each pair of which are equal. You are given a set of pairwise distinct points and an even integer $d$. Your tas...
[{"input": "6\n6 4\n3 1\n0 0\n0 -2\n5 -3\n3 -5\n2 -2\n5 4\n0 0\n0 -2\n5 -3\n3 -5\n2 -2\n6 6\n3 1\n0 0\n0 -2\n5 -3\n3 -5\n2 -2\n4 4\n3 0\n0 3\n-3 0\n0 -3\n10 8\n2 1\n-5 -1\n-4 -1\n-5 -3\n0 1\n-2 5\n-4 4\n-4 2\n0 0\n-4 1\n4 400000\n100000 100000\n-100000 100000\n100000 -100000\n-100000 -100000", "output": "2 6 1\n4 3 5\n...
cf-546e2bfd848ad791
This is an interactive problem. Kostyanych has chosen a complete undirected graph$^{\dagger}$ with $n$ vertices, and then removed exactly $(n - 2)$ edges from it. You can ask queries of the following type: * "? $d$" โ€” Kostyanych tells you the number of vertex $v$ with a degree at least $d$. Among all possible such...
[{"input": "3\n4\n\n0 0\n\n1 4\n\n2 3\n\n4\n\n1 0\n\n4 2\n\n2\n\n1 0", "output": "? 3\n\n? 2\n\n? 1\n\n! 4 3 1 2\n\n? 3\n\n? 0\n\n! 4 1 2 3\n\n? 0\n\n! 2 1"}]
cf-c5781db3fd9b0c93
Vlad is planning to hold $m$ rounds next month. Each round should contain one problem of difficulty levels 'A', 'B', 'C', 'D', 'E', 'F', and 'G'. Vlad already has a bank of $n$ problems, where the $i$-th problem has a difficulty level of $a_i$. There may not be enough of these problems, so he may have to come up with...
[{"input": "3\n10 1\nBGECDCBDED\n10 2\nBGECDCBDED\n9 1\nBBCDEFFGG", "output": "2\n5\n1"}]
cf-6b1da5c26358bb68
Dmitry has $n$ cubes, numbered from left to right from $1$ to $n$. The cube with index $f$ is his favorite. Dmitry threw all the cubes on the table, and the $i$-th cube showed the value $a_i$ ($1 \le a_i \le 100$). After that, he arranged the cubes in non-increasing order of their values, from largest to smallest. If...
[{"input": "12\n5 2 2\n4 3 3 2 3\n5 5 3\n4 2 1 3 5\n5 5 2\n5 2 4 1 3\n5 5 5\n1 2 5 4 3\n5 5 4\n3 1 2 4 5\n5 5 5\n4 3 2 1 5\n6 5 3\n1 2 3 1 2 3\n10 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1\n42\n5 2 3\n2 2 1 1 2\n2 1 1\n2 1\n5 3 1\n3 3 2 3 2", "output": "MAYBE\nYES\nNO\nYES\nYES\nYES\nMAYBE\nMAYBE\nYES\nYES\nYES\nNO"}]
cf-bc5062c8c3e0ab6e
Sofia had an array of $n$ integers $a_1, a_2, \ldots, a_n$. One day she got bored with it, so she decided to sequentially apply $m$ modification operations to it. Each modification operation is described by a pair of numbers $\langle c_j, d_j \rangle$ and means that the element of the array with index $c_j$ should be...
[{"input": "7\n3\n1 2 1\n1 3 2\n4\n1 3 1 2\n4\n1 2 3 5\n2 1 3 5\n2\n2 3\n5\n7 6 1 10 10\n3 6 1 11 11\n3\n4 3 11\n4\n3 1 7 8\n2 2 7 10\n5\n10 3 2 2 1\n5\n5 7 1 7 9\n4 10 1 2 9\n8\n1 1 9 8 7 2 10 4\n4\n1000000000 203 203 203\n203 1000000000 203 1000000000\n2\n203 1000000000\n1\n1\n1\n5\n1 3 4 5 1", "output": "YES\nNO\nNO...
cf-d0c531ba295dc35b
GCD (Greatest Common Divisor) of two integers $x$ and $y$ is the maximum integer $z$ by which both $x$ and $y$ are divisible. For example, $GCD(36, 48) = 12$, $GCD(5, 10) = 5$, and $GCD(7,11) = 1$. Kristina has an array $a$ consisting of exactly $n$ positive integers. She wants to count the GCD of each neighbouring p...
[{"input": "12\n6\n20 6 12 3 48 36\n4\n12 6 3 4\n3\n10 12 3\n5\n32 16 8 4 2\n5\n100 50 2 10 20\n4\n2 4 8 1\n10\n7 4 6 2 4 5 1 4 2 8\n7\n5 9 6 8 5 9 2\n6\n11 14 8 12 9 3\n9\n5 7 3 10 6 3 12 6 3\n3\n4 2 4\n8\n1 6 11 12 6 12 3 6", "output": "YES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES"}]
cf-7ab2686a86e7e11b
You have been given a matrix $a$ of size $n$ by $m$, containing a permutation of integers from $1$ to $n \cdot m$. A permutation of $n$ integers is an array containing all numbers from $1$ to $n$ exactly once. For example, the arrays $[1]$, $[2, 1, 3]$, $[5, 4, 3, 2, 1]$ are permutations, while the arrays $[1, 1]$, $...
[{"input": "7\n1 1\n1\n1\n2 2\n1 2\n3 4\n4 3\n2 1\n2 2\n1 2\n3 4\n4 3\n1 2\n3 4\n1 5 9 6\n12 10 4 8\n7 11 3 2\n1 5 9 6\n12 10 4 8\n7 11 3 2\n3 3\n1 5 9\n6 4 2\n3 8 7\n9 5 1\n2 4 6\n7 8 3\n2 3\n1 2 6\n5 4 3\n6 1 2\n3 4 5\n1 5\n5 1 2 3 4\n4 2 5 1 3", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES"}]
cf-46b5d0f266fb5973
This is an easy version of the problem; it differs from the hard version only by the question. The easy version only needs you to print whether some values are non-zero or not. The hard version needs you to print the exact values. Alice and Bob are dividing the field. The field is a rectangle of size $n \times m$ ($2...
[{"input": "5\n2 2 3\n1 1\n1 2\n2 2\n5 5 4\n1 2\n2 2\n3 4\n4 3\n2 5 9\n1 2\n1 5\n1 1\n2 2\n2 4\n2 5\n1 4\n2 3\n1 3\n6 4 4\n6 2\n1 3\n1 4\n1 2\n3 4 5\n2 1\n3 2\n1 4\n1 3\n2 4", "output": "1\n1 0 1 \n11\n0 1 0 1 \n1\n0 0 1 1 0 0 0 0 0 \n6\n1 0 0 0 \n1\n1 1 0 0 0"}]
cf-575a7dd3dacefcac
This is a hard version of the problem; it differs from the easy version only by the question. The easy version only needs you to print whether some values are non-zero or not. The hard version needs you to print the exact values. Alice and Bob are dividing the field. The field is a rectangle of size $n \times m$ ($2 ...
[{"input": "5\n2 2 3\n1 1\n1 2\n2 2\n5 5 4\n1 2\n2 2\n3 4\n4 3\n2 5 9\n1 2\n1 5\n1 1\n2 2\n2 4\n2 5\n1 4\n2 3\n1 3\n6 4 4\n6 2\n1 3\n1 4\n1 2\n3 4 5\n2 1\n3 2\n1 4\n1 3\n2 4", "output": "1\n1 0 1 \n11\n0 1 0 4 \n1\n0 0 1 1 0 0 0 0 0 \n6\n15 0 0 0 \n1\n2 3 0 0 0"}]
cf-62950c42317da0ea
Yasya was walking in the forest and accidentally found a tree with $n$ vertices. A tree is a connected undirected graph with no cycles. Next to the tree, the girl found an ancient manuscript with $m$ queries written on it. The queries can be of two types. The first type of query is described by the integer $y$. The ...
[{"input": "2\n3 7\n1 2 1\n3 1 8\n^ 5\n? 2 9\n^ 1\n? 1 10\n^ 6\n? 3 1\n? 2 9\n5 6\n1 2 777\n3 2 2812\n4 1 16\n5 3 1000000000\n^ 4\n? 3 123\n? 5 1000000000\n^ 1000000000\n? 1 908070\n? 2 1", "output": "13 15 11 10 \n1000000127 2812 999756331 999999756"}, {"input": "3\n8 4\n8 6 3\n6 3 4\n2 5 4\n7 6 2\n7 1 10\n4 1 4\n5 1 ...
cf-4035efd555f39da9
Turtle and Piggy are playing a number game. First, Turtle will choose an integer $x$, such that $l \le x \le r$, where $l, r$ are given. It's also guaranteed that $2l \le r$. Then, Piggy will keep doing the following operation until $x$ becomes $1$: * Choose an integer $p$ such that $p \ge 2$ and $p \mid x$ (i.e....
[{"input": "5\n2 4\n3 6\n2 15\n6 22\n114514 1919810", "output": "2\n2\n3\n4\n20"}]
cf-71583b418f5b422f
There is a sequence $a_0, a_1, a_2, \ldots$ of infinite length. Initially $a_i = i$ for every non-negative integer $i$. After every second, each element of the sequence will simultaneously change. $a_i$ will change to $a_{i - 1} \mid a_i \mid a_{i + 1}$ for every positive integer $i$. $a_0$ will change to $a_0 \mid a...
[{"input": "9\n0 0\n0 1\n0 2\n1 0\n5 2\n10 1\n20 3\n1145 14\n19198 10", "output": "0\n1\n3\n1\n7\n11\n23\n1279\n19455"}]
cf-d9a92f5b1ca467a7
Turtle was playing with a sequence $a_1, a_2, \ldots, a_n$ consisting of positive integers. Unfortunately, some of the integers went missing while playing. Now the sequence becomes incomplete. There may exist an arbitrary number of indices $i$ such that $a_i$ becomes $-1$. Let the new sequence be $a'$. Turtle is sad...
[{"input": "9\n8\n-1 -1 -1 2 -1 -1 1 -1\n4\n-1 -1 -1 -1\n6\n3 -1 -1 -1 9 -1\n4\n-1 5 -1 6\n4\n2 -1 -1 3\n4\n1 2 3 4\n2\n4 2\n5\n-1 3 -1 3 6\n13\n-1 -1 3 -1 -1 -1 -1 7 -1 -1 3 -1 -1", "output": "4 9 4 2 4 2 1 2\n7 3 6 13\n3 1 2 4 9 18\n-1\n-1\n-1\n4 2\n6 3 1 3 6\n3 1 3 1 3 7 3 7 3 1 3 1 3"}]
cf-ee148c8d94fef8f0
Turtle just learned how to multiply two integers in his math class, and he was very excited. Then Piggy gave him an integer $n$, and asked him to construct a sequence $a_1, a_2, \ldots, a_n$ consisting of integers which satisfied the following conditions: * For all $1 \le i \le n$, $1 \le a_i \le 3 \cdot 10^5$. ...
[{"input": "3\n2\n3\n4", "output": "114514 114514\n1 2 2\n3 3 4 4"}]
cf-12ded724e7b4e8ce
Turtle just received $n$ segments and a sequence $a_1, a_2, \ldots, a_n$. The $i$-th segment is $[l_i, r_i]$. Turtle will create an undirected graph $G$. If segment $i$ and segment $j$ intersect, then Turtle will add an undirected edge between $i$ and $j$ with a weight of $|a_i - a_j|$, for every $i \ne j$. Turtle w...
[{"input": "4\n5\n1 7 3\n2 4 6\n3 5 5\n6 7 9\n3 4 4\n5\n2 7 3\n1 3 6\n4 5 5\n6 7 9\n1 1 4\n4\n1 4 3\n1 2 1\n3 4 5\n1 4 4\n3\n1 3 1\n2 3 3\n4 5 8", "output": "9\n13\n4\n-1"}]
cf-e3b3e78d8d33ea08
Note the unusual definition of $\text{MEX}$ in this problem. Piggy gave Turtle a binary tree$^{\dagger}$ with $n$ vertices and a sequence $a_1, a_2, \ldots, a_n$ on his birthday. The binary tree is rooted at vertex $1$. If a set of paths $P = \\{(x_i, y_i)\\}$ in the tree covers each edge exactly once, then Turtle w...
[{"input": "5\n5\n3 2 2 1 1\n1 1 2 2\n5\n3 2 1 1 1\n1 1 2 2\n6\n1 2 1 2 1 3\n1 2 3 3 4\n7\n2 1 2 3 1 2 1\n1 1 2 2 3 3\n10\n1 2 2 1 4 2 3 1 2 1\n1 1 2 2 3 3 4 5 5", "output": "4\n6\n6\n6\n7"}]
cf-6948ecd6286e913c
Dima loves watching soccer. In such a game, the score on the scoreboard is represented as $x$ : $y$, where $x$ is the number of goals of the first team, and $y$ is the number of goals of the second team. At any given time, only one team can score a goal, so the score $x$ : $y$ can change to either $(x + 1)$ : $y$, or ...
[{"input": "6\n1 0\n5 0\n1 2\n3 2\n1 2\n4 5\n1 2\n4 3\n1 2\n1 2\n998244353 0\n1000000000 999999999", "output": "YES\nNO\nYES\nNO\nYES\nYES"}]
cf-5fdd0e04ea336294
Recently, the first-year student Maxim learned about the Collatz conjecture, but he didn't pay much attention during the lecture, so he believes that the following process is mentioned in the conjecture: There is a variable $x$ and a constant $y$. The following operation is performed $k$ times: * increase $x$ by $...
[{"input": "13\n1 3 1\n2 3 1\n24 5 5\n16 3 2\n2 2 1\n1337 18 1\n1 2 144133\n12345678 3 10\n998244353 2 998244353\n998244353 123456789 998244352\n998244354 998241111 998244352\n998244355 2 9982443\n1000000000 1000000000 1000000000", "output": "2\n1\n1\n2\n3\n1338\n1\n16936\n1\n21180097\n6486\n1\n2"}]
cf-50b61b3d8c1fef5e
On another boring day, Egor got bored and decided to do something. But since he has no friends, he came up with a game to play. Egor has a deck of $n$ cards, the $i$-th card from the top has a number $a_i$ written on it. Egor wants to play a certain number of rounds until the cards run out. In each round, he takes a ...
[{"input": "8\n5 3 10\n2 1 11 3 7\n10 1 5\n17 8 12 11 7 11 21 13 10 8\n3 4 5\n3 4 2\n8 12 25\n10 7 5 13 8 9 12 7\n2 3 3\n5 2\n9 7 9\n2 10 5 1 3 7 6 2 3\n1 8 10\n9\n5 5 6\n1 4 2 6 4", "output": "3\n0\n1\n4\n0\n3\n1\n2"}]
cf-895ee117276fc985
Nikita loves mountains and has finally decided to visit the Berlyand mountain range! The range was so beautiful that Nikita decided to capture it on a map. The map is a table of $n$ rows and $m$ columns, with each cell containing a non-negative integer representing the height of the mountain. He also noticed that mou...
[{"input": "8\n3 3 2\n7 11 3\n4 2 3\n0 1 15\n100\n010\n000\n4 4 3\n123 413 24 233\n123 42 0 216\n22 1 1 53\n427 763 22 6\n0101\n1111\n1010\n0101\n3 3 2\n2 1 1\n1 1 2\n1 5 4\n010\n101\n010\n3 3 2\n2 1 1\n1 1 2\n1 5 3\n010\n101\n010\n3 4 3\n46 49 50 1\n19 30 23 12\n30 25 1 46\n1000\n0100\n0010\n5 4 4\n39 30 0 17\n22 42 3...
cf-b9be4f453fa811fd
Let $bit(x)$ denote the number of ones in the binary representation of a non-negative integer $x$. A subarray of an array is called $k$-good if it consists only of numbers with no more than $k$ ones in their binary representation, i.e., a subarray $(l, r)$ of array $a$ is good if for any $i$ such that $l \le i \le r$...
[{"input": "10\n6 1\n16 2\n1 1\n3 1\n31 3\n14 1\n1337 5\n100000 20\n795569939321040850 56\n576460752303423268 59", "output": "7\n35\n1\n6\n155\n8\n7323\n49965\n741136395\n66679884"}]
cf-35558baff322d158
You have an array $a$ of $n$ elements. There are also $q$ modifications of the array. Before the first modification and after each modification, you would like to know the following: What is the minimum length subarray that needs to be sorted in non-decreasing order in order for the array $a$ to be completely sorted ...
[{"input": "2\n5\n2 2 3 4 5\n3\n2 1\n4 1\n1 1\n5\n1 2 3 4 5\n9\n1 4\n2 3\n5 2\n3 1\n1 1\n5 1\n4 1\n3 1\n2 1", "output": "-1 -1\n1 2\n1 4\n3 4\n-1 -1\n1 3\n1 3\n1 5\n1 5\n2 5\n2 5\n2 5\n2 5\n-1 -1"}]
cf-39dc6d797ec012dc
An array of integers $a_1,a_2,\cdots,a_n$ is beautiful subject to an integer $k$ if it satisfies the following: * The sum of $a_{j}$ over all $j$ such that $j$ is a multiple of $k$ and $1 \le j \le n $, itself, is a multiple of $k$. * More formally, if $\sum_{k | j} a_{j}$ is divisible by $k$ for all $1 \le j \l...
[{"input": "3\n3\n6\n7", "output": "4 22 18\n10 6 15 32 125 54\n23 18 27 36 5 66 7"}]
cf-26164dd358b25b03
You are given two grids of numbers $a$ and $b$, with $n$ rows and $m$ columns. All the values in the grid are $0$, $1$ or $2$. You can perform the following operation on $a$ any number of times: * Pick any subrectangle in the grid with length and width $\ge 2$. You are allowed to choose the entire grid as a subrec...
[{"input": "7\n3 3\n000\n000\n000\n111\n111\n111\n4 4\n0000\n0000\n0000\n0000\n2100\n1200\n0012\n0021\n4 4\n1020\n1200\n1210\n0000\n0000\n1200\n2200\n0000\n3 3\n012\n012\n012\n010\n111\n011\n8 8\n00000000\n00000000\n00000000\n00000000\n00000000\n00000000\n00000000\n10000000\n00000000\n01200000\n02010000\n00102000\n0002...
cf-85d614b42c653847
Alice, Bob and Charlie want to share a rectangular cake cut into $n$ pieces. Each person considers every piece to be worth a different value. The $i$-th piece is considered to be of value $a_i$ by Alice, $b_i$ by Bob and $c_i$ by Charlie. The sum over all $a_i$, all $b_i$ and all $c_i$ individually is the same, equal...
[{"input": "10\n5\n5 1 1 1 1\n1 1 5 1 1\n1 1 1 1 5\n6\n1 2 3 4 5 6\n5 6 1 2 3 4\n3 4 5 6 1 2\n4\n4 4 4 4\n4 4 4 4\n4 4 4 4\n5\n5 10 5 2 10\n9 6 9 7 1\n10 7 10 2 3\n3\n4 5 2\n6 1 4\n1 8 2\n3\n10 4 10\n8 7 9\n10 4 10\n7\n57113 65383 19795 53580 74452 3879 23255\n12917 16782 89147 93107 27365 15044 43095\n33518 63581 3356...
cf-3b24035b37b7e3d0
Given two arrays of distinct positive integers $a$ and $b$ of length $n$, we would like to make both the arrays the same. Two arrays $x$ and $y$ of length $k$ are said to be the same when for all $1 \le i \le k$, $x_i = y_i$. Now in one move, you can choose some index $l$ and $r$ in $a$ ($l \le r$) and swap $a_l$ and...
[{"input": "6\n4\n1 2 3 4\n1 2 3 4\n5\n1 3 4 2 5\n7 1 2 5 4\n4\n1 2 3 4\n4 3 2 1\n3\n1 2 3\n1 3 2\n5\n1 5 7 1000 4\n4 1 7 5 1000\n3\n1 4 2\n1 3 2", "output": "YES\nNO\nYES\nNO\nNO\nNO"}]
cf-5f489f6285179bc0
Alice and Bob are playing a game. There are $n$ balls, out of which $k$ are special. Each ball has a value associated with it. The players play turn by turn. In each turn, the player randomly picks a ball and adds the value of the ball to their score, which is $0$ at the beginning of the game. The selected ball is re...
[{"input": "1\n5 2\n10 20 5 15 25", "output": "45 30"}, {"input": "5\n1 1\n732507\n2 2\n5817860 5398510\n5 1\n2122894 4951549 2750585 7821535 3214167\n8 4\n1405323 5069867 6883092 6972029 328406 2478975 7628890 9973340\n4 2\n9662050 3566134 3996473 9872255", "output": "732507 0\n11216370 0\n810642660 210218077\n7224029...
cf-4d8452a6dc8692ee
You have an array of non-negative integers $a_1, a_2, \ldots, a_n$. The value of a sub-array of length $\ge 2$, $a[l, r] = [a_l, a_{l+1}, \ldots, a_r]$ is the minimum value of $a_i \oplus a_j$ such that $l \le i < j \le r$, where $\oplus$ is the xor (exclusive-or) operator. You have to find the $k$-th smallest value...
[{"input": "4\n5 2\n1 2 3 4 5\n2 1\n4 3\n4 6\n1 2 4 8\n5 9\n1 2 3 4 5", "output": "1\n7\n12\n3"}]
cf-3210cc15125b1902
You are given a tree with $n$ nodes numbered from $1$ to $n$, along with an array of size $n$. The value of $i$-th node is $a_{i}$. There are $q$ queries. In each query, you are given 2 nodes numbered as $x$ and $y$. Consider the path from the node numbered as $x$ to the node numbered as $y$. Let the path be represen...
[{"input": "1\n4\n1 2\n2 3\n3 4\n2 3 6 5\n3\n1 4\n3 4\n1 1", "output": "14\n10\n2"}]
cf-68791d88924e8208
Define the range of a non-empty array to be the maximum value minus the minimum value. For example, the range of $[1,4,2]$ is $4-1=3$. You are given an array $a_1, a_2, \ldots, a_n$ of length $n \geq 3$. It is guaranteed $a$ is sorted. You have to color each element of $a$ red or blue so that: * the range of the ...
[{"input": "7\n4\n1 1 2 2\n5\n1 2 3 4 5\n3\n3 3 3\n4\n1 2 2 2\n3\n1 2 2\n3\n1 1 2\n3\n1 9 84", "output": "YES\nRBRR\nYES\nBBRBB\nNO\nYES\nRBBR\nYES\nRRB\nYES\nBRR\nYES\nBRB"}]
cf-d81d9c8ba952a505
A digit is large if it is between $5$ and $9$, inclusive. A positive integer is large if all of its digits are large. You are given an integer $x$. Can it be the sum of two large positive integers with the same number of digits? Input Format: The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) โ€” the ...
[{"input": "11\n1337\n200\n1393938\n1434\n98765432123456789\n11111111111111111\n420\n1984\n10\n69\n119", "output": "YES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nNO"}]
cf-5fa3fb3b49dbd702
The two versions of the problem are different. You may want to read both versions. You can make hacks only if both versions are solved. You are given an array $a$ of length $n$. Start with $c = 0$. Then, for each $i$ from $1$ to $n$ (in increasing order) do exactly one of the following: * Option $1$: set $c$ to $c...
[{"input": "5\n4\n10 -9 -3 4\n8\n1 4 3 4 1 4 3 4\n3\n-1 -2 -3\n4\n-1000000000 1000000000 1000000000 1000000000\n4\n1 9 8 4", "output": "6\n24\n6\n4000000000\n22"}]
cf-a7fa9759eff61255
The two versions of the problem are different. You may want to read both versions. You can make hacks only if both versions are solved. You are given an array $a$ of length $n$. Start with $c = 0$. Then, for each $i$ from $1$ to $n$ (in increasing order) do exactly one of the following: * Option $1$: set $c$ to $c...
[{"input": "5\n4\n2 -5 3 -3\n8\n1 4 3 4 1 4 3 4\n3\n-1 -2 -3\n4\n-1000000000 1000000000 1000000000 1000000000\n4\n1 9 8 4", "output": "12\n256\n1\n8\n16"}]
cf-5118104022fa64fe
You are given a string $s$ consisting of lowercase Latin characters. Count the number of nonempty strings $t \neq$ "$\texttt{a}$" such that it is possible to partition$^{\dagger}$ $s$ into some substrings satisfying the following conditions: * each substring either equals $t$ or "$\texttt{a}$", and * at least on...
[{"input": "8\naaaaa\nbaba\ncabacb\naaabaaa\nbitset\nab\nabbaaaabbb\nyearnineteeneightyfour", "output": "4\n4\n1\n16\n1\n2\n3\n1"}]
cf-7d90be3588221da2
Two hungry red pandas, Oscar and Lura, have a tree $T$ with $n$ nodes. They are willing to perform the following shuffle procedure on the whole tree $T$ exactly once. With this shuffle procedure, they will create a new tree out of the nodes of the old tree. 1. Choose any node $V$ from the original tree $T$. Create ...
[{"input": "4\n5\n1 2\n1 3\n2 4\n2 5\n5\n1 2\n2 3\n3 4\n4 5\n6\n1 2\n1 3\n1 4\n1 5\n1 6\n10\n9 3\n8 1\n10 6\n8 5\n7 8\n4 6\n1 3\n10 1\n2 7", "output": "4\n3\n5\n6"}]
cf-650d93f12b4cd5ba
There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive. You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$. For each $i$ from $1$ to $n...
[{"input": "6\n4 10\nPSPP\n1 9 8 10\n4 1000000000\n????\n1 1 1 4000000000\n8 1000000000\n?P?SSP?P\n-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332\n4 7\nPPSS\n4 2 1 3\n9 20\n?????????\n1 2 3 4 5 6 7 8 9\n3 1000000000\nP??\n-145463248 -974068460 -1287458396", "output": "1\n0\n2\n1\n...
cf-2034d12ca0220544
The secret behind Oscar's first magic trick has been revealed! Because he still wants to impress Lura, he comes up with a new idea: he still wants to sort a permutation $p_1, p_2, \ldots, p_n$ of $[1, 2, \ldots, n]$. This time, he chooses an integer $k$. He wants to sort the permutation in non-decreasing order using ...
[{"input": "3\n5\n5 1 2 3 4\n5\n2 3 5 4 1\n6\n1 2 3 4 5 6", "output": "4\n1\n2 1\n3\n2\n1 3\n2 1\n6\n0"}]
cf-8a750ad6391674a9
There are $n$ towers at $n$ distinct points $(x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)$, such that no three are collinear and no four are concyclic. Initially, you own towers $(x_1, y_1)$ and $(x_2, y_2)$, and you want to capture all of them. To do this, you can do the following operation any number of times: * Pi...
[{"input": "3\n5\n1 1\n2 5\n3 3\n4 2\n5 4\n6\n1 1\n3 3\n1 2\n2 1\n3 10000\n19 84\n7\n2 7\n-4 -3\n-3 6\n3 1\n-5 2\n1 -4\n-1 7", "output": "1\n0\n10"}]
cf-1f0b89e27db09b4b
Matthew is given two strings $a$ and $b$, both of length $3$. He thinks it's particularly funny to create two new words by swapping the first character of $a$ with the first character of $b$. He wants you to output $a$ and $b$ after the swap. Note that the new words may not necessarily be different. Input Format: Th...
[{"input": "6\nbit set\ncat dog\nhot dog\nuwu owo\ncat cat\nzzz zzz", "output": "sit bet\ndat cog\ndot hog\nowu uwo\ncat cat\nzzz zzz"}]
cf-f90a85e39db3bde3
Given an integer $n$, find an integer $x$ such that: * $2 \leq x \leq n$. * The sum of multiples of $x$ that are less than or equal to $n$ is maximized. Formally, $x + 2x + 3x + \dots + kx$ where $kx \leq n$ is maximized over all possible values of $x$. Input Format: The first line contains $t$ ($1 \leq t \leq ...
[{"input": "2\n3\n15", "output": "3\n2"}]
cf-9474cceabd190d0e
Alex thinks some array is good if there exists some element that can be represented as the sum of all other elements (the sum of all other elements is $0$ if there are no other elements). For example, the array $[1,6,3,2]$ is good since $1+3+2=6$. Furthermore, the array $[0]$ is also good. However, the arrays $[1,2,3,...
[{"input": "7\n1\n0\n1\n1\n4\n1 1 2 0\n5\n0 1 2 1 4\n7\n1 1 0 3 5 2 12\n7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 294967296\n10\n0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 589934592", "output": "1\n0\n3\n3\n4\n1\n2"}]
cf-10c296908f2b0a5f
Given a $n$ by $m$ grid consisting of '.' and '#' characters, there exists a whole manhattan circle on the grid. The top left corner of the grid has coordinates $(1,1)$, and the bottom right corner has coordinates $(n, m)$. Point ($a, b$) belongs to the manhattan circle centered at ($h, k$) if $|h - a| + |k - b| < r$...
[{"input": "6\n5 5\n.....\n.....\n..#..\n.....\n.....\n5 5\n..#..\n.###.\n#####\n.###.\n..#..\n5 6\n......\n......\n.#....\n###...\n.#....\n1 1\n#\n5 6\n...#..\n..###.\n.#####\n..###.\n...#..\n2 10\n..........\n...#......", "output": "3 3\n3 3\n4 2\n1 1\n3 4\n2 4"}]
End of preview. Expand in Data Studio

DeepCoder Codeforces test 408 independent val for zero-code-l1. Source agentica-org/DeepCoder-Preview-Dataset codeforces/test plus id. See also Tommysha/zero-code-l1-val.

Downloads last month
76