messages
listlengths
1
1
ground_truth
stringlengths
41
746
dataset
stringclasses
1 value
[ { "content": "Suneet and Slavic play a card game. The rules of the game are as follows:\n\n * Each card has an integer value between $1$ and $10$. * Each player receives $2$ cards which are face-down (so a player doesn't know their cards). * The game is turn-based and consists exactly of two turns. In a ...
[{"input": "5\n3 8 2 6\n1 1 1 1\n10 10 2 2\n1 1 10 10\n3 8 7 2", "output": "2\n0\n4\n0\n2"}]
code_stdio_codeforces
[ { "content": "As a computer science student, Alex faces a hard challenge β€” showering. He tries to shower daily, but despite his best efforts there are always challenges. He takes $s$ minutes to shower and a day only has $m$ minutes!\n\nHe already has $n$ tasks planned for the day. Task $i$ is represented as an ...
[{"input": "4\n3 3 10\n3 5\n6 8\n9 10\n3 3 10\n1 2\n3 5\n6 7\n3 3 10\n1 2\n3 5\n6 8\n3 4 10\n1 2\n6 7\n8 9", "output": "YES\nYES\nNO\nYES"}]
code_stdio_codeforces
[ { "content": "Slavic has a very tough exam and needs your help in order to pass it. Here is the question he is struggling with:\n\nThere exists a string $s$, which consists of lowercase English letters and possibly zero or more \"?\".\n\nSlavic is asked to change each \"?\" to a lowercase English letter such th...
[{"input": "5\n?????\nxbx\nab??e\nabcde\nayy?x\na\nab??e\ndac\npaiu\nmom", "output": "YES\nxabax\nYES\nabcde\nYES\nayyyx\nNO\nNO"}]
code_stdio_codeforces
[ { "content": "On the board Ivy wrote down all integers from $l$ to $r$, inclusive.\n\nIn an operation, she does the following:\n\n * pick two numbers $x$ and $y$ on the board, erase them, and in their place write the numbers $3x$ and $\\lfloor \\frac{y}{3} \\rfloor$. (Here $\\lfloor \\bullet \\rfloor$ denotes ...
[{"input": "4\n1 3\n2 4\n199999 200000\n19 84", "output": "5\n6\n36\n263"}]
code_stdio_codeforces
[ { "content": "Arul has a binary array$^{\\text{βˆ—}}$ $a$ of length $n$.\n\nHe will take all subsequences$^{\\text{†}}$ of length $k$ ($k$ is odd) of this array and find their median.$^{\\text{‑}}$\n\nWhat is the sum of all these values?\n\nAs this sum can be very large, output it modulo $10^9 + 7$. In other word...
[{"input": "8\n4 3\n1 0 0 1\n5 1\n1 1 1 1 1\n5 5\n0 1 0 1 0\n6 3\n1 0 1 0 1 1\n4 3\n1 0 1 1\n5 3\n1 0 1 1 0\n2 1\n0 0\n34 17\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2\n5\n0\n16\n4\n7\n0\n333606206"}]
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. The only difference between the two versions is that in this version, you can make at most $\\mathbf{10}$ queries.\n\nThis is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read [the guide for participants...
[{"input": "2\n\n18\n\n25\n\n\n9999", "output": "? 3 5\n\n? 4 4\n\n! 4\n? 99 100\n\n! 100"}]
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. The only difference between the two versions is that in this version, you can make at most $\\mathbf{7}$ queries.\n\nThis is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read [the guide for participants]...
[{"input": "2\n\n18\n\n25\n\n\n9999", "output": "? 3 5\n\n? 4 4\n\n! 4\n? 99 100\n\n! 100"}]
code_stdio_codeforces
[ { "content": "Dmitry wrote down $t$ integers on the board, and that is good. He is sure that he lost an important integer $n$ among them, and that is bad.\n\nThe integer $n$ had the form $\\text{10^x}$ ($x \\ge 2$), where the symbol '$\\text{^}$' denotes exponentiation.. Something went wrong, and Dmitry missed ...
[{"input": "7\n100\n1010\n101\n105\n2033\n1019\n1002", "output": "NO\nYES\nNO\nYES\nNO\nYES\nNO"}]
code_stdio_codeforces
[ { "content": "In Berland, a bus consists of a row of $n$ seats numbered from $1$ to $n$. Passengers are advised to always board the bus following these rules:\n\n * If there are no occupied seats in the bus, a passenger can sit in any free seat; * Otherwise, a passenger should sit in any free seat that has a...
[{"input": "4\n5\n5 4 2 1 3\n3\n2 3 1\n4\n2 3 1 4\n5\n1 2 3 5 4", "output": "NO\nYES\nYES\nNO"}]
code_stdio_codeforces
[ { "content": "Kristina has an array $a$, called a template, consisting of $n$ integers. She also has $m$ strings, each consisting only of lowercase Latin letters. The strings are numbered from $1$ to $m$. She wants to check which strings match the template.\n\nA string $s$ is considered to match the template if...
[{"input": "3\n5\n3 5 2 1 3\n2\nabfda\nafbfa\n2\n1 2\n3\nab\nabc\naa\n4\n5 -3 5 -3\n4\naaaa\nbcbc\naba\ncbcb", "output": "YES\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nYES"}]
code_stdio_codeforces
[ { "content": "Vlad found a strip of $n$ cells, numbered from left to right from $1$ to $n$. In the $i$-th cell, there is a positive integer $a_i$ and a letter $s_i$, where all $s_i$ are either 'L' or 'R'.\n\nVlad invites you to try to score the maximum possible points by performing any (possibly zero) number of...
[{"input": "4\n6\n3 5 1 4 3 2\nLRLLLR\n2\n2 8\nLR\n2\n3 9\nRL\n5\n1 2 3 4 5\nLRLRR", "output": "18\n10\n0\n22"}]
code_stdio_codeforces
[ { "content": "You really love gorillas, so you decided to organize a photoshoot for them. Gorillas live in the jungle. The jungle is represented as a grid of $n$ rows and $m$ columns. $w$ gorillas agreed to participate in the photoshoot, and the gorilla with index $i$ ($1 \\le i \\le w$) has a height of $a_i$. ...
[{"input": "5\n3 4 2\n9\n1 1 1 1 1 1 1 1 1\n2 1 1\n2\n5 7\n20 15 7\n9\n4 1 4 5 6 1 1000000000 898 777\n1984 1 1\n4\n5 4 1499 2004\n9 5 5\n6\n6 7 14 16 16 6", "output": "21\n12\n49000083104\n3512\n319"}]
code_stdio_codeforces
[ { "content": "You have $n$ rectangles, the $i$-th of which has a width of $a_i$ and a height of $b_i$.\n\nYou can perform the following operation an unlimited number of times: choose a rectangle and a cell in it, and then color it.\n\nEach time you completely color any row or column, you earn $1$ point. Your ta...
[{"input": "7\n1 4\n6 3\n1 5\n4 4\n5 10\n1 1\n1 1\n1 1\n1 1\n1 1\n2 100\n1 2\n5 6\n3 11\n2 2\n3 3\n4 4\n3 25\n9 2\n4 3\n8 10\n4 18\n5 4\n8 5\n8 3\n6 2", "output": "12\n14\n5\n-1\n17\n80\n35"}]
code_stdio_codeforces
[ { "content": "You live in a city consisting of $n$ intersections and $m$ streets connecting some pairs of intersections. You can travel in either direction on each street. No two streets connect the same pair of intersections, and no street connects an intersection to itself. You can reach any intersection from...
[{"input": "7\n5 5\n100 20 80\n1 5 30 100\n1 2 20 50\n2 3 20 50\n3 4 20 50\n4 5 20 50\n2 1\n100 50 60\n1 2 55 110\n4 4\n100 40 60\n1 2 30 100\n2 4 30 100\n1 3 20 50\n3 4 20 50\n3 3\n100 80 90\n1 2 1 10\n2 3 10 50\n1 3 20 21\n3 2\n58 55 57\n2 1 1 3\n2 3 3 4\n2 1\n12 9 10\n2 1 6 10\n5 5\n8 5 6\n2 1 1 8\n2 3 4 8\n4 2 2 4\...
code_stdio_codeforces
[ { "content": "Ksyusha decided to start a game development company. To stand out among competitors and achieve success, she decided to write her own game engine. The engine must support a set initially consisting of $n$ distinct integers $a_1, a_2, \\ldots, a_n$.\n\nThe set will undergo $m$ operations sequential...
[{"input": "3\n5\n1 2 5 905 2000000\n15\n- 2\n? 2\n? 1\n- 1\n? 1\n+ 4\n+ 2\n? 2\n+ 6\n- 4\n+ 7\n? 2\n? 3\n? 4\n? 2000000\n5\n3 4 5 6 8\n9\n? 5\n- 5\n? 5\n+ 1\n? 2\n- 6\n- 8\n+ 6\n? 5\n5\n6 7 8 9 10\n10\n? 5\n- 6\n? 4\n- 10\n+ 5\n- 8\n+ 3\n+ 2\n- 3\n+ 10", "output": "2 2 1 6 3 8 8 2000001 \n9 9 9 7 \n1 1"}]
code_stdio_codeforces
[ { "content": "You are given a cyclic array $a_1, a_2, \\ldots, a_n$.\n\nYou can perform the following operation on $a$ at most $n - 1$ times:\n\n * Let $m$ be the current size of $a$, you can choose any two adjacent elements where the previous one is no greater than the latter one (In particular, $a_m$ and $a_...
[{"input": "7\n1\n1\n3\n1 2 3\n3\n1 2 2\n5\n5 4 3 2 1\n6\n1 1 2 2 3 3\n8\n8 7 6 3 8 7 6 3\n6\n1 1 4 5 1 4", "output": "0\n2\n1\n4\n4\n6\n3"}]
code_stdio_codeforces
[ { "content": "There is an integer sequence $a$ of length $n$, where each element is initially $-1$.\n\nMisuki has two typewriters where the first one writes letters from left to right, with a pointer initially pointing to $1$, and another writes letters from right to left with a pointer initially pointing to $n...
[{"input": "3\n1\n2\n3", "output": "1\n-1\n3 1 2"}]
code_stdio_codeforces
[ { "content": "This is an interactive problem.\n\nMisuki has chosen a secret tree with $n$ nodes, indexed from $1$ to $n$, and asked you to guess it by using queries of the following type:\n\n * \"? a b\" β€” Misuki will tell you which node $x$ minimizes $|d(a,x) - d(b,x)|$, where $d(x,y)$ is the distance between...
[{"input": "1\n4\n1\n1\n3", "output": "? 1 2\n\n? 1 3\n\n? 1 4\n\n! 1 2 1 3 3 4"}]
code_stdio_codeforces
[ { "content": "You are given an integer sequence $a_1, a_2, \\ldots, a_n$. Let $S$ be the set of all possible non-empty subsequences of $a$ without duplicate elements. Your goal is to find the longest sequence in $S$. If there are multiple of them, find the one that minimizes lexicographical order after multiply...
[{"input": "10\n2\n1 2\n10\n5 2 1 7 9 7 2 5 5 2\n2\n1 2\n10\n2 2 8 7 7 9 8 1 9 6\n9\n9 1 7 5 8 5 6 4 1\n3\n3 3 3\n6\n1 6 4 4 6 5\n6\n3 4 4 5 3 3\n10\n4 1 4 5 4 5 10 1 5 1\n7\n1 2 1 3 2 4 6", "output": "2\n1 2\n5\n5 1 9 7 2\n2\n1 2\n6\n2 7 9 8 1 6\n7\n9 1 7 5 8 6 4\n1\n3\n4\n1 4 6 5\n3\n4 5 3\n4\n5 4 10 1\n5\n2 1 3 4 6"...
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. The difference between the two versions is the definition of deterministic max-heap, time limit, and constraints on $n$ and $t$. You can make hacks only if both versions of the problem are solved.\n\nConsider a perfect binary tree with size $2^n - 1$, with ...
[{"input": "6\n87 63 100000037\n77 77 100000039\n100 200 998244353\n200 100 998244353\n32 59 998244853\n1 1 998244353", "output": "26831232\n94573603\n37147649\n847564946\n727060898\n1"}, {"input": "7\n1 13 998244353\n2 1 998244353\n3 2 998244853\n3 3 998244353\n3 4 100000037\n4 2 100000039\n4 3 100000037", "output": "...
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. The difference between the two versions is the definition of deterministic max-heap, time limit, and constraints on $n$ and $t$. You can make hacks only if both versions of the problem are solved.\n\nConsider a perfect binary tree with size $2^n - 1$, with ...
[{"input": "6\n2 1 998244353\n3 2 998244853\n3 3 998244353\n3 4 100000037\n4 2 100000039\n4 3 100000037", "output": "2\n12\n40\n100\n32\n224"}, {"input": "2\n87 63 100000037\n13 437 100000039", "output": "83566569\n54517140"}, {"input": "1\n100 500 100000037", "output": "66681128"}]
code_stdio_codeforces
[ { "content": "You received an $n\\times m$ grid from a mysterious source. The source also gave you a magic positive integer constant $k$.\n\nThe source told you to color the grid with some colors, satisfying the following condition:\n\n * If $(x_1,y_1)$, $(x_2,y_2)$ are two distinct cells with the same color, ...
[{"input": "6\n3 3 2\n5 1 10000\n7 3 4\n3 2 7\n8 9 6\n2 5 4", "output": "4\n5\n12\n6\n36\n8"}]
code_stdio_codeforces
[ { "content": "Alice got a permutation $a_1, a_2, \\ldots, a_n$ of $[1,2,\\ldots,n]$, and Bob got another permutation $b_1, b_2, \\ldots, b_n$ of $[1,2,\\ldots,n]$. They are going to play a game with these arrays.\n\nIn each turn, the following events happen in order:\n\n * Alice chooses either the first or the...
[{"input": "2\n2\n1 2\n1 2\n3\n1 2 3\n2 3 1", "output": "Bob\nAlice"}]
code_stdio_codeforces
[ { "content": "There are $n$ circles on a two-dimensional plane. The $i$-th circle is centered at $(x_i,y_i)$. Initially, all circles have a radius of $0$.\n\nThe circles' radii increase at a rate of $1$ unit per second.\n\nYou are currently at $(x_s,y_s)$; your goal is to reach $(x_t,y_t)$ without touching the ...
[{"input": "7\n3\n2 5\n2 14\n10 13\n4 9 9 7\n3\n10 11\n6 9\n12 12\n14 13 4 8\n1\n5 7\n12 6 11 13\n2\n1000000000 2\n2 1000000000\n1 1 2 2\n1\n999999998 1000000000\n999999999 999999999 1 1\n1\n1000000000 1\n1 1000000000 1 1\n10\n989237121 2397081\n206669655 527238537\n522705783 380636165\n532545346 320061691\n207818728 1...
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. In this version, the given tree is a perfect binary tree and the constraints on $n$ and $q$ are lower. You can make hacks only if both versions of the problem are solved.\n\nYou are given a perfect binary tree$^\\dagger$ consisting of $n$ vertices. The vert...
[{"input": "2\n3 3\n1 1\n1 2 3\n2 3\n3 2\n1 3\n7 4\n1 1 2 2 3 3\n1 2 3 4 5 6 7\n3 5\n2 5\n3 7\n4 6", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES"}]
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. In this version, you are given a generic tree and the constraints on $n$ and $q$ are higher. You can make hacks only if both versions of the problem are solved.\n\nYou are given a rooted tree consisting of $n$ vertices. The vertices are numbered from $1$ to...
[{"input": "3\n3 3\n1 1\n1 2 3\n2 3\n3 2\n1 3\n7 4\n1 1 2 2 3 3\n1 2 3 4 5 6 7\n3 5\n2 5\n3 7\n4 6\n5 4\n1 1 3 4\n2 3 4 5 1\n5 1\n4 5\n3 4\n2 3", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES"}]
code_stdio_codeforces
[ { "content": "Given an array of integers $s_1, s_2, \\ldots, s_l$, every second, cosmic rays will cause all $s_i$ such that $i=1$ or $s_i\\neq s_{i-1}$ to be deleted simultaneously, and the remaining parts will be concatenated together in order to form the new array $s_1, s_2, \\ldots, s_{l'}$.\n\nDefine the st...
[{"input": "4\n4\n2 0\n1 1\n3 0\n5 1\n6\n4 6\n1 3\n4 6\n4 0\n7 6\n6 3\n7\n9 0\n7 1\n5 0\n7 1\n9 0\n1 1\n2 0\n10\n10 7\n4 9\n2 2\n7 9\n2 8\n8 5\n11 7\n15 5\n12 7\n4 0", "output": "2 2 4 5 \n4 4 7 7 10 10 \n9 9 9 9 9 9 10 \n10 10 10 10 10 10 12 15 15 15"}]
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. In this version, $n=m$ and the time limit is lower. You can make hacks only if both versions of the problem are solved.\n\nIn the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, ei...
[{"input": "8\n3 3 2 5\n4 4 1 4\n6 6 2 2\n7 7 2 3\n9 9 9 1\n2 2 1 4\n5 5 1 4\n8 8 6 7", "output": "19\n17\n18\n33\n86\n9\n24\n86"}, {"input": "2\n1984 1984 19 84\n9982 9982 44 35", "output": "204143\n788403"}, {"input": "1\n20000000 20000000 1341 331", "output": "33439999007"}]
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.\n\nIn the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of sever...
[{"input": "8\n3 4 2 5\n4 4 1 4\n6 6 2 2\n7 9 2 3\n8 9 9 1\n2 7 1 4\n5 9 1 4\n5 6 6 7", "output": "22\n17\n18\n37\n77\n30\n41\n59"}, {"input": "2\n3082823 20000000 1341 331\n20000000 20000000 3 5", "output": "10754065643\n159999991"}, {"input": "1\n139 1293 193 412", "output": "559543"}]
code_stdio_codeforces
[ { "content": "Consider a grid graph with $n$ rows and $n$ columns. Let the cell in row $x$ and column $y$ be $(x,y)$. There exists a directed edge from $(x,y)$ to $(x+1,y)$, with non-negative integer value $d_{x,y}$, for all $1\\le x < n, 1\\le y \\le n$, and there also exists a directed edge from $(x,y)$ to $(...
[{"input": "1\n10\n16 7 3 15 9 17 1 15 9 0\n4 3 1 12 13 10 10 14 6 12\n3 1 3 9 5 16 0 12 7 12\n11 4 8 7 13 7 15 13 9 2\n2 3 9 9 4 12 17 7 10 15\n10 6 15 17 13 6 15 9 4 9\n13 3 3 14 1 2 10 10 12 16\n8 2 9 13 18 7 1 6 2 6\n15 12 2 6 0 0 13 3 7 17\n7 3 17 17 10 15 12 14 15\n4 3 3 17 3 13 11 16 6\n16 17 7 7 12 5 2 4 10\n18...
code_stdio_codeforces
[ { "content": "It's been a long summer's day, with the constant chirping of cicadas and the heat which never seemed to end. Finally, it has drawn to a close. The showdown has passed, the gates are open, and only a gentle breeze is left behind.\n\nYour predecessors had taken their final bow; it's your turn to tak...
[{"input": "2\n3 2\n10 10", "output": "6 2 \n1590121 23399118 382293180 213020758 379696760"}]
code_stdio_codeforces
[ { "content": "Turtle thinks a string $s$ is a good string if there exists a sequence of strings $t_1, t_2, \\ldots, t_k$ ($k$ is an arbitrary integer) such that:\n\n * $k \\ge 2$. * $s = t_1 + t_2 + \\ldots + t_k$, where $+$ represents the concatenation operation. For example, $\\texttt{abc} = \\texttt{a} +...
[{"input": "4\n2\naa\n3\naba\n4\nabcb\n12\nabcabcabcabc", "output": "No\nnO\nYes\nYES"}]
code_stdio_codeforces
[ { "content": "Turtle and Piggy are playing a game on a sequence. They are given a sequence $a_1, a_2, \\ldots, a_n$, and Turtle goes first. Turtle and Piggy alternate in turns (so, Turtle does the first turn, Piggy does the second, Turtle does the third, etc.).\n\nThe game goes as follows:\n\n * Let the curren...
[{"input": "5\n2\n1 2\n3\n1 1 2\n3\n1 2 3\n5\n3 1 2 2 3\n10\n10 2 5 2 7 9 2 5 10 7", "output": "2\n1\n2\n2\n7"}]
code_stdio_codeforces
[ { "content": "Turtle gives you a string $s$, consisting of lowercase Latin letters.\n\nTurtle considers a pair of integers $(i, j)$ ($1 \\le i < j \\le n$) to be a pleasant pair if and only if there exists an integer $k$ such that $i \\le k < j$ and both of the following two conditions hold:\n\n * $s_k \\ne s_...
[{"input": "5\n3\nabc\n5\nedddf\n6\nturtle\n8\npppppppp\n10\ncodeforces", "output": "acb\nddedf\nurtlet\npppppppp\ncodeforces"}]
code_stdio_codeforces
[ { "content": "The two versions are different problems. In this version of the problem, you can choose the same integer twice or more. You can make hacks only if both versions are solved.\n\nOne day, Turtle was playing with $n$ sequences. Let the length of the $i$-th sequence be $l_i$. Then the $i$-th sequence w...
[{"input": "6\n3 4\n2 0 2\n3 2 3 3\n4 7 0 1 5\n3 4\n5 0 2 0 4 11\n1 1\n5 1 3 0 3 3\n2 50\n2 1 2\n2 1 2\n1 1\n7 1 2 4 1 4 9 5\n4 114514\n2 2 2\n5 7 3 6 0 3\n3 0 1 1\n5 0 9 2 1 5\n5 1919810\n1 2\n2 324003 0\n3 1416324 2 1460728\n4 1312631 2 0 1415195\n5 1223554 192248 2 1492515 725556", "output": "16\n20\n1281\n6\n655678...
code_stdio_codeforces
[ { "content": "The two versions are different problems. In this version of the problem, you can't choose the same integer twice or more. You can make hacks only if both versions are solved.\n\nOne day, Turtle was playing with $n$ sequences. Let the length of the $i$-th sequence be $l_i$. Then the $i$-th sequence...
[{"input": "6\n3 4\n2 0 2\n3 2 3 3\n4 7 0 1 5\n3 4\n5 0 2 0 4 11\n1 1\n5 1 3 0 3 3\n2 50\n2 1 2\n2 1 2\n1 1\n7 1 2 4 1 4 9 5\n4 114514\n2 2 2\n5 7 3 6 0 3\n3 0 1 1\n5 0 9 2 1 5\n5 1919810\n1 2\n2 324003 0\n3 1416324 2 1460728\n4 1312631 2 0 1415195\n5 1223554 192248 2 1492515 725556", "output": "16\n18\n1281\n4\n655678...
code_stdio_codeforces
[ { "content": "This is an easy version of this problem. The differences between the versions are the constraint on $m$ and $r_i < l_{i + 1}$ holds for each $i$ from $1$ to $m - 1$ in the easy version. You can make hacks only if both versions of the problem are solved.\n\nTurtle gives you $m$ intervals $[l_1, r_1...
[{"input": "6\n2 0\n2 1\n1 2\n5 1\n2 4\n8 2\n1 4\n6 8\n7 2\n1 3\n4 7\n7 3\n1 2\n3 4\n5 6", "output": "1\n0\n8\n21\n15\n15"}]
code_stdio_codeforces
[ { "content": "This is a hard version of this problem. The differences between the versions are the constraint on $m$ and $r_i < l_{i + 1}$ holds for each $i$ from $1$ to $m - 1$ in the easy version. You can make hacks only if both versions of the problem are solved.\n\nTurtle gives you $m$ intervals $[l_1, r_1]...
[{"input": "8\n2 0\n2 1\n1 2\n5 1\n2 4\n8 3\n1 4\n2 5\n7 8\n7 2\n1 4\n4 7\n7 3\n1 2\n1 7\n3 7\n7 4\n1 3\n4 7\n1 3\n4 7\n7 3\n1 2\n3 4\n5 6", "output": "1\n0\n8\n18\n-1\n-1\n15\n15"}]
code_stdio_codeforces
[ { "content": "Piggy gives Turtle three sequences $a_1, a_2, \\ldots, a_n$, $b_1, b_2, \\ldots, b_n$, and $c_1, c_2, \\ldots, c_n$.\n\nTurtle will choose a subsequence of $1, 2, \\ldots, n$ of length $m$, let it be $p_1, p_2, \\ldots, p_m$. The subsequence should satisfy the following conditions:\n\n * $a_{p_1}...
[{"input": "7 3\n1 4 5 2 3 6 7\n1 2 2 1 1 3 2\n1 5 6 7 3 2 4", "output": "13"}, {"input": "5 3\n1 2 3 4 5\n1 1 2 1 2\n5 4 3 2 1", "output": "-1"}, {"input": "4 2\n2 3 4 2\n1 3 3 2\n1 4 2 3", "output": "5"}]
code_stdio_codeforces
[ { "content": "Consider a set of points on a line. The distance between two points $i$ and $j$ is $|i - j|$.\n\nThe point $i$ from the set is the closest to the point $j$ from the set, if there is no other point $k$ in the set such that the distance from $j$ to $k$ is strictly less than the distance from $j$ to ...
[{"input": "3\n2\n3 8\n2\n5 6\n6\n1 2 3 4 5 10", "output": "YES\nNO\nNO"}]
code_stdio_codeforces
[ { "content": "There are $100$ rooms arranged in a row and $99$ doors between them; the $i$-th door connects rooms $i$ and $i+1$. Each door can be either locked or unlocked. Initially, all doors are unlocked.\n\nWe say that room $x$ is reachable from room $y$ if all doors between them are unlocked.\n\nYou know t...
[{"input": "4\n1 2\n3 4\n2 5\n2 5\n3 7\n6 7\n4 5\n2 8", "output": "1\n3\n2\n3"}]
code_stdio_codeforces
[ { "content": "Alice and Bob have $n$ items they'd like to split between them, so they decided to play a game. All items have a cost, and the $i$-th item costs $a_i$. Players move in turns starting from Alice.\n\nIn each turn, the player chooses one of the remaining items and takes it. The game goes on until no ...
[{"input": "4\n2 5\n1 10\n3 0\n10 15 12\n4 6\n3 1 2 4\n2 4\n6 9", "output": "4\n13\n0\n0"}]
code_stdio_codeforces
[ { "content": "There are $n$ cities located on a straight line. The cities are numbered from $1$ to $n$.\n\nPortals are used to move between cities. There are $4$ colors of portals: blue, green, red, and yellow. Each city has portals of two different colors. You can move from city $i$ to city $j$ if they have po...
[{"input": "2\n4 5\nBR BR GY GR\n1 2\n3 1\n4 4\n1 4\n4 2\n2 1\nBG RY\n1 2", "output": "1\n4\n0\n3\n2\n-1"}]
code_stdio_codeforces
[ { "content": "Two players, Alice and Bob, are playing a game. They have $n$ piles of stones, with the $i$-th pile initially containing $a_i$ stones.\n\nOn their turn, a player can choose any pile of stones and take any positive number of stones from it, with one condition:\n\n * let the current number of stone...
[{"input": "3\n3\n3 2 9\n4\n3 3 6 1\n5\n1 2 3 4 5", "output": "Bob\nAlice\nBob"}]
code_stdio_codeforces
[ { "content": "You are given an array $a$ consisting of $n$ integers.\n\nLet the function $f(b)$ return the minimum number of operations needed to make an array $b$ a palindrome. The operations you can make are:\n\n * choose two adjacent elements $b_i$ and $b_{i+1}$, remove them, and replace them with a single ...
[{"input": "4\n3\n2 1 3\n4\n1 1 1 1\n5\n4 2 3 1 5\n4\n1 2 1 2", "output": "3\n0\n14\n5"}]
code_stdio_codeforces
[ { "content": "Let's define the operation of compressing a string $t$, consisting of at least $2$ digits from $1$ to $9$, as follows:\n\n * split it into an even number of non-empty substrings β€” let these substrings be $t_1, t_2, \\dots, t_m$ (so, $t = t_1 + t_2 + \\dots + t_m$, where $+$ is the concatenation o...
[{"input": "11 4\n49998641312", "output": "12 18 17 15 12 7 7 2"}, {"input": "10 3\n1111111111", "output": "2 2 2 2 2 2 2 2"}, {"input": "4 4\n5999", "output": "14"}]
code_stdio_codeforces
[ { "content": "Narek has to spend 2 hours with some 2-year-old kids at the kindergarten. He wants to teach them competitive programming, and their first lesson is about palindromes.\n\nNarek found out that the kids only know the vowels of the English alphabet (the letters $\\mathtt{a}$, $\\mathtt{e}$, $\\mathtt{...
[{"input": "3\n2\n3\n6", "output": "uo\niae\noeiiua"}]
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. The only differences between the two versions are the constraints on $m$ and $q$. In this version, $m=2$ and $q=1$. You can make hacks only if both versions of the problem are solved.\n\nNarek and Tsovak were busy preparing this round, so they have not mana...
[{"input": "3\n10 2 1\n1 4\n2\n8 2 1\n3 6\n1\n8 2 1\n3 6\n8", "output": "1\n2\n2"}]
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. The only differences between the two versions are the constraints on $m$ and $q$. In this version, $m, q \\le 10^5$. You can make hacks only if both versions of the problem are solved.\n\nNarek and Tsovak were busy preparing this round, so they have not man...
[{"input": "2\n8 1 1\n6\n3\n10 3 3\n1 4 8\n2 3 10", "output": "5\n1\n1\n2"}]
code_stdio_codeforces
[ { "content": "Narek is too lazy to create the third problem of this contest. His friend Artur suggests that he should use ChatGPT. ChatGPT creates $n$ problems, each consisting of $m$ letters, so Narek has $n$ strings. To make the problem harder, he combines the problems by selecting some of the $n$ strings pos...
[{"input": "4\n5 2\nnn\naa\nrr\nee\nkk\n1 5\nnarek\n1 4\nnare\n5 7\nnrrarek\nnrnekan\nuuuuuuu\nppppppp\nnkarekz", "output": "0\n5\n0\n7"}]
code_stdio_codeforces
[ { "content": "You are given two arrays $a_1, a_2, \\ldots, a_n$ and $b_1, b_2, \\ldots, b_n$.\n\nYou must perform the following operation exactly once:\n\n * choose any indices $l$ and $r$ such that $1 \\le l \\le r \\le n$; * swap $a_i$ and $b_i$ for all $i$ such that $l \\leq i \\leq r$. \n\nFind the maxi...
[{"input": "5\n8\n11 4 16 17 3 24 25 8\n8 10 4 21 17 18 25 21\n4\n6 4 24 13\n15 3 1 14\n2\n13 14\n5 8\n8\n20 17 15 11 21 10 3 7\n9 9 4 20 14 9 13 1\n2\n18 13\n15 20", "output": "2 36\n3 2\n2 3\n2 36\n6 1"}]
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. The differences between the two versions are the constraints on all the variables. You can make hacks only if both versions of the problem are solved.\n\nTsovak and Narek are playing a game. They have an array $a$ and a matrix $b$ of integers with $n$ rows ...
[{"input": "3\n2 2 3\n1 2\n1 3 5\n4 5 2\n2 2 4\n1 2\n1 1 3 2\n4 2 5 1\n2 4 2\n1 2\n3 4\n5 5\n5 5\n5 5", "output": "N\nT\nN"}]
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. The differences between the two versions are the constraints on all the variables. You can make hacks only if both versions of the problem are solved.\n\nTsovak and Narek are playing a game. They have an array $a$ and a matrix $b$ of integers with $n$ rows ...
[{"input": "3\n2 2 3\n1 2\n1 3 6\n4 6 2\n2 2 4\n1 2\n1 1 3 2\n4 2 5 1\n2 4 2\n1 2\n3 4\n5 6\n7 8\n8 8", "output": "N\nT\nN"}]
code_stdio_codeforces
[ { "content": "Iris has a tree rooted at vertex $1$. Each vertex has a value of $\\mathtt 0$ or $\\mathtt 1$.\n\nLet's consider a leaf of the tree (the vertex $1$ is never considered a leaf) and define its weight. Construct a string formed by the values of the vertices on the path starting at the root and ending...
[{"input": "6\n4\n1 2\n1 3\n4 1\n0101\n4\n1 2\n3 2\n2 4\n???0\n5\n1 2\n1 3\n2 4\n2 5\n?1?01\n6\n1 2\n2 3\n3 4\n5 3\n3 6\n?0????\n5\n1 2\n1 3\n1 4\n1 5\n11?1?\n2\n2 1\n??", "output": "2\n1\n1\n2\n1\n0"}]
code_stdio_codeforces
[ { "content": "Given a rooted tree with the root at vertex $1$. For any vertex $i$ ($1 < i \\leq n$) in the tree, there is an edge connecting vertices $i$ and $p_i$ ($1 \\leq p_i < i$), with a weight equal to $t_i$.\n\nIris does not know the values of $t_i$, but she knows that $\\displaystyle\\sum_{i=2}^n t_i = ...
[{"input": "4\n2 1000000000000\n1\n2 1000000000000\n4 9\n1 1 1\n2 2\n4 4\n3 3\n6 100\n1 2 3 2 1\n6 17\n3 32\n2 4\n4 26\n5 21\n10 511\n1 2 2 4 2 1 1 8 8\n3 2\n6 16\n10 256\n9 128\n2 1\n5 8\n8 64\n4 4\n7 32", "output": "2000000000000\n25 18 18\n449 302 247 200 200\n4585 4473 2681 1567 1454 1322 1094 1022 1022"}]
code_stdio_codeforces
[ { "content": "Let there be a set that contains distinct positive integers. To expand the set to contain as many integers as possible, Eri can choose two integers $x\\neq y$ from the set such that their average $\\frac{x+y}2$ is still a positive integer and isn't contained in the set, and add it to the set. The ...
[{"input": "6\n2\n2 2\n6\n1 3 6 10 15 21\n5\n6 30 18 36 9\n1\n1000000000\n6\n1 1 4 5 1 4\n12\n70 130 90 90 90 108 612 500 451 171 193 193", "output": "3\n18\n5\n1\n18\n53"}]
code_stdio_codeforces
[ { "content": "Iris has just learned multiplication in her Maths lessons. However, since her brain is unable to withstand too complex calculations, she could not multiply two integers with the product greater than $k$ together. Otherwise, her brain may explode!\n\nHer teacher sets a difficult task every day as h...
[{"input": "5\n3 1 1\n1 1 1\n1 3\n3 2 10\n1 10 9\n1 3\n2 3\n5 4 2\n2 2 2 2 2\n1 2\n2 4\n2 5\n1 5\n6 5 10\n3 2 5 10 10 1\n1 4\n3 6\n1 6\n2 5\n5 6\n10 10 10\n10 9 8 7 6 5 4 3 2 1\n1 10\n1 9\n1 8\n1 7\n2 10\n3 10\n4 10\n5 10\n3 9\n6 8", "output": "0 \n0 1 \n1 1 2 2 \n1 1 1 1 0 \n3 3 4 3 2 2 1 1 2 1"}]
code_stdio_codeforces
[ { "content": "Iris likes full binary trees.\n\nLet's define the depth of a rooted tree as the maximum number of vertices on the simple paths from some vertex to the root. A full binary tree of depth $d$ is a binary tree of depth $d$ with exactly $2^d - 1$ vertices.\n\nIris calls a tree a $d$-binary tree if some...
[{"input": "7\n3\n1 1\n6\n1 2 3 4 5\n7\n1 1 3 2 5 1\n10\n1 1 2 1 4 2 4 5 8\n10\n1 1 3 1 3 2 2 2 6\n20\n1 1 2 2 4 4 5 5 7 6 8 6 11 14 11 8 13 13 12\n25\n1 1 3 3 1 5 4 4 6 8 11 12 8 7 11 13 7 13 15 6 19 14 10 23", "output": "1 2 2 \n1 2 2 3 3 4 \n1 2 2 3 3 4 4 \n1 2 2 3 3 3 4 4 5 5 \n1 2 2 3 3 4 4 4 -1 -1 \n1 2 2 3 3 4 4...
code_stdio_codeforces
[ { "content": "Sadly, Dora poured the paint when painting the class mural. Dora considers the mural as the matrix $b$ of size $n \\times n$. Initially, $b_{i,j} = 0$ for all $1 \\le i, j \\le n$.\n\nDora has only two brushes which have two different colors. In one operation, she can paint the matrix with one of ...
[{"input": "7\n2 2\n1 1\n1 2\n2 1\n1 1\n3 2\n1 1\n3 3\n6 0\n5 10\n1 1\n1 2\n1 3\n2 1\n2 3\n5 1\n5 2\n5 3\n5 4\n5 5\n3 5\n1 1\n1 3\n2 2\n3 1\n3 3\n4 3\n1 1\n2 3\n2 4", "output": "1\n499122178\n665496236\n120\n79859554\n776412275\n1"}]
code_stdio_codeforces
[ { "content": "Dora has a set $s$ containing integers. In the beginning, she will put all integers in $[l, r]$ into the set $s$. That is, an integer $x$ is initially contained in the set if and only if $l \\leq x \\leq r$. Then she allows you to perform the following operations:\n\n * Select three distinct inte...
[{"input": "8\n1 3\n3 7\n10 21\n2 8\n51 60\n2 15\n10 26\n1 1000", "output": "1\n1\n3\n1\n2\n3\n4\n250"}]
code_stdio_codeforces
[ { "content": "After receiving yet another integer array $a_1, a_2, \\ldots, a_n$ at her birthday party, Index decides to perform some operations on it.\n\nFormally, there are $m$ operations that she is going to perform in order. Each of them belongs to one of the two types:\n\n * $\\texttt{+ l r}$. Given two i...
[{"input": "5\n5 5\n1 2 3 2 1\n+ 1 3\n- 2 3\n+ 1 2\n+ 2 4\n- 6 8\n5 5\n1 3 3 4 5\n+ 1 4\n+ 2 3\n- 4 5\n- 3 3\n- 2 6\n5 5\n1 1 1 1 1\n+ 2 3\n- 4 5\n+ 1 6\n- 2 5\n+ 1 8\n1 1\n1\n- 1 1\n1 1\n1000000000\n+ 1000000000 1000000000", "output": "4 4 4 5 5\n5 5 4 4 3\n1 1 2 1 2\n0\n1000000001"}]
code_stdio_codeforces
[ { "content": "Dora has just learned the programming language C++!\n\nHowever, she has completely misunderstood the meaning of C++. She considers it as two kinds of adding operations on the array $c$ with $n$ elements. Dora has two integers $a$ and $b$. In one operation, she can choose one of the following thing...
[{"input": "10\n4 5 5\n1 3 4 4\n4 2 3\n1 3 4 6\n4 7 7\n1 1 2 6\n3 15 9\n1 9 5\n3 18 12\n1 4 5\n7 27 36\n33 13 23 12 35 24 41\n10 6 9\n15 5 6 9 8 2 12 15 3 8\n2 1 1000000000\n1 1000000000\n6 336718728 709848696\n552806726 474775724 15129785 371139304 178408298 13106071\n6 335734893 671469786\n138885253 70095920 45687677...
code_stdio_codeforces
[ { "content": "Iris has a tree rooted at vertex $1$. Each vertex has a value of $\\mathtt 0$ or $\\mathtt 1$.\n\nLet's consider a leaf of the tree (the vertex $1$ is never considered a leaf) and define its weight. Construct a string formed by the values of the vertices on the path starting at the root and ending...
[{"input": "6\n4\n1 2\n1 3\n4 1\n0101\n4\n1 2\n3 2\n2 4\n???0\n5\n1 2\n1 3\n2 4\n2 5\n?1?01\n6\n1 2\n2 3\n3 4\n5 3\n3 6\n?0????\n5\n1 2\n1 3\n1 4\n1 5\n11?1?\n2\n2 1\n??", "output": "2\n1\n1\n2\n1\n0"}]
code_stdio_codeforces
[ { "content": "Given a rooted tree with the root at vertex $1$. For any vertex $i$ ($1 < i \\leq n$) in the tree, there is an edge connecting vertices $i$ and $p_i$ ($1 \\leq p_i < i$), with a weight equal to $t_i$.\n\nIris does not know the values of $t_i$, but she knows that $\\displaystyle\\sum_{i=2}^n t_i = ...
[{"input": "4\n2 1000000000000\n1\n2 1000000000000\n4 9\n1 1 1\n2 2\n4 4\n3 3\n6 100\n1 2 3 2 1\n6 17\n3 32\n2 4\n4 26\n5 21\n10 511\n1 2 2 4 2 1 1 8 8\n3 2\n6 16\n10 256\n9 128\n2 1\n5 8\n8 64\n4 4\n7 32", "output": "2000000000000\n25 18 18\n449 302 247 200 200\n4585 4473 2681 1567 1454 1322 1094 1022 1022"}]
code_stdio_codeforces
[ { "content": "Let there be a set that contains distinct positive integers. To expand the set to contain as many integers as possible, Eri can choose two integers $x\\neq y$ from the set such that their average $\\frac{x+y}2$ is still a positive integer and isn't contained in the set, and add it to the set. The ...
[{"input": "6\n2\n2 2\n6\n1 3 6 10 15 21\n5\n6 30 18 36 9\n1\n1000000000\n6\n1 1 4 5 1 4\n12\n70 130 90 90 90 108 612 500 451 171 193 193", "output": "3\n18\n5\n1\n18\n53"}]
code_stdio_codeforces
[ { "content": "Today, Sakurako has a math exam. The teacher gave the array, consisting of $a$ ones and $b$ twos.\n\nIn an array, Sakurako must place either a '+' or a '-' in front of each element so that the sum of all elements in the array equals $0$.\n\nSakurako is not sure if it is possible to solve this prob...
[{"input": "5\n0 1\n0 3\n2 0\n2 3\n3 1", "output": "NO\nNO\nYES\nYES\nNO"}]
code_stdio_codeforces
[ { "content": "A beautiful binary matrix is a matrix that has ones on its edges and zeros inside.\n\n![](CDN_BASE_URL/5df31946486165887b31c82158ed558d) Examples of four beautiful binary matrices.\n\nToday, Sakurako was playing with a beautiful binary matrix of size $r \\times c$ and created a binary string $s$ b...
[{"input": "5\n2\n11\n4\n1111\n9\n111101111\n9\n111111111\n12\n111110011111", "output": "No\nYes\nYes\nNo\nNo"}]
code_stdio_codeforces
[ { "content": "Today, Sakurako was studying arrays. An array $a$ of length $n$ is considered good if and only if:\n\n * the array $a$ is increasing, meaning $a_{i - 1} < a_i$ for all $2 \\le i \\le n$; * the differences between adjacent elements are increasing, meaning $a_i - a_{i-1} < a_{i+1} - a_i$ for all...
[{"input": "5\n1 2\n1 5\n2 2\n10 20\n1 1000000000", "output": "2\n3\n1\n5\n44721"}]
code_stdio_codeforces
[ { "content": "For a certain permutation $p$$^{\\text{βˆ—}}$ Sakurako calls an integer $j$ reachable from an integer $i$ if it is possible to make $i$ equal to $j$ by assigning $i=p_i$ a certain number of times.\n\nIf $p=[3,5,6,1,2,4]$, then, for example, $4$ is reachable from $1$, because: $i=1$ $\\rightarrow$ $i...
[{"input": "5\n1\n1\n0\n5\n1 2 4 5 3\n10101\n5\n5 4 1 3 2\n10011\n6\n3 5 6 1 2 4\n010000\n6\n1 2 3 4 5 6\n100110", "output": "1 \n0 1 1 1 1 \n2 2 2 2 2 \n4 1 4 4 1 4 \n0 1 1 0 0 1"}]
code_stdio_codeforces
[ { "content": "Sakurako really loves alternating strings. She calls a string $s$ of lowercase Latin letters an alternating string if characters in the even positions are the same, if characters in the odd positions are the same, and the length of the string is even.\n\nFor example, the strings 'abab' and 'gg' ar...
[{"input": "10\n1\na\n2\nca\n3\naab\n5\nababa\n6\nacdada\n9\nejibmyyju\n6\nbbccbc\n6\nabacba\n5\nbcbca\n5\ndcbdb", "output": "1\n0\n1\n1\n2\n6\n2\n3\n1\n1"}]
code_stdio_codeforces
[ { "content": "Sakurako has a box with $n$ balls. Each ball has it's value. She wants to bet with her friend that if the friend randomly picks two balls from the box (it could be two distinct balls, but they may have the same value), the product of their values will be the same as the number that Sakurako guesse...
[{"input": "3\n3\n3 2 3\n4\n2 2 2 4\n5\n1 2 3 4 5", "output": "7\n6\n500000012"}]
code_stdio_codeforces
[ { "content": "Sakurako has prepared a task for you:\n\nShe gives you an array of $n$ integers and allows you to choose $i$ and $j$ such that $i \\neq j$ and $a_i \\ge a_j$, and then assign $a_i = a_i - a_j$ or $a_i = a_i + a_j$. You can perform this operation any number of times for any $i$ and $j$, as long as ...
[{"input": "6\n1 3\n3\n2 10\n1 1\n3 1\n1 2 3\n3 2\n1 2 4\n4 5\n2 2 2 16\n4 5\n2 2 2 3", "output": "2\n11\n3\n4\n8\n8"}]
code_stdio_codeforces
[ { "content": "Sakurako will soon take a test. The test can be described as an array of integers $n$ and a task on it:\n\nGiven an integer $x$, Sakurako can perform the following operation any number of times:\n\n * Choose an integer $i$ ($1\\le i\\le n$) such that $a_i\\ge x$; * Change the value of $a_i$ to...
[{"input": "2\n5 5\n1 2 3 4 5\n1\n2\n3\n4\n5\n6 3\n1 2 6 4 1 3\n2\n1\n5", "output": "0 1 1 1 2 \n1 0 2"}]
code_stdio_codeforces
[ { "content": "Today, a club fair was held at \"NSPhM\". In order to advertise his pastry club, Zhan decided to demonstrate the power of his blender.\n\nTo demonstrate the power of his blender, Zhan has $n$ fruits.\n\nThe blender can mix up to $x$ fruits per second.\n\nIn each second, Zhan can put up to $y$ frui...
[{"input": "5\n5\n3 4\n3\n1 2\n6\n4 3\n100\n4 3\n9\n3 3", "output": "2\n3\n2\n34\n3"}]
code_stdio_codeforces
[ { "content": "Eralim, being the mafia boss, manages a group of $n$ fighters. Fighter $i$ has a rating of $a_i$.\n\nEralim arranges a tournament of $n - 1$ battles, in each of which two not yet eliminated fighters $i$ and $j$ ($1 \\le i < j \\le n$) are chosen, and as a result of the battle, fighter $i$ is elimi...
[{"input": "5\n2\n2 1\n3\n2 2 8\n4\n1 2 4 3\n5\n1 2 3 4 5\n5\n3 2 4 5 4", "output": "-1\n8\n2\n7\n8"}]
code_stdio_codeforces
[ { "content": "Dimash learned that Mansur wrote something very unpleasant about him to a friend, so he decided to find out his password at all costs and discover what exactly he wrote.\n\nBelieving in the strength of his password, Mansur stated that his password β€” is a binary string of length $n$. He is also rea...
[{"input": "4\n3\n\n0\n\n0\n\n1\n\n4\n\n4\n\n2", "output": "? 00\n\n? 000\n\n? 010\n\n! 010\n\n! 1100\n\n! 0110\n\n! 10"}]
code_stdio_codeforces
[ { "content": "Zhan, tired after the contest, gave the only task that he did not solve during the contest to his friend, Sungat. However, he could not solve it either, so we ask you to try to solve this problem.\n\nYou are given an array $a_1, a_2, \\ldots, a_n$ of length $n$. We can perform any number (possibly...
[{"input": "5\n1\n1\n3\n1 2 3\n4\n4 1 2 3\n4\n4 2 3 1\n5\n5 14 4 10 2", "output": "0\n2\n1\n1\n3"}]
code_stdio_codeforces
[ { "content": "Since Mansur is tired of making legends, there will be no legends for this task.\n\nYou are given an array of positive integer numbers $a_1, a_2, \\ldots, a_n$. The elements of the array can be rearranged in any order. You need to find the smallest possible value of the expression $$\\gcd(a_1) + \...
[{"input": "5\n3\n4 2 2\n2\n6 3\n3\n10 15 6\n5\n6 42 12 52 20\n4\n42 154 231 66", "output": "6\n6\n9\n14\n51"}]
code_stdio_codeforces
[ { "content": "This is the easy version of the problem. In this version, $\\mathbf{u = v}$. You can make hacks only if both versions of the problem are solved.\n\nAlice and Bob are playing a fun game on a tree. This game is played on a tree with $n$ vertices, numbered from $1$ to $n$. Recall that a tree with $n$...
[{"input": "3\n3\n1 2\n2 3\n2 2\n3\n1 2\n2 3\n3 3\n6\n1 2\n1 3\n2 4\n2 5\n1 6\n4 4", "output": "Bob\nAlice\nAlice"}]
code_stdio_codeforces
[ { "content": "This is the hard version of the problem. In this version, it is not guaranteed that $u = v$. You can make hacks only if both versions of the problem are solved.\n\nAlice and Bob are playing a fun game on a tree. This game is played on a tree with $n$ vertices, numbered from $1$ to $n$. Recall that...
[{"input": "3\n3\n1 2\n2 3\n2 3\n6\n1 2\n1 3\n2 4\n2 5\n1 6\n4 5\n4\n1 2\n1 3\n2 4\n2 4", "output": "Bob\nAlice\nAlice\nBob\nAlice\nBob\nAlice"}]
code_stdio_codeforces
[ { "content": "There is a little bit of the outlaw in everyone, and a little bit of the hero too.\n\nThe heroic outlaw Robin Hood is famous for taking from the rich and giving to the poor.\n\nRobin encounters $n$ people starting from the $1$-st and ending with the $n$-th. The $i$-th person has $a_i$ gold. If $a_...
[{"input": "4\n2 2\n2 0\n3 2\n3 0 0\n6 2\n0 3 0 0 0 0\n2 5\n5 4", "output": "1\n2\n3\n0"}]
code_stdio_codeforces
[ { "content": "In Sherwood, the trees are our shelter, and we are all children of the forest.\n\nThe Major Oak in Sherwood is known for its majestic foliage, which provided shelter to Robin Hood and his band of merry men and women.\n\nThe Major Oak grows $i^i$ new leaves in the $i$-th year. It starts with $1$ le...
[{"input": "5\n1 1\n2 1\n2 2\n3 2\n4 4", "output": "NO\nYES\nNO\nNO\nYES"}]
code_stdio_codeforces
[ { "content": "In Sherwood, we judge a man not by his wealth, but by his merit.\n\nLook around, the rich are getting richer, and the poor are getting poorer. We need to take from the rich and give to the poor. We need Robin Hood!\n\nThere are $n$ people living in the town. Just now, the wealth of the $i$-th pers...
[{"input": "6\n1\n2\n2\n2 19\n3\n1 3 20\n4\n1 2 3 4\n5\n1 2 3 4 5\n6\n1 2 1 1 1 25", "output": "-1\n-1\n0\n15\n16\n0"}]
code_stdio_codeforces
[ { "content": "Impress thy brother, yet fret not thy mother.\n\nRobin's brother and mother are visiting, and Robin gets to choose the start day for each visitor.\n\nAll days are numbered from $1$ to $n$. Visitors stay for $d$ continuous days, all of those $d$ days must be between day $1$ and $n$ inclusive.\n\nRo...
[{"input": "6\n2 1 1\n1 2\n4 1 2\n1 2\n2 4\n7 2 3\n1 2\n1 3\n6 7\n5 1 2\n1 2\n3 5\n9 2 1\n2 8\n9 2 4\n7 9\n4 8\n1 3\n2 3", "output": "1 1\n2 1\n1 4\n1 1\n1 1\n3 4"}]
code_stdio_codeforces
[ { "content": "In the humble act of meeting, joy doth unfold like a flower in bloom.\n\nAbsence makes the heart grow fonder. Marian sold her last ware at the Market at the same time Robin finished training at the Major Oak. They couldn't wait to meet, so they both start without delay.\n\nThe travel network is re...
[{"input": "6\n2 1 1\n1\n1 2 10\n3 1 2\n2 3\n1 2 10\n3 3 1\n2\n1 2 4\n1 3 10\n2 3 6\n4 3 2\n2 3\n1 2 10\n2 3 18\n3 4 16\n3 2 1\n2\n1 2 4\n1 3 16\n7 7 1\n3\n1 5 2\n2 6 12\n1 2 12\n6 4 8\n7 3 4\n6 3 4\n7 6 4", "output": "5\n-1\n6\n19\n14\n12"}]
code_stdio_codeforces
[ { "content": "\"Why, master,\" quoth Little John, taking the bags and weighing them in his hand, \"here is the chink of gold.\"\n\nThe folk hero Robin Hood has been troubling Sheriff of Nottingham greatly. Sheriff knows that Robin Hood is about to attack his camps and he wants to be prepared.\n\nSheriff of Nott...
[{"input": "5\n3 1\n2 3 1\n1 2\n2 3\n3 1\n3 6 3\n1 2\n2 3\n3 1\n-2 -3 -1\n1 2\n2 3\n6 1\n5 -4 3 6 7 3\n4 1\n5 1\n3 5\n3 6\n1 2\n8 1\n3 5 2 7 8 5 -3 -4\n7 3\n1 8\n4 3\n3 5\n7 6\n8 7\n2 1", "output": "3\n8\n0\n17\n26"}]
code_stdio_codeforces
[ { "content": "What is done is done, and the spoilt milk cannot be helped.\n\nLittle John is as little as night is day β€” he was known to be a giant, at possibly $2.1$ metres tall. It has everything to do with his love for milk.\n\nHis dairy diary has $n$ entries, showing that he acquired $a_i$ pints of fresh mil...
[{"input": "6\n1 1 3\n1 5\n2 3 3\n1 5\n2 7\n4 5 2\n1 9\n2 6\n4 9\n5 6\n5 2 4\n4 7\n5 3\n7 1\n11 2\n12 1\n4 1 3\n5 10\n9 4\n14 8\n15 3\n5 5 5\n8 9\n10 7\n16 10\n21 5\n28 9", "output": "3\n3\n4\n5\n10\n6"}]
code_stdio_codeforces
[ { "content": "At such times archery was always the main sport of the day, for the Nottinghamshire yeomen were the best hand at the longbow in all merry England, but this year the Sheriff hesitated...\n\nSheriff of Nottingham has organized a tournament in archery. It's the final round and Robin Hood is playing a...
[{"input": "2\n3 3\n1 2 2\n1 2\n1 3\n2 3\n5 3\n2 1 2 1 1\n1 2\n1 3\n4 5", "output": "NO\nNO\nYES\nNO\nNO\nYES"}]
code_stdio_codeforces
[ { "content": "[DJ Genki vs Gram - Einherjar Joker](https://soundcloud.com/leon- hwang-368077289/einherjar-joker-dj-genki-vs-gram)\n\nβ €\n\nYou 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$ writte...
[{"input": "9\n3 1\n3 2 2\n5 4\n2 6 1 2 4\n2 100\n1410065408 10000000000\n10 8\n7 4 6 6 9 3 10 2 8 7\n2 12\n2 2\n2 70\n0 1\n1 0\n1\n3 0\n2 1 2\n3 1\n0 3 3", "output": "2\n3\n1\n7\n2\n2\n1\n1\n2"}]
code_stdio_codeforces
[ { "content": "[Djjaner - Speedbreaker](https://soundcloud.com/luciano- ferrari-151560131/speedbreaker)\n\nβ €\n\nThere are $n$ cities in a row, numbered $1, 2, \\ldots, n$ left to right.\n\n * At time $1$, you conquer exactly one city, called the starting city. * At time $2, 3, \\ldots, n$, you can choose a c...
[{"input": "3\n6\n6 3 3 3 5 5\n6\n5 6 4 1 4 5\n9\n8 6 4 2 1 3 5 7 9", "output": "3\n0\n1"}]
code_stdio_codeforces
[ { "content": "[t+pazolite, ginkiha, Hommarju - Paved Garden](https://soundcloud.com/fractalex-gd/ginkiha-paved-garden-little)\n\nβ €\n\nYou are given a tree with $n$ nodes, rooted at node $1$. In this problem, a leaf is a non-root node with degree $1$.\n\nIn one operation, you can remove a leaf and the edge adjac...
[{"input": "3\n7\n1 2\n1 3\n2 4\n2 5\n4 6\n4 7\n7\n1 2\n1 3\n1 4\n2 5\n3 6\n5 7\n15\n12 9\n1 6\n6 14\n9 11\n8 7\n3 5\n13 5\n6 10\n13 15\n13 6\n14 12\n7 2\n8 1\n1 4", "output": "2\n2\n5"}]
code_stdio_codeforces
[ { "content": "[EnV - The Dusty Dragon Tavern](https://soundcloud.com/envyofficial/env-the- dusty-dragon-tavern)\n\nβ €\n\nYou are given an array $a_1, a_2, \\ldots, a_n$ of positive integers.\n\nYou can color some elements of the array red, but there cannot be two adjacent red elements (i.e., for $1 \\leq i \\leq...
[{"input": "4\n3\n5 4 5\n3\n4 5 4\n10\n3 3 3 3 4 1 2 3 5 4\n10\n17 89 92 42 29 41 92 14 70 45", "output": "12\n11\n12\n186"}]
code_stdio_codeforces
[ { "content": "[Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)\n\nβ €\n\nThis is the easy version of the problem. In this version, the constraints on $n$ and the time limit are lower. You can make hacks only if both versions of the problem are solved.\n\nA set of (closed) segments is complex if ...
[{"input": "3\n3\n1 2 3\n5 4 6\n5\n1 2 3 6 8\n5 4 7 9 10\n5\n3 1 4 1 5\n7 2 6 5 10", "output": "3\n4\n4"}]
code_stdio_codeforces
[ { "content": "[Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)\n\nβ €\n\nThis is the hard version of the problem. In this version, the constraints on $n$ and the time limit are higher. You can make hacks only if both versions of the problem are solved.\n\nA set of (closed) segments is complex if...
[{"input": "3\n3\n1 2 3\n5 4 6\n5\n1 2 3 6 8\n5 4 7 9 10\n5\n3 1 4 1 5\n7 2 6 5 10", "output": "3\n4\n4"}]
code_stdio_codeforces
[ { "content": "[NightHawk22 - Isolation](https://soundcloud.com/vepium/nighthawk22-isolation- official-limbo-remix)\n\nβ €\n\nThis is the easy version of the problem. In the three versions, the constraints on $n$ and the time limit are different. You can make hacks only if all the versions of the problem are solve...
[{"input": "11\n1 998244353\n2 998244353\n3 998244353\n4 998244353\n5 998244353\n6 998244353\n7 998244353\n8 998244353\n9 998244353\n10 102275857\n10 999662017", "output": "0 1 \n1 2 1 \n14 7 4 2 \n183 34 19 16 4 \n2624 209 112 120 48 12 \n42605 1546 793 992 468 216 36 \n785910 13327 6556 9190 4672 2880 864 144 \n16382...
code_stdio_codeforces
[ { "content": "[NightHawk22 - Isolation](https://soundcloud.com/vepium/nighthawk22-isolation- official-limbo-remix)\n\nβ €\n\nThis is the medium version of the problem. In the three versions, the constraints on $n$ and the time limit are different. You can make hacks only if all the versions of the problem are sol...
[{"input": "11\n1 998244353\n2 998244353\n3 998244353\n4 998244353\n5 998244353\n6 998244353\n7 998244353\n8 998244353\n9 998244353\n10 102275857\n10 999662017", "output": "0 1 \n1 2 1 \n14 7 4 2 \n183 34 19 16 4 \n2624 209 112 120 48 12 \n42605 1546 793 992 468 216 36 \n785910 13327 6556 9190 4672 2880 864 144 \n16382...
code_stdio_codeforces
[ { "content": "[NightHawk22 - Isolation](https://soundcloud.com/vepium/nighthawk22-isolation- official-limbo-remix)\n\nβ €\n\nThis is the hard version of the problem. In the three versions, the constraints on $n$ and the time limit are different. You can make hacks only if all the versions of the problem are solve...
[{"input": "11\n1 998244353\n2 998244353\n3 998244353\n4 998244353\n5 998244353\n6 998244353\n7 998244353\n8 998244353\n9 998244353\n10 102275857\n10 999662017", "output": "0 1 \n1 2 1 \n14 7 4 2 \n183 34 19 16 4 \n2624 209 112 120 48 12 \n42605 1546 793 992 468 216 36 \n785910 13327 6556 9190 4672 2880 864 144 \n16382...
code_stdio_codeforces
[ { "content": "[EnV - Dynasty](https://soundcloud.com/envyofficial/env-dynasty)\n\nβ €\n\nYou are given an array $a_1, a_2, \\ldots, a_n$ of positive integers.\n\nYou can color some elements of the array red, but there cannot be two adjacent red elements (i.e., for $1 \\leq i \\leq n-1$, at least one of $a_i$ and ...
[{"input": "4\n3\n5 4 5\n3\n4 5 4\n10\n3 3 3 3 4 1 2 3 4 5\n9\n17 89 92 42 29 92 14 70 45", "output": "7\n6\n10\n97"}]
code_stdio_codeforces
[ { "content": "[Shirobon - FOX](https://soundcloud.com/shirobon/fox?in=mart_207/sets/fav)\n\nβ €\n\nYou are given $n$ points on the $x$ axis, at increasing positive integer coordinates $x_1 < x_2 < \\ldots < x_n$.\n\nFor each pair $(i, j)$ with $1 \\leq i < j \\leq n$, you draw the segment $[x_i, x_j]$. The segmen...
[{"input": "3\n2 2\n101 200\n2 1\n6 15\n1 2 3 5 6 7\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n5 8\n254618033 265675151 461318786 557391198 848083778\n6 9 15 10 6 9 4 4294967300", "output": "0 100 \n0 0 0 0 2 0 0 0 3 0 2 0 0 0 0 \n291716045 0 0 0 291716045 0 301749698 0"}]
code_stdio_codeforces
[ { "content": "[DJ Genki vs Gram - Einherjar Joker](https://soundcloud.com/leon- hwang-368077289/einherjar-joker-dj-genki-vs-gram)\n\nβ €\n\nYou 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$ writte...
[{"input": "9\n3 1\n3 2 2\n5 4\n2 6 1 2 4\n2 100\n1410065408 10000000000\n10 8\n7 4 6 6 9 3 10 2 8 7\n2 12\n2 2\n2 70\n0 1\n1 0\n1\n3 0\n2 1 2\n3 1\n0 3 3", "output": "2\n3\n1\n7\n2\n2\n1\n1\n2"}]
code_stdio_codeforces