Dataset Viewer
Auto-converted to Parquet Duplicate
messages
listlengths
1
1
ground_truth
stringlengths
41
746
dataset
stringclasses
1 value
[ { "content": "You are given two integers $x$ and $y$.\n\nOutput two integers: the minimum of $x$ and $y$, followed by the maximum of $x$ and $y$.\n\nInput Format:\nThe first line contains a single integer $t$ ($1 \\leq t \\leq 100$) — the number of test cases.\n\nThe only line of each test case contains two spa...
[{"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"}]
code_stdio
[ { "content": "You are given a string $s$ consisting of lowercase English letters.\n\nRearrange the characters of $s$ to form a new string $r$ that is not equal to $s$, or report that it's impossible.\n\nInput Format:\nThe first line contains a single integer $t$ ($1 \\leq t \\leq 1000$) — the number of test cas...
[{"input": "8\ncodeforces\naaaaa\nxxxxy\nco\nd\nnutdealer\nmwistht\nhhhhhhhhhh", "output": "YES\nforcodesec\nNO\nYES\nxxyxx\nYES\noc\nNO\nYES\nundertale\nYES\nthtsiwm\nNO"}]
code_stdio
[ { "content": "There is a clock labeled with the numbers $1$ through $12$ in clockwise order, as shown below.\n\n![](CDN_BASE_URL/d18290022594db5fbc2eb2c94222b5d4)\n\nIn this example, $(a,b,c,d)=(2,9,10,6)$, and the strings intersect.\n\nAlice and Bob have four distinct integers $a$, $b$, $c$, $d$ not more than ...
[{"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"}]
code_stdio
[ { "content": "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.\n\n![](CDN_BASE_URL/f49d41e3510eec9591123a65ee9389ab)\n\nNote that:\n\n * each character must lie in exactly on...
[{"input": "6\n11010\n00000000\n1\n10\n0001111\n0110", "output": "3\n1\n1\n2\n1\n2"}]
code_stdio
[ { "content": "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$.\n\nThere 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$, respectiv...
[{"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"}]
code_stdio
[ { "content": "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$.\n\nA 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": "6\n1\n2\n3\n4\n5\n1984", "output": "8\n16\n20\n24\n40\n12504"}]
code_stdio
[ { "content": "You are given an array $a$ consisting of $n$ nonnegative integers.\n\nYou 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).\n\nFind the lexicographically smallest...
[{"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"}]
code_stdio
[ { "content": "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:\n\n$$\\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 \\...
[{"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"}]
code_stdio
[ { "content": "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 or...
[{"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"}]
code_stdio
[ { "content": "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.\n\nIn each operation, the player chooses a facing-up coin, removes the coin, and flips the two coins that are adjacent to ...
[{"input": "3\n5\nUUDUD\n5\nUDDUD\n2\nUU", "output": "YES\nNO\nNO"}]
code_stdio
[ { "content": "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.\n\nThere is also a shop which contains unlimited cards of each type. You have $k$ coins, so you can buy $k$ new c...
[{"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"}]
code_stdio
[ { "content": "The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved.\n\nYou are given two positive integers $n$, $m$.\n\nCalculate the number of ordered pairs $(a, b)$ satisfying the following conditions:\n\n * $1\\le a\\le n$, $1\\le b...
[{"input": "6\n1 1\n2 3\n3 5\n10 8\n100 1233\n1000000 1145141", "output": "1\n3\n4\n14\n153\n1643498"}]
code_stdio
[ { "content": "The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved.\n\nYou are given two positive integers $n$, $m$.\n\nCalculate the number of ordered pairs $(a, b)$ satisfying the following conditions:\n\n * $1\\le a\\le n$, $1\\le b...
[{"input": "6\n1 1\n2 3\n3 5\n10 8\n100 1233\n1000000 1145141", "output": "0\n1\n1\n6\n423\n5933961"}]
code_stdio
[ { "content": "Let $\\operatorname{lowbit}(x)$ denote the value of the lowest binary bit of $x$, e.g. $\\operatorname{lowbit}(12)=4$, $\\operatorname{lowbit}(8)=8$.\n\nFor 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...
[{"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"}]
code_stdio
[ { "content": "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$.\n\nTo do this, she can perform several m...
[{"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"}]
code_stdio
[ { "content": "Three friends gathered to play a few games of chess together.\n\nIn 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 nu...
[{"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"}]
code_stdio
[ { "content": "Today, Cat and Fox found an array $a$ consisting of $n$ non-negative integers.\n\nDefine 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} | \\ldot...
[{"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"}]
code_stdio
[ { "content": "Fox loves permutations! She came up with the following problem and asked Cat to solve it:\n\nYou are given an even positive integer $n$ and a permutation$^\\dagger$ $p$ of length $n$.\n\nThe score of another permutation $q$ of length $n$ is the number of local maximums in the array $a$ of length $...
[{"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"}]
code_stdio
[ { "content": "This is an interactive problem.\n\nFox 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:\n\nFor any two integers $l, r$ such that $1 \\leq l \\leq 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"}]
code_stdio
[ { "content": "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...
[{"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"}]
code_stdio
[ { "content": "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$.\n\nYou are given three arrays $a...
[{"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": "3 4\n1 2 3\n4 5 6\n1 1 1\n0 1 2 3", "output": "2 3 3 3"}, {"input": "1 1\n3\n4\n5\n0", "output": "7"}]
code_stdio
[ { "content": "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.\n\nThere are $x$ applications with an icon size of $1 \\times 1$ cells; such an ic...
[{"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"}]
code_stdio
[ { "content": "Polycarp has a string $s$, which consists of lowercase Latin letters. He encodes this string using the following algorithm:\n\n * 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 happen...
[{"input": "5\n10\nserofedsoc\n3\nttf\n9\ntlrhgmaoi\n1\nw\n15\nhnndledmnhlttin", "output": "codeforces\nfft\nalgorithm\nw\nmeetinthemiddle"}]
code_stdio
[ { "content": "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}]$.\n\nPolycarp considers a pair of triples $b$ and $c$ beautiful if they differ in exactly one position, that ...
[{"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"}]
code_stdio
[ { "content": "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...
[{"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"}]
code_stdio
[ { "content": "Being a physicist, Charlie likes to plan his life in simple and precise terms.\n\nFor 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 ...
[{"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"}]
code_stdio
[ { "content": "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)$.\n\nAlice made the first move, ...
[{"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"}]
code_stdio
[ { "content": "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.\n\nBeing a physicist, Charlie likes to plan his life in simpl...
[{"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"}]
code_stdio
[ { "content": "Mocha likes arrays, so before her departure, Bazoka gave her an array $a$ consisting of $n$ positive integers as a gift.\n\nNow Mocha wants to know whether array $a$ could become sorted in non- decreasing order after performing the following operation some (possibly, zero) times:\n\n * Split the ...
[{"input": "3\n6\n1 1 4 5 1 4\n5\n7 9 2 2 3\n3\n1 2 3", "output": "No\nYes\nYes"}]
code_stdio
[ { "content": "Mocha likes arrays, so before her departure, 378QAQ gave her an array $a$ consisting of $n$ positive integers as a gift.\n\nMocha 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$^\...
[{"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"}]
code_stdio
[ { "content": "Mocha likes arrays, so before her departure, Chamo gave her an array $a$ consisting of $n$ positive integers as a gift.\n\nMocha 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,...
[{"input": "2\n2\n1 2\n5\n1 2 3 4 5", "output": "1\n4"}]
code_stdio
[ { "content": "378QAQ has a tree with $n$ vertices. Initially, all vertices are white.\n\nThere 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:\n\n 1. Move $P_A$ to a neighbor...
[{"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"}]
code_stdio
[ { "content": "You are given a tree of $n$ vertices numbered from $1$ to $n$. Initially, all vertices are colored white or black.\n\nYou are asked to perform $q$ queries:\n\n * \"u\" — toggle the color of vertex $u$ (if it was white, change it to black and vice versa). \n\nAfter each query, you should answer wh...
[{"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"}, {"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"}]
code_stdio
[ { "content": "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...
[{"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"}, {"input": "3\n15 15 15 15 15 15 12", "output": "4\n3\n5\n6\n7"}]
code_stdio
[ { "content": "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 *.\n\nYou need to replace all occurr...
[{"input": "20 18\nbulijiojio-dibuliduo\n*li*ji-*ox*i*-du*-", "output": "Yes"}, {"input": "13 11\nasoulwangziji\n-soulg*z-y-", "output": "No"}, {"input": "10 10\njustmonika\nj-stsayori", "output": "No"}, {"input": "7 8\nttk-wxx\n*tt-l-xx", "output": "Yes"}, {"input": "7 3\nabc*cba\na*c", "output": "No"}]
code_stdio
[ { "content": "378QAQ has a string $s$ of length $n$. Define the core of a string as the substring$^\\dagger$ with maximum lexicographic$^\\ddagger$ order.\n\nFor example, the core of \"$\\mathtt{bazoka}$\" is \"$\\mathtt{zoka}$\", and the core of \"$\\mathtt{aaa}$\" is \"$\\mathtt{aaa}$\".\n\n378QAQ wants to re...
[{"input": "6\n3\nqaq\n4\ncccc\n6\nbazoka\n6\nzazzzz\n7\nababbbb\n7\nccbabcc", "output": "qaq\ncccc\nz\nzzz\nbbababb\ncbcacbc"}]
code_stdio
[ { "content": "This is the way it always was.\n\nThis is the way it always will be.\n\nAll will be forgotten again soon...\n\nJellyfish 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$.\n\nThere is a binary string ...
[{"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"}]
code_stdio
[ { "content": "Monocarp is working on his new site, and the current challenge is to make the users pick strong passwords.\n\nMonocarp decided that strong passwords should satisfy the following conditions:\n\n * password should consist only of lowercase Latin letters and digits; * there should be no digit tha...
[{"input": "5\n4\n12ac\n5\n123wa\n9\nallllmost\n5\nac123\n6\n011679", "output": "YES\nNO\nYES\nNO\nYES"}]
code_stdio
[ { "content": "You are given two integer arrays: array $a$ of length $n$ and array $b$ of length $n+1$.\n\nYou can perform the following operations any number of times in any order:\n\n * choose any element of the array $a$ and increase it by $1$; * choose any element of the array $a$ and decrease it by $1$;...
[{"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"}]
code_stdio
[ { "content": "Monocarp is opening his own IT company. He wants to hire $n$ programmers and $m$ testers.\n\nThere 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 sk...
[{"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"}]
code_stdio
[ { "content": "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:\n\n * bracket sequences \"()()\" and \"(())\" are regular (the resulting expressions are:...
[{"input": "4\n(())\n()\n()()()\n(()())(())", "output": "1\n0\n3\n13"}]
code_stdio
[ { "content": "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).\n\nWe performed $q$ operations. During the $i$-th operation, we did the following:\n\n * choose any array we have with at least $2$ elements; * split...
[{"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"}]
code_stdio
[ { "content": "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.\n\nYou are asked to add exactly $k$ edges to the tree (possibly, multiple edges and/or edges already existing in the tree).\n\nRecall that a bridge ...
[{"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"}]
code_stdio
[ { "content": "The little boy Nikita was given some cubes as a present. He decided to build a tower out of them.\n\nInitially, 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...
[{"input": "3\n3 3\n2 4\n5 3", "output": "Yes\nNo\nYes"}]
code_stdio
[ { "content": "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:\n\n * $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...
[{"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"}]
code_stdio
[ { "content": "Nikita is a student passionate about number theory and algorithms. He faces an interesting problem related to an array of numbers.\n\nSuppose 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://e...
[{"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"}]
code_stdio
[ { "content": "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).\n\nA column in the matrix is considered special if it contains exactly one 1. Your task is t...
[{"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"}]
code_stdio
[ { "content": "This is an interactive problem.\n\nYou are given an integer $n$.\n\nThe 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:\n\n * The graph only contains edges of the form $i \\leftarrow j$, where $1 \\le i <...
[{"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"}]
code_stdio
[ { "content": "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:\n\n * She divides all the books into two non-empty piles. Thus, each book ends up in exactly one of the two piles. * Alice ...
[{"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"}]
code_stdio
[ { "content": "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:\n\n * Bob chooses some integer $k$ ($0 \\le k \\le \\min(n, b)$). * Bob sells the first $k$ buns at a mod...
[{"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"}]
code_stdio
[ { "content": "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|$.\n\nFor 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 ...
[{"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"}]
code_stdio
[ { "content": "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. Undec...
[{"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"}]
code_stdio
[ { "content": "Sasha has two binary strings $s$ and $t$ of the same length $n$, consisting of the characters 0 and 1.\n\nThere is also a computing machine that can perform two types of operations on binary strings $a$ and $b$ of the same length $k$:\n\n 1. If $a_{i} = a_{i + 2} =$ 0, then you can assign $b_{i +...
[{"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"}]
code_stdio
[ { "content": "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\n\n$$b = \\begin{bmatrix} 3 & 4 & 5 \\\\\\ 5 ...
[{"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"}]
code_stdio
[ { "content": "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:\n\n * Bob chooses two integers $i$ and $j$ ($1 \\le i < j \\le n$), and then finds the maximum among the i...
[{"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"}]
code_stdio
[ { "content": "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\n\n * $a_n = n \\oplus x$; * $b_n = n \\oplus y$. \n\nHere, $x \\oplus y$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_o...
[{"input": "4\n0 1\n12 4\n57 37\n316560849 14570961", "output": "1\n8\n4\n33554432"}]
code_stdio
[ { "content": "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, mult...
[{"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"}]
code_stdio
[ { "content": "You are given a binary string $s$ of length $n$, consisting of zeros and ones. You can perform the following operation exactly once:\n\n 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 $...
[{"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"}]
code_stdio
[ { "content": "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|.$$\n\nWe call a Manhattan triangle three points on the plane, the Manhattan distances between each pair of which are equal.\n\nYou are given a set of pairwise distinct points and an e...
[{"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...
code_stdio
[ { "content": "This is an interactive problem.\n\nKostyanych 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:\n\n * \"? $d$\" — Kostyanych tells you the number of vertex $v$ with a degree at least ...
[{"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"}]
code_stdio
[ { "content": "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'.\n\nVlad 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 m...
[{"input": "3\n10 1\nBGECDCBDED\n10 2\nBGECDCBDED\n9 1\nBBCDEFFGG", "output": "2\n5\n1"}]
code_stdio
[ { "content": "Dmitry has $n$ cubes, numbered from left to right from $1$ to $n$. The cube with index $f$ is his favorite.\n\nDmitry 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, fro...
[{"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"}]
code_stdio
[ { "content": "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.\n\nEach modification operation is described by a pair of numbers $\\langle c_j, d_j \\rangle$ and means that the element of the array ...
[{"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...
code_stdio
[ { "content": "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$.\n\nKristina has an array $a$ consisting of exactly $n$ positive integers. She wants to count the GCD...
[{"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"}]
code_stdio
[ { "content": "You have been given a matrix $a$ of size $n$ by $m$, containing a permutation of integers from $1$ to $n \\cdot m$.\n\nA 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, whil...
[{"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"}]
code_stdio
[ { "content": "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.\n\nAlice and Bob are dividing the field. The field is a rectangle o...
[{"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"}]
code_stdio
[ { "content": "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.\n\nAlice and Bob are dividing the field. The field is a rectangle of...
[{"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"}]
code_stdio
[ { "content": "Yasya was walking in the forest and accidentally found a tree with $n$ vertices. A tree is a connected undirected graph with no cycles.\n\nNext to the tree, the girl found an ancient manuscript with $m$ queries written on it. The queries can be of two types.\n\nThe first type of query is described...
[{"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 ...
code_stdio
[ { "content": "Turtle and Piggy are playing a number game.\n\nFirst, 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$.\n\nThen, Piggy will keep doing the following operation until $x$ becomes $1$:\n\n * Choose an integer $p$ such that ...
[{"input": "5\n2 4\n3 6\n2 15\n6 22\n114514 1919810", "output": "2\n2\n3\n4\n20"}]
code_stdio
[ { "content": "There is a sequence $a_0, a_1, a_2, \\ldots$ of infinite length. Initially $a_i = i$ for every non-negative integer $i$.\n\nAfter 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$ ...
[{"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"}]
code_stdio
[ { "content": "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.\n\nNow the sequence becomes incomplete. There may exist an arbitrary number of indices $i$ such that $a_i$ becomes $-1$. Let the new sequence...
[{"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"}]
code_stdio
[ { "content": "Turtle just learned how to multiply two integers in his math class, and he was very excited.\n\nThen 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:\n\n * For all $1 \\le i \\le n$, $1 \...
[{"input": "3\n2\n3\n4", "output": "114514 114514\n1 2 2\n3 3 4 4"}]
code_stdio
[ { "content": "Turtle just received $n$ segments and a sequence $a_1, a_2, \\ldots, a_n$. The $i$-th segment is $[l_i, r_i]$.\n\nTurtle 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 ev...
[{"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"}]
code_stdio
[ { "content": "Note the unusual definition of $\\text{MEX}$ in this problem.\n\nPiggy 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$.\n\nIf a set of paths $P = \\\\{(x_i, y_i)\\\\}$ in the tree covers each ...
[{"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"}]
code_stdio
[ { "content": "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...
[{"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"}]
code_stdio
[ { "content": "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:\n\nThere is a variable $x$ and a constant $y$. The following operation is performed $k$ times:...
[{"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"}]
code_stdio
[ { "content": "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.\n\nEgor 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 ...
[{"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"}]
code_stdio
[ { "content": "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.\n\nH...
[{"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...
code_stdio
[ { "content": "Let $bit(x)$ denote the number of ones in the binary representation of a non-negative integer $x$.\n\nA 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$ su...
[{"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"}]
code_stdio
[ { "content": "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:\n\nWhat is the minimum length subarray that needs to be sorted in non-decreasing order in order for the array $a$ t...
[{"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"}]
code_stdio
[ { "content": "An array of integers $a_1,a_2,\\cdots,a_n$ is beautiful subject to an integer $k$ if it satisfies the following:\n\n * 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...
[{"input": "3\n3\n6\n7", "output": "4 22 18\n10 6 15 32 125 54\n23 18 27 36 5 66 7"}]
code_stdio
[ { "content": "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$.\n\nYou can perform the following operation on $a$ any number of times:\n\n * Pick any subrectangle in the grid with length and width $\\ge 2$. You are allowed to choose t...
[{"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...
code_stdio
[ { "content": "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.\n\nThe sum over all $a_i$, all $b_i$ and all $c_i$ individu...
[{"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...
code_stdio
[ { "content": "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$.\n\nNow in one move, you can choose some index $l$ and $r$ in $a$ ($l \...
[{"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"}]
code_stdio
[ { "content": "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.\n\nThe 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. ...
[{"input": "5\n3 3\n1095611 8219204 7773462\n2 1\n8176490 2774103\n3 1\n9178636 5138057 3367761\n12 9\n7597698 6843019 2298534 1522386 4969588 1340345 3967362 9152890 6689668 9986080 4745473 7407325\n10 5\n6986368 2397882 5804127 6980694 3740836 3215836 5195724 3179261 4136769 4544231", "output": "17088277 0\n6862348 4...
code_stdio
[ { "content": "You have an array of non-negative integers $a_1, a_2, \\ldots, a_n$.\n\nThe 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.\n\nYou have t...
[{"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"}]
code_stdio
[ { "content": "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$.\n\nConsider the path from the node numbered as $x$ to the node numbered as $y$. L...
[{"input": "1\n4\n1 2\n2 3\n3 4\n2 3 6 5\n3\n1 4\n3 4\n1 1", "output": "14\n10\n2"}]
code_stdio
[ { "content": "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$.\n\nYou are given an array $a_1, a_2, \\ldots, a_n$ of length $n \\geq 3$. It is guaranteed $a$ is sorted.\n\nYou have to color each element of $a$ red or blue so t...
[{"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"}]
code_stdio
[ { "content": "A digit is large if it is between $5$ and $9$, inclusive. A positive integer is large if all of its digits are large.\n\nYou are given an integer $x$. Can it be the sum of two large positive integers with the same number of digits?\n\nInput Format:\nThe first line contains a single integer $t$ ($1...
[{"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"}]
code_stdio
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
41