id
stringlengths
19
19
problem
stringlengths
445
3.52k
tests
stringlengths
41
746
cf-927ef5ee37abb90f
[Djjaner - Speedbreaker](https://soundcloud.com/luciano- ferrari-151560131/speedbreaker) ⠀ There are $n$ cities in a row, numbered $1, 2, \ldots, n$ left to right. * At time $1$, you conquer exactly one city, called the starting city. * At time $2, 3, \ldots, n$, you can choose a city adjacent to the ones conq...
[{"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"}]
cf-7353ae3e3d5f3d0b
[t+pazolite, ginkiha, Hommarju - Paved Garden](https://soundcloud.com/fractalex-gd/ginkiha-paved-garden-little) ⠀ You are given a tree with $n$ nodes, rooted at node $1$. In this problem, a leaf is a non-root node with degree $1$. In one operation, you can remove a leaf and the edge adjacent to it (possibly, new le...
[{"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"}]
cf-ea1f1541b5c8454f
[EnV - The Dusty Dragon Tavern](https://soundcloud.com/envyofficial/env-the- dusty-dragon-tavern) ⠀ You are given an array $a_1, a_2, \ldots, a_n$ of positive integers. You 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$ a...
[{"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"}]
cf-15e45b1911b3e4e7
You are given two integers $n$ and $k$. In one operation, you can subtract any power of $k$ from $n$. Formally, in one operation, you can replace $n$ by $(n-k^x)$ for any non-negative integer $x$. Find the minimum number of operations required to make $n$ equal to $0$. Input Format: Each test contains multiple test...
[{"input": "6\n5 2\n3 5\n16 4\n100 3\n6492 10\n10 1", "output": "2\n3\n1\n4\n21\n10"}]
cf-6fef6d1056feef04
Imagine you have $n$ light bulbs numbered $1, 2, \ldots, n$. Initially, all bulbs are on. To flip the state of a bulb means to turn it off if it used to be on, and to turn it on otherwise. Next, you do the following: * for each $i = 1, 2, \ldots, n$, flip the state of all bulbs $j$ such that $j$ is divisible by $i...
[{"input": "3\n1\n3\n8", "output": "2\n5\n11"}]
cf-94b6b03e91be2643
You are given three non-negative integers $b$, $c$, and $d$. Please find a non-negative integer $a \in [0, 2^{61}]$ such that $(a\, |\, b)-(a\, \&\, c)=d$, where $|$ and $\&$ denote the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR) and the [bitwise AND operation](https://en.wikipedia.org/...
[{"input": "3\n2 2 2\n4 2 6\n10 2 14", "output": "0\n-1\n12"}]
cf-6ab0ad36a045292b
One fine evening, Alice sat down to play the classic game "Connect the Dots", but with a twist. To play the game, Alice draws a straight line and marks $n$ points on it, indexed from $1$ to $n$. Initially, there are no arcs between the points, so they are all disjoint. After that, Alice performs $m$ operations of the...
[{"input": "3\n10 2\n1 2 4\n2 2 4\n100 1\n19 2 4\n100 3\n1 2 5\n7 2 6\n17 2 31", "output": "2\n96\n61"}]
cf-76d6ed3b05e44cc5
You are given an array of $n$ integers $a_1,a_2,\ldots,a_n$. You are also given an array $p_1, p_2, \ldots, p_n$. Let $S$ denote the random multiset (i. e., it may contain equal elements) constructed as follows: * Initially, $S$ is empty. * For each $i$ from $1$ to $n$, insert $a_i$ into $S$ with probability $\...
[{"input": "4\n2\n1 2\n5000 5000\n2\n1 1\n1000 2000\n6\n343 624 675 451 902 820\n6536 5326 7648 2165 9430 5428\n1\n1\n10000", "output": "500000007\n820000006\n280120536\n1"}]
cf-ccc86e312b9a72b6
Let $n$ and $d$ be positive integers. We build the the divisor tree $T_{n,d}$ as follows: * The root of the tree is a node marked with number $n$. This is the $0$-th layer of the tree. * For each $i$ from $0$ to $d - 1$, for each vertex of the $i$-th layer, do the following. If the current vertex is marked with ...
[{"input": "3\n6 1 1\n1 3 3\n10 1 2", "output": "14\n1\n53"}]
cf-e46f5d10f4f6b9e2
Pak Chanek has an array $a$ of $n$ positive integers. Since he is currently learning how to calculate the floored average of two numbers, he wants to practice it on his array $a$. While the array $a$ has at least two elements, Pak Chanek will perform the following three-step operation: 1. Pick two different indice...
[{"input": "3\n5\n1 7 8 4 5\n3\n2 6 5\n5\n5 5 5 5 5", "output": "6\n4\n5"}]
cf-e80ee4f1bd66e00c
You are given an array $a$ of $n$ positive integers and an integer $x$. You can do the following two-step operation any (possibly zero) number of times: 1. Choose an index $i$ ($1 \leq i \leq n$). 2. Increase $a_i$ by $x$, in other words $a_i := a_i + x$. Find the maximum value of the $\operatorname{MEX}$ of $...
[{"input": "3\n6 3\n0 3 2 1 5 2\n6 2\n1 3 4 1 0 2\n4 5\n2 5 10 3", "output": "4\n6\n0"}]
cf-3ff70330e9bd5851
This is the easy version of the problem. In the two versions, the constraints on $q$ and the time limit are different. In this version, $q=0$. You can make hacks only if all the versions of the problem are solved. A team consisting of $n$ members, numbered from $1$ to $n$, is set to present a slide show at a large me...
[{"input": "3\n4 2 0\n1 2 3 4\n1 1\n3 6 0\n1 2 3\n1 1 2 3 3 2\n4 6 0\n3 1 4 2\n3 1 1 2 3 4", "output": "YA\nYA\nTIDAK"}]
cf-66b44d18bf3f1229
This is the hard version of the problem. In the two versions, the constraints on $q$ and the time limit are different. In this version, $0 \leq q \leq 2 \cdot 10^5$. You can make hacks only if all the versions of the problem are solved. A team consisting of $n$ members, numbered from $1$ to $n$, is set to present a s...
[{"input": "3\n4 2 2\n1 2 3 4\n1 1\n1 2\n1 1\n3 6 2\n1 2 3\n1 1 2 3 3 2\n3 3\n2 2\n4 6 2\n3 1 4 2\n3 1 1 2 3 4\n3 4\n4 2", "output": "YA\nTIDAK\nYA\nYA\nTIDAK\nYA\nTIDAK\nYA\nYA"}]
cf-436f82981620c033
Pak Chanek has a friend who runs a drink stall in a canteen. His friend will sell drinks for $n$ days, numbered from day $1$ to day $n$. There are also $m$ types of drinks, numbered from $1$ to $m$. The profit gained from selling a drink on a particular day can vary. On day $i$, the projected profit from selling drin...
[{"input": "1\n3 6\n79 20 49 5 -1000 500\n-105 9 109 24 -98 -499\n14 47 12 39 23 50", "output": "475"}]
cf-89eea5f86fb6ebb4
This is the easy version of the problem. In the three versions, the constraints on $n$ and $m$ are different. You can make hacks only if all the versions of the problem are solved. Pak Chanek is setting up internet connections for the village of Khuntien. The village can be represented as a connected simple graph wit...
[{"input": "2\n9 8 5\n2 5 6 8 9\n1 2 1\n1 3 2\n3 4 10\n4 5 3\n4 6 5\n1 7 10\n7 8 4\n7 9 2\n3 3 2\n3 1\n1 2 1\n2 3 3\n1 3 2", "output": "34 19 9 4 0 0 0 0 0\n2 0 0"}]
cf-706e3e333b48079e
This is the hard version of the problem. In the three versions, the constraints on $n$ and $m$ are different. You can make hacks only if all the versions of the problem are solved. Pak Chanek is setting up internet connections for the village of Khuntien. The village can be represented as a connected simple graph wit...
[{"input": "2\n9 8 5\n2 5 6 8 9\n1 2 1\n1 3 2\n3 4 10\n4 5 3\n4 6 5\n1 7 10\n7 8 4\n7 9 2\n3 3 2\n3 1\n1 2 1\n2 3 3\n1 3 2", "output": "34 19 9 4 0 0 0 0 0\n2 0 0"}]
cf-d54a1d5f15855120
This is the extreme version of the problem. In the three versions, the constraints on $n$ and $m$ are different. You can make hacks only if all the versions of the problem are solved. Pak Chanek is setting up internet connections for the village of Khuntien. The village can be represented as a connected simple graph ...
[{"input": "2\n9 8 5\n2 5 6 8 9\n1 2 1\n1 3 2\n3 4 10\n4 5 3\n4 6 5\n1 7 10\n7 8 4\n7 9 2\n3 3 2\n3 1\n1 2 1\n2 3 3\n1 3 2", "output": "34 19 9 4 0 0 0 0 0\n2 0 0"}]
cf-843c7943207d0df5
Ya vamos llegando a Péeeenjamoo ♫♫♫ There are $n$ families travelling to Pénjamo to witness Mexico's largest- ever "walking a chicken on a leash" marathon. The $i$-th family has $a_i$ family members. All families will travel using a single bus consisting of $r$ rows with $2$ seats each. A person is considered happy ...
[{"input": "4\n3 3\n2 3 1\n3 3\n2 2 2\n4 5\n1 1 2 2\n4 5\n3 1 1 3", "output": "4\n6\n6\n6"}]
cf-5fbb4804b2415192
Karel is a salesman in a car dealership. The dealership has $n$ different models of cars. There are $a_i$ cars of the $i$-th model. Karel is an excellent salesperson and can convince customers to buy up to $x$ cars (of Karel's choice), as long as the cars are from different models. Determine the minimum number of...
[{"input": "4\n3 2\n3 1 2\n3 3\n2 1 3\n5 3\n2 2 1 9 2\n7 4\n2 5 3 3 5 2 5", "output": "3\n3\n9\n7"}]
cf-71cf2d6283f94dfd
We all steal a little bit. But I have only one hand, while my adversaries have two. Álvaro Obregón Álvaro and José are the only candidates running for the presidency of Tepito, a rectangular grid of $2$ rows and $n$ columns, where each cell represents a house. It is guaranteed that $n$ is a multiple of $3$. Under t...
[{"input": "4\n3\nAAA\nAJJ\n6\nJAJAJJ\nJJAJAJ\n6\nAJJJAJ\nAJJAAA\n9\nAJJJJAJAJ\nJAAJJJJJA", "output": "2\n2\n3\n2"}]
cf-67aa378e15b57d64
This is the easy version of the problem. In this version, you can ask at most $n+69$ questions. You can make hacks only if both versions of the problem are solved. This is an interactive problem. It is a tradition in Mexico's national IOI trainings to play the game "Asesino", which is similar to "Among Us" or "Mafia...
[{"input": "2\n7\n\n1\n\n0\n\n0\n\n1\n\n1\n\n0\n\n0\n\n1\n\n4\n\n0\n\n1\n\n1\n\n1", "output": "? 1 3\n\n? 7 6\n\n? 2 5\n\n? 6 2\n\n? 4 5\n\n? 4 6\n\n? 1 4\n\n? 2 4\n\n! 4\n\n? 1 2\n\n? 2 3\n\n? 3 4\n\n? 4 1\n\n! 3"}]
cf-43fb67e72853e2e5
This is the hard version of the problem. In this version, you must use the minimum number of queries possible. You can make hacks only if both versions of the problem are solved. This is an interactive problem. It is a tradition in Mexico's national IOI trainings to play the game "Asesino", which is similar to "Amon...
[{"input": "2\n7\n\n1\n\n0\n\n0\n\n1\n\n1\n\n0\n\n0\n\n4\n\n0\n\n1\n\n1\n\n1", "output": "? 1 3\n\n? 7 6\n\n? 2 5\n\n? 6 2\n\n? 4 5\n\n? 4 6\n\n? 1 4\n\n! 4\n\n? 1 2\n\n? 2 3\n\n? 3 4\n\n? 4 1\n\n! 3"}]
cf-3ce83ec5e0603ae5
This is the easy version of the problem. In this version, it is guaranteed that $q = 0$. You can make hacks only if both versions of the problem are solved. An integer grid $A$ with $p$ rows and $q$ columns is called beautiful if: * All elements of the grid are integers between $0$ and $2^{30}-1$, and * For any...
[{"input": "2\n3 3 8 0\n2 1 6\n3 2 12\n1 2 6\n2 2 0\n1 3 10\n1 1 0\n2 3 12\n3 1 10\n2 5 2 0\n1 1 10\n1 2 30", "output": "1\n489373567"}]
cf-19a38180e0e87858
This is the hard version of the problem. In this version, it is guaranteed that $q \leq 10^5$. You can make hacks only if both versions of the problem are solved. An integer grid $A$ with $p$ rows and $q$ columns is called beautiful if: * All elements of the grid are integers between $0$ and $2^{30}-1$, and * F...
[{"input": "3\n3 3 8 1\n2 1 6\n3 2 12\n1 2 6\n2 2 0\n1 3 10\n1 1 0\n2 3 12\n3 1 10\n3 3 1\n2 5 2 0\n1 1 10\n1 2 30\n2 5 0 2\n1 1 10\n1 2 30", "output": "1\n0\n489373567\n651321892\n769740174\n489373567"}]
cf-df0dc437c0fbbdeb
You are given $n$ arrays $a_1$, $\ldots$, $a_n$. The length of each array is two. Thus, $a_i = [a_{i, 1}, a_{i, 2}]$. You need to concatenate the arrays into a single array of length $2n$ such that the number of inversions$^{\dagger}$ in the resulting array is minimized. Note that you do not need to count the actual n...
[{"input": "4\n2\n1 4\n2 3\n3\n3 2\n4 3\n2 1\n5\n5 10\n2 3\n9 6\n4 1\n8 7\n1\n10 20", "output": "2 3 1 4\n2 1 3 2 4 3\n4 1 2 3 5 10 8 7 9 6\n10 20"}]
cf-73e865e4391e99f0
It is already the year $3024$, ideas for problems have long run out, and the olympiad now takes place in a modified individual format. The olympiad consists of $n$ problems, numbered from $1$ to $n$. The $i$-th problem has its own score $a_i$ and a certain parameter $b_i$ ($1 \le b_i \le n$). Initially, the testing s...
[{"input": "4\n2\n15 16\n2 1\n5\n10 10 100 100 1000\n3 4 1 1 1\n3\n100 49 50\n3 2 2\n4\n100 200 300 1000\n2 3 4 1", "output": "16\n200\n100\n1000"}]
cf-7e8845d65ed86a24
You are given two strongly connected$^{\dagger}$ directed graphs, each with exactly $n$ vertices, but possibly different numbers of edges. Upon closer inspection, you noticed an important feature — the length of any cycle in these graphs is divisible by $k$. Each of the $2n$ vertices belongs to exactly one of two typ...
[{"input": "3\n4 2\n1 0 0 1\n4\n1 2\n2 3\n3 4\n4 1\n1 0 0 1\n4\n1 3\n3 2\n2 4\n4 1\n3 3\n0 0 0\n3\n1 2\n2 3\n3 1\n1 1 0\n3\n1 2\n2 3\n3 1\n4 2\n1 1 1 1\n4\n1 2\n2 3\n3 4\n4 1\n0 0 0 0\n6\n1 2\n2 1\n1 3\n3 1\n1 4\n4 1", "output": "YES\nNO\nYES"}]
cf-d512d677498083dd
Recently, you received a rare ticket to the only casino in the world where you can actually earn something, and you want to take full advantage of this opportunity. The conditions in this casino are as follows: * There are a total of $n$ games in the casino. * You can play each game at most once. * Each game...
[{"input": "3\n80 80\n70 100\n50 200", "output": "112.00000000"}, {"input": "2\n100 1\n100 1", "output": "2.00000000"}, {"input": "4\n1 100\n2 1000\n2 100\n3 1", "output": "20.00000000"}, {"input": "5\n34 804\n78 209\n99 191\n61 439\n90 79", "output": "395.20423800"}]
cf-a4dc6a5905b6f0a7
In the heart of an ancient kingdom grows the legendary Tree of Life — the only one of its kind and the source of magical power for the entire world. The tree consists of $n$ nodes. Each node of this tree is a magical source, connected to other such sources through magical channels (edges). In total, there are $n-1$ ch...
[{"input": "5\n4\n1 2\n2 3\n3 4\n2\n1 2\n4\n1 2\n1 3\n1 4\n8\n3 7\n2 4\n1 2\n2 5\n3 6\n1 3\n3 8\n6\n2 3\n1 2\n3 6\n1 5\n1 4", "output": "1\n0\n3\n7\n3"}]
cf-9f6d0188dbcd667c
In a desert city with a hilly landscape, the city hall decided to level the road surface by purchasing a dump truck. The road is divided into $n$ sections, numbered from $1$ to $n$ from left to right. The height of the surface in the $i$-th section is equal to $a_i$. If the height of the $i$-th section is greater than...
[{"input": "5\n1 1\n-179\n1 1\n5 3\n-2 2 -1 3 -1\n2 4\n1 5\n1 3\n7 1\n1 1 1 -4 1 1 1\n1 7\n7 2\n2 -2 2 -2 1 2 -1\n1 7\n2 7\n4 4\n1000000000 1000000000 999999999 -1000000000\n2 4\n3 4\n2 3\n1 3", "output": "-1\n2\n5\n-1\n8\n6\n6\n2\n-1\n1\n2"}]
cf-ad3dd8ea8e119aa8
Alice has $a$ coins. She can open a bank deposit called "Profitable", but the minimum amount required to open this deposit is $b$ coins. There is also a deposit called "Unprofitable", which can be opened with any amount of coins. Alice noticed that if she opens the "Unprofitable" deposit with $x$ coins, the minimum a...
[{"input": "5\n10 5\n7 9\n5 100\n1 1\n1 2", "output": "10\n5\n0\n1\n0"}]
cf-281938abb20c7d61
There is a vending machine that sells lemonade. The machine has a total of $n$ slots. You know that initially, the $i$-th slot contains $a_i$ cans of lemonade. There are also $n$ buttons on the machine, each button corresponds to a slot, with exactly one button corresponding to each slot. Unfortunately, the labels on ...
[{"input": "5\n2 1\n1 1\n2 2\n1 2\n3 4\n2 1 3\n10 50\n1 1 3 8 8 9 12 13 27 27\n2 1000000000\n1000000000 500000000", "output": "1\n2\n5\n53\n1000000000"}]
cf-d667316e2d79898f
You are given $n$ arrays $a_1$, $\ldots$, $a_n$. The length of each array is two. Thus, $a_i = [a_{i, 1}, a_{i, 2}]$. You need to concatenate the arrays into a single array of length $2n$ such that the number of inversions$^{\dagger}$ in the resulting array is minimized. Note that you do not need to count the actual n...
[{"input": "4\n2\n1 4\n2 3\n3\n3 2\n4 3\n2 1\n5\n5 10\n2 3\n9 6\n4 1\n8 7\n1\n10 20", "output": "2 3 1 4\n2 1 3 2 4 3\n4 1 2 3 5 10 8 7 9 6\n10 20"}]
cf-f95b769319395f3e
It is already the year $3024$, ideas for problems have long run out, and the olympiad now takes place in a modified individual format. The olympiad consists of $n$ problems, numbered from $1$ to $n$. The $i$-th problem has its own score $a_i$ and a certain parameter $b_i$ ($1 \le b_i \le n$). Initially, the testing s...
[{"input": "4\n2\n15 16\n2 1\n5\n10 10 100 100 1000\n3 4 1 1 1\n3\n100 49 50\n3 2 2\n4\n100 200 300 1000\n2 3 4 1", "output": "16\n200\n100\n1000"}]
cf-07291d50bf76371a
You are given two strongly connected$^{\dagger}$ directed graphs, each with exactly $n$ vertices, but possibly different numbers of edges. Upon closer inspection, you noticed an important feature — the length of any cycle in these graphs is divisible by $k$. Each of the $2n$ vertices belongs to exactly one of two typ...
[{"input": "3\n4 2\n1 0 0 1\n4\n1 2\n2 3\n3 4\n4 1\n1 0 0 1\n4\n1 3\n3 2\n2 4\n4 1\n3 3\n0 0 0\n3\n1 2\n2 3\n3 1\n1 1 0\n3\n1 2\n2 3\n3 1\n4 2\n1 1 1 1\n4\n1 2\n2 3\n3 4\n4 1\n0 0 0 0\n6\n1 2\n2 1\n1 3\n3 1\n1 4\n4 1", "output": "YES\nNO\nYES"}]
cf-aefaed1c66d42f67
Recently, you received a rare ticket to the only casino in the world where you can actually earn something, and you want to take full advantage of this opportunity. The conditions in this casino are as follows: * There are a total of $n$ games in the casino. * You can play each game at most once. * Each game...
[{"input": "3\n80 80\n70 100\n50 200", "output": "112.00000000"}, {"input": "2\n100 1\n100 1", "output": "2.00000000"}, {"input": "4\n1 100\n2 1000\n2 100\n3 1", "output": "20.00000000"}, {"input": "5\n34 804\n78 209\n99 191\n61 439\n90 79", "output": "395.20423800"}]
cf-2efb650f65bf54c1
There are two screens which can display sequences of uppercase Latin letters. Initially, both screens display nothing. In one second, you can do one of the following two actions: * choose a screen and an uppercase Latin letter, and append that letter to the end of the sequence displayed on that screen; * choose...
[{"input": "3\nGARAGE\nGARAGEFORSALE\nABCDE\nAABCD\nTRAINING\nDRAINING", "output": "14\n10\n16"}]
cf-eb056907043004f5
Recently, akshiM met a task that needed binomial coefficients to solve. He wrote a code he usually does that looked like this: for (int n = 0; n < N; n++) { // loop over n from 0 to N-1 (inclusive) C[n][0] = 1; C[n][n] = 1; for (int k = 1; k < n; k++) // loo...
[{"input": "7\n2 5 5 100000 100000 100000 100000\n1 2 3 1 33333 66666 99999", "output": "2\n4\n8\n2\n326186014\n984426998\n303861760"}]
cf-69860e572ae76e65
There's a new game Monocarp wants to play. The game uses a deck of $n$ cards, where the $i$-th card has exactly one integer $a_i$ written on it. At the beginning of the game, on the first turn, Monocarp can take any card from the deck. During each subsequent turn, Monocarp can take exactly one card that has either th...
[{"input": "4\n10 2\n5 2 4 3 4 3 4 5 3 2\n5 1\n10 11 10 11 10\n9 3\n4 5 4 4 6 5 4 4 6\n3 2\n1 3 1", "output": "6\n3\n9\n2"}]
cf-f167a4c521d758ef
Imagine a game where you play as a character that has two attributes: "Strength" and "Intelligence", that are at zero level initially. During the game, you'll acquire $m$ attribute points that allow you to increase your attribute levels — one point will increase one of the attributes by one level. But sometimes, you'...
[{"input": "10 5\n0 1 0 2 0 -3 0 -4 0 -5", "output": "3"}, {"input": "3 1\n1 -1 0", "output": "0"}, {"input": "9 3\n0 0 1 0 2 -3 -2 -2 1", "output": "4"}]
cf-04ab4db50fee9878
In the most popular card game in Berland, a deck of $n \times m$ cards is used. Each card has two parameters: suit and rank. Suits in the game are numbered from $1$ to $n$, and ranks are numbered from $1$ to $m$. There is exactly one card in the deck for each combination of suit and rank. A card with suit $a$ and ran...
[{"input": "1 4", "output": "2"}, {"input": "2 2", "output": "2"}, {"input": "3 6", "output": "1690"}, {"input": "5 4", "output": "568"}, {"input": "500 500", "output": "84693741"}]
cf-a20b0f12afdb98d1
You are given an array $a$, consisting of $n$ integers (numbered from $1$ to $n$). Initially, they are all zeroes. You have to process $q$ queries. The $i$-th query consists of two different integers $x_i$ and $y_i$. During the $i$-th query, you have to choose an integer $p$ (which is either $x_i$ or $y_i$) and an in...
[{"input": "3 4\n1 2\n3 2\n3 1\n1 2", "output": "y+\nx+\nx-\ny-"}, {"input": "4 4\n1 2\n2 3\n3 4\n3 2", "output": "y+\ny+\nx-\ny-"}, {"input": "4 2\n2 1\n4 3", "output": "y+\nx+"}]
cf-096ac99dd6272319
Monocarp is gathering an army to fight a dragon in a videogame. The army consists of two parts: the heroes and the defensive artifacts. Each hero has one parameter — his health. Each defensive artifact also has one parameter — its durability. Before the battle begins, Monocarp distributes artifacts to the heroes so ...
[{"input": "3\n2 5\n1 4\n1 10", "output": "0\n8\n19"}, {"input": "10\n1 9\n1 6\n2 4\n1 8\n1 3\n2 10\n1 3\n1 6\n1 10\n2 6", "output": "9\n15\n19\n27\n30\n39\n42\n48\n59\n65"}]
cf-76e6da6b6bf3d9eb
You are given a coordinate plane and three integers $X$, $Y$, and $K$. Find two line segments $AB$ and $CD$ such that 1. the coordinates of points $A$, $B$, $C$, and $D$ are integers; 2. $0 \le A_x, B_x, C_x, D_x \le X$ and $0 \le A_y, B_y, C_y, D_y \le Y$; 3. the length of segment $AB$ is at least $K$; 4....
[{"input": "4\n1 1 1\n3 4 1\n4 3 3\n3 4 4", "output": "0 0 1 0\n0 0 0 1\n2 4 2 2\n0 1 1 1\n0 0 1 3\n1 2 4 1\n0 1 3 4\n0 3 3 0"}]
cf-7ef1f384d514abab
You are given a strip divided into cells, numbered from left to right from $0$ to $10^{18}$. Initially, all cells are white. You can perform the following operation: choose two white cells $i$ and $j$, such that $i \ne j$ and $|i - j| \le k$, and paint them black. A list $a$ is given. All cells from this list must b...
[{"input": "4\n2\n1 2\n1\n7\n3\n2 4 9\n5\n1 5 8 10 13", "output": "1\n1\n2\n3"}]
cf-16bd8fc76704aa81
There is a shop that sells action figures near Monocarp's house. A new set of action figures will be released shortly; this set contains $n$ figures, the $i$-th figure costs $i$ coins and is available for purchase from day $i$ to day $n$. For each of the $n$ days, Monocarp knows whether he can visit the shop. Every ...
[{"input": "4\n1\n1\n6\n101101\n7\n1110001\n5\n11111", "output": "1\n8\n18\n6"}]
cf-dc923558da033b1c
You are given a sequence of integers $[a_1, a_2, \dots, a_n]$. Let $s(l,r)$ be the sum of elements from $a_l$ to $a_r$ (i. e. $s(l,r) = \sum\limits_{i=l}^{r} a_i$). Let's construct another sequence $b$ of size $\frac{n(n+1)}{2}$ as follows: $b = [s(1,1), s(1,2), \dots, s(1,n), s(2,2), s(2,3), \dots, s(2,n), s(3,3), \...
[{"input": "4\n1 2 5 10\n15\n1 1\n1 2\n1 3\n1 4\n1 5\n1 10\n5 10\n6 10\n2 8\n3 4\n3 10\n3 8\n5 6\n5 5\n1 8", "output": "1\n4\n12\n30\n32\n86\n56\n54\n60\n26\n82\n57\n9\n2\n61"}]
cf-7c13dfa0ef352a16
Given an integer array $a$ of size $n$. Let's define the value of the array as its size minus the number of set bits in the bitwise OR of all elements of the array. For example, for the array $[1, 0, 1, 2]$, the bitwise OR is $3$ (which contains $2$ set bits), and the value of the array is $4-2=2$. Your task is to ...
[{"input": "4\n3\n0 0 0\n4\n1 0 1 2\n1\n5\n8\n7 1 48 14 13 8 7 6", "output": "3\n2\n0\n3"}]
cf-c98fee3bc1536f4e
In the Bermart chain of stores, a variety of ice cream is sold. Each type of ice cream has two parameters: price and tastiness. Initially, there is one store numbered $1$, which sells nothing. You have to process $q$ queries of the following types: * $1~x$ — a new store opens, that sells the same types of ice crea...
[{"input": "12\n2 1 5 7\n2 1 3 4\n4 1 4\n4 1 8\n4 1 2\n1 1\n2 2 4 10\n4 1 9\n4 2 9\n3 1\n4 1 9\n4 2 9", "output": "4\n11\n0\n11\n17\n4\n17"}]
cf-d65b9cb01a214927
You are coloring an infinite square grid, in which all cells are initially white. To do this, you are given $n$ stamps. Each stamp is a rectangle of width $w_i$ and height $h_i$. You will use each stamp exactly once to color a rectangle of the same size as the stamp on the grid in black. You cannot rotate the stamp, ...
[{"input": "5\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n3\n2 2\n1 1\n1 2\n1\n3 2\n3\n100 100\n100 100\n100 100\n4\n1 4\n2 3\n1 5\n3 2", "output": "20\n8\n10\n400\n16"}]
cf-9de31a6b4b6c49e1
Stalin Sort is a humorous sorting algorithm designed to eliminate elements which are out of place instead of bothering to sort them properly, lending itself to an $\mathcal{O}(n)$ time complexity. It goes as follows: starting from the second element in the array, if it is strictly smaller than the previous element (i...
[{"input": "6\n7\n3 6 4 9 2 5 2\n5\n5 4 4 2 2\n8\n2 2 4 4 6 6 10 10\n1\n1000\n9\n6 8 9 10 12 9 7 5 4\n7\n300000000 600000000 400000000 900000000 200000000 400000000 200000000", "output": "2\n0\n6\n0\n4\n2"}]
cf-4af7a96237e05e2b
You're given an array $a$ initially containing $n$ integers. In one operation, you must do the following: * Choose a position $i$ such that $1 < i \le |a|$ and $a_i = |a| + 1 - i$, where $|a|$ is the current size of the array. * Append $i - 1$ zeros onto the end of $a$. After performing this operation as many ...
[{"input": "4\n5\n2 4 6 2 5\n5\n5 4 4 5 1\n4\n6 8 2 3\n1\n1", "output": "10\n11\n10\n1"}]
cf-a4f2e07ca1096000
This is the easy version of this problem. The only difference is that you only need to output the minimum total cost of operations in this version. You must solve both versions to be able to hack. You're given an array $a$ of length $n$, and an array $b$ of length $m$ ($b_i > b_{i+1}$ for all $1 \le i < m$). Initiall...
[{"input": "5\n4 2\n9 3 4 3\n11 7\n1 2\n20\n19 18\n10 2\n2 5 2 1 10 3 2 9 9 6\n17 9\n10 11\n2 2 2 2 2 2 2 2 2 2\n20 18 16 14 12 10 8 6 4 2 1\n1 6\n10\n32 16 8 4 2 1", "output": "1\n-1\n2\n10\n4"}]
cf-13dfdd9a1d14bc2f
This is the hard version of this problem. The only difference is that you need to also output the number of optimal sequences in this version. You must solve both versions to be able to hack. You're given an array $a$ of length $n$, and an array $b$ of length $m$ ($b_i > b_{i+1}$ for all $1 \le i < m$). Initially, th...
[{"input": "5\n4 2\n9 3 4 3\n11 7\n1 2\n20\n19 18\n10 2\n2 5 2 1 10 3 2 9 9 6\n17 9\n10 11\n2 2 2 2 2 2 2 2 2 2\n20 18 16 14 12 10 8 6 4 2 1\n1 6\n10\n32 16 8 4 2 1", "output": "1 3\n-1\n2 11\n10 42\n4 1"}]
cf-25378698aa2a5f89
This is the easy version of this problem. The only difference is that you need to output the winner of the game in this version, and the number of stones in each pile are fixed. You must solve both versions to be able to hack. Alice and Bob are playing a familiar game where they take turns removing stones from $n$ pi...
[{"input": "7\n2\n1 6\n10 7\n3\n10 8 15\n25 4 14\n4\n8 32 65 64\n7 45 126 94\n3\n20 40 1\n23 55 1\n5\n12345 9876 86419 8641 1\n6789 54321 7532 97532 1\n2\n20 64\n44 61\n3\n57 109 55\n69 90 85", "output": "Bob\nBob\nBob\nBob\nBob\nAlice\nAlice"}]
cf-536c180a69717c33
This is the hard version of this problem. The only difference is that you need to output the number of choices of games where Bob wins in this version, where the number of stones in each pile are not fixed. You must solve both versions to be able to hack. Alice and Bob are playing a familiar game where they take turn...
[{"input": "7\n3\n1 2 3\n3 2 2\n1\n13\n45\n5\n5 4 7 8 6\n4 4 5 5 5\n4\n6 4 8 8\n12 13 14 12\n3\n92856133 46637598 12345678\n29384774 73775896 87654321\n2\n65 12\n110 31\n4\n677810235 275091182 428565855 720629731\n74522416 889934149 3394714 230851724", "output": "4\n4\n0\n6552\n722019507\n541\n665443265"}]
cf-045a216da08d07f3
Alice is trying to meet up with the Red Queen in the countryside! Right now, Alice is at position $(0, 0)$, and the Red Queen is at position $(a, b)$. Alice can only move in the four cardinal directions (north, east, south, west). More formally, if Alice is at the point $(x, y)$, she will do one of the following: ...
[{"input": "6\n2 2 2\nNE\n3 2 2\nNNE\n6 2 1\nNNEESW\n6 10 10\nNNEESW\n3 4 2\nNEE\n4 5 5\nNEWS", "output": "YES\nNO\nYES\nYES\nYES\nNO"}]
cf-f64a6806bfedd6a7
Alice mixed up the words transmutation and permutation! She has an array $a$ specified via three integers $n$, $b$, $c$: the array $a$ has length $n$ and is given via $a_i = b\cdot (i - 1) + c$ for $1\le i\le n$. For example, if $n=3$, $b=2$, and $c=1$, then $a=[2 \cdot 0 + 1, 2 \cdot 1 + 1, 2 \cdot 2 + 1] = [1, 3, 5]...
[{"input": "7\n10 1 0\n1 2 3\n100 2 1\n3 0 1\n3 0 0\n1000000000000000000 0 0\n1000000000000000000 1000000000000000000 1000000000000000000", "output": "0\n1\n50\n2\n-1\n-1\n1000000000000000000"}]
cf-8b1215cf044e376e
Alice is at the Mad Hatter's tea party! There is a long sheet cake made up of $n$ sections with tastiness values $a_1, a_2, \ldots, a_n$. There are $m$ creatures at the tea party, excluding Alice. Alice will cut the cake into $m + 1$ pieces. Formally, she will partition the cake into $m + 1$ subarrays, where each sub...
[{"input": "7\n6 2 1\n1 1 10 1 1 10\n6 2 2\n1 1 10 1 1 10\n6 2 3\n1 1 10 1 1 10\n6 2 10\n1 1 10 1 1 10\n6 2 11\n1 1 10 1 1 10\n6 2 12\n1 1 10 1 1 10\n6 2 12\n1 1 1 1 10 10", "output": "22\n12\n2\n2\n2\n0\n-1"}]
cf-8ab490bf85751d6a
Alice is playing cards with the Queen of Hearts, King of Hearts, and Jack of Hearts. There are $n$ different types of cards in their card game. Alice currently has a card of type $1$ and needs a card of type $n$ to escape Wonderland. The other players have one of each kind of card. In this card game, Alice can trade ...
[{"input": "2\n3\n1 3 2\n2 1 3\n1 2 3\n4\n2 3 1 4\n1 2 3 4\n1 4 2 3", "output": "YES\n2\nk 2\nq 3\nNO"}]
cf-f0a263534d579fe0
Alice is at the bottom of the rabbit hole! The rabbit hole can be modeled as a tree$^{\text{∗}}$ which has an exit at vertex $1$, and Alice starts at some vertex $v$. She wants to get out of the hole, but unfortunately, the Queen of Hearts has ordered her execution. Each minute, a fair coin is flipped. If it lands he...
[{"input": "2\n5\n1 2\n1 3\n2 4\n3 5\n9\n1 2\n2 3\n4 5\n5 6\n7 8\n8 9\n2 4\n5 7", "output": "1 499122177 499122177 0 0 \n1 499122177 0 332748118 166374059 0 443664157 720954255 0"}]
cf-f533054f83e34460
Note that the memory limit is unusual. The Cheshire Cat has a riddle for Alice: given $n$ integers $a_1, a_2, \ldots, a_n$ and a target $m$, is there a way to insert $+$ and $\times$ into the circles of the expression $$a_1 \circ a_2 \circ \cdots \circ a_n = m$$ to make it true? We follow the usual order of operation...
[{"input": "6\n5 4\n2 1 1 1 2\n5 5\n2 1 1 1 2\n5 6\n2 1 1 1 2\n5 7\n2 1 1 1 2\n5 8\n2 1 1 1 2\n5 6\n2 0 2 2 3", "output": "YES\nYES\nYES\nYES\nNO\nYES"}]
cf-1668e0321983a6ae
You are given a positive integer $k$ and a set $S$ of all integers from $l$ to $r$ (inclusive). You can perform the following two-step operation any number of times (possibly zero): 1. First, choose a number $x$ from the set $S$, such that there are at least $k$ multiples of $x$ in $S$ (including $x$ itself); 2...
[{"input": "8\n3 9 2\n4 9 1\n7 9 2\n2 10 2\n154 220 2\n147 294 2\n998 24435 3\n1 1000000000 2", "output": "2\n6\n0\n4\n0\n1\n7148\n500000000"}]
cf-8720db27d7cd975a
You have a binary string$^{\text{∗}}$ $s$ of length $n$, and Iris gives you another binary string $r$ of length $n-1$. Iris is going to play a game with you. During the game, you will perform $n-1$ operations on $s$. In the $i$-th operation ($1 \le i \le n-1$): * First, you choose an index $k$ such that $1\le k\le...
[{"input": "6\n2\n11\n0\n2\n01\n1\n4\n1101\n001\n6\n111110\n10000\n6\n010010\n11010\n8\n10010010\n0010010", "output": "NO\nYES\nYES\nNO\nYES\nNO"}]
cf-292ab5a75e2207ef
Hello, Codeforces Forcescode! Kevin used to be a participant of Codeforces. Recently, the KDOI Team has developed a new Online Judge called Forcescode. Kevin has participated in $n$ contests on Forcescode. In the $i$-th contest, his performance rating is $a_i$. Now he has hacked into the backend of Forcescode and...
[{"input": "5\n6\n1 2 3 4 5 6\n7\n1 2 1 1 1 3 4\n1\n1\n9\n9 9 8 2 4 4 3 5 3\n10\n1 2 3 4 1 3 2 1 1 10", "output": "5\n4\n0\n4\n5"}]
cf-61b2729dbba80f00
You are given an undirected graph with $n$ vertices and $m$ edges. You can perform the following operation at most $2\cdot \max(n,m)$ times: * Choose three distinct vertices $a$, $b$, and $c$, then for each of the edges $(a,b)$, $(b,c)$, and $(c,a)$, do the following: * If the edge does not exist, add it. On ...
[{"input": "5\n3 0\n3 1\n1 2\n3 2\n1 2\n2 3\n3 3\n1 2\n2 3\n3 1\n6 6\n1 2\n1 6\n4 5\n3 4\n4 6\n3 6", "output": "0\n1\n1 2 3\n0\n1\n1 2 3\n3\n1 3 6\n2 4 5\n3 4 6"}]
cf-d5deaceac78834a9
For two integers $x$ and $y$ ($x,y\ge 2$), we will say that $x$ is a generator of $y$ if and only if $x$ can be transformed to $y$ by performing the following operation some number of times (possibly zero): * Choose a divisor $d$ ($d\ge 2$) of $x$, then increase $x$ by $d$. For example, * $3$ is a generator of...
[{"input": "4\n3\n8 9 10\n4\n2 3 4 5\n2\n147 154\n5\n3 6 8 25 100000", "output": "2\n-1\n7\n3"}]
cf-03d5b1dd2e52eb5b
You are given a cycle with $n$ vertices numbered from $0$ to $n-1$. For each $0\le i\le n-1$, there is an undirected edge between vertex $i$ and vertex $((i+1)\bmod n)$ with the color $c_i$ ($c_i=\texttt{R}$ or $\texttt{B}$). Determine whether the following condition holds for every pair of vertices $(i,j)$ ($0\le i<...
[{"input": "7\n5\nRRRRR\n5\nRRRRB\n5\nRBBRB\n6\nRBRBRB\n6\nRRBBRB\n5\nRBRBR\n12\nRRBRRBRRBRRB", "output": "YES\nYES\nYES\nNO\nNO\nYES\nNO"}]
cf-8f8bd06f486e8d1c
There is an array $a$ consisting of $n$ integers. Initially, all elements of $a$ are equal to $0$. Kevin can perform several operations on the array. Each operation is one of the following two types: * Prefix addition — Kevin first selects an index $x$ ($1\le x\le n$), and then for each $1\le j\le x$, increases $a...
[{"input": "5\n3 3 2\n1 2 4\nL 3\nR 3\nL 1\n3 3 2\n5 1 4\nL 3\nR 3\nL 1\n5 4 5\n1 1 1 1 1\nL 3\nR 2\nL 5\nL 4\n10 12 9\n10 9 8 7 6 5 4 3 2 1\nL 2\nL 4\nR 4\nR 4\nL 6\nR 8\nL 3\nL 2\nR 1\nR 10\nL 8\nL 1\n1 1 4\n1000000000\nL 1", "output": "2 6\n1 9\n0 1 3 5 5\n0 0 0 6 25 32 35 44 51\n1000000000 1000000000 1000000000 100...
cf-20b318abdf7ae6d9
Given is an undirected graph with $n$ vertices and $m$ edges. Each edge connects two vertices $(u, v)$ and has a probability of $\frac{p}{q}$ of appearing each day. Initially, vertex $1$ has a message. At the end of the day, a vertex has a message if and only if itself or at least one of the vertices adjacent to it h...
[{"input": "2 1\n1 2 1 10", "output": "10"}, {"input": "3 3\n1 2 1 2\n1 3 1 2\n2 3 1 2", "output": "887328316"}, {"input": "1 0", "output": "0"}, {"input": "5 8\n1 2 1 11\n1 3 2 11\n1 4 3 11\n1 5 4 11\n2 4 5 11\n2 5 6 11\n3 4 7 11\n4 5 8 11", "output": "469993557"}, {"input": "21 22\n1 2 3 4\n2 3 4 5\n3 4 5 6\n5 6 7 8\...
cf-32977146b46780d6
Kevin has recently learned the definition of variance. For an array $a$ of length $n$, the variance of $a$ is defined as follows: * Let $x=\dfrac{1}{n}\displaystyle\sum_{i=1}^n a_i$, i.e., $x$ is the mean of the array $a$; * Then, the variance of $a$ is $$ V(a)=\frac{1}{n}\sum_{i=1}^n(a_i-x)^2. $$ Now, Kevin g...
[{"input": "9\n3 2 1\n1 2 2\n3 2 2\n1 2 2\n10 2 1\n10 1 1 1 1 10 1 1 1 1\n6 8 2\n1 1 4 5 1 3\n8 8 7\n20 43 24 2 4 3 20 43\n8 8 3\n20 43 24 2 4 3 20 43\n10 12 1\n5 3 3 5 4 1 8 1 1 1\n13 10 100000\n1 2 3 4 5 6 7 8 9 10 11 5 4\n10 5 10000\n2308 9982 4435 3310 100000 9 7 8100 1919 100000", "output": "0 0\n2 2\n1161 1024\n5...
cf-c7d80a8a8df85cd6
While exploring the jungle, you have bumped into a rare orangutan with a bow tie! You shake hands with the orangutan and offer him some food and water. In return... The orangutan has gifted you an array $a$ of length $n$. Using $a$, you will construct two arrays $b$ and $c$, both containing $n$ elements, in the follo...
[{"input": "3\n1\n69\n3\n7 6 5\n5\n1 1 1 2 2", "output": "0\n4\n4"}]
cf-e51817fc02f9f753
For an arbitrary binary string $t$$^{\text{∗}}$, let $f(t)$ be the number of non-empty subsequences$^{\text{†}}$ of $t$ that contain only $\mathtt{0}$, and let $g(t)$ be the number of non-empty subsequences of $t$ that contain at least one $\mathtt{1}$. Note that for $f(t)$ and for $g(t)$, each subsequence is counted...
[{"input": "3\n1\n2\n3", "output": "0\n01\n010"}]
cf-45e99b03d772395c
Alice and Bob are playing a game. There is a list of $n$ booleans, each of which is either true or false, given as a binary string $^{\text{∗}}$ of length $n$ (where $\texttt{1}$ represents true, and $\texttt{0}$ represents false). Initially, there are no operators between the booleans. Alice and Bob will take altern...
[{"input": "5\n2\n11\n3\n010\n12\n101111111100\n10\n0111111011\n8\n01000010", "output": "YES\nNO\nYES\nYES\nNO"}]
cf-246910d3d3940676
QED is given a permutation$^{\text{∗}}$ $p$ of length $n$. He also has a string $s$ of length $n$ containing only characters $\texttt{L}$ and $\texttt{R}$. QED only likes permutations that are sorted in non-decreasing order. To sort $p$, he can select any of the following operations and perform them any number of time...
[{"input": "3\n5 3\n1 4 2 5 3\nRLRLL\n2\n4\n3\n8 5\n1 5 2 4 8 3 6 7\nRRLLRRRL\n4\n3\n5\n3\n4\n6 2\n1 2 3 4 5 6\nRLRLRL\n4\n5", "output": "YES\nYES\nNO\nNO\nYES\nNO\nNO\nNO\nYES\nYES"}]
cf-deb17639a6b2b215
Suppose we partition the elements of an array $b$ into any number $k$ of non-empty multisets $S_1, S_2, \ldots, S_k$, where $k$ is an arbitrary positive integer. Define the score of $b$ as the maximum value of $\operatorname{MEX}(S_1)$$^{\text{∗}}$$ + \operatorname{MEX}(S_2) + \ldots + \operatorname{MEX}(S_k)$ over al...
[{"input": "4\n3\n0 0 1\n4\n0 0 1 1\n5\n0 0 1 2 2\n4\n1 1 1 1", "output": "11\n26\n53\n0"}]
cf-6658c2b63bd7a06b
Suppose you have an array $b$. Initially, you also have a set $S$ that contains all distinct elements of $b$. The array $b$ is called orangutan-approved if it can be emptied by repeatedly performing the following operation: * In one operation, select indices $l$ and $r$ ($1 \leq l \leq r \leq |b|$) such that $v = b...
[{"input": "3\n4 2\n1 2 2 1\n1 4\n1 3\n5 3\n1 2 1 2 1\n2 5\n3 5\n1 3\n8 4\n1 2 3 2 1 3 2 3\n1 5\n2 8\n3 5\n6 8", "output": "YES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES"}]
cf-bc8d0c3f3a71c6b8
This is the easy version of the problem. In this version, $n \leq 5000$. You can only make hacks if both versions of the problem are solved. Orangutans are powerful beings—so powerful that they only need $1$ unit of time to destroy every vulnerable planet in the universe! There are $n$ planets in the universe. Each ...
[{"input": "3\n3\n1 1\n2 3\n3 3\n4\n1 4\n2 3\n2 4\n1 1\n5\n1 2\n2 3\n3 4\n4 5\n1 5", "output": "5\n6\n24"}]
cf-fb6a192dbcaa9a01
This is the hard version of the problem. In this version, $n \leq 10^6$. You can only make hacks if both versions of the problem are solved. Orangutans are powerful beings—so powerful that they only need $1$ unit of time to destroy every vulnerable planet in the universe! There are $n$ planets in the universe. Each ...
[{"input": "3\n3\n1 1\n2 3\n3 3\n4\n1 4\n2 3\n2 4\n1 1\n5\n1 2\n2 3\n3 4\n4 5\n1 5", "output": "5\n6\n24"}]
cf-af2def7b035bf294
Alice has just crafted a circuit with $n$ lights and $2n$ switches. Each component (a light or a switch) has two states: on or off. The lights and switches are arranged in a way that: * Each light is connected to exactly two switches. * Each switch is connected to exactly one light. It's unknown which light each...
[{"input": "5\n1\n0 0\n1\n0 1\n1\n1 1\n3\n0 0 1 0 1 0\n3\n0 1 1 1 0 0", "output": "0 0\n1 1\n0 0\n0 2\n1 3"}]
cf-ed181f91c348aa5d
You are given an array $a = [1, 2, \ldots, n]$, where $n$ is odd, and an integer $k$. Your task is to choose an odd positive integer $m$ and to split $a$ into $m$ subarrays$^{\dagger}$ $b_1, b_2, \ldots, b_m$ such that: * Each element of the array $a$ belongs to exactly one subarray. * For all $1 \le i \le m$, ...
[{"input": "4\n1 1\n3 2\n3 3\n15 8", "output": "1\n1\n3\n1 2 3\n-1\n5\n1 4 7 10 13"}]
cf-f5920212ad402b18
You are given an array $a$ of $n$ elements $a_1, a_2, \ldots, a_n$. You can perform the following operation any number (possibly $0$) of times: * Choose two integers $i$ and $j$, where $1 \le i, j \le n$, and assign $a_i := a_j$. Find the minimum number of operations required to make the array $a$ satisfy the co...
[{"input": "4\n7\n1 2 3 4 5 6 7\n3\n1 3 2\n3\n4 5 3\n15\n9 3 8 1 6 5 3 8 2 1 4 2 9 4 7", "output": "3\n1\n0\n8"}]
cf-2a0e1ce2ca1fc740
This is an interactive problem. Upon clearing the Waterside Area, Gretel has found a monster named Genokraken, and she's keeping it contained for her scientific studies. The monster's nerve system can be structured as a tree$^{\dagger}$ of $n$ nodes (really, everything should stop resembling trees all the time$\ldot...
[{"input": "3\n4\n\n1\n\n5\n\n1\n\n0\n\n9", "output": "? 2 3\n\n! 0 0 1\n\n? 2 3\n\n? 2 4\n\n! 0 0 1 2\n\n! 0 0 0 1 3 5 6 7"}]
cf-2915154b1688e74a
You are given a cyclic array $a$ with $n$ elements, where $n$ is odd. In each operation, you can do the following: * Choose an index $1 \le i \le n$ and increase $a_{i - 1}$ by $1$, $a_i$ by $2$, and $a_{i + 1}$ by $1$. The element before the first element is the last element because this is a cyclic array. A cyc...
[{"input": "6\n3\n2 1 2\n3\n1 2 3\n5\n1 2 1 2 1\n7\n1 2 1 2 1 3 1\n9\n10000 10000 10000 10000 10000 10001 10002 10001 10000\n1\n10", "output": "0 1 0 \n2 1 0 \n2 0 3 0 2 \n4 2 7 0 8 0 6 \n1 1 1 1 1 1 0 1 1 \n0"}]
cf-4e32f442e57c2a77
Having the magical beanstalk, Jack has been gathering a lot of peanuts lately. Eventually, he has obtained $n$ pockets of peanuts, conveniently numbered $1$ to $n$ from left to right. The $i$-th pocket has $a_i$ peanuts. Jack and his childhood friend Alice decide to play a game around the peanuts. First, Alice divide...
[{"input": "5\n3\n1 2 3\n4\n1 2 3 1\n5\n1 1 1 1 1\n2\n1 1\n10\n1 2 3 4 5 6 7 8 9 10", "output": "1\n4\n16\n0\n205"}]
cf-010ecd306c4e0a9f
Sakurako and Kosuke decided to play some games with a dot on a coordinate line. The dot is currently located in position $x=0$. They will be taking turns, and Sakurako will be the one to start. On the $i$-th move, the current player will move the dot in some direction by $2\cdot i-1$ units. Sakurako will always be mo...
[{"input": "4\n1\n6\n3\n98", "output": "Kosuke\nSakurako\nKosuke\nSakurako"}]
cf-ce04106a30b8ac00
During her journey with Kosuke, Sakurako and Kosuke found a valley that can be represented as a matrix of size $n \times n$, where at the intersection of the $i$-th row and the $j$-th column is a mountain with a height of $a_{i,j}$. If $a_{i,j} < 0$, then there is a lake there. Kosuke is very afraid of water, so Saku...
[{"input": "4\n1\n1\n2\n-1 2\n3 0\n3\n1 2 3\n-2 1 -1\n0 0 -1\n5\n1 1 -1 -1 3\n-3 1 4 4 -4\n-1 -1 3 0 -5\n4 5 3 -3 -1\n3 1 -3 -1 5", "output": "0\n1\n4\n19"}]
cf-957b94809727ae81
Even in university, students need to relax. That is why Sakurakos teacher decided to go on a field trip. It is known that all of the students will be walking in one line. The student with index $i$ has some topic of interest which is described as $a_i$. As a teacher, you want to minimise the disturbance of the line of...
[{"input": "9\n5\n1 1 1 2 3\n6\n2 1 2 2 1 1\n4\n1 2 1 1\n6\n2 1 1 2 2 4\n4\n2 1 2 3\n6\n1 2 2 1 2 1\n5\n4 5 5 1 5\n7\n1 4 3 5 1 1 3\n7\n3 1 3 2 2 3 3", "output": "1\n2\n1\n0\n0\n1\n1\n0\n2"}]
cf-ad33e1233cd4c342
After a trip with Sakurako, Kousuke was very scared because he forgot about his programming assignment. In this assignment, the teacher gave him an array $a$ of $n$ integers and asked him to calculate the number of non- overlapping segments of the array $a$, such that each segment is considered beautiful. A segment $...
[{"input": "3\n5\n2 1 -3 2 1\n7\n12 -4 4 43 -3 -5 8\n6\n0 -4 0 3 0 1", "output": "1\n2\n3"}]
cf-d5491a1f34bd4b65
Sakurako's exams are over, and she did excellently. As a reward, she received a permutation $p$. Kosuke was not entirely satisfied because he failed one exam and did not receive a gift. He decided to sneak into her room (thanks to the code for her lock) and spoil the permutation so that it becomes simple. A permutati...
[{"input": "6\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n5\n2 3 4 5 1\n4\n2 3 4 1\n3\n1 3 2\n7\n2 3 1 5 6 7 4", "output": "0\n0\n2\n1\n0\n2"}]
cf-bc4af4d11e791351
Kosuke is too lazy. He will not give you any legend, just the task: Fibonacci numbers are defined as follows: * $f(1)=f(2)=1$. * $f(n)=f(n-1)+f(n-2)$ $(3\le n)$ We denote $G(n,k)$ as an index of the $n$-th Fibonacci number that is divisible by $k$. For given $n$ and $k$, compute $G(n,k)$. As this number can ...
[{"input": "3\n3 2\n100 1\n1000000000000 1377", "output": "9\n100\n999244007"}]
cf-0de916666c619ddf
Given a tree with $n$ vertices rooted at vertex $1$. While walking through it with her cat Chefir, Sakurako got distracted, and Chefir ran away. To help Sakurako, Kosuke recorded his $q$ guesses. In the $i$-th guess, he assumes that Chefir got lost at vertex $v_i$ and had $k_i$ stamina. Also, for each guess, Kosuke ...
[{"input": "3\n5\n1 2\n2 3\n3 4\n3 5\n3\n5 1\n3 1\n2 0\n9\n8 1\n1 7\n1 4\n7 3\n4 9\n3 2\n1 5\n3 6\n7\n6 0\n2 3\n6 2\n8 2\n2 4\n9 2\n6 3\n6\n2 1\n2 5\n2 4\n5 6\n4 3\n3\n3 1\n1 3\n6 5", "output": "2 1 2 \n0 5 2 4 5 5 5 \n1 3 4"}]
cf-2b49b989c0a12b12
Red was ejected. They were not the imposter. There are $n$ rows of $m$ people. Let the position in the $r$-th row and the $c$-th column be denoted by $(r, c)$. Number each person starting from $1$ in row-major order, i.e., the person numbered $(r-1)\cdot m+c$ is initially at $(r,c)$. The person at $(r, c)$ decides t...
[{"input": "4\n2 3 1 2\n2 2 2 1\n1 1 1 1\n1000000 1000000 1 1", "output": "6\n1\n0\n1999998000000"}]
cf-a8b24e975163e76d
There are 3 heroes and 3 villains, so 6 people in total. Given a positive integer $n$. Find the smallest integer whose decimal representation has length $n$ and consists only of $3$s and $6$s such that it is divisible by both $33$ and $66$. If no such integer exists, print $-1$. Input Format: The first line contains...
[{"input": "6\n1\n2\n3\n4\n5\n7", "output": "-1\n66\n-1\n3366\n36366\n3336366"}]
cf-355edd46e49305a6
Alya has been given a hard problem. Unfortunately, she is too busy running for student council. Please solve this problem for her. Given an integer $n$, construct a permutation $p$ of integers $1, 2, \ldots, n$ that maximizes the value of $k$ (which is initially $0$) after the following process. Perform $n$ operatio...
[{"input": "6\n5\n6\n7\n8\n9\n10", "output": "5\n2 1 3 4 5 \n7\n1 2 4 6 5 3 \n7\n2 4 5 1 3 6 7 \n15\n2 4 5 1 3 6 7 8 \n9\n2 4 5 6 7 1 3 8 9 \n15\n1 2 3 4 5 6 8 10 9 7"}]
cf-5f35ca6cc5422f64
Three r there are's in strawberry. You are given an array $b$ of length $m$. You can perform the following operation any number of times (possibly zero): * Choose two distinct indices $i$ and $j$ where $\bf{1\le i < j\le m}$ and $b_i$ is even, divide $b_i$ by $2$ and multiply $b_j$ by $2$. Your task is to maximi...
[{"input": "3\n10\n1 2 3 4 5 6 7 8 9 10\n11\n1 6 9 4 7 4 4 10 3 2 3\n4\n527792568 502211460 850237282 374773208", "output": "1 3 8 13 46 59 126 149 1174 1311 \n1 7 22 26 70 74 150 1303 1306 1308 1568 \n527792568 83665723 399119771 773892979"}]
cf-86515d2a498d71a5
Man, this Genshin boss is so hard. Good thing they have a top-up of $6$ coins for only $ \$4.99$. I should be careful and spend no more than I need to, lest my mom catches me... You are fighting a monster with $z$ health using a weapon with $d$ damage. Initially, $d=0$. You can perform the following operations. * ...
[{"input": "4\n2 3 5 5\n10 20 40 5\n1 60 100 10\n60 1 100 10", "output": "12\n190\n280\n160"}]
cf-56de34d27bf720f6
This really says a lot about our society. One day, a turtle gives you a tree with $n$ nodes rooted at node $x$. Each node has an initial nonnegative value; the $i$-th node has starting value $a_i$. You want to make the values of all nodes equal to $0$. To do so, you will perform a series of operations on the tree, w...
[{"input": "5\n2 1\n1 2\n1 2\n3 2\n2 1 3\n2 1\n3 2\n4 1\n1 1 0 1\n1 2\n2 3\n1 4\n12 6\n14 4 5 6 12 9 5 11 6 2 1 12\n3 9\n10 6\n6 12\n4 3\n3 1\n5 11\n9 7\n5 6\n1 8\n2 8\n5 1\n1 1\n0", "output": "3\n6\n5\n145\n0"}]
cf-173f76cf8bfaef3b
The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3000$ and the sum of $n$ does not exceed $10^4$. You can only make hacks if both versions are solved. Well, well, well, let's see how Bessie is managing her finances. She seems to be in the trenc...
[{"input": "2\n5 4\n1 1\n2 2\n4 3\n5 4\n5 4\n5 4\n2 5\n1 2\n3 3", "output": "0 1\n1 3"}, {"input": "2\n6 6\n1 3\n2 5\n3 1\n4 2\n5 4\n6 6\n30 8\n19 22\n6 12\n12 1\n28 27\n3 4\n14 25\n29 14\n11 15", "output": "3 78\n3 839271911"}]
cf-996e5eed51fcd7b6
The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3\cdot 10^5$ and the sum of $n$ does not exceed $10^6$. You can only make hacks if both versions are solved. Well, well, well, let's see how Bessie is managing her finances. She seems to be in th...
[{"input": "2\n5 4\n1 1\n2 2\n4 3\n5 4\n5 4\n5 4\n2 5\n1 2\n3 3", "output": "0 1\n1 3"}, {"input": "3\n6 6\n1 3\n2 5\n3 1\n4 2\n5 4\n6 6\n30 8\n19 22\n6 12\n12 1\n28 27\n3 4\n14 25\n29 14\n11 15\n300000 1\n5 10", "output": "3 78\n3 839271911\n0 702730519"}]