problem_id stringlengths 5 6 | url stringlengths 48 49 | title stringlengths 2 46 | rating int64 800 3.5k | tags listlengths 1 11 | div stringclasses 16
values | time_limit_ms int64 1k 13k | memory_limit_mb int64 32 1.02k | description stringlengths 67 2.52k | input stringlengths 99 1.93k ⌀ | output stringlengths 47 1.35k ⌀ | examples listlengths 1 5 | note stringlengths 0 1.68k | prompt stringlengths 505 6.96k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2000C | https://codeforces.com/problemset/problem/2000/C | Numeric String Template | 1,000 | [
"data structures",
"strings"
] | Div. 3 | 2,000 | 256 | 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.
A string $s$ is considered to match the template if all of the following co... | The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The following descriptions are for the test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $a$.
The second line of each test... | For each test case, output $m$ lines. On the $i$-th line ($1 \le i \le m$) output:
* "YES", if the string with index $i$ matches the template; * "NO" otherwise.
You may output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer). | [
[
"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",
"YES\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nYES"
]
] | The first test case is explained in the problem statement. | Title: Numeric String Template
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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 t... |
2030F | https://codeforces.com/problemset/problem/2030/F | Orangutan Approved Subarrays | 2,400 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | Div. 2 | 3,000 | 512 | 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_... | The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first line of each test case contains integers $n$ and $q$ ($1 \leq n,q \leq 2 \cdot 10^5$) — the size of $a$ and the number of queries, respectively.
The following line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n... | For each query, output "YES" (without quotes) if the subarray from $l$ to $r$ is orangutan-approved, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response). | [
[
"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",
"YES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES"
]
] | In the first query of the first testcase, the answer is YES.
* Initially, $S=\\{1,2\\}$ and $b=[1,2,2,1]$ * Select $l=2$ and $r=3$. Since $b_2=b_3=2$ is in $S$, we may erase $b_2$ and $b_3$ from the array, as well as erasing $2$ from $S$. The set $S$ becomes $\\{1\\}$ and the array becomes $[1,1]$. * Select $l... | Title: Orangutan Approved Subarrays
time_limit_ms: 3000
memory_limit_mb: 512
Description: 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:
* I... |
2014H | https://codeforces.com/problemset/problem/2014/H | Robin Hood Archery | 1,900 | [
"data structures",
"divide and conquer",
"greedy",
"hashing"
] | Div. 3 | 3,000 | 256 | 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...
Sheriff of Nottingham has organized a tournament in archery. It's the final round and Robin Hood is playing against Sheriff!
There a... | The first line of input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains two integers $n$, $q$ ($1 \le n,q \le 2\cdot10^5$) — the number of targets and the queries Sheriff will pose.
The second line of each test case contains $n$ integers $a_1, a_2, \... | For each query, output "YES", if the Sheriff does not lose the game when only considering the targets $l, l+1, \dots, r$, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"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",
"NO\nNO\nYES\nNO\nNO\nYES"
]
] | Title: Robin Hood Archery
time_limit_ms: 3000
memory_limit_mb: 256
Description: 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...
Sheriff of Nottingham has organized a tournament in a... | |
1995D | https://codeforces.com/problemset/problem/1995/D | Cases | 2,300 | [
"bitmasks",
"brute force",
"dp",
"strings"
] | Div. 2 | 2,000 | 256 | You're a linguist studying a mysterious ancient language. You know that
1. Its words consist only of the first $c$ letters of the Latin alphabet. 2. Each word has a case which can be unambiguously determined by its last letter (different letters correspond to different cases). For example, words "ABACABA" and "AB... | Each test consists of several test cases. The first line contains a single integer $t$ ($1 \le t \le 10\,000$) — the number of test cases. It is followed by descriptions of the test cases.
The first line of each test case contains three integers $n$, $c$, $k$ ($1 \le k \le n \le 2^{18}$, $1 \le c \le 18$) — the length... | For each test case, output a single line consisting of a single integer — the minimum number of cases in the language. | [
[
"7\n5 5 1\nABCDE\n3 1 2\nAAA\n3 2 2\nAAB\n10 2 2\nABABABABAB\n4 4 4\nDCBA\n1 17 1\nQ\n9 3 2\nABCABCABC",
"5\n1\n2\n1\n1\n1\n2"
]
] | In the first test case, there must be five cases in the language (for each of the letters 'A', 'B', 'C', 'D', and 'E' there must be a case that has a corresponding ending).
In the fourth test case, one case with ending 'B' is sufficient. | Title: Cases
time_limit_ms: 2000
memory_limit_mb: 256
Description: You're a linguist studying a mysterious ancient language. You know that
1. Its words consist only of the first $c$ letters of the Latin alphabet. 2. Each word has a case which can be unambiguously determined by its last letter (different letters c... |
1980D | https://codeforces.com/problemset/problem/1980/D | GCD-sequence | 1,400 | [
"greedy",
"implementation",
"math",
"number theory"
] | Div. 3 | 2,000 | 256 | GCD (Greatest Common Divisor) of two integers $x$ and $y$ is the maximum integer $z$ by which both $x$ and $y$ are divisible. For example, $GCD(36, 48) = 12$, $GCD(5, 10) = 5$, and $GCD(7,11) = 1$.
Kristina has an array $a$ consisting of exactly $n$ positive integers. She wants to count the GCD of each neighbouring pa... | The first line of input data contains a single number $t$ ($1 \le t \le 10^4$) — he number of test cases in the test.
This is followed by the descriptions of the test cases.
The first line of each test case contains a single integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of elements in the array $a$.
The seco... | For each test case, output a single line:
* "YES" if you can remove exactly one number from the array $a$ so that the GCD-sequence of $b$ is non-decreasing; * "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answe... | [
[
"12\n6\n20 6 12 3 48 36\n4\n12 6 3 4\n3\n10 12 3\n5\n32 16 8 4 2\n5\n100 50 2 10 20\n4\n2 4 8 1\n10\n7 4 6 2 4 5 1 4 2 8\n7\n5 9 6 8 5 9 2\n6\n11 14 8 12 9 3\n9\n5 7 3 10 6 3 12 6 3\n3\n4 2 4\n8\n1 6 11 12 6 12 3 6",
"YES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES"
]
] | The first test case is explained in the problem statement. | Title: GCD-sequence
time_limit_ms: 2000
memory_limit_mb: 256
Description: GCD (Greatest Common Divisor) of two integers $x$ and $y$ is the maximum integer $z$ by which both $x$ and $y$ are divisible. For example, $GCD(36, 48) = 12$, $GCD(5, 10) = 5$, and $GCD(7,11) = 1$.
Kristina has an array $a$ consisting of exactly... |
2019A | https://codeforces.com/problemset/problem/2019/A | Max Plus Size | 800 | [
"brute force",
"dp",
"greedy"
] | Div. 2 | 1,000 | 256 | [EnV - Dynasty](https://soundcloud.com/envyofficial/env-dynasty)
⠀
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$ and $a_{i+1}$ must not be red).
Yo... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the length of the array.
The second line of each test case contains $n$ inte... | For each test case, output a single integer: the maximum possible score you can get after coloring some elements red according to the statement. | [
[
"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",
"7\n6\n10\n97"
]
] | In the first test case, you can color the array as follows: $[\color{red}{5}, 4, \color{red}{5}]$. Your score is $\max([5, 5]) + \text{size}([5, 5]) = 5+2 = 7$. This is the maximum score you can get.
In the second test case, you can color the array as follows: $[\color{red}{4}, 5, \color{red}{4}]$. Your score is $\max... | Title: Max Plus Size
time_limit_ms: 1000
memory_limit_mb: 256
Description: [EnV - Dynasty](https://soundcloud.com/envyofficial/env-dynasty)
⠀
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 ... |
2022C | https://codeforces.com/problemset/problem/2022/C | Gerrymandering | 1,800 | [
"dp",
"implementation"
] | Div. 2 | 2,000 | 256 | 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 th... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains one integer $n$ ($3 \le n \le 10^5$; $n$ is a multiple of $3$) — the number of columns of Tepito.
The following two li... | For each test case, output a single integer — the maximum number of districts Álvaro can win by optimally dividing the houses into districts. | [
[
"4\n3\nAAA\nAJJ\n6\nJAJAJJ\nJJAJAJ\n6\nAJJJAJ\nAJJAAA\n9\nAJJJJAJAJ\nJAAJJJJJA",
"2\n2\n3\n2"
]
] | The image below showcases the optimal arrangement of districts Álvaro can use for each test case in the example.
 | Title: Gerrymandering
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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 r... |
2003D2 | https://codeforces.com/problemset/problem/2003/D2 | Turtle and a MEX Problem (Hard Version) | 2,100 | [
"dfs and similar",
"dp",
"graphs",
"greedy",
"implementation",
"math"
] | Div. 2 | 2,000 | 256 | 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.
One day, Turtle was playing with $n$ sequences. Let the length of the $i$-th sequence be $l_i$. Then the $i$-th sequence was $a_{i, 1}, a_{i, 2}... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains two integers $n, m$ ($1 \le n \le 2 \cdot 10^5, 0 \le m \le 10^9$).
Each of the following $n$ lines contains several i... | For each test case, output a single integer — the value of $\sum\limits_{i = 0}^m f(i)$. | [
[
"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",
"16\n18\n1281\n4\n6556785365\n1... | In the first test case, when $x$ is initially $2$, Turtle can choose $i = 3$ and set $x$ to $\text{mex}(x, a_{3, 1}, a_{3, 2}, a_{3, 3}, a_{3, 4}) = \text{mex}(2, 7, 0, 1, 5) = 3$. It can be proved that Turtle can't make the value of $x$ greater than $3$, so $f(2) = 3$.
It can be seen that $f(0) = 3$, $f(1) = 3$, $f(2... | Title: Turtle and a MEX Problem (Hard Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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.
One day, Turtle was playing with $n$ sequen... |
2002A | https://codeforces.com/problemset/problem/2002/A | Distanced Coloring | 800 | [
"constructive algorithms",
"implementation",
"math"
] | Div. 1 + 2 | 1,000 | 256 | You received an $n\times m$ grid from a mysterious source. The source also gave you a magic positive integer constant $k$.
The source told you to color the grid with some colors, satisfying the following condition:
* If $(x_1,y_1)$, $(x_2,y_2)$ are two distinct cells with the same color, then $\max(|x_1-x_2|,|y_1-y... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le1000$). The description of the test cases follows.
The only line of each test case consists of three positive integers $n$, $m$, $k$ ($1\le n,m,k\le10^4$) — the dimensions of the grid and the magic constant. | For each test case, print a single integer — the minimum number of colors needed to color the grid. | [
[
"6\n3 3 2\n5 1 10000\n7 3 4\n3 2 7\n8 9 6\n2 5 4",
"4\n5\n12\n6\n36\n8"
]
] | In the first test case, one of the optimal constructions is:

In the second test case, the color of all cells must be pairwise different, so the answer is $5$. | Title: Distanced Coloring
time_limit_ms: 1000
memory_limit_mb: 256
Description: You received an $n\times m$ grid from a mysterious source. The source also gave you a magic positive integer constant $k$.
The source told you to color the grid with some colors, satisfying the following condition:
* If $(x_1,y_1)$, $(x... |
2005B2 | https://codeforces.com/problemset/problem/2005/B2 | The Strict Teacher (Hard Version) | 1,200 | [
"binary search",
"greedy",
"math",
"sortings"
] | Div. 2 | 1,500 | 256 | 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.
Narek and Tsovak were busy preparing this round, so they have not managed to do their homework... | In the first line of the input, you are given a single integer $t$ ($1 \le t \le 10^5$) — the number of test cases. The description of each test case follows.
In the first line of each test case, you are given three integers $n$, $m$, and $q$ ($3 \le n \le 10^9$, $1 \le m, q \le 10^5$) — the number of cells on the lin... | For each test case, output $q$ lines, the $i$-th of them containing the answer of the $i$-th query. | [
[
"2\n8 1 1\n6\n3\n10 3 3\n1 4 8\n2 3 10",
"5\n1\n1\n2"
]
] | In the only query of the first example, the student can run to cell $1$. It will take the teacher five moves to reach from cell $6$ to cell $1$, so the answer is $5$.
In the second query of the second example, the student can just stay at cell $3$. The teacher, initially located in cell $4$, can reach cell $3$ in one ... | Title: The Strict Teacher (Hard Version)
time_limit_ms: 1500
memory_limit_mb: 256
Description: 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.
... |
2020A | https://codeforces.com/problemset/problem/2020/A | Find Minimum Operations | 800 | [
"bitmasks",
"brute force",
"greedy",
"math",
"number theory"
] | Div. 2 | 1,000 | 256 | 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$. | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The only line of each test case contains two integers $n$ and $k$ ($1 \le n, k \le 10^9$). | For each test case, output the minimum number of operations on a new line. | [
[
"6\n5 2\n3 5\n16 4\n100 3\n6492 10\n10 1",
"2\n3\n1\n4\n21\n10"
]
] | In the first test case, $n = 5$ and $k = 2$. We can perform the following sequence of operations:
1. Subtract $2^0 = 1$ from $5$. The current value of $n$ becomes $5 - 1 = 4$. 2. Subtract $2^2 = 4$ from $4$. The current value of $n$ becomes $4 - 4 = 0$.
It can be shown that there is no way to make $n$ equal to ... | Title: Find Minimum Operations
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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 operation... |
1985C | https://codeforces.com/problemset/problem/1985/C | Good Prefixes | 1,000 | [
"greedy"
] | Div. 4 | 2,000 | 256 | Alex thinks some array is good if there exists some element that can be represented as the sum of all other elements (the sum of all other elements is $0$ if there are no other elements). For example, the array $[1,6,3,2]$ is good since $1+3+2=6$. Furthermore, the array $[0]$ is also good. However, the arrays $[1,2,3,4... | The first line of the input contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array.
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ (... | For each test case, output a single integer — the number of good non-empty prefixes of the array $a$. | [
[
"7\n1\n0\n1\n1\n4\n1 1 2 0\n5\n0 1 2 1 4\n7\n1 1 0 3 5 2 12\n7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 294967296\n10\n0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 589934592",
"1\n0\n3\n3\n4\n1\n2"
]
] | In the fourth test case, the array has five prefixes:
* prefix $[0]$ is a good array, as mentioned in the statement; * prefix $[0, 1]$ is not a good array, since $0 \ne 1$; * prefix $[0, 1, 2]$ is not a good array, since $0 \ne 1 + 2$, $1 \ne 0 + 2$ and $2 \ne 0 + 1$; * prefix $[0, 1, 2, 1]$ is a good array... | Title: Good Prefixes
time_limit_ms: 2000
memory_limit_mb: 256
Description: Alex thinks some array is good if there exists some element that can be represented as the sum of all other elements (the sum of all other elements is $0$ if there are no other elements). For example, the array $[1,6,3,2]$ is good since $1+3+2=6... |
1990F | https://codeforces.com/problemset/problem/1990/F | Polygonal Segments | 2,800 | [
"brute force",
"data structures",
"divide and conquer",
"dp",
"greedy",
"two pointers"
] | Div. 2 | 8,000 | 512 | You are given an array $a$ of size $n$.
A segment $[l, r](1 \le l < r \le n)$ is called a polygonal segment only if the following conditions hold:
* $(r-l+1) \geq 3$; * Considering $a_l, a_{l+1}, \ldots, a_r$ as side lengths, these sides can form a polygon with $(r-l+1)$ sides.
Process $q$ queries of two types... | The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
For each test case:
* The first line of each testcase contains two integers $n$, $q$ ($4 \le n \le 2\cdot 10^5$, $1 \le q \le 10^5$); * The second line of each testcase contains $n$ integers $a_1,a_2,\ldots, a_n$ ($1 \le a_... | For each query, if there is no suitable segment, output $-1$ in a new line. Otherwise, output the length of the longest segment satisfying the condition above in a new line. | [
[
"2\n5 6\n3 1 2 2 8\n1 1 3\n1 1 4\n1 1 5\n2 1 5\n1 1 4\n1 1 5\n4 10\n500000000000 500000000000 1000000000000 500000000000\n1 1 3\n1 2 4\n1 1 4\n2 1 499999999999\n2 3 999999999999\n1 1 3\n1 2 4\n1 1 4\n2 3 1000000000000\n1 1 3",
"-1\n4\n4\n3\n5\n-1\n-1\n4\n-1\n3\n4\n-1"
]
] | In the first query of the first test case, there is no polygonal segment under the given condition. For example, considering segment $[1,3]$, you can not form a triangle with side lengths of $a_1=3$, $a_2=1$, and $a_3=2$.
In the second query of the first test case, the longest polygonal segment is $[1,4]$. You can for... | Title: Polygonal Segments
time_limit_ms: 8000
memory_limit_mb: 512
Description: You are given an array $a$ of size $n$.
A segment $[l, r](1 \le l < r \le n)$ is called a polygonal segment only if the following conditions hold:
* $(r-l+1) \geq 3$; * Considering $a_l, a_{l+1}, \ldots, a_r$ as side lengths, these s... |
1997F | https://codeforces.com/problemset/problem/1997/F | Chips on a Line | 2,700 | [
"brute force",
"combinatorics",
"dp",
"greedy",
"math"
] | Div. 2 | 5,000 | 512 | You have $n$ chips, and you are going to place all of them in one of $x$ points, numbered from $1$ to $x$. There can be multiple chips in each point.
After placing the chips, you can perform the following four operations (in any order, any number of times):
* choose a chip in point $i \ge 3$, remove it and place tw... | The only line contains three integers $n$, $x$ and $m$ ($1 \le m \le n \le 1000$; $2 \le x \le 10$). | Print one integer — the number of placements with cost equal to $m$, taken modulo $998244353$. | [
[
"2 3 1",
"5"
],
[
"42 10 5",
"902673363"
],
[
"1000 10 8",
"187821763"
]
] | In the first example, there are five ways to place $2$ chips in points from $1$ to $3$ so that the cost is $1$:
* $(1, 1)$; * $(1, 2)$; * $(1, 3)$; * $(2, 2)$; * $(2, 3)$. | Title: Chips on a Line
time_limit_ms: 5000
memory_limit_mb: 512
Description: You have $n$ chips, and you are going to place all of them in one of $x$ points, numbered from $1$ to $x$. There can be multiple chips in each point.
After placing the chips, you can perform the following four operations (in any order, any nu... |
1990D | https://codeforces.com/problemset/problem/1990/D | Grid Puzzle | 1,800 | [
"bitmasks",
"brute force",
"dp",
"greedy",
"implementation"
] | Div. 2 | 2,000 | 256 | You are given an array $a$ of size $n$.
There is an $n \times n$ grid. In the $i$-th row, the first $a_i$ cells are black and the other cells are white. In other words, note $(i,j)$ as the cell in the $i$-th row and $j$-th column, cells $(i,1), (i,2), \ldots, (i,a_i)$ are black, and cells $(i,a_i+1), \ldots, (i,n)$ ar... | The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
For each test case:
* The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the size of the array $a$. * The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq n$).
It's guarante... | For each test case, output a single integer — the minimum number of operations to dye all cells white. | [
[
"10\n1\n0\n4\n2 4 4 2\n4\n3 2 1 0\n3\n0 3 0\n3\n0 1 3\n3\n3 1 0\n4\n3 1 0 3\n4\n0 2 2 2\n6\n1 3 4 2 0 4\n8\n2 2 5 2 3 4 2 4",
"0\n3\n2\n1\n2\n2\n3\n2\n4\n6"
]
] | In the first test case, you don't need to do any operation.
In the second test case, you can do:
* Dye $(1,1), (1,2), (2,1)$, and $(2,2)$ white; * Dye $(2,3), (2,4), (3,3)$, and $(3,4)$ white; * Dye $(3,1), (3,2), (4,1)$, and $(4,2)$ white.
It can be proven $3$ is the minimum number of operations.
In the t... | Title: Grid Puzzle
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given an array $a$ of size $n$.
There is an $n \times n$ grid. In the $i$-th row, the first $a_i$ cells are black and the other cells are white. In other words, note $(i,j)$ as the cell in the $i$-th row and $j$-th column, cells $(i,1), (... |
1997E | https://codeforces.com/problemset/problem/1997/E | Level Up | 2,200 | [
"binary search",
"brute force",
"data structures",
"divide and conquer",
"implementation"
] | Div. 2 | 4,000 | 512 | Monocarp is playing a computer game. He starts the game being level $1$. He is about to fight $n$ monsters, in order from $1$ to $n$. The level of the $i$-th monster is $a_i$.
For each monster in the given order, Monocarp's encounter goes as follows:
* if Monocarp's level is strictly higher than the monster's level... | The first line contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of monsters and the number of queries.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$) — the levels of the monsters.
In the $j$-th of the following $q$ lines, two integers $i$ and ... | For each query, output "YES", if Monocarp will fight the $i$-th monster in this query, and "NO", if the $i$-th monster flees. | [
[
"4 16\n2 1 2 1\n1 1\n2 1\n3 1\n4 1\n1 2\n2 2\n3 2\n4 2\n1 3\n2 3\n3 3\n4 3\n1 4\n2 4\n3 4\n4 4",
"YES\nNO\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES"
],
[
"7 15\n1 1 2 1 1 1 1\n5 3\n2 2\n2 2\n1 6\n5 1\n5 5\n7 7\n3 5\n7 4\n4 3\n2 5\n1 2\n5 6\n4 1\n6 1",
"NO\nYES\nYES\nYE... | Title: Level Up
time_limit_ms: 4000
memory_limit_mb: 512
Description: Monocarp is playing a computer game. He starts the game being level $1$. He is about to fight $n$ monsters, in order from $1$ to $n$. The level of the $i$-th monster is $a_i$.
For each monster in the given order, Monocarp's encounter goes as follows... | |
1993F2 | https://codeforces.com/problemset/problem/1993/F2 | Dyn-scripted Robot (Hard Version) | 2,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | Div. 2 | 3,000 | 256 | This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.
Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.
You also ... | The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).
The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, ... | For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously. | [
[
"6\n2 4 2 2\nUR\n4 2 1 1\nLLDD\n6 3 3 1\nRLRRRL\n5 6 3 3\nRUURD\n7 5 3 4\nRRDLUUU\n7 123456789999 3 2\nULULURD",
"1\n4\n3\n1\n1\n41152263332"
]
] | In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.
In the second test case, each time executing the script the robot visits the origin ... | Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.
Given a $w \times h$ rectangle on the $Oxy$ plane, wit... |
1975E | https://codeforces.com/problemset/problem/1975/E | Chain Queries | 2,100 | [
"binary search",
"data structures",
"dfs and similar",
"implementation",
"trees"
] | Div. 1 + 2 | 2,000 | 256 | You are given a tree of $n$ vertices numbered from $1$ to $n$. Initially, all vertices are colored white or black.
You are asked to perform $q$ queries:
* "u" — toggle the color of vertex $u$ (if it was white, change it to black and vice versa).
After each query, you should answer whether all the black vertices f... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\leq t\leq 10^4$). The description of the test cases follows.
The first line of each test case contains two integers $n$ and $q$ ($1\leq n,q\leq 2\cdot 10^5$).
The second line of each test case contains $n$ integers $c_1,c... | For each query, output "Yes" if the black vertices form a chain, and output "No" otherwise.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response). | [
[
"2\n2 1\n1 0\n1 2\n1\n5 4\n1 0 0 0 0\n1 2\n1 3\n1 5\n3 4\n4\n3\n2\n5",
"No\nNo\nYes\nYes\nNo"
],
[
"4\n5 3\n1 1 1 1 1\n3 5\n2 5\n3 4\n1 5\n1\n1\n1\n4 4\n0 0 0 0\n1 2\n2 3\n1 4\n1\n2\n3\n2\n1 1\n1\n1\n1 1\n0\n1",
"Yes\nNo\nYes\nYes\nYes\nYes\nNo\nNo\nYes"
]
] | In the second test case, the color of the vertices are as follows:
The initial tree:

The first query toggles the color of vertex $4$:

The second query toggles the color of vertex $3$:
 — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 100$). | For each test case, output "Yes" (without quotes) if Nikita can obtain a tower with $m$ cubes, and "No" (without quotes) otherwise.
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer. | [
[
"3\n3 3\n2 4\n5 3",
"Yes\nNo\nYes"
]
] | In the first test case, Nikita can put $1$ cube on top of the tower $3$ times in a row, so the answer is "Yes".
In the second test case, Nikita can only end up with either a tower with no blocks or a tower with $2$ blocks, so the answer is "No". | Title: Little Nikita
time_limit_ms: 1000
memory_limit_mb: 256
Description: The little boy Nikita was given some cubes as a present. He decided to build a tower out of them.
Initially, the tower doesn't have any cubes. In one move, Nikita either puts exactly $1$ cube on top of the tower or removes exactly $1$ cube from... |
2018E2 | https://codeforces.com/problemset/problem/2018/E2 | Complex Segments (Hard Version) | 3,400 | [
"binary search",
"data structures",
"divide and conquer",
"dsu",
"greedy",
"math",
"sortings"
] | Div. 1 | 13,000 | 256 | [Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)
⠀
This 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.
A set of (closed) segments is complex if it can be partitioned into ... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of segments.
The second line of each test case contains... | For each test case, output a single integer: the maximum size of a complex subset of the given segments. | [
[
"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",
"3\n4\n4"
]
] | In the first test case, all pairs of segments intersect, therefore it is optimal to form a single group containing all of the three segments.
In the second test case, there is no valid partition for all of the five segments. A valid partition with four segments is the following: $\\{\\{ [1, 5], [2, 4] \\}, \\{ [6, 9],... | Title: Complex Segments (Hard Version)
time_limit_ms: 13000
memory_limit_mb: 256
Description: [Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)
⠀
This 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... |
1996G | https://codeforces.com/problemset/problem/1996/G | Penacony | 2,200 | [
"brute force",
"data structures",
"graphs",
"greedy",
"hashing"
] | Div. 3 | 3,000 | 512 | On Penacony, The Land of the Dreams, there exists $n$ houses and $n$ roads. There exists a road between house $i$ and $i+1$ for all $1 \leq i \leq n-1$ and a road between house $n$ and house $1$. All roads are bidirectional. However, due to the crisis on Penacony, the overseeing family has gone into debt and may not be... | The first line contains $t$ ($1 \leq t \leq 10^4$) – the number of test cases.
The first line of each test case contains two integers $n$ and $m$ ($3 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5$) – the number of houses and the number of friendships.
The next $m$ lines contain two integers $a$ and $b$ ($1 \le... | For each test case, output an integer, the minimum number of roads that must be maintained. | [
[
"7\n8 3\n1 8\n2 7\n4 5\n13 4\n1 13\n2 12\n3 11\n4 10\n10 2\n2 3\n3 4\n10 4\n3 8\n5 10\n2 10\n4 10\n4 1\n1 3\n5 2\n3 5\n1 4\n5 2\n2 5\n1 3",
"4\n7\n2\n7\n2\n3\n3"
]
] | For the first test case, the following roads must be maintained:
* $8 \leftarrow \rightarrow 1$ * $7 \leftarrow \rightarrow 8$ * $1 \leftarrow \rightarrow 2$ * $4 \leftarrow \rightarrow 5$ | Title: Penacony
time_limit_ms: 3000
memory_limit_mb: 512
Description: On Penacony, The Land of the Dreams, there exists $n$ houses and $n$ roads. There exists a road between house $i$ and $i+1$ for all $1 \leq i \leq n-1$ and a road between house $n$ and house $1$. All roads are bidirectional. However, due to the crisi... |
2004E | https://codeforces.com/problemset/problem/2004/E | Not a Nim Problem | 2,100 | [
"brute force",
"games",
"math",
"number theory"
] | Div. 2 | 2,000 | 512 | 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.
On their turn, a player can choose any pile of stones and take any positive number of stones from it, with one condition:
* let the current number of stones in the pile be $x$. It i... | The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
Each test case consists of two lines:
* the first line contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$); * the second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^7$).
Additional cons... | For each test case, output Alice if Alice wins, or Bob if Bob wins. | [
[
"3\n3\n3 2 9\n4\n3 3 6 1\n5\n1 2 3 4 5",
"Bob\nAlice\nBob"
]
] | Title: Not a Nim Problem
time_limit_ms: 2000
memory_limit_mb: 512
Description: 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.
On their turn, a player can choose any pile of stones and take any positive number of stones from it, wit... | |
2022E1 | https://codeforces.com/problemset/problem/2022/E1 | Billetes MX (Easy Version) | 2,500 | [
"2-sat",
"binary search",
"combinatorics",
"constructive algorithms",
"dfs and similar",
"dsu",
"graphs"
] | Div. 2 | 2,000 | 512 | 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 ... | The first line contains $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains four integers $n$, $m$, $k$ and $q$ ($2 \le n, m \le 10^5$; $0 \le k \le 10^5$; $q = 0$) — the number of rows, the number of columns, the number of fixed cells, and the number of updates.
The followi... | For each test case, output $q + 1$ lines. The $i$-th line of output should contain the answer of the $i$-th state of the grid modulo $10^9 + 7$. | [
[
"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",
"1\n489373567"
]
] | In the first test case of the example, we have the following grid:
$0$| $6$| $10$ ---|---|--- $6$| $0$| $12$ $10$| $12$| $?$ It can be proven that the only valid value for tile $(3, 3)$ is $0$. | Title: Billetes MX (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 512
Description: 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:
... |
2027D1 | https://codeforces.com/problemset/problem/2027/D1 | The Endspeaker (Easy Version) | 1,700 | [
"binary search",
"dp",
"graphs",
"greedy",
"implementation",
"two pointers"
] | Div. 2 | 2,000 | 256 | 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$). Initially... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.
The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$, $\boldsymbol{1 \le n \cdot m \le 3 \cdot 10^5}$).
The second ... | For each test case, if it's possible to make $a$ empty, then output the minimum total cost of the operations.
If there is no possible sequence of operations which makes $a$ empty, then output a single integer $-1$. | [
[
"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",
"1\n-1\n2\n10\n4"
]
] | In the first test case, one optimal sequence of operations which yields a total cost of $1$ is as follows:
* Perform an operation of type $2$. Choose the prefix to be $[9]$. This incurs a cost of $1$. * Perform an operation of type $1$. The value of $k$ is now $2$. This incurs no cost. * Perform an operation o... | Title: The Endspeaker (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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 le... |
1991H | https://codeforces.com/problemset/problem/1991/H | Prime Split Game | 3,300 | [
"bitmasks",
"dp",
"fft",
"games",
"math",
"number theory"
] | Div. 1 + 2 | 2,000 | 256 | Alice and Bob are playing a game with $n$ piles of stones, where the $i$-th pile has $a_i$ stones. Players take turns making moves, with Alice going first.
On each move, the player does the following three-step process:
1. Choose an integer $k$ ($1 \leq k \leq \frac n 2$). Note that the value of $k$ can be differen... | Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of piles of stones.
The second line of e... | For each test case, output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise.
You can output each letter in any case (upper or lower). For example, the strings "alIcE", "Alice", and "alice" will all be considered identical. | [
[
"4\n2\n2 1\n3\n3 5 7\n4\n4 6 8 10\n5\n8 8 8 8 8",
"Bob\nAlice\nAlice\nBob"
]
] | In the first test case, there are $2$ piles of stones with $2$ and $1$ stones respectively. Since neither $1$ nor $2$ can be split into two prime numbers, Alice cannot make a move, so Bob wins.
In the second test case, there are $3$ piles of stones with $3$, $5$, and $7$ stones respectively. Alice can choose $k = 1$, ... | Title: Prime Split Game
time_limit_ms: 2000
memory_limit_mb: 256
Description: Alice and Bob are playing a game with $n$ piles of stones, where the $i$-th pile has $a_i$ stones. Players take turns making moves, with Alice going first.
On each move, the player does the following three-step process:
1. Choose an integ... |
2007C | https://codeforces.com/problemset/problem/2007/C | Dora and C++ | 1,500 | [
"math",
"number theory"
] | Div. 2 | 2,000 | 256 | Dora has just learned the programming language C++!
However, 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 things to do.
* Choose an ... | Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of test cases follows.
The first line of each test case contains three integers $n$, $a$, and $b$ ($1 \leq n \leq 10^5$, $1 \leq a, b \leq 10^9$) — the length of th... | For each test case, output a single integer — the minimum possible range of the array after any number of operations. | [
[
"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 456876775... | In the first test case, we can increase $c_1 = 1$ by $a = 5$. The array $c$ will become $[6, 3, 4, 4]$, and the range is $3$. Note that there is more than one way to reach the answer.
In the second test case, we can increase $c_1 = 1$ by $a = 2$ and then increase $c_1 = 3$ by $b = 3$. Also, we can increase $c_2 = 3$ b... | Title: Dora and C++
time_limit_ms: 2000
memory_limit_mb: 256
Description: Dora has just learned the programming language C++!
However, 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 op... |
1995E1 | https://codeforces.com/problemset/problem/1995/E1 | Let Me Teach You a Lesson (Easy Version) | 2,700 | [
"2-sat",
"data structures",
"dp",
"matrices",
"two pointers"
] | Div. 2 | 2,000 | 256 | This is the easy version of a problem. The only difference between an easy and a hard version is the constraints on $t$ and $n$. You can make hacks only if both versions of the problem are solved.
Arthur is giving a lesson to his famous $2 n$ knights. Like any other students, they're sitting at the desks in pairs, but... | Each test consists of several test cases. The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. It is followed by descriptions of the test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2000$) — the number of desks.
The second line consists ... | For each test case, output a single line containing one integer — the minimal difference Arthur can achieve. | [
[
"5\n2\n6 6 4 4\n1\n10 17\n3\n1 10 1 10 1 10\n3\n3 3 4 5 5 4\n5\n1 2 3 4 5 6 7 8 9 10",
"0\n0\n0\n2\n4"
]
] | In the first test case, Arthur can swap the second and the fourth knights. Then the total intelligence at both desks will be $10$.
In the third test case, Arthur can make $0$ operations, which will result in the total intelligence of $11$ at each of the desks.
In the fourth test case, Arthur can swap knights with ind... | Title: Let Me Teach You a Lesson (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the easy version of a problem. The only difference between an easy and a hard version is the constraints on $t$ and $n$. You can make hacks only if both versions of the problem are solved.
Arthur is giving a l... |
1994B | https://codeforces.com/problemset/problem/1994/B | Fun Game | 1,100 | [
"bitmasks",
"constructive algorithms",
"greedy",
"math"
] | Div. 1 + 2 | 1,000 | 256 | Vova really loves the [XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation (denoted as $\oplus$). Recently, when he was going to sleep, he came up with a fun game.
At the beginning of the game, Vova chooses two binary sequences $s$ and $t$ of length $n$ and gives them to Vanya. A binary sequence is a s... | Each test consists of multiple test cases. The first line contains an integer $q$ ($1 \le q \le 10^{4}$) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of the sequences $s$ and $t$.
... | For each test case, output "Yes" if the game will be interesting, otherwise output "No".
You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer). | [
[
"6\n1\n0\n1\n7\n0110100\n0110100\n9\n100101010\n101111110\n4\n0011\n1011\n4\n0100\n0001\n8\n10110111\n01100000",
"NO\nYES\nYES\nNO\nYES\nYES"
]
] | In the first test case, Vanya will not be able to change the sequence $s$ with the only possible action of choosing $l = r = 1$.
In the second test case, the sequences $s$ and $t$ are already equal.
In the third test case, Vanya can act as follows:
1. Choose $l = 3$ and $r = 5$, then $s$ will become $\mathtt{10110... | Title: Fun Game
time_limit_ms: 1000
memory_limit_mb: 256
Description: Vova really loves the [XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation (denoted as $\oplus$). Recently, when he was going to sleep, he came up with a fun game.
At the beginning of the game, Vova chooses two binary sequences $s$ a... |
1997D | https://codeforces.com/problemset/problem/1997/D | Maximize the Root | 1,500 | [
"binary search",
"dfs and similar",
"dp",
"greedy",
"trees"
] | Div. 2 | 3,000 | 256 | You are given a rooted tree, consisting of $n$ vertices. The vertices in the tree are numbered from $1$ to $n$, and the root is the vertex $1$. The value $a_i$ is written at the $i$-th vertex.
You can perform the following operation any number of times (possibly zero): choose a vertex $v$ which has at least one child;... | The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of vertices in the tree.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$) — the init... | For each test case, print a single integer — the maximum possible value written at the root using the aforementioned operation. | [
[
"3\n4\n0 1 0 2\n1 1 3\n2\n3 0\n1\n5\n2 5 3 9 6\n3 1 5 2",
"1\n3\n6"
]
] | In the first test case, the following sequence of operations is possible:
* perform the operation on $v=3$, then the values on the vertices will be $[0, 1, 1, 1]$; * perform the operation on $v=1$, then the values on the vertices will be $[1, 0, 0, 0]$. | Title: Maximize the Root
time_limit_ms: 3000
memory_limit_mb: 256
Description: You are given a rooted tree, consisting of $n$ vertices. The vertices in the tree are numbered from $1$ to $n$, and the root is the vertex $1$. The value $a_i$ is written at the $i$-th vertex.
You can perform the following operation any num... |
2030E | https://codeforces.com/problemset/problem/2030/E | MEXimize the Score | 2,200 | [
"combinatorics",
"data structures",
"dp",
"greedy",
"implementation",
"math"
] | Div. 2 | 2,000 | 256 | 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 all... | The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i < n$) — the elements of th... | For each test case, output the answer, modulo $998\,244\,353$. | [
[
"4\n3\n0 0 1\n4\n0 0 1 1\n5\n0 0 1 2 2\n4\n1 1 1 1",
"11\n26\n53\n0"
]
] | In the first testcase, we must consider seven subsequences:
* $[0]$: The score is $1$. * $[0]$: The score is $1$. * $[1]$: The score is $0$. * $[0,0]$: The score is $2$. * $[0,1]$: The score is $2$. * $[0,1]$: The score is $2$. * $[0,0,1]$: The score is $3$.
The answer for the first testcase is $... | Title: MEXimize the Score
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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)$$^{\t... |
2025G | https://codeforces.com/problemset/problem/2025/G | Variable Damage | 3,000 | [
"data structures",
"flows"
] | Div. 2 | 5,000 | 512 | 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 t... | The first line contains one integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries.
In the $i$-th of the following $q$ lines, there are two integers $t_i$ and $v_i$ ($t_i \in \\{1, 2\\}$; $1 \le v_i \le 10^9$) — the type of the query and the value of the query parameter. If the type is $1$, a hero with healt... | Print $q$ integers. After each query, output the maximum number of rounds that Monocarp can survive if he distributes the artifacts optimally. | [
[
"3\n2 5\n1 4\n1 10",
"0\n8\n19"
],
[
"10\n1 9\n1 6\n2 4\n1 8\n1 3\n2 10\n1 3\n1 6\n1 10\n2 6",
"9\n15\n19\n27\n30\n39\n42\n48\n59\n65"
]
] | Let's consider the first example.
* An artifact with durability $5$ is added. Since there are no heroes yet, the battle ends immediately. * A hero with health $4$ is added. Monocarp can give him an artifact with durability $5$. First, there are rounds in which the hero takes $\frac{1}{1 + 1} = \frac{1}{2}$ damage... | Title: Variable Damage
time_limit_ms: 5000
memory_limit_mb: 512
Description: 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.... |
2014C | https://codeforces.com/problemset/problem/2014/C | Robin Hood in Town | 1,100 | [
"binary search",
"greedy",
"math"
] | Div. 3 | 2,000 | 256 | In Sherwood, we judge a man not by his wealth, but by his merit.
Look 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!
There are $n$ people living in the town. Just now, the wealth of the $i$-th person was $a_i$ gold. But gue... | The first line of input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains an integer $n$ ($1 \le n \le 2\cdot10^5$) — the total population.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$) — the wea... | For each test case, output one integer — the minimum number of gold that the richest person must find for Robin Hood to appear. If it is impossible, output $-1$ instead. | [
[
"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",
"-1\n-1\n0\n15\n16\n0"
]
] | In the first test case, it is impossible for a single person to be unhappy.
In the second test case, there is always $1$ happy person (the richest).
In the third test case, no additional gold are required, so the answer is $0$.
In the fourth test case, after adding $15$ gold, the average wealth becomes $\frac{25}{4}... | Title: Robin Hood in Town
time_limit_ms: 2000
memory_limit_mb: 256
Description: In Sherwood, we judge a man not by his wealth, but by his merit.
Look 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!
There are $n$ people livin... |
1987A | https://codeforces.com/problemset/problem/1987/A | Upload More RAM | 800 | [
"greedy",
"math"
] | Div. 1 + 2 | 1,000 | 256 | Oh no, the ForceCodes servers are running out of memory! Luckily, you can help them out by uploading some of your RAM!
You want to upload $n$ GBs of RAM. Every second, you will upload either $0$ or $1$ GB of RAM. However, there is a restriction on your network speed: in any $k$ consecutive seconds, you can upload only... | Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
The first and only line of each test case contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of GBs that you want ... | For each test case, output a single integer — the minimum number of seconds needed to upload $n$ GBs of RAM. | [
[
"6\n5 1\n2 2\n2 3\n1 7\n11 5\n100 100",
"5\n3\n4\n1\n51\n9901"
]
] | In the first test case, you can upload $1$ GB of RAM per second, so to upload $5$ GBs, you need $5$ seconds.
In the second test case, you can upload $1$ GB in the first second, $0$ GBs in the second second, and $1$ GB in the third second, which in total adds up to exactly $2$ GBs of uploaded RAM.
In the third test ca... | Title: Upload More RAM
time_limit_ms: 1000
memory_limit_mb: 256
Description: Oh no, the ForceCodes servers are running out of memory! Luckily, you can help them out by uploading some of your RAM!
You want to upload $n$ GBs of RAM. Every second, you will upload either $0$ or $1$ GB of RAM. However, there is a restricti... |
1982D | https://codeforces.com/problemset/problem/1982/D | Beauty of the mountains | 1,700 | [
"brute force",
"data structures",
"implementation",
"math",
"number theory"
] | Div. 2 | 2,000 | 256 | Nikita loves mountains and has finally decided to visit the Berlyand mountain range! The range was so beautiful that Nikita decided to capture it on a map. The map is a table of $n$ rows and $m$ columns, with each cell containing a non-negative integer representing the height of the mountain.
He also noticed that moun... | Each test consists of several test cases. The first line contains an integer $t$ ($1 \le t \le 10^{4}$) — the number of test cases. This is followed by a description of test cases.
The first line of each test case contains three integers $n, m, k$ ($1 \le n, m \le 500, 1 \le k \le min(n, m)$).
The next $n$ lines of e... | For each test case, output "YES" without quotes if it is possible to equalize the sums of the mountain heights, otherwise output "NO" without quotes. You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer). | [
[
"8\n3 3 2\n7 11 3\n4 2 3\n0 1 15\n100\n010\n000\n4 4 3\n123 413 24 233\n123 42 0 216\n22 1 1 53\n427 763 22 6\n0101\n1111\n1010\n0101\n3 3 2\n2 1 1\n1 1 2\n1 5 4\n010\n101\n010\n3 3 2\n2 1 1\n1 1 2\n1 5 3\n010\n101\n010\n3 4 3\n46 49 50 1\n19 30 23 12\n30 25 1 46\n1000\n0100\n0010\n5 4 4\n39 30 0 17\n22 42 30... | The mountain array from the first test case looks like this:

Initially, the sum of the heights of the mountains with snowy caps is $11 + 3 + 4 + 3 + 0 + 1 + 15 = 37$, and without them is $7 + 2 = 9$.
To equalize these sums, we can perform two transformations:
First... | Title: Beauty of the mountains
time_limit_ms: 2000
memory_limit_mb: 256
Description: Nikita loves mountains and has finally decided to visit the Berlyand mountain range! The range was so beautiful that Nikita decided to capture it on a map. The map is a table of $n$ rows and $m$ columns, with each cell containing a non... |
1972D1 | https://codeforces.com/problemset/problem/1972/D1 | Reverse Card (Easy Version) | 1,400 | [
"brute force",
"math",
"number theory"
] | Div. 2 | 2,000 | 256 | The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved.
You are given two positive integers $n$, $m$.
Calculate the number of ordered pairs $(a, b)$ satisfying the following conditions:
* $1\le a\le n$, $1\le b\le m$; * $a+b$ is a multipl... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le 10^4$). The description of the test cases follows.
The first line of each test case contains two integers $n$, $m$ ($1\le n,m\le 2 \cdot 10^6$).
It is guaranteed that neither the sum of $n$ nor the sum of $m$ over... | For each test case, print a single integer: the number of valid pairs. | [
[
"6\n1 1\n2 3\n3 5\n10 8\n100 1233\n1000000 1145141",
"1\n3\n4\n14\n153\n1643498"
]
] | In the first test case, only $(1,1)$ satisfies the conditions.
In the fourth test case, $(1,1),(2,1),(2,2),(3,1),(4,1),(5,1),(6,1),(6,2),(6,3),(7,1),(8,1),(9,1),(10,1),(10,2)$ satisfy the conditions. | Title: Reverse Card (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved.
You are given two positive integers $n$, $m$.
Calculate the number of ordered pairs $(a, b)$ satisf... |
1987E | https://codeforces.com/problemset/problem/1987/E | Wonderful Tree! | 2,000 | [
"brute force",
"data structures",
"dfs and similar",
"dsu",
"greedy",
"trees"
] | Div. 1 + 2 | 2,000 | 256 | God's Blessing on This ArrayForces!
A Random Pebble
You are given a tree with $n$ vertices, rooted at vertex $1$. The $i$-th vertex has an integer $a_i$ written on it.
Let $L$ be the set of all direct children$^{\text{∗}}$ of $v$. A tree is called wonderful, if for all vertices $v$ where $L$ is not empty, $$a_v \le ... | Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2 \le n \le 5000$) — the number of vertices in the tree.
The second... | For each test case, output a single integer — the minimum number of operations needed to make the tree wonderful. | [
[
"4\n5\n9 3 4 1 2\n1 1 3 3\n2\n5 3\n1\n2\n36 54\n1\n3\n0 0 0\n1 2",
"3\n2\n0\n0"
]
] | The tree in the first test case:

You can apply the operation once on vertex $5$ and twice on vertex $2$ to get a wonderful tree.
In the second test case, you can apply the operation twice on vertex $2$ to get a wonderful tree.
In the third and fourth test cases, th... | Title: Wonderful Tree!
time_limit_ms: 2000
memory_limit_mb: 256
Description: God's Blessing on This ArrayForces!
A Random Pebble
You are given a tree with $n$ vertices, rooted at vertex $1$. The $i$-th vertex has an integer $a_i$ written on it.
Let $L$ be the set of all direct children$^{\text{∗}}$ of $v$. A tree is... |
1999F | https://codeforces.com/problemset/problem/1999/F | Expected Median | 1,500 | [
"combinatorics",
"math"
] | Div. 4 | 3,000 | 256 | Arul has a binary array$^{\text{∗}}$ $a$ of length $n$.
He will take all subsequences$^{\text{†}}$ of length $k$ ($k$ is odd) of this array and find their median.$^{\text{‡}}$
What is the sum of all these values?
As this sum can be very large, output it modulo $10^9 + 7$. In other words, print the remainder of this ... | The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 2 \cdot 10^5$, $k$ is odd) — the length of the array and the length of the subsequence, respectively.
The second line of each test c... | For each test case, print the sum modulo $10^9 + 7$. | [
[
"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",
"2\n5\n0\n16\n4\n7\n0\n333606206"
]
] | In the first test case, there are four subsequences of $[1,0,0,1]$ with length $k=3$:
* $[1,0,0]$: median $= 0$. * $[1,0,1]$: median $= 1$. * $[1,0,1]$: median $= 1$. * $[0,0,1]$: median $= 0$.
The sum of the results is $0+1+1+0=2$.
In the second test case, all subsequences of length $1$ have median $1$,... | Title: Expected Median
time_limit_ms: 3000
memory_limit_mb: 256
Description: Arul has a binary array$^{\text{∗}}$ $a$ of length $n$.
He will take all subsequences$^{\text{†}}$ of length $k$ ($k$ is odd) of this array and find their median.$^{\text{‡}}$
What is the sum of all these values?
As this sum can be very lar... |
1985H1 | https://codeforces.com/problemset/problem/1985/H1 | Maximize the Largest Component (Easy Version) | 1,700 | [
"brute force",
"data structures",
"dfs and similar",
"dsu",
"graphs",
"implementation"
] | Div. 4 | 2,000 | 512 | Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. The only difference between the two versions is the operation.
Alex has a grid with $n$ rows and $m$ columns consisting of '.' and '#' characters. A set of '#' cells forms a connected component if from... | The first line of the input contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first line of each test case contains two integers $n$ and $m$ ($1 \le n \cdot m \le 10^6$) — the number of rows and columns of the grid.
The next $n$ lines each contain $m$ characters. Each character is e... | For each test case, output a single integer — the maximum possible size of a connected component of '#' cells that Alex can achieve. | [
[
"6\n1 1\n.\n4 2\n..\n#.\n#.\n.#\n3 5\n.#.#.\n..#..\n.#.#.\n5 5\n#...#\n....#\n#...#\n.....\n...##\n6 6\n.#..#.\n#..#..\n.#...#\n#.#.#.\n.#.##.\n###..#\n6 8\n..#....#\n.####.#.\n###.#..#\n.##.#.##\n.#.##.##\n#..##.#.",
"1\n6\n9\n11\n15\n30"
]
] | In the second test case, it is optimal for Alex to set all cells in column $2$ to be '#'. Doing so will lead to the largest connected component of '#' having a size of $6$.
In the third test case, it is optimal for Alex to set all cells in row $2$ to be '#'. Doing so will lead to the largest connected component of '#'... | Title: Maximize the Largest Component (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 512
Description: Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. The only difference between the two versions is the operation.
Alex has a grid with $n$ rows a... |
1996E | https://codeforces.com/problemset/problem/1996/E | Decode | 1,600 | [
"combinatorics",
"data structures",
"implementation",
"math"
] | Div. 3 | 2,000 | 256 | In a desperate attempt to obtain your waifu favorite character, you have hacked into the source code of the game. After days of struggling, you finally find the binary string that encodes the gacha system of the game. In order to decode it, you must first solve the following problem.
You are given a binary string $s$ ... | The first line contains $t$ ($1 \leq t \leq 1000$) — the number of test cases.
Each test case contains a binary string $s$ ($1 \leq |s| \leq 2 \cdot 10^5$). It is guaranteed $s$ only contains characters $\mathtt{0}$ and $\mathtt{1}$.
It is guaranteed the sum of $|s|$ over all test cases does not exceed $2 \cdot 10^5$... | For each test case, output an integer, the answer modulo $10^9+7$. | [
[
"4\n0000\n01010101\n1100111001\n11000000111",
"0\n130\n147\n70"
]
] | Title: Decode
time_limit_ms: 2000
memory_limit_mb: 256
Description: In a desperate attempt to obtain your waifu favorite character, you have hacked into the source code of the game. After days of struggling, you finally find the binary string that encodes the gacha system of the game. In order to decode it, you must fi... | |
2001A | https://codeforces.com/problemset/problem/2001/A | Make All Equal | 800 | [
"greedy",
"implementation"
] | Div. 2 | 1,000 | 256 | You are given a cyclic array $a_1, a_2, \ldots, a_n$.
You can perform the following operation on $a$ at most $n - 1$ times:
* 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_1$ are adjacent and $a_m$ i... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the length of the array $a$.
The second line of each test case contains $n$ ... | For each test case, output a single line containing an integer: the minimum number of operations needed to make all elements in $a$ equal. | [
[
"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",
"0\n2\n1\n4\n4\n6\n3"
]
] | In the first test case, there is only one element in $a$, so we can't do any operation.
In the second test case, we can perform the following operations to make all elements in $a$ equal:
* choose $i = 2$, delete $a_3$, then $a$ would become $[1, 2]$. * choose $i = 1$, delete $a_1$, then $a$ would become $[2]$. ... | Title: Make All Equal
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are given a cyclic array $a_1, a_2, \ldots, a_n$.
You can perform the following operation on $a$ at most $n - 1$ times:
* Let $m$ be the current size of $a$, you can choose any two adjacent elements where the previous one is no greater ... |
2022A | https://codeforces.com/problemset/problem/2022/A | Bus to Pénjamo | 800 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | Div. 2 | 1,000 | 256 | 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 i... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.
The first line of each test case contains two integers $n$ and $r$ ($1 \le n \le 100$; $1 \le r \le 500$) — the number of families and the number of rows in the ... | For each test case, output the maximum number of happy people in an optimal seating arrangement. | [
[
"4\n3 3\n2 3 1\n3 3\n2 2 2\n4 5\n1 1 2 2\n4 5\n3 1 1 3",
"4\n6\n6\n6"
]
] | In the first test case, the two members of the first family can sit together in the first row, while the two members of the second family can sit together in the second row. The remaining member of the second family can sit in the third row along with a member of the third family. This seating arrangement is shown belo... | Title: Bus to Pénjamo
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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... |
2007A | https://codeforces.com/problemset/problem/2007/A | Dora's Set | 800 | [
"greedy",
"math",
"number theory"
] | Div. 2 | 1,000 | 256 | 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:
* Select three distinct integers $a$, $b$, and $c$ fro... | Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 500$) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers $l$ and $r$ ($1 \leq l \leq r \leq 1000$) — the range of integers in the initial set... | For each test case, output a single integer — the maximum number of operations you can perform. | [
[
"8\n1 3\n3 7\n10 21\n2 8\n51 60\n2 15\n10 26\n1 1000",
"1\n1\n3\n1\n2\n3\n4\n250"
]
] | In the first test case, you can choose $a = 1$, $b = 2$, $c = 3$ in the only operation, since $\gcd(1, 2) = \gcd(2, 3) = \gcd(1, 3) = 1$, and then there are no more integers in the set, so no more operations can be performed.
In the second test case, you can choose $a = 3$, $b = 5$, $c = 7$ in the only operation.
In ... | Title: Dora's Set
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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 followi... |
1987F1 | https://codeforces.com/problemset/problem/1987/F1 | Interesting Problem (Easy Version) | 2,500 | [
"dp"
] | Div. 1 + 2 | 2,000 | 256 | This is the easy version of the problem. The only difference between the two versions is the constraint on $n$. You can make hacks only if both versions of the problem are solved.
You are given an array of integers $a$ of length $n$.
In one operation, you will perform the following two-step process:
1. Choose an i... | Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the length of the array $a$.
The second line of ... | For each test case, output a single integer — the maximum number of times that you can perform the operation. | [
[
"6\n5\n1 5 3 2 4\n8\n2 1 3 4 5 6 7 8\n3\n1 2 3\n4\n1 2 4 4\n5\n4 4 1 3 5\n1\n1",
"2\n3\n1\n2\n0\n0"
]
] | In the first test case, one possible optimal sequence of operations is $[ 1, 5, \color{red}{3}, \color{red}{2}, 4 ] \rightarrow [\color{red}{1}, \color{red}{5}, 4] \rightarrow [4]$.
In the third test case, one possible optimal sequence of operations is $[1, \color{red}{2}, \color{red}{3}] \rightarrow [1]$. | Title: Interesting Problem (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the easy version of the problem. The only difference between the two versions is the constraint on $n$. You can make hacks only if both versions of the problem are solved.
You are given an array of integers $a$ of l... |
1980G | https://codeforces.com/problemset/problem/1980/G | Yasya and the Mysterious Tree | 2,300 | [
"bitmasks",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"strings",
"trees"
] | Div. 3 | 2,500 | 512 | Yasya was walking in the forest and accidentally found a tree with $n$ vertices. A tree is a connected undirected graph with no cycles.
Next to the tree, the girl found an ancient manuscript with $m$ queries written on it. The queries can be of two types.
The first type of query is described by the integer $y$. The w... | The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The descriptions of the test cases follow.
The first line of each test case contains two integers $n$, $m$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m \le 2 \cdot 10^5$) — the number of vertices in the tree and the number of queries.
T... | For each test case, output the answers to the queries of the second type. | [
[
"2\n3 7\n1 2 1\n3 1 8\n^ 5\n? 2 9\n^ 1\n? 1 10\n^ 6\n? 3 1\n? 2 9\n5 6\n1 2 777\n3 2 2812\n4 1 16\n5 3 1000000000\n^ 4\n? 3 123\n? 5 1000000000\n^ 1000000000\n? 1 908070\n? 2 1",
"13 15 11 10 \n1000000127 2812 999756331 999999756"
],
[
"3\n8 4\n8 6 3\n6 3 4\n2 5 4\n7 6 2\n7 1 10\n4 1 4\n5 1 2\n^ 4... | Title: Yasya and the Mysterious Tree
time_limit_ms: 2500
memory_limit_mb: 512
Description: Yasya was walking in the forest and accidentally found a tree with $n$ vertices. A tree is a connected undirected graph with no cycles.
Next to the tree, the girl found an ancient manuscript with $m$ queries written on it. The q... | |
1975F | https://codeforces.com/problemset/problem/1975/F | Set | 2,600 | [
"bitmasks",
"brute force",
"combinatorics",
"dfs and similar",
"divide and conquer",
"dp",
"math"
] | Div. 1 + 2 | 2,000 | 512 | Define the binary encoding of a finite set of natural numbers $T \subseteq \\{0,1,2,\ldots\\}$ as $f(T) = \sum\limits_{i \in T} 2^i$. For example, $f(\\{0,2\\}) = 2^0 + 2^2 = 5$ and $f(\\{\\}) = 0$. Notice that $f$ is a bijection from all such sets to all non-negative integers. As such, $f^{-1}$ is also defined.
You a... | The first line of input contains a single integer $n$ ($1 \leq n \leq 20$).
The second line of input contains $2^n-1$ integers $v_1,v_2,\ldots,v_{2^n-1}$ ($0 \leq v_i < 2^{n+1}$) — the sets $V_i$ given in their binary encoding where $V_i = f^{-1}(v_i)$. | The first line of output should contain an integer $k$ indicating the number of possible $S$.
In the following $k$ lines, you should output $f(S)$ for all possible $S$ in increasing order. | [
[
"3\n15 15 15 15 15 15 12",
"4\n3\n5\n6\n7"
],
[
"5\n63 63 63 63 6 63 63 63 63 63 63 5 63 63 63 63 63 63 8 63 63 63 63 2 63 63 63 63 63 63 63",
"1\n19"
]
] | In the first test case, one possible $S$ is $f^{-1}(3) = \\{0,1\\}$. All the non-empty subsets $T \subseteq \\{0,1,2\\}$ and the corresponding $|S \cap T|$, $f(T)$ and $V_f(T)$ are as follows:
$T$| $|S\cap T|$| $f(T)$| $V_{f(T)}$ ---|---|---|--- $\\{0\\}$| $1$| $1$| $\\{0,1,2,3\\}$ $\\{1\\}$| $1$| $2$| $\\{0,1,2... | Title: Set
time_limit_ms: 2000
memory_limit_mb: 512
Description: Define the binary encoding of a finite set of natural numbers $T \subseteq \\{0,1,2,\ldots\\}$ as $f(T) = \sum\limits_{i \in T} 2^i$. For example, $f(\\{0,2\\}) = 2^0 + 2^2 = 5$ and $f(\\{\\}) = 0$. Notice that $f$ is a bijection from all such sets to all... |
1974B | https://codeforces.com/problemset/problem/1974/B | Symmetric Encoding | 800 | [
"implementation",
"sortings",
"strings"
] | Div. 3 | 2,000 | 256 | Polycarp has a string $s$, which consists of lowercase Latin letters. He encodes this string using the following algorithm:
* first, he constructs a new auxiliary string $r$, which consists of all distinct letters of the string $s$, written in alphabetical order; * then the encoding happens as follows: each chara... | The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the string $b$.
The second line of each test case contains a string $b$ of length $n$, consisting of lowercase Latin... | For each test case, output the string $s$ from which the encoding result $b$ was obtained. | [
[
"5\n10\nserofedsoc\n3\nttf\n9\ntlrhgmaoi\n1\nw\n15\nhnndledmnhlttin",
"codeforces\nfft\nalgorithm\nw\nmeetinthemiddle"
]
] | Title: Symmetric Encoding
time_limit_ms: 2000
memory_limit_mb: 256
Description: Polycarp has a string $s$, which consists of lowercase Latin letters. He encodes this string using the following algorithm:
* first, he constructs a new auxiliary string $r$, which consists of all distinct letters of the string $s$, writ... | |
2036D | https://codeforces.com/problemset/problem/2036/D | I Love 1543 | 1,300 | [
"brute force",
"implementation",
"matrices"
] | Div. 3 | 2,000 | 256 | One morning, Polycarp woke up and realized that $1543$ is the most favorite number in his life.
The first thing that Polycarp saw that day as soon as he opened his eyes was a large wall carpet of size $n$ by $m$ cells; $n$ and $m$ are even integers. Each cell contains one of the digits from $0$ to $9$.
Polycarp becam... | The first line of the input contains a single integer $t$ ($1 \leq t \leq 100$) — the number of test cases. The following lines describe the test cases.
The first line of each test case contains a pair of numbers $n$ and $m$ ($2 \leq n, m \leq 10^3$, $n, m$ — even integers).
This is followed by $n$ lines of length $m... | For each test case, output a single number — the total number of times $1543$ appears in all layers of the carpet in the order of traversal clockwise. | [
[
"8\n2 4\n1543\n7777\n2 4\n7154\n8903\n2 4\n3451\n8888\n2 2\n54\n13\n2 2\n51\n43\n2 6\n432015\n512034\n4 4\n5431\n1435\n5518\n7634\n6 4\n5432\n1152\n4542\n2432\n2302\n5942",
"1\n1\n0\n1\n0\n2\n2\n2"
]
] |  Occurrences of $1543$ in the seventh example. Different layers are colored in different colors. | Title: I Love 1543
time_limit_ms: 2000
memory_limit_mb: 256
Description: One morning, Polycarp woke up and realized that $1543$ is the most favorite number in his life.
The first thing that Polycarp saw that day as soon as he opened his eyes was a large wall carpet of size $n$ by $m$ cells; $n$ and $m$ are even intege... |
2006E | https://codeforces.com/problemset/problem/2006/E | Iris's Full Binary Tree | 3,100 | [
"brute force",
"data structures",
"dfs and similar",
"trees"
] | Div. 1 | 4,000 | 1,024 | Iris likes full binary trees.
Let'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.
Iris calls a tree a $d$-binary tree if some vertices and edges can be... | Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2 \leq n \leq 5 \cdot 10^5$) — the final size of the tree.
The second l... | For each test case output $n$ integers, $i$-th of them representing the binary depth of the tree formed by the first $i$ vertices. | [
[
"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",
"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 4 4 5 ... | In the first test case, the final tree is shown below:

* The tree consisting of the vertex $1$ has the binary depth $1$ (the tree itself is a full binary tree of depth $1$). * The tree consisting of the vertices $1$ and $2$ has the binary depth $2$ (we can add t... | Title: Iris's Full Binary Tree
time_limit_ms: 4000
memory_limit_mb: 1024
Description: Iris likes full binary trees.
Let'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... |
1988A | https://codeforces.com/problemset/problem/1988/A | Split the Multiset | 900 | [
"brute force",
"greedy",
"implementation",
"math"
] | Div. 2 | 1,000 | 512 | A multiset is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. For example, $\\{2,2,4\\}$ is a multiset.
You have a multiset $S$. Initially, the multiset contains only one positive integer $n$. That is, $S=\\{n\\}$. Additionally, there is a given positive integer $k$... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.
The only line of each testcase contains two integers $n,k$ ($1\le n\le 1000,2\le k\le 1000$). | For each testcase, print one integer, which is the required answer. | [
[
"4\n1 5\n5 2\n6 3\n16 4",
"0\n4\n3\n5"
]
] | For the first test case, initially $S=\\{1\\}$, already satisfying the requirement. Therefore, we need zero operations.
For the second test case, initially $S=\\{5\\}$. We can apply the following operations:
* Select $u=5$, remove $u$ from $S$, and insert $2,3$ into $S$. Now, $S=\\{2,3\\}$. * Select $u=2$, remov... | Title: Split the Multiset
time_limit_ms: 1000
memory_limit_mb: 512
Description: A multiset is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. For example, $\\{2,2,4\\}$ is a multiset.
You have a multiset $S$. Initially, the multiset contains only one positive intege... |
2020B | https://codeforces.com/problemset/problem/2020/B | Brightness Begins | 1,200 | [
"binary search",
"math"
] | Div. 2 | 1,000 | 256 | 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^... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The only line of each test case contains a single integer $k$ ($1 \le k \le 10^{18}$). | For each test case, output $n$ — the minimum number of bulbs. | [
[
"3\n1\n3\n8",
"2\n5\n11"
]
] | In the first test case, the minimum number of bulbs is $2$. Let's denote the state of all bulbs with an array, where $1$ corresponds to a turned on bulb, and $0$ corresponds to a turned off bulb. Initially, the array is $[1, 1]$.
* After performing the operation with $i = 1$, the array becomes $[\underline{0}, \unde... | Title: Brightness Begins
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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... |
1992G | https://codeforces.com/problemset/problem/1992/G | Ultra-Meow | 2,000 | [
"combinatorics",
"dp",
"math"
] | Div. 3 | 2,500 | 256 | K1o0n gave you an array $a$ of length $n$, consisting of numbers $1, 2, \ldots, n$. Accept it? Of course! But what to do with it? Of course, calculate $\text{MEOW}(a)$.
Let $\text{MEX}(S, k)$ be the $k$-th positive (strictly greater than zero) integer in ascending order that is not present in the set $S$. Denote $\tex... | The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
In a single line of each test case, an integer $n$ ($1 \le n \le 5000$) is entered, the size of the array of gifted numbers.
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $25 \cdot 10^6$. | For each test case, output a single number — $\text{MEOW}(a)$. Since it may be very large, output it modulo $10^9 + 7$. | [
[
"5\n2\n3\n4999\n5\n1",
"12\n31\n354226409\n184\n4"
]
] | Title: Ultra-Meow
time_limit_ms: 2500
memory_limit_mb: 256
Description: K1o0n gave you an array $a$ of length $n$, consisting of numbers $1, 2, \ldots, n$. Accept it? Of course! But what to do with it? Of course, calculate $\text{MEOW}(a)$.
Let $\text{MEX}(S, k)$ be the $k$-th positive (strictly greater than zero) int... | |
1974F | https://codeforces.com/problemset/problem/1974/F | Cutting Game | 1,900 | [
"binary search",
"brute force",
"data structures",
"implementation",
"sortings",
"two pointers"
] | Div. 3 | 3,000 | 256 | Alice and Bob were playing a game again. They have a grid of size $a \times b$ ($1 \le a, b \le 10^9$), on which there are $n$ chips, with at most one chip in each cell. The cell at the intersection of the $x$-th row and the $y$-th column has coordinates $(x, y)$.
Alice made the first move, and the players took turns.... | The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains four integers $a$, $b$, $n$, and $m$ ($2 \le a, b \le 10^9$, $1 \le n, m \le 2 \cdot 10^5$) — the dimensions of the grid, the number of chips, and the number of moves.
Each of the ne... | For each test case, output two integers — the number of points earned by Alice and Bob, respectively. | [
[
"6\n4 4 3 2\n4 1\n3 3\n2 4\nD 2\nR 1\n4 4 3 3\n4 1\n3 2\n2 3\nD 1\nL 1\nU 2\n3 5 3 2\n1 3\n2 2\n3 3\nR 2\nR 2\n6 4 4 2\n1 4\n2 3\n5 3\n1 1\nR 1\nU 1\n9 3 2 1\n6 1\n3 3\nD 8\n10 10 2 5\n7 5\n9 1\nR 1\nL 2\nD 1\nU 4\nD 1",
"2 1\n2 0\n0 3\n1 1\n2 0\n0 1"
]
] | Below is the game from the first example:

On her turn, Alice cut $2$ rows from the bottom and scored $2$ points, then Bob cut $1$ column from the right and scored one point. Note that if Bob had cut $1$ row from the bottom, he would have also scored $1$ point. | Title: Cutting Game
time_limit_ms: 3000
memory_limit_mb: 256
Description: Alice and Bob were playing a game again. They have a grid of size $a \times b$ ($1 \le a, b \le 10^9$), on which there are $n$ chips, with at most one chip in each cell. The cell at the intersection of the $x$-th row and the $y$-th column has coo... |
2013B | https://codeforces.com/problemset/problem/2013/B | Battle for Survive | 900 | [
"constructive algorithms",
"greedy",
"math"
] | Div. 2 | 1,000 | 256 | Eralim, being the mafia boss, manages a group of $n$ fighters. Fighter $i$ has a rating of $a_i$.
Eralim 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 eliminated from the tournament,... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of fighters.
The second line of each test case contains... | For each testcase, output a single integer — the maximum rating that the last remaining fighter can preserve. | [
[
"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",
"-1\n8\n2\n7\n8"
]
] | In the first example, you can arrange a fight between fighters with indices $1$ and $2$, where the fighter with index $2$ will win. The rating of the last fighter, that is, the fighter with index $2$, will be $1 - 2 = -1$.
In the second example, you can first conduct a fight between fighters with indices $1$ and $2$, ... | Title: Battle for Survive
time_limit_ms: 1000
memory_limit_mb: 256
Description: Eralim, being the mafia boss, manages a group of $n$ fighters. Fighter $i$ has a rating of $a_i$.
Eralim 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 chose... |
1975B | https://codeforces.com/problemset/problem/1975/B | 378QAQ and Mocha's Array | 1,000 | [
"brute force",
"greedy",
"math",
"sortings"
] | Div. 1 + 2 | 1,000 | 256 | Mocha likes arrays, so before her departure, 378QAQ gave her an array $a$ consisting of $n$ positive integers as a gift.
Mocha thinks that $a$ is beautiful if there exist two numbers $i$ and $j$ ($1\leq i,j\leq n$, $i\neq j$) such that for all $k$ ($1 \leq k \leq n$), $a_k$ is divisible$^\dagger$ by either $a_i$ or $a... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\leq t\leq 500$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($3\leq n\leq 10^5$) — the length of the array $a$.
The second line of each test case contains $n$... | For each test case, output "Yes" if array $a$ is beautiful, and output "No" otherwise.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response). | [
[
"4\n3\n7 3 8\n5\n7 1 9 3 5\n5\n4 12 2 6 3\n5\n7 49 9 3 1000000000",
"No\nYes\nYes\nNo"
]
] | In the first test case, any two numbers in the array are coprime, so the answer is "No".
In the second test case, we can pick $i=2$ and $j=1$. Since every number in the array is divisible by $a_i = 1$, the answer is "Yes".
In the third test case, we can pick $i=3$ and $j=5$. $2$ and $4$ is divisible by $a_i = 2$ whil... | Title: 378QAQ and Mocha's Array
time_limit_ms: 1000
memory_limit_mb: 256
Description: Mocha likes arrays, so before her departure, 378QAQ gave her an array $a$ consisting of $n$ positive integers as a gift.
Mocha thinks that $a$ is beautiful if there exist two numbers $i$ and $j$ ($1\leq i,j\leq n$, $i\neq j$) such th... |
2025A | https://codeforces.com/problemset/problem/2025/A | Two Screens | 800 | [
"binary search",
"greedy",
"strings",
"two pointers"
] | Div. 2 | 2,000 | 512 | 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 ... | The first line contains one integer $q$ ($1 \le q \le 500$) — the number of test cases.
Each test case consists of two lines. The first line contains the string $s$, and the second line contains the string $t$ ($1 \le |s|, |t| \le 100$). Both strings consist of uppercase Latin letters. | For each test case, print one integer — the minimum possible number of seconds you have to spend so that the first screen displays the sequence $s$, and the second screen displays the sequence $t$. | [
[
"3\nGARAGE\nGARAGEFORSALE\nABCDE\nAABCD\nTRAINING\nDRAINING",
"14\n10\n16"
]
] | In the first test case, the following sequence of actions is possible:
* spend $6$ seconds to write the sequence GARAGE on the first screen; * copy the sequence from the first screen to the second screen; * spend $7$ seconds to complete the sequence on the second screen by writing FORSALE.
In the second test... | Title: Two Screens
time_limit_ms: 2000
memory_limit_mb: 512
Description: 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... |
2000E | https://codeforces.com/problemset/problem/2000/E | Photoshoot for Gorillas | 1,400 | [
"combinatorics",
"data structures",
"greedy",
"math"
] | Div. 3 | 2,000 | 256 | 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$. You want to place all th... | The first line contains an integer $t$ ($1 \le t \le 10^3$) — the number of test cases.
The descriptions of the test cases follow.
The first line contains integers $n$, $m$, $k$ ($1 \le n, m \le 2 \cdot 10^5$, $1 \le n \cdot m \le 2 \cdot 10^5$, $1 \le k \le \min(n, m)$) — the dimensions of the grid and the side leng... | For each test case, output a single integer — the maximum spectacle of a suitable arrangement. | [
[
"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",
"21\n12\n49000083104\n3512\n319"
]
] | In the first test case of the first input set, the spectacle of the following sub-squares is summed:
 Yellow color corresponds to the sub-squares, green — to the rest of the grid squares.
The picture shows the optimal arrangement of the gorillas. The spectacle of the ... | Title: Photoshoot for Gorillas
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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 gor... |
1988E | https://codeforces.com/problemset/problem/1988/E | Range Minimum Sum | 2,300 | [
"binary search",
"brute force",
"data structures",
"divide and conquer",
"implementation"
] | Div. 2 | 4,000 | 512 | For an array $[a_1,a_2,\ldots,a_n]$ of length $n$, define $f(a)$ as the sum of the minimum element over all subsegments. That is, $$f(a)=\sum_{l=1}^n\sum_{r=l}^n \min_{l\le i\le r}a_i.$$
A permutation is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. You are given a permutati... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1\le n\le 5\cdot 10^5$).
The second line of each test case contains $n$ distinct integers $a_1,\ldots,a_n... | For each test case, print one line containing $n$ integers. The $i$-th integer should be the answer when erasing $a_i$. | [
[
"4\n1\n1\n3\n3 1 2\n5\n4 2 1 5 3\n8\n8 1 4 6 7 3 5 2",
"0 \n4 7 5 \n19 21 27 17 19 \n79 100 72 68 67 80 73 80"
]
] | In the second test case, $a=[3,1,2]$.
* When removing $a_1$, $b=[1,2]$. $f(b)=1+2+\min\\{1,2\\}=4$. * When removing $a_2$, $b=[3,2]$. $f(b)=3+2+\min\\{3,2\\}=7$. * When removing $a_3$, $b=[3,1]$. $f(b)=3+1+\min\\{3,1\\}=5$. | Title: Range Minimum Sum
time_limit_ms: 4000
memory_limit_mb: 512
Description: For an array $[a_1,a_2,\ldots,a_n]$ of length $n$, define $f(a)$ as the sum of the minimum element over all subsegments. That is, $$f(a)=\sum_{l=1}^n\sum_{r=l}^n \min_{l\le i\le r}a_i.$$
A permutation is a sequence of integers from $1$ to $... |
1996A | https://codeforces.com/problemset/problem/1996/A | Legs | 800 | [
"binary search",
"math",
"ternary search"
] | Div. 3 | 2,000 | 256 | It's another beautiful day on Farmer John's farm.
After Farmer John arrived at his farm, he counted $n$ legs. It is known only chickens and cows live on the farm, and a chicken has $2$ legs while a cow has $4$.
What is the minimum number of animals Farmer John can have on his farm assuming he counted the legs of all ... | The first line contains single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.
Each test case contains an integer $n$ ($2 \leq n \leq 2 \cdot 10^3$, $n$ is even). | For each test case, output an integer, the minimum number of animals Farmer John can have on his farm. | [
[
"3\n2\n6\n8",
"1\n2\n2"
]
] | Title: Legs
time_limit_ms: 2000
memory_limit_mb: 256
Description: It's another beautiful day on Farmer John's farm.
After Farmer John arrived at his farm, he counted $n$ legs. It is known only chickens and cows live on the farm, and a chicken has $2$ legs while a cow has $4$.
What is the minimum number of animals Far... | |
2028E | https://codeforces.com/problemset/problem/2028/E | Alice's Adventures in the Rabbit Hole | 2,300 | [
"combinatorics",
"dfs and similar",
"dp",
"games",
"greedy",
"math",
"probabilities",
"trees"
] | Div. 2 | 2,000 | 256 | 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 hea... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$) — the number of vertices in the tree.
The $i$-th of the next $n - 1$ li... | For each test case, output $n$ integers on one line — the probabilities of Alice escaping starting from vertex $1, 2, \ldots, n$. Since these probabilities can be very small, output them modulo $998\,244\,353$. | [
[
"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",
"1 499122177 499122177 0 0 \n1 499122177 0 332748118 166374059 0 443664157 720954255 0"
]
] | For the first test case:
1. Alice escapes from the root (vertex $1$) by definition with probability $1$. 2. Alice immediately loses from vertices $4$ and $5$ since they are leaves. 3. From the other two vertices, Alice escapes with probability $\frac 12$ since the Queen will pull her to the leaves. | Title: Alice's Adventures in the Rabbit Hole
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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, t... |
1999E | https://codeforces.com/problemset/problem/1999/E | Triple Operations | 1,300 | [
"dp",
"implementation",
"math"
] | Div. 4 | 1,000 | 256 | On the board Ivy wrote down all integers from $l$ to $r$, inclusive.
In an operation, she does the following:
* 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 rounding down to the nearest int... | The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The only line of each test case contains two integers $l$ and $r$ ($1 \leq l < r \leq 2 \cdot 10^5$). | For each test case, output a single integer — the minimum number of operations needed to make all numbers on the board equal $0$. | [
[
"4\n1 3\n2 4\n199999 200000\n19 84",
"5\n6\n36\n263"
]
] | In the first test case, we can perform $5$ operations as follows: $$ 1,2,3 \xrightarrow[x=1,\,y=2]{} 3,0,3 \xrightarrow[x=0,\,y=3]{} 1,0,3 \xrightarrow[x=0,\,y=3]{} 1,0,1 \xrightarrow[x=0,\,y=1]{} 0,0,1 \xrightarrow[x=0,\,y=1]{} 0,0,0 .$$ | Title: Triple Operations
time_limit_ms: 1000
memory_limit_mb: 256
Description: On the board Ivy wrote down all integers from $l$ to $r$, inclusive.
In an operation, she does the following:
* pick two numbers $x$ and $y$ on the board, erase them, and in their place write the numbers $3x$ and $\lfloor \frac{y}{3} \rf... |
1983B | https://codeforces.com/problemset/problem/1983/B | Corner Twist | 1,200 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | Div. 2 | 1,000 | 256 | You are given two grids of numbers $a$ and $b$, with $n$ rows and $m$ columns. All the values in the grid are $0$, $1$ or $2$.
You can perform the following operation on $a$ any number of times:
* Pick any subrectangle in the grid with length and width $\ge 2$. You are allowed to choose the entire grid as a subrect... | The first line contains an integer $t$, the number of testcases ($1 \le t \le 250$).
For each testcase:
The first line contains two integers $n$ and $m$, the number of rows and columns in the grid ($2 \le n,m \le 500$).
Each of the next n lines contain m characters — the $j$-th character of the $i$-th line represent... | For each test case print "YES" (without quotes) if it is possible to convert grid $a$ into grid $b$ and "NO" (without quotes) otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"7\n3 3\n000\n000\n000\n111\n111\n111\n4 4\n0000\n0000\n0000\n0000\n2100\n1200\n0012\n0021\n4 4\n1020\n1200\n1210\n0000\n0000\n1200\n2200\n0000\n3 3\n012\n012\n012\n010\n111\n011\n8 8\n00000000\n00000000\n00000000\n00000000\n00000000\n00000000\n00000000\n10000000\n00000000\n01200000\n02010000\n00102000\n00020... | In the first testcase, grid $a$ can be converted into $b$ in the following manner:
$\begin{matrix}\fbox{0} & 0 & \fbox{0}\\\ 0 & 0 & 0\\\ \fbox{0} & 0 & \fbox{0}\end{matrix} \Rightarrow \begin{matrix}1 & 0 & 2\\\ 0 & \fbox{0} & \fbox{0}\\\ 2 & \fbox{0} & \fbox{1}\end{matrix} \Rightarrow \begin{matrix}1 & 0 & 2\\\ \fbo... | Title: Corner Twist
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are given two grids of numbers $a$ and $b$, with $n$ rows and $m$ columns. All the values in the grid are $0$, $1$ or $2$.
You can perform the following operation on $a$ any number of times:
* Pick any subrectangle in the grid with length... |
1995B2 | https://codeforces.com/problemset/problem/1995/B2 | Bouquet (Hard Version) | 1,700 | [
"binary search",
"data structures",
"greedy",
"math",
"sortings",
"two pointers"
] | Div. 2 | 1,500 | 256 | This is the hard version of the problem. The only difference is that in this version, instead of listing the number of petals for each flower, the number of petals and the quantity of flowers in the store is set for all types of flowers.
A girl is preparing for her birthday and wants to buy the most beautiful bouquet.... | Each test consists of several test cases. The first line contains a single integer $t$ ($1 \le t \le 10\,000$) — the number of test cases. This is followed by descriptions of the test cases.
The first line of each test case contains two integers $n$, $m$ ($1 \le n \le 2 \cdot 10^5, 1 \le m \le 10^{18}$) — the number o... | For each test case, print one integer — the maximum possible number of petals in a bouquet that a girl can collect, observing all the conditions listed above. | [
[
"7\n3 10\n1 2 3\n2 2 1\n3 1033\n206 207 1000\n3 4 1\n6 20\n4 2 7 5 6 1\n1 2 1 3 1 7\n8 100000\n239 30 610 122 24 40 8 2\n12 13123 112 1456 124 100 123 10982\n6 13\n2 4 11 1 3 5\n2 2 1 2 2 1\n8 10330\n206 210 200 201 198 199 222 1000\n9 10 11 12 13 14 15 16\n2 10000000000\n11 12\n87312315 753297050",
"7\n1... | In the first test case, some valid bouquets are $(1, 1, 2, 2), (2, 2, 3), (1, 1), (2, 2)$. The maximum over all valid bouquets not greater than $10$ is $7$ for $(2, 2, 3)$. In the second test case, you can assemble a valid bouquet with $(206, 206, 207, 207, 207)$ with a sum of $1033$, which is the maximum number of pet... | Title: Bouquet (Hard Version)
time_limit_ms: 1500
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version, instead of listing the number of petals for each flower, the number of petals and the quantity of flowers in the store is set for all types of flowers... |
1985B | https://codeforces.com/problemset/problem/1985/B | Maximum Multiple Sum | 800 | [
"brute force",
"math",
"number theory"
] | Div. 4 | 1,000 | 256 | Given an integer $n$, find an integer $x$ such that:
* $2 \leq x \leq n$. * The sum of multiples of $x$ that are less than or equal to $n$ is maximized. Formally, $x + 2x + 3x + \dots + kx$ where $kx \leq n$ is maximized over all possible values of $x$. | The first line contains $t$ ($1 \leq t \leq 100$) — the number of test cases.
Each test case contains a single integer $n$ ($2 \leq n \leq 100$). | For each test case, output an integer, the optimal value of $x$. It can be shown there is only one unique answer. | [
[
"2\n3\n15",
"3\n2"
]
] | For $n = 3$, the possible values of $x$ are $2$ and $3$. The sum of all multiples of $2$ less than or equal to $n$ is just $2$, and the sum of all multiples of $3$ less than or equal to $n$ is $3$. Therefore, $3$ is the optimal value of $x$.
For $n = 15$, the optimal value of $x$ is $2$. The sum of all multiples of $2... | Title: Maximum Multiple Sum
time_limit_ms: 1000
memory_limit_mb: 256
Description: Given an integer $n$, find an integer $x$ such that:
* $2 \leq x \leq n$. * The sum of multiples of $x$ that are less than or equal to $n$ is maximized. Formally, $x + 2x + 3x + \dots + kx$ where $kx \leq n$ is maximized over all po... |
1985G | https://codeforces.com/problemset/problem/1985/G | D-Function | 1,600 | [
"combinatorics",
"math",
"number theory"
] | Div. 4 | 2,000 | 256 | Let $D(n)$ represent the sum of digits of $n$. For how many integers $n$ where $10^{l} \leq n < 10^{r}$ satisfy $D(k \cdot n) = k \cdot D(n)$? Output the answer modulo $10^9+7$. | The first line contains an integer $t$ ($1 \leq t \leq 10^4$) – the number of test cases.
Each test case contains three integers $l$, $r$, and $k$ ($0 \leq l < r \leq 10^9$, $1 \leq k \leq 10^9$). | For each test case, output an integer, the answer, modulo $10^9 + 7$. | [
[
"6\n0 1 4\n0 2 7\n1 2 1\n1 2 3\n582 74663 3\n0 3 1",
"2\n3\n90\n12\n974995667\n999"
]
] | For the first test case, the only values of $n$ that satisfy the condition are $1$ and $2$.
For the second test case, the only values of $n$ that satisfy the condition are $1$, $10$, and $11$.
For the third test case, all values of $n$ between $10$ inclusive and $100$ exclusive satisfy the condition. | Title: D-Function
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let $D(n)$ represent the sum of digits of $n$. For how many integers $n$ where $10^{l} \leq n < 10^{r}$ satisfy $D(k \cdot n) = k \cdot D(n)$? Output the answer modulo $10^9+7$.
Input: The first line contains an integer $t$ ($1 \leq t \leq 10^4$) ... |
2013D | https://codeforces.com/problemset/problem/2013/D | Minimize the Difference | 1,900 | [
"binary search",
"greedy"
] | Div. 2 | 2,000 | 256 | 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.
You are given an array $a_1, a_2, \ldots, a_n$ of length $n$. We can perform any number (possibly, zero) of operations on ... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$).
The second line of each test case contains $n$ integers $a_1, a_2, \ldo... | For each test case, output a single integer: the minimum possible value of $\max(a_1, a_2, \ldots, a_n) - \min(a_1, a_2, \ldots, a_n)$. | [
[
"5\n1\n1\n3\n1 2 3\n4\n4 1 2 3\n4\n4 2 3 1\n5\n5 14 4 10 2",
"0\n2\n1\n1\n3"
]
] | In the third testcase, you can perform the operation twice with $i = 1$.
After that, the array is $a = [2, 3, 2, 3]$, and $\max(2, 3, 2, 3) - \min(2, 3, 2, 3) = 3 - 2 = 1$. | Title: Minimize the Difference
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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.
You are given an array $a_1, a_2, \ld... |
2021D | https://codeforces.com/problemset/problem/2021/D | Boss, Thirsty | 2,500 | [
"dp",
"greedy",
"implementation"
] | Div. 2 | 2,000 | 256 | 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 drink... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.
The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 2 \cdot 10^5$; $3 \leq m \leq 2 \cdot 10^5$; $n \cdot m \leq 2 \cdot 10^5$) — ... | For each test case, output a single integer: the maximum profit that Pak Chanek can achieve. | [
[
"1\n3 6\n79 20 49 5 -1000 500\n-105 9 109 24 -98 -499\n14 47 12 39 23 50",
"475"
]
] | Here is Pak Chanek's optimal plan:
| |  ---|---|--- * On day $1$, Pak Chanek sells drink types $1$ to $3$. Generating a profit of $79+20+49 = 148$. * On day ... | Title: Boss, Thirsty
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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 p... |
1975I | https://codeforces.com/problemset/problem/1975/I | Mind Bloom | 3,500 | [
"dp"
] | Div. 1 + 2 | 5,000 | 1,024 | This is the way it always was.
This is the way it always will be.
All will be forgotten again soon...
Jellyfish is playing a one-player card game called "Slay the Spire". There are $n$ cards in total numbered from $1$ to $n$. The $i$-th card has power $c_i$.
There is a binary string $s$ of length $n$. If $s_i = \te... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\leq t\leq 100$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 120$) — the number of cards.
The second line of each test case contains $n$ intege... | For each test case, output the probability that Jellyfish can empty the draw pile modulo $1\,000\,000\,007$. | [
[
"4\n5\n0 1 1 1 2\n00100\n3\n2 3 3\n000\n10\n0 0 0 0 0 0 0 1 1 1\n1111011111\n20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 3 3 4\n00000000001000101010",
"500000004\n0\n0\n675898154"
]
] | In the first test case, Jellyfish will keep playing cards with power $1$ until Jellyfish draws a card with power $0$ or power $2$. If Jellyfish draws a card with power $0$, she will eventually empty her hand. If Jellyfish draws a card with power $2$, she will eventually empty the draw pile. Since there is an equal chan... | Title: Mind Bloom
time_limit_ms: 5000
memory_limit_mb: 1024
Description: This is the way it always was.
This is the way it always will be.
All will be forgotten again soon...
Jellyfish is playing a one-player card game called "Slay the Spire". There are $n$ cards in total numbered from $1$ to $n$. The $i$-th card ha... |
2021E1 | https://codeforces.com/problemset/problem/2021/E1 | Digital Village (Easy Version) | 2,300 | [
"brute force",
"data structures",
"dfs and similar",
"dp",
"dsu",
"fft",
"graphs",
"greedy",
"implementation",
"math",
"trees"
] | Div. 2 | 2,000 | 256 | 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 with... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.
The first line of each test case contains three integers $n$, $m$, $p$ ($2 \le n \le 400$; $n-1 \le m \le 400$; $1 \le p \le n$) — the number of houses, the numbe... | For each test case, output $n$ integers: the minimum total latency that can be achieved for all the houses requiring internet for each $k = 1,2,\ldots,n$. | [
[
"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",
"34 19 9 4 0 0 0 0 0\n2 0 0"
]
] | In the first test case for $k=3$, a possible optimal solution is to install servers at vertices $2$, $6$ and $8$ and obtain the following latency:
* $\text{latency}(2) = 0$ * $\text{latency}(5) = \max(3, 5) = 5$ * $\text{latency}(6) = 0$ * $\text{latency}(8) = 0$ * $\text{latency}(9) = \max(2, 4) = 4$
... | Title: Digital Village (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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 ... |
2003E2 | https://codeforces.com/problemset/problem/2003/E2 | Turtle and Inversions (Hard Version) | 2,700 | [
"brute force",
"data structures",
"divide and conquer",
"dp",
"greedy",
"math",
"two pointers"
] | Div. 2 | 2,000 | 512 | 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.
Turtle gives you $m$ intervals $[l_1, r_1], [l_2, r_2], \ldots, [l... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.
The first line of each test case contains two integers $n, m$ ($2 \le n \le 5 \cdot 10^3, 0 \le m \le 5 \cdot 10^3$) — the length of the permutation and the numb... | For each test case, if there is no interesting permutation, output a single integer $-1$.
Otherwise, output a single integer — the maximum number of inversions. | [
[
"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",
"1\n0\n8\n18\n-1\n-1\n15\n15"
]
] | In the third test case, the interesting permutation with the maximum number of inversions is $[5, 2, 4, 3, 1]$.
In the fourth test case, the interesting permutation with the maximum number of inversions is $[4, 3, 8, 7, 6, 2, 1, 5]$. In this case, we can let $[k_1, k_2, k_3] = [2, 2, 7]$.
In the fifth and the sixth t... | Title: Turtle and Inversions (Hard Version)
time_limit_ms: 2000
memory_limit_mb: 512
Description: 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 versi... |
2004F | https://codeforces.com/problemset/problem/2004/F | Make a Palindrome | 2,600 | [
"binary search",
"brute force",
"data structures",
"greedy",
"math"
] | Div. 2 | 5,000 | 512 | You are given an array $a$ consisting of $n$ integers.
Let the function $f(b)$ return the minimum number of operations needed to make an array $b$ a palindrome. The operations you can make are:
* choose two adjacent elements $b_i$ and $b_{i+1}$, remove them, and replace them with a single element equal to $(b_i + b... | The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2000$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^5$).
Additional constraint on the input: the sum of $n$ ov... | For each test case, print a single integer — the sum of the values of the function $f$ for all subarrays of the array $a$. | [
[
"4\n3\n2 1 3\n4\n1 1 1 1\n5\n4 2 3 1 5\n4\n1 2 1 2",
"3\n0\n14\n5"
]
] | Title: Make a Palindrome
time_limit_ms: 5000
memory_limit_mb: 512
Description: You are given an array $a$ consisting of $n$ integers.
Let the function $f(b)$ return the minimum number of operations needed to make an array $b$ a palindrome. The operations you can make are:
* choose two adjacent elements $b_i$ and $b... | |
2025D | https://codeforces.com/problemset/problem/2025/D | Attribute Checks | 1,800 | [
"brute force",
"data structures",
"dp",
"implementation",
"math",
"two pointers"
] | Div. 2 | 2,500 | 512 | 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'l... | The first line contains two integers $n$ and $m$ ($1 \le m \le 5000$; $m < n \le 2 \cdot 10^6$) — the number of records in the list and the total number of points you'll get during the game.
The second line contains $n$ integers $r_1, r_2, \dots, r_n$ ($-m \le r_i \le m$), where $r_i$ encodes the $i$-th record:
* I... | Print one integer — the maximum number of checks you can pass. | [
[
"10 5\n0 1 0 2 0 -3 0 -4 0 -5",
"3"
],
[
"3 1\n1 -1 0",
"0"
],
[
"9 3\n0 0 1 0 2 -3 -2 -2 1",
"4"
]
] | In the first test, it's optimal to spend each point in Strength, so you'll fail $2$ Intelligence checks but pass $3$ Strength checks.
In the second test, you'll fail both checks, since the first point you get comes after the checks.
In the third test, one of the optimal strategies is:
1. spend the first point on I... | Title: Attribute Checks
time_limit_ms: 2500
memory_limit_mb: 512
Description: 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 — on... |
2028B | https://codeforces.com/problemset/problem/2028/B | Alice's Adventures in Permuting | 1,400 | [
"binary search",
"implementation",
"math"
] | Div. 2 | 1,000 | 256 | 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]$... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.
The only line of each test case contains three integers $n$, $b$, $c$ ($1\le n\le 10^{18}$; $0\le b$, $c\le 10^{18}$) — the parameters of the array. | For each test case, if the array can never become a permutation, output $-1$. Otherwise, output the minimum number of operations for the array to become a permutation. | [
[
"7\n10 1 0\n1 2 3\n100 2 1\n3 0 1\n3 0 0\n1000000000000000000 0 0\n1000000000000000000 1000000000000000000 1000000000000000000",
"0\n1\n50\n2\n-1\n-1\n1000000000000000000"
]
] | In the first test case, the array is already $[0, 1, \ldots, 9]$, so no operations are required.
In the third test case, the starting array is $[1, 3, 5, \ldots, 199]$. After the first operation, the $199$ gets transformed into a $0$. In the second operation, the $197$ gets transformed into a $2$. If we continue this,... | Title: Alice's Adventures in Permuting
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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, i... |
2026D | https://codeforces.com/problemset/problem/2026/D | Sums of Segments | 1,900 | [
"binary search",
"data structures",
"dp",
"implementation",
"math"
] | Div. 2 | 4,000 | 512 | 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), \d... | The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10 \le a_i \le 10$).
The third line contains one integer $q$ ($1 \le q \le 3 \cdot 10^5$).
Then $q$ lines follow, the $i$-th of them contains two integers $l_i$ and $r_i$ ($1 \le l_i ... | Print $q$ integers, the $i$-th of which should be equal to $\sum \limits_{j=l_i}^{r_i} b_j$. | [
[
"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",
"1\n4\n12\n30\n32\n86\n56\n54\n60\n26\n82\n57\n9\n2\n61"
]
] | Title: Sums of Segments
time_limit_ms: 4000
memory_limit_mb: 512
Description: 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: ... | |
2036F | https://codeforces.com/problemset/problem/2036/F | XORificator 3000 | 1,900 | [
"bitmasks",
"dp",
"number theory",
"two pointers"
] | Div. 3 | 1,000 | 256 | Alice has been giving gifts to Bob for many years, and she knows that what he enjoys the most is performing [bitwise XOR](http://tiny.cc/xor_wiki_eng) of interesting integers. Bob considers a positive integer $x$ to be interesting if it satisfies $x \not\equiv k (\bmod 2^i)$. Therefore, this year for his birthday, she ... | The first line of input contains a single integer $t$ $(1 \leq t \leq 10^4)$ — the number of XOR queries on the segment. The following $t$ lines contain the queries, each consisting of the integers $l$, $r$, $i$, $k$ $(1 \leq l \leq r \leq 10^{18}$, $0 \leq i \leq 30$, $0 \leq k < 2^i)$. | For each query, output a single integer — the XOR of all integers $x$ in the range $[l, r]$ such that $x \not\equiv k \mod 2^i$. | [
[
"6\n1 3 1 0\n2 28 3 7\n15 43 1 0\n57 2007 1 0\n1010 1993 2 2\n1 1000000000 30 1543",
"2\n2\n13\n0\n4\n1000000519"
]
] | In the first query, the interesting integers in the range $[1, 3]$ are $1$ and $3$, so the answer will be $1 \oplus 3 = 2$. | Title: XORificator 3000
time_limit_ms: 1000
memory_limit_mb: 256
Description: Alice has been giving gifts to Bob for many years, and she knows that what he enjoys the most is performing [bitwise XOR](http://tiny.cc/xor_wiki_eng) of interesting integers. Bob considers a positive integer $x$ to be interesting if it satis... |
1975G | https://codeforces.com/problemset/problem/1975/G | Zimpha Fan Club | 3,000 | [
"fft",
"greedy",
"math",
"strings"
] | Div. 1 + 2 | 12,000 | 512 | One day, Zimpha casually came up with a problem. As a member of "Zimpha fan club", you decided to solve that problem. You are given two strings $s$ and $t$ of length $n$ and $m$, respectively. Both strings only consist of lowercase English letters, - and *.
You need to replace all occurrences of * and -, observin... | The first line of input contains two integers $n$ and $m$ ($1 \leq n, m \leq 2 \cdot 10^6$) — the length of the strings $s$ and $t$, respectively.
The second line contains the string $s$ of length $n$. It is guaranteed that $s$ only consists of lowercase English letters, - and *.
The third line contains the string $t... | For each test case, output "Yes" if there is a replacement that makes $s'=t'$, and output "No" otherwise.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response). | [
[
"10 10\njustmonika\nj-stsayori",
"No"
],
[
"7 8\nttk-wxx\n*tt-l-xx",
"Yes"
],
[
"13 11\nasoulwangziji\n-soulg*z-y-",
"No"
],
[
"7 3\nabc*cba\na*c",
"No"
],
[
"20 18\nbulijiojio-dibuliduo\n*li*ji-*ox*i*-du*-",
"Yes"
]
] | In the second test case, we can transform both strings into ttklwxx. In $s$, - will be replaced with l. In $t$, * will be replaced by the empty string with the first and second - will be replaced with k and w respectively.
In the fifth test case, we can transform both strings into bulijiojioxdibuliduo. | Title: Zimpha Fan Club
time_limit_ms: 12000
memory_limit_mb: 512
Description: One day, Zimpha casually came up with a problem. As a member of "Zimpha fan club", you decided to solve that problem. You are given two strings $s$ and $t$ of length $n$ and $m$, respectively. Both strings only consist of lowercase Engli... |
2014B | https://codeforces.com/problemset/problem/2014/B | Robin Hood and the Major Oak | 800 | [
"math"
] | Div. 3 | 1,000 | 256 | In Sherwood, the trees are our shelter, and we are all children of the forest.
The Major Oak in Sherwood is known for its majestic foliage, which provided shelter to Robin Hood and his band of merry men and women.
The Major Oak grows $i^i$ new leaves in the $i$-th year. It starts with $1$ leaf in year $1$.
Leaves la... | The first line of the input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
Each test case consists of two integers $n$, $k$ ($1 \le n \le 10^9$, $1 \le k \le n$) — the requested year and the number of years during which the leaves remain. | For each test case, output one line, "YES" if in year $n$ the Major Oak will have an even number of leaves and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"5\n1 1\n2 1\n2 2\n3 2\n4 4",
"NO\nYES\nNO\nNO\nYES"
]
] | In the first test case, there is only $1$ leaf.
In the second test case, $k=1$, so in the $2$-nd year there will be $2^2=4$ leaves.
In the third test case, $k=2$, so in the $2$-nd year there will be $1+2^2=5$ leaves.
In the fourth test case, $k=2$, so in the $3$-rd year there will be $2^2 + 3^3 = 4 + 27 = 31$ leaves... | Title: Robin Hood and the Major Oak
time_limit_ms: 1000
memory_limit_mb: 256
Description: In Sherwood, the trees are our shelter, and we are all children of the forest.
The Major Oak in Sherwood is known for its majestic foliage, which provided shelter to Robin Hood and his band of merry men and women.
The Major Oak ... |
2026C | https://codeforces.com/problemset/problem/2026/C | Action Figures | 1,500 | [
"binary search",
"brute force",
"constructive algorithms",
"data structures",
"greedy",
"implementation"
] | Div. 2 | 2,500 | 512 | 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 t... | The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
Each test case consists of two lines:
* the first line contains one integer $n$ ($1 \le n \le 4 \cdot 10^5$) — the number of figures in the set (and the number of days); * the second line contains a string $s$ ($|s| = n$, ea... | For each test case, print one integer — the minimum amount of money Monocarp has to spend. | [
[
"4\n1\n1\n6\n101101\n7\n1110001\n5\n11111",
"1\n8\n18\n6"
]
] | In the first test case, Monocarp buys the $1$-st figure on the $1$-st day and spends $1$ coin.
In the second test case, Monocarp can buy the $1$-st and the $3$-rd figure on the $3$-rd day, the $2$-nd and the $4$-th figure on the $4$-th day, and the $5$-th and the $6$-th figure on the $6$-th day. Then, he will spend $1... | Title: Action Figures
time_limit_ms: 2500
memory_limit_mb: 512
Description: 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 ... |
2008H | https://codeforces.com/problemset/problem/2008/H | Sakurako's Test | 2,100 | [
"binary search",
"brute force",
"greedy",
"math",
"number theory"
] | Div. 3 | 1,000 | 256 | Sakurako will soon take a test. The test can be described as an array of integers $n$ and a task on it:
Given an integer $x$, Sakurako can perform the following operation any number of times:
* Choose an integer $i$ ($1\le i\le n$) such that $a_i\ge x$; * Change the value of $a_i$ to $a_i-x$.
Using this operat... | The first line contains one integer $t$ ($1\le t\le 10^4$) — the number of test cases.
The first line of each test case contains two integers $n$ and $q$ ($1\le n,q\le 10^5$) — the number of elements in the array and the number of queries.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_... | For each test case, output $q$ integers — the answer for each query. | [
[
"2\n5 5\n1 2 3 4 5\n1\n2\n3\n4\n5\n6 3\n1 2 6 4 1 3\n2\n1\n5",
"0 1 1 1 2 \n1 0 2"
]
] | Title: Sakurako's Test
time_limit_ms: 1000
memory_limit_mb: 256
Description: Sakurako will soon take a test. The test can be described as an array of integers $n$ and a task on it:
Given an integer $x$, Sakurako can perform the following operation any number of times:
* Choose an integer $i$ ($1\le i\le n$) such th... | |
1988B | https://codeforces.com/problemset/problem/1988/B | Make Majority | 900 | [
"greedy",
"implementation"
] | Div. 2 | 1,500 | 512 | You are given a sequence $[a_1,\ldots,a_n]$ where each element $a_i$ is either $0$ or $1$. You can apply several (possibly zero) operations to the sequence. In each operation, you select two integers $1\le l\le r\le |a|$ (where $|a|$ is the current length of $a$) and replace $[a_l,\ldots,a_r]$ with a single element $x$... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 4\cdot 10^4$). Description of the test cases follows.
The first line of each testcase contains one integer $n$ ($1\le n\le 2\cdot 10^5$).
The second line of each testcase contains a string consisting of $0$ and ... | For each testcase, if it's possible to make $a=[1]$, print YES. Otherwise, print NO. You can output the answer in any case (upper or lower). For example, the strings yEs, yes, Yes, and YES will be recognized as positive responses. | [
[
"5\n1\n0\n1\n1\n2\n01\n9\n100000001\n9\n000011000",
"No\nYes\nNo\nYes\nNo"
]
] | In the fourth testcase of the example, initially $a=[1,0,0,0,0,0,0,0,1]$. A valid sequence of operations is:
1. Select $l=2,r=8$ and apply the operation. $a$ becomes $[1,0,1]$. 2. Select $l=1,r=3$ and apply the operation. $a$ becomes $[1]$. | Title: Make Majority
time_limit_ms: 1500
memory_limit_mb: 512
Description: You are given a sequence $[a_1,\ldots,a_n]$ where each element $a_i$ is either $0$ or $1$. You can apply several (possibly zero) operations to the sequence. In each operation, you select two integers $1\le l\le r\le |a|$ (where $|a|$ is the curr... |
2032F | https://codeforces.com/problemset/problem/2032/F | Peanuts | 2,700 | [
"combinatorics",
"dp",
"games",
"math"
] | Div. 2 | 4,000 | 256 | 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 divides... | Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^6$) — the number of pockets.
The second line of each tes... | For each test case, output a single integer — the number of ways for Alice to divide the pockets into boxes at the start of the game to guarantee her win, assuming both players play optimally, modulo $998\,244\,353$. | [
[
"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",
"1\n4\n16\n0\n205"
]
] | In the first test case, the only way for Alice to win is to divide the pockets into two boxes as follows: $([1, 2], [3])$ (the first box contains the first two pockets and the second box contains the third pocket). Alice wins by taking both peanuts from the second pocket, leaving Jack with $([1], [3])$. Jack is forced ... | Title: Peanuts
time_limit_ms: 4000
memory_limit_mb: 256
Description: 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... |
2018E1 | https://codeforces.com/problemset/problem/2018/E1 | Complex Segments (Easy Version) | 3,300 | [
"binary search",
"data structures",
"divide and conquer",
"dsu",
"greedy",
"math",
"sortings"
] | Div. 1 | 6,000 | 256 | [Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)
⠀
This 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.
A set of (closed) segments is complex if it can be partitioned into s... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^4$) — the number of segments.
The second line of each test case contains... | For each test case, output a single integer: the maximum size of a complex subset of the given segments. | [
[
"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",
"3\n4\n4"
]
] | In the first test case, all pairs of segments intersect, therefore it is optimal to form a single group containing all of the three segments.
In the second test case, there is no valid partition for all of the five segments. A valid partition with four segments is the following: $\\{\\{ [1, 5], [2, 4] \\}, \\{ [6, 9],... | Title: Complex Segments (Easy Version)
time_limit_ms: 6000
memory_limit_mb: 256
Description: [Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)
⠀
This 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 t... |
1989F | https://codeforces.com/problemset/problem/1989/F | Simultaneous Coloring | 3,000 | [
"dfs and similar",
"divide and conquer",
"graphs"
] | Div. 2 | 6,000 | 512 | You are given a matrix, consisting of $n$ rows and $m$ columns.
You can perform two types of actions on it:
* paint the entire column in blue; * paint the entire row in red.
Note that you cannot choose which color to paint the row or column.
In one second, you can perform either one action or multiple actions... | The first line contains three integers $n, m$ and $q$ ($1 \le n, m, q \le 2 \cdot 10^5$) — the size of the matrix and the number of queries.
In the $i$-th of the next $q$ lines, two integers $x_i, y_i$ and a character $c_i$ ($1 \le x_i \le n$; $1 \le y_i \le m$; $c_i \in$ {'R', 'B'}, where 'R' means red, and 'B' means... | Print $q$ integers — after each query, output the minimum cost of painting the matrix according to the restrictions. | [
[
"2 2 4\n1 1 R\n2 2 R\n1 2 B\n2 1 B",
"0\n0\n0\n16"
],
[
"3 5 10\n1 1 B\n2 5 B\n2 2 B\n2 3 R\n2 1 B\n3 2 R\n3 3 B\n1 2 R\n1 3 B\n3 1 B",
"0\n0\n0\n0\n0\n0\n16\n16\n25\n25"
]
] | Title: Simultaneous Coloring
time_limit_ms: 6000
memory_limit_mb: 512
Description: You are given a matrix, consisting of $n$ rows and $m$ columns.
You can perform two types of actions on it:
* paint the entire column in blue; * paint the entire row in red.
Note that you cannot choose which color to paint the r... | |
2021A | https://codeforces.com/problemset/problem/2021/A | Meaning Mean | 800 | [
"data structures",
"greedy",
"math",
"sortings"
] | Div. 2 | 1,000 | 256 | 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 indices... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2 \le n \le 50$) — the length of the array $a$.
The second line of each test case contains $n$ ... | For each test case, output a single integer: the maximum possible value of $x$ after all numbers have been picked. | [
[
"3\n5\n1 7 8 4 5\n3\n2 6 5\n5\n5 5 5 5 5",
"6\n4\n5"
]
] | In the first test case, the array is initially $a=[1,7,8,4,5]$. Pak Chanek will perform the following operations:
1. Pick $i=1$ and $j=2$, then $a=[8,4,5,4]$. 2. Pick $i=3$ and $j=2$, then $a=[8,4,4]$. 3. Pick $i=2$ and $j=3$, then $a=[8,4]$. 4. Pick $i=1$ and $j=2$, then $a=[6]$.
After all the operations... | Title: Meaning Mean
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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 pe... |
2036A | https://codeforces.com/problemset/problem/2036/A | Quintomania | 800 | [
"implementation"
] | Div. 3 | 1,000 | 256 | Boris Notkin composes melodies. He represents them as a sequence of notes, where each note is encoded as an integer from $0$ to $127$ inclusive. The interval between two notes $a$ and $b$ is equal to $|a - b|$ semitones.
Boris considers a melody perfect if the interval between each two adjacent notes is either $5$ sem... | The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of melodies.
Each melody is described by two lines.
The first line contains an integer $n$ ($2 \leq n \leq 50$) — the number of notes in the melody.
The second line contains $n$ integers $a_{1}, a_{2}, \dots, a_{n}$ ($0 \leq a_{i} \leq 127$) ... | For each melody, output "YES", if it is perfect; otherwise, output "NO".
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"8\n2\n114 109\n2\n17 10\n3\n76 83 88\n8\n38 45 38 80 85 92 99 106\n5\n63 58 65 58 65\n8\n117 124 48 53 48 43 54 49\n5\n95 102 107 114 121\n10\n72 77 82 75 70 75 68 75 68 75",
"YES\nYES\nYES\nNO\nYES\nNO\nYES\nYES"
]
] | Title: Quintomania
time_limit_ms: 1000
memory_limit_mb: 256
Description: Boris Notkin composes melodies. He represents them as a sequence of notes, where each note is encoded as an integer from $0$ to $127$ inclusive. The interval between two notes $a$ and $b$ is equal to $|a - b|$ semitones.
Boris considers a melody ... | |
1999A | https://codeforces.com/problemset/problem/1999/A | A+B Again? | 800 | [
"implementation",
"math"
] | Div. 4 | 1,000 | 256 | Given a two-digit positive integer $n$, find the sum of its digits. | The first line contains an integer $t$ ($1 \leq t \leq 90$) — the number of test cases.
The only line of each test case contains a single two-digit positive integer $n$ ($10 \leq n \leq 99$). | For each test case, output a single integer — the sum of the digits of $n$. | [
[
"8\n77\n21\n40\n34\n19\n84\n10\n99",
"14\n3\n4\n7\n10\n12\n1\n18"
]
] | Title: A+B Again?
time_limit_ms: 1000
memory_limit_mb: 256
Description: Given a two-digit positive integer $n$, find the sum of its digits.
Input: The first line contains an integer $t$ ($1 \leq t \leq 90$) — the number of test cases.
The only line of each test case contains a single two-digit positive integer $n$ ($... | |
2013F1 | https://codeforces.com/problemset/problem/2013/F1 | Game in Tree (Easy Version) | 2,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"games",
"greedy",
"implementation",
"trees"
] | Div. 2 | 4,000 | 256 | 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.
Alice 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$ vertices is an undirecte... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of vertices in the tree.
Each of the following $n - 1$ ... | For each test case, output $m$ lines.
In the $i$-th line, print the winner of the game if Alice starts at vertex $1$ and Bob starts at vertex $p_i$. Print "Alice" (without quotes) if Alice wins, or "Bob" (without quotes) otherwise. | [
[
"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",
"Bob\nAlice\nAlice"
]
] |  Tree from the first and second examples.
In the first test case, the path will be ($2,2$). Bob starts at vertex $2$, Alice will not be able to move anywhere on her first turn and will lose.
In the second test case, the path will be ($3,3$). Bob starts at vertex $3$, ... | Title: Game in Tree (Easy Version)
time_limit_ms: 4000
memory_limit_mb: 256
Description: 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.
Alice and Bob are playing a fun game on a tree. This game is played on a tree with $n$... |
1988F | https://codeforces.com/problemset/problem/1988/F | Heartbeat | 3,000 | [
"combinatorics",
"dp",
"fft",
"math"
] | Div. 2 | 5,000 | 512 | For an array $u_1, u_2, \ldots, u_n$, define
* a prefix maximum as an index $i$ such that $u_i>u_j$ for all $j<i$; * a suffix maximum as an index $i$ such that $u_i>u_j$ for all $j>i$; * an ascent as an index $i$ ($i>1$) such that $u_i>u_{i-1}$.
You are given three cost arrays: $[a_1, a_2, \ldots, a_n]$, $[b... | The first line contains an integer $n$ ($1\le n\le 700$).
The second line contains $n$ integers $a_1,\ldots,a_n$ ($0\le a_i<998\,244\,353$).
The third line contains $n$ integers $b_1,\ldots,b_n$ ($0\le b_i<998\,244\,353$).
The fourth line contains $n$ integers $c_0,\ldots,c_{n-1}$ ($0\le c_i<998\,244\,353$). | Print $n$ integers: the $i$-th one is $f(i)$ modulo $998\,244\,353$. | [
[
"3\n1 1 1\n1 1 1\n1 1 1",
"1 2 6"
],
[
"3\n1 2 3\n2 3 1\n3 1 2",
"6 13 34"
],
[
"5\n1 4 2 5 3\n2 5 1 3 4\n300000000 100000000 500000000 400000000 200000000",
"600000000 303511294 612289529 324650937 947905622"
]
] | In the second example:
* Consider permutation $[1,2,3]$. Indices $1,2,3$ are prefix maximums. Index $3$ is the only suffix maximum. Indices $2,3$ are ascents. In conclusion, it has $3$ prefix maximums, $1$ suffix maximums, and $2$ ascents. Therefore, its cost is $a_3b_1c_2=12$. * Permutation $[1,3,2]$ has $2$ pre... | Title: Heartbeat
time_limit_ms: 5000
memory_limit_mb: 512
Description: For an array $u_1, u_2, \ldots, u_n$, define
* a prefix maximum as an index $i$ such that $u_i>u_j$ for all $j<i$; * a suffix maximum as an index $i$ such that $u_i>u_j$ for all $j>i$; * an ascent as an index $i$ ($i>1$) such that $u_i>u_{i... |
2002G | https://codeforces.com/problemset/problem/2002/G | Lattice Optimizing | 3,400 | [
"bitmasks",
"brute force",
"hashing",
"meet-in-the-middle"
] | Div. 1 + 2 | 7,000 | 1,024 | 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 $(x,y+1)$, with non-negativ... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le100$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2\le n\le20$) — the number of rows and columns.
Each of the next $n-1$ lines contains $n$ integers ... | For each test case, print a single integer — the maximum MEX of $S$ when you reach $(n,n)$. | [
[
"2\n3\n1 0 2\n0 1 3\n2 1\n0 3\n3 0\n3\n1 2 0\n0 1 2\n2 0\n1 2\n0 1",
"3\n2"
],
[
"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... | In the first test case, the grid graph and one of the optimal paths are as follows:

In the second test case, the grid graph and one of the optimal paths are as follows:
 | Title: Lattice Optimizing
time_limit_ms: 7000
memory_limit_mb: 1024
Description: 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$, ... |
1998C | https://codeforces.com/problemset/problem/1998/C | Perform Operations to Maximize Score | 1,900 | [
"binary search",
"brute force",
"constructive algorithms",
"greedy",
"implementation"
] | Div. 2 | 3,000 | 256 | I see satyam343. I'm shaking. Please more median problems this time. I love those. Please satyam343 we believe in you.
— satyam343's biggest fan
You are given an array $a$ of length $n$ and an integer $k$. You are also given a binary array $b$ of length $n$.
You can perform the following operation at most $k$ times:... | The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
Each test case begins with two integers $n$ and $k$ ($2 \leq n \leq 2 \cdot 10^5$, $0 \leq k \leq 10^9$) — the length of the $a$ and the number of operations you can perform.
The following line contains $n$ space separated integ... | For each test case, output the maximum value of score you can get on a new line. | [
[
"8\n2 10\n3 3\n1 1\n3 10\n3 3 3\n0 0 0\n4 4\n2 1 5 1\n0 1 0 1\n5 4\n7 5 2 5 4\n0 0 1 0 1\n5 1\n5 15 15 2 11\n1 0 0 1 1\n5 2\n10 11 4 10 15\n1 1 0 1 0\n4 4\n1 1 2 5\n1 1 0 0\n2 1000000000\n1000000000 1000000000\n1 1",
"16\n6\n8\n13\n21\n26\n8\n3000000000"
]
] | For the first test case, it is optimal to perform $5$ operations on both elements so $a = [8,8]$. So, the maximum score we can achieve is $\max(8 + \operatorname{median}[8], 8 + \operatorname{median}[8]) = 16$, as $c_1 = [a_2] = [8]$. It can be proven that you cannot get a better score.
For the second test case, you a... | Title: Perform Operations to Maximize Score
time_limit_ms: 3000
memory_limit_mb: 256
Description: I see satyam343. I'm shaking. Please more median problems this time. I love those. Please satyam343 we believe in you.
— satyam343's biggest fan
You are given an array $a$ of length $n$ and an integer $k$. You are also g... |
1987F2 | https://codeforces.com/problemset/problem/1987/F2 | Interesting Problem (Hard Version) | 2,600 | [
"dp"
] | Div. 1 + 2 | 2,000 | 256 | This is the hard version of the problem. The only difference between the two versions is the constraint on $n$. You can make hacks only if both versions of the problem are solved.
You are given an array of integers $a$ of length $n$.
In one operation, you will perform the following two-step process:
1. Choose an i... | Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 800$) — the length of the array $a$.
The second line of ... | For each test case, output a single integer — the maximum number of times that you can perform the operation. | [
[
"6\n5\n1 5 3 2 4\n8\n2 1 3 4 5 6 7 8\n3\n1 2 3\n4\n1 2 4 4\n5\n4 4 1 3 5\n1\n1",
"2\n3\n1\n2\n0\n0"
]
] | In the first test case, one possible optimal sequence of operations is $[ 1, 5, \color{red}{3}, \color{red}{2}, 4 ] \rightarrow [\color{red}{1}, \color{red}{5}, 4] \rightarrow [4]$.
In the third test case, one possible optimal sequence of operations is $[1, \color{red}{2}, \color{red}{3}] \rightarrow [1]$. | Title: Interesting Problem (Hard Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference between the two versions is the constraint on $n$. You can make hacks only if both versions of the problem are solved.
You are given an array of integers $a$ of l... |
1979B | https://codeforces.com/problemset/problem/1979/B | XOR Sequences | 1,000 | [
"bitmasks",
"greedy"
] | Div. 2 | 1,000 | 256 | You are given two distinct non-negative integers $x$ and $y$. Consider two infinite sequences $a_1, a_2, a_3, \ldots$ and $b_1, b_2, b_3, \ldots$, where
* $a_n = n \oplus x$; * $b_n = n \oplus y$.
Here, $x \oplus y$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation of inte... | Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers $x$ and $y$ ($0 \le x, y \le 10^9, x \neq y$) — the parameters of the sequences. | For each test case, output a single integer — the length of the longest common subsegment. | [
[
"4\n0 1\n12 4\n57 37\n316560849 14570961",
"1\n8\n4\n33554432"
]
] | In the first test case, the first $7$ elements of sequences $a$ and $b$ are as follows:
$a = [1, 2, 3, 4, 5, 6, 7,\ldots]$
$b = [0, 3, 2, 5, 4, 7, 6,\ldots]$
It can be shown that there isn't a positive integer $k$ such that the sequence $[k, k + 1]$ occurs in $b$ as a subsegment. So the answer is $1$.
In the third ... | Title: XOR Sequences
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are given two distinct non-negative integers $x$ and $y$. Consider two infinite sequences $a_1, a_2, a_3, \ldots$ and $b_1, b_2, b_3, \ldots$, where
* $a_n = n \oplus x$; * $b_n = n \oplus y$.
Here, $x \oplus y$ denotes the [bitwise ... |
2001D | https://codeforces.com/problemset/problem/2001/D | Longest Max Min Subsequence | 1,900 | [
"brute force",
"constructive algorithms",
"data structures",
"greedy",
"implementation"
] | Div. 2 | 2,000 | 256 | 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 multiplying terms at odd positi... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5 \cdot 10^4$). The description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of $a$.
The second line of each test case contains $n... | For each test case, output the answer in the following format:
Output an integer $m$ in the first line — the length of $b$.
Then output $m$ integers $b_1, b_2, \ldots, b_m$ in the second line — the sequence $b$. | [
[
"4\n4\n3 2 1 3\n4\n1 1 1 1\n9\n3 2 1 3 2 1 3 2 1\n1\n1",
"3\n3 2 1\n1\n1\n3\n3 1 2\n1\n1"
],
[
"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",
"2\n1 2\n5\n5 1 9 7... | In the first example, $S = \\{[1], [2], [3], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2], [2, 1, 3], [3, 2, 1]\\}$. Among them, $[2, 1, 3]$ and $[3, 2, 1]$ are the longest and $[-3, 2, -1]$ is lexicographical smaller than $[-2, 1, -3]$, so $[3, 2, 1]$ is the answer.
In the second example, $S = \\{[1]\\}$, so $[1]$ is the a... | Title: Longest Max Min Subsequence
time_limit_ms: 2000
memory_limit_mb: 256
Description: 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... |
2029A | https://codeforces.com/problemset/problem/2029/A | Set | 800 | [
"binary search",
"greedy",
"math"
] | Div. 1 + 2 | 1,000 | 256 | 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.... | Each test contains multiple test cases. The first line of the input contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. The description of test cases follows.
The only line of each test case contains three integers $l$, $r$, and $k$ ($1\le l\le r\leq 10^9$, $1\leq k\le r-l+1$) — the minimum in... | For each test case, output a single integer — the maximum possible number of operations that can be performed. | [
[
"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",
"2\n6\n0\n4\n0\n1\n7148\n500000000"
]
] | In the first test case, initially, $S = \\{3,4,5,6,7,8,9\\}$. One possible optimal sequence of operations is:
1. Choose $x = 4$ for the first operation, since there are two multiples of $4$ in $S$: $4$ and $8$. $S$ becomes equal to $\\{3,5,6,7,8,9\\}$; 2. Choose $x = 3$ for the second operation, since there are t... | Title: Set
time_limit_ms: 1000
memory_limit_mb: 256
Description: 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 a... |
2019B | https://codeforces.com/problemset/problem/2019/B | All Pairs Segments | 1,200 | [
"implementation",
"math"
] | Div. 2 | 1,500 | 256 | [Shirobon - FOX](https://soundcloud.com/shirobon/fox?in=mart_207/sets/fav)
⠀
You are given $n$ points on the $x$ axis, at increasing positive integer coordinates $x_1 < x_2 < \ldots < x_n$.
For each pair $(i, j)$ with $1 \leq i < j \leq n$, you draw the segment $[x_i, x_j]$. The segments are closed, i.e., a segment ... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains two integers $n$, $q$ ($2 \le n \le 10^5$, $1 \le q \le 10^5$) — the number of points and the number of queries.
The s... | For each test case, output a single line with $q$ integers: the $i$-th integer is the answer to the $i$-th query. | [
[
"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",
"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"
]
] | In the first example, you only draw the segment $[101, 200]$. No point is contained in exactly $2$ segments, and the $100$ points $101, 102, \ldots, 200$ are contained in exactly $1$ segment.
In the second example, you draw $15$ segments: $[1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [2, 3], [2, 5], [2, 6], [2, 7], [3, 5],... | Title: All Pairs Segments
time_limit_ms: 1500
memory_limit_mb: 256
Description: [Shirobon - FOX](https://soundcloud.com/shirobon/fox?in=mart_207/sets/fav)
⠀
You are given $n$ points on the $x$ axis, at increasing positive integer coordinates $x_1 < x_2 < \ldots < x_n$.
For each pair $(i, j)$ with $1 \leq i < j \leq ... |
1976E | https://codeforces.com/problemset/problem/1976/E | Splittable Permutations | 2,500 | [
"combinatorics",
"data structures",
"dfs and similar",
"greedy",
"math",
"trees"
] | Div. 2 | 2,000 | 512 | Initially, we had one array, which was a permutation of size $n$ (an array of size $n$ where each integer from $1$ to $n$ appears exactly once).
We performed $q$ operations. During the $i$-th operation, we did the following:
* choose any array we have with at least $2$ elements; * split it into two non-empty arr... | The first line contains two integers $n$ and $q$ ($1 \le q < n \le 3 \cdot 10^5$).
The second line contains $q$ integers $l_1, l_2, \dots, l_q$ ($1 \le l_i \le n$).
The third line contains $q$ integers $r_1, r_2, \dots, r_q$ ($1 \le r_i \le n$).
Additional constraint on the input: there exists at least one permutati... | Print one integer — the number of valid permutations, taken modulo $998244353$. | [
[
"6 3\n6 4 4\n5 5 2",
"30"
],
[
"10 1\n10\n9",
"1814400"
],
[
"4 1\n2\n4",
"8"
]
] | Title: Splittable Permutations
time_limit_ms: 2000
memory_limit_mb: 512
Description: Initially, we had one array, which was a permutation of size $n$ (an array of size $n$ where each integer from $1$ to $n$ appears exactly once).
We performed $q$ operations. During the $i$-th operation, we did the following:
* choo... | |
2025B | https://codeforces.com/problemset/problem/2025/B | Binomial Coefficients, Kind Of | 1,100 | [
"combinatorics",
"dp",
"math"
] | Div. 2 | 2,000 | 512 | 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++) // loop... | The first line contains a single integer $t$ ($1 \le t \le 10^5$) — the number of pairs. Next, $t$ pairs are written in two lines.
The second line contains $t$ integers $n_1, n_2, \dots, n_t$ ($2 \le n_i \le 10^5$).
The third line contains $t$ integers $k_1, k_2, \dots, k_t$ ($1 \le k_i < n_i$). | Print $t$ integers $C[n_i][k_i]$ modulo $10^9 + 7$. | [
[
"7\n2 5 5 100000 100000 100000 100000\n1 2 3 1 33333 66666 99999",
"2\n4\n8\n2\n326186014\n984426998\n303861760"
]
] | Title: Binomial Coefficients, Kind Of
time_limit_ms: 2000
memory_limit_mb: 512
Description: 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) ... | |
2003F | https://codeforces.com/problemset/problem/2003/F | Turtle and Three Sequences | 2,800 | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"probabilities",
"two pointers"
] | Div. 2 | 3,000 | 256 | 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$.
Turtle 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:
* $a_{p_1} \le a_{p_2} \le \cdots \le a_{... | The first line contains two integers $n$ and $m$ ($1 \le n \le 3000$, $1 \le m \le 5$) — the lengths of the three sequences and the required length of the subsequence.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the elements of the sequence $a$.
The third line contains $n$ inte... | Output a single integer — the maximum value of $\sum\limits_{i = 1}^m c_{p_i}$. If it is impossible to choose a subsequence of length $m$ that satisfies the conditions above, output $-1$. | [
[
"4 2\n2 3 4 2\n1 3 3 2\n1 4 2 3",
"5"
],
[
"7 3\n1 4 5 2 3 6 7\n1 2 2 1 1 3 2\n1 5 6 7 3 2 4",
"13"
],
[
"5 3\n1 2 3 4 5\n1 1 2 1 2\n5 4 3 2 1",
"-1"
]
] | In the first example, we can choose $p = [1, 2]$, then $c_{p_1} + c_{p_2} = 1 + 4 = 5$. We can't choose $p = [2, 4]$ since $a_2 > a_4$, violating the first condition. We can't choose $p = [2, 3]$ either since $b_2 = b_3$, violating the second condition. We can choose $p = [1, 4]$, but $c_1 + c_4 = 4$, which isn't maxim... | Title: Turtle and Three Sequences
time_limit_ms: 3000
memory_limit_mb: 256
Description: 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$.
Turtle will choose a subsequence of $1, 2, \ldots, n$ of length $m$, let it be $p_1, p_2, \ldots, p_m$. The subsequen... |
1983D | https://codeforces.com/problemset/problem/1983/D | Swap Dilemma | 1,700 | [
"constructive algorithms",
"data structures",
"divide and conquer",
"greedy",
"math",
"sortings"
] | Div. 2 | 1,000 | 256 | Given two arrays of distinct positive integers $a$ and $b$ of length $n$, we would like to make both the arrays the same. Two arrays $x$ and $y$ of length $k$ are said to be the same when for all $1 \le i \le k$, $x_i = y_i$.
Now in one move, you can choose some index $l$ and $r$ in $a$ ($l \le r$) and swap $a_l$ and ... | Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2 \cdot 10^4$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the arrays $a$ and $b$.
The second line of each test... | For each testcase, print "YES" if the arrays $a$ and $b$ can be made the same. Otherwise, print "NO". can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"6\n4\n1 2 3 4\n1 2 3 4\n5\n1 3 4 2 5\n7 1 2 5 4\n4\n1 2 3 4\n4 3 2 1\n3\n1 2 3\n1 3 2\n5\n1 5 7 1000 4\n4 1 7 5 1000\n3\n1 4 2\n1 3 2",
"YES\nNO\nYES\nNO\nNO\nNO"
]
] | In the first testcase, you don't need to perform any operations since the arrays are same.
In the second testcase, it can be proven there exists no way to make the arrays same.
In the third testcase, one of the ways to make the arrays same is to first choose $l=1$, $r=3$, $p=1$, $q=3$ then choose $l=1$, $r=2$, $p=3$,... | Title: Swap Dilemma
time_limit_ms: 1000
memory_limit_mb: 256
Description: Given two arrays of distinct positive integers $a$ and $b$ of length $n$, we would like to make both the arrays the same. Two arrays $x$ and $y$ of length $k$ are said to be the same when for all $1 \le i \le k$, $x_i = y_i$.
Now in one move, yo... |
1995A | https://codeforces.com/problemset/problem/1995/A | Diagonals | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | Div. 2 | 1,000 | 256 | Vitaly503 is given a checkered board with a side of $n$ and $k$ chips. He realized that all these $k$ chips need to be placed on the cells of the board (no more than one chip can be placed on a single cell).
Let's denote the cell in the $i$-th row and $j$-th column as $(i ,j)$. A diagonal is the set of cells for which... | Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of sets of input data. Then follow the descriptions of the sets of input data.
The only line of each set of input data contains two integers $n$, $k$ ($1 \le n \le 100, 0 \le k \le n^2$) — th... | For each set of input data, output a single integer — the minimum number of occupied diagonals with at least one chip that he can get after placing all $k$ chips. | [
[
"7\n1 0\n2 2\n2 3\n2 4\n10 50\n100 239\n3 9",
"0\n1\n2\n3\n6\n3\n5"
]
] | In the first test case, there are no chips, so 0 diagonals will be occupied. In the second test case, both chips can be placed on diagonal $(2, 1), (1, 2)$, so the answer is 1. In the third test case, 3 chips can't be placed on one diagonal, but placing them on $(1, 2), (2, 1), (1, 1)$ makes 2 diagonals occupied. In th... | Title: Diagonals
time_limit_ms: 1000
memory_limit_mb: 256
Description: Vitaly503 is given a checkered board with a side of $n$ and $k$ chips. He realized that all these $k$ chips need to be placed on the cells of the board (no more than one chip can be placed on a single cell).
Let's denote the cell in the $i$-th row ... |
1971E | https://codeforces.com/problemset/problem/1971/E | Find the Car | 1,500 | [
"binary search",
"math",
"sortings"
] | Div. 4 | 3,000 | 256 | Timur is in a car traveling on the number line from point $0$ to point $n$. The car starts moving from point $0$ at minute $0$.
There are $k+1$ signs on the line at points $0, a_1, a_2, \dots, a_k$, and Timur knows that the car will arrive there at minutes $0, b_1, b_2, \dots, b_k$, respectively. The sequences $a$ and... | The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first line of each test case contains three integers $n$, $k$, and $q$, ($k \leq n \leq 10^9$; $1 \leq k, q \leq 10^5$) — the final destination, the number of points Timur knows the time for, and the number of queries r... | For each query, output a single integer — the number of minutes passed until the car reaches the point $d$, rounded down. | [
[
"4\n10 1 3\n10\n10\n0\n6\n7\n10 2 4\n4 10\n4 7\n6\n4\n2\n7\n1000000000 1 1\n1000000000\n1000000000\n99999999\n6 1 3\n6\n5\n2\n6\n5",
"0 6 7 \n5 4 2 5 \n99999999 \n1 5 4"
]
] | For the first test case, the car goes from point $0$ to point $10$ in $10$ minutes, so the speed is $1$ unit per minute and:
* At point $0$, the time will be $0$ minutes. * At point $6$, the time will be $6$ minutes. * At point $7$, the time will be $7$ minutes.
For the second test case, between points $0$ a... | Title: Find the Car
time_limit_ms: 3000
memory_limit_mb: 256
Description: Timur is in a car traveling on the number line from point $0$ to point $n$. The car starts moving from point $0$ at minute $0$.
There are $k+1$ signs on the line at points $0, a_1, a_2, \dots, a_k$, and Timur knows that the car will arrive there... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.