inclusionAI/AReaL-boba-2-RL-Code huggingface dataset:
[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 $[a, b]$ contains the points $a, a+1, \ldots, b$.

You are given $q$ queries. In the $i$-th query, you are given a positive integer $k_i$, and you have to determine how many points with integer coordinates are contained in exactly $k_i$ segments.

Input Format:
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 second line of each test case contains $n$ integers $x_1, x_2, \ldots, x_n$ ($1 \leq x_1 < x_2 < \ldots < x_n \leq 10^9$) — the coordinates of the $n$ points.

The third line of each test case contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{18}$) — the parameters of the $q$ queries.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$, and the sum of $q$ over all test cases does not exceed $10^5$.

Output Format:
For each test case, output a single line with $q$ integers: the $i$-th integer is the answer to the $i$-th query.

Tags:
['implementation', 'math']

Time Limit: 1500 ms
Memory Limit: 256 MB
[DJ Genki vs Gram - Einherjar Joker](https://soundcloud.com/leon- hwang-368077289/einherjar-joker-dj-genki-vs-gram)

⠀

You have some cards. An integer between $1$ and $n$ is written on each card: specifically, for each $i$ from $1$ to $n$, you have $a_i$ cards which have the number $i$ written on them.

There is also a shop which contains unlimited cards of each type. You have $k$ coins, so you can buy at most $k$ new cards in total, and the cards you buy can contain any integer between $\mathbf{1}$ and $\mathbf{n}$, inclusive.

After buying the new cards, you must partition all your cards into decks, according to the following rules:

  * all the decks must have the same size;    * there are no pairs of cards with the same value in the same deck. 

Find the maximum possible size of a deck after buying cards and partitioning them optimally.

Input Format:
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$, $k$ ($1 \leq n \leq 2 \cdot 10^5$, $0 \leq k \leq 10^{16}$) — the number of distinct types of cards and the number of coins.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^{10}$, $\sum a_i \geq 1$) — the number of cards of type $i$ you have at the beginning, for each $1 \leq i \leq n$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output Format:
For each test case, output a single integer: the maximum possible size of a deck if you operate optimally.

Tags:
['greedy', 'implementation', 'math']

Time Limit: 2000 ms
Memory Limit: 256 MB
[Djjaner - Speedbreaker](https://soundcloud.com/luciano- ferrari-151560131/speedbreaker)

⠀

There are $n$ cities in a row, numbered $1, 2, \ldots, n$ left to right.

  * At time $1$, you conquer exactly one city, called the starting city.    * At time $2, 3, \ldots, n$, you can choose a city adjacent to the ones conquered so far and conquer it. 

You win if, for each $i$, you conquer city $i$ at a time no later than $a_i$. A winning strategy may or may not exist, also depending on the starting city. How many starting cities allow you to win?

Input Format:
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$ ($1 \le n \le 2 \cdot 10^5$) — the number of cities.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the deadlines for conquering the cities.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output Format:
For each test case, output a single integer: the number of starting cities that allow you to win.

Tags:
['binary search', 'constructive algorithms', 'data structures', 'greedy', 'math']

Time Limit: 2000 ms
Memory Limit: 256 MB
[t+pazolite, ginkiha, Hommarju - Paved Garden](https://soundcloud.com/fractalex-gd/ginkiha-paved-garden-little)

⠀

You are given a tree with $n$ nodes, rooted at node $1$. In this problem, a leaf is a non-root node with degree $1$.

In one operation, you can remove a leaf and the edge adjacent to it (possibly, new leaves appear). What is the minimum number of operations that you have to perform to get a tree, also rooted at node $1$, where all the leaves are at the same distance from the root?

Input Format:
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$ ($3 \leq n \leq 5 \cdot 10^5$) — the number of nodes.

Each of the next $n-1$ lines contains two integers $u$, $v$ ($1 \leq u, v \leq n$, $u \neq v$), describing an edge that connects $u$ and $v$. It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^5$.

Output Format:
For each test case, output a single integer: the minimum number of operations needed to achieve your goal.

Tags:
['constructive algorithms', 'dfs and similar', 'dp', 'sortings', 'trees']

Time Limit: 3000 ms
Memory Limit: 256 MB
[EnV - The Dusty Dragon Tavern](https://soundcloud.com/envyofficial/env-the- dusty-dragon-tavern)

⠀

You are given an array $a_1, a_2, \ldots, a_n$ of positive integers.

You can color some elements of the array red, but there cannot be two adjacent red elements (i.e., for $1 \leq i \leq n-1$, at least one of $a_i$ and $a_{i+1}$ must not be red).

Your score is the maximum value of a red element, plus the minimum value of a red element, plus the number of red elements. Find the maximum score you can get.

Input Format:
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$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the given array.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output Format:
For each test case, output a single integer: the maximum possible score you can get after coloring some elements red according to the statement.

Tags:
['data structures', 'dp', 'dsu', 'greedy', 'sortings']

Time Limit: 2000 ms
Memory Limit: 256 MB
You are given two integers $n$ and $k$.

In one operation, you can subtract any power of $k$ from $n$. Formally, in one operation, you can replace $n$ by $(n-k^x)$ for any non-negative integer $x$.

Find the minimum number of operations required to make $n$ equal to $0$.

Input Format:
Each test contains multiple test 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$).

Output Format:
For each test case, output the minimum number of operations on a new line.

Tags:
['bitmasks', 'brute force', 'greedy', 'math', 'number theory']

Time Limit: 1000 ms
Memory Limit: 256 MB
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^\dagger$. 

After performing all operations, there will be several bulbs that are still on. Your goal is to make this number exactly $k$.

Find the smallest suitable $n$ such that after performing the operations there will be exactly $k$ bulbs on. We can show that an answer always exists.

$^\dagger$ An integer $x$ is divisible by $y$ if there exists an integer $z$ such that $x = y\cdot z$.

Input Format:
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}$).

Output Format:
For each test case, output $n$ — the minimum number of bulbs.

Tags:
['binary search', 'math']

Time Limit: 1000 ms
Memory Limit: 256 MB
You are given three non-negative integers $b$, $c$, and $d$.

Please find a non-negative integer $a \in [0, 2^{61}]$ such that $(a\, |\, b)-(a\, \&\, c)=d$, where $|$ and $\&$ denote the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR) and the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), respectively.

If such an $a$ exists, print its value. If there is no solution, print a single integer $-1$. If there are multiple solutions, print any of them.

Input Format:
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 positive integers $b$, $c$, and $d$ ($0 \le b, c, d \le 10^{18}$).

Output Format:
For each test case, output the value of $a$, or $-1$ if there is no solution. Please note that $a$ must be non-negative and cannot exceed $2^{61}$.

Tags:
['bitmasks', 'hashing', 'implementation', 'math', 'schedules', 'ternary search']

Time Limit: 2000 ms
Memory Limit: 256 MB
One fine evening, Alice sat down to play the classic game "Connect the Dots", but with a twist.

To play the game, Alice draws a straight line and marks $n$ points on it, indexed from $1$ to $n$. Initially, there are no arcs between the points, so they are all disjoint. After that, Alice performs $m$ operations of the following type:

  * She picks three integers $a_i$, $d_i$ ($1 \le d_i \le 10$), and $k_i$.    * She selects points $a_i, a_i+d_i, a_i+2d_i, a_i+3d_i, \ldots, a_i+k_i\cdot d_i$ and connects each pair of these points with arcs. 

After performing all $m$ operations, she wants to know the number of connected components$^\dagger$ these points form. Please help her find this number.

$^\dagger$ Two points are said to be in one connected component if there is a path between them via several (possibly zero) arcs and other points.

Input Format:
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 two integers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5$, $1 \le m \le 2 \cdot 10^5$).

The $i$-th of the following $m$ lines contains three integers $a_i$, $d_i$, and $k_i$ ($1 \le a_i \le a_i + k_i\cdot d_i \le n$, $1 \le d_i \le 10$, $0 \le k_i \le n$).

It is guaranteed that both the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.

Output Format:
For each test case, output the number of connected components.

Tags:
['brute force', 'dp', 'dsu', 'graphs', 'math', 'trees']

Time Limit: 2000 ms
Memory Limit: 512 MB
You are given an array of $n$ integers $a_1,a_2,\ldots,a_n$. You are also given an array $p_1, p_2, \ldots, p_n$.

Let $S$ denote the random multiset (i. e., it may contain equal elements) constructed as follows:

  * Initially, $S$ is empty.    * For each $i$ from $1$ to $n$, insert $a_i$ into $S$ with probability $\frac{p_i}{10^4}$. Note that each element is inserted independently. 

Denote $f(S)$ as the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all elements of $S$. Please calculate the expected value of $(f(S))^2$. Output the answer modulo $10^9 + 7$.

Formally, let $M = 10^9 + 7$. It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$, where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$. Output the integer equal to $p \cdot q^{-1} \bmod M$. In other words, output such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$.

Input Format:
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$ ($1 \le n \le 2 \cdot 10^5$).

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 1023$).

The third line of each test case contains $n$ integers $p_1,p_2,\ldots,p_n$ ($1 \le p_i \le 10^4$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output Format:
For each test case, output the expected value of $(f(S))^2$, modulo $10^9 + 7$.

Tags:
['bitmasks', 'dp', 'math', 'probabilities']

Time Limit: 4000 ms
Memory Limit: 256 MB
Let $n$ and $d$ be positive integers. We build the the divisor tree $T_{n,d}$ as follows:

  * The root of the tree is a node marked with number $n$. This is the $0$-th layer of the tree.    * For each $i$ from $0$ to $d - 1$, for each vertex of the $i$-th layer, do the following. If the current vertex is marked with $x$, create its children and mark them with all possible distinct divisors$^\dagger$ of $x$. These children will be in the $(i+1)$-st layer.    * The vertices on the $d$-th layer are the leaves of the tree. 

For example, $T_{6,2}$ (the divisor tree for $n = 6$ and $d = 2$) looks like this:

![](CDN_BASE_URL/782ea6d6fe622ee5ec986b0d8cae274d)

Define $f(n,d)$ as the number of leaves in $T_{n,d}$.

Given integers $n$, $k$, and $d$, please compute $\sum\limits_{i=1}^{n} f(i^k,d)$, modulo $10^9+7$.

$^\dagger$ In this problem, we say that an integer $y$ is a divisor of $x$ if $y \ge 1$ and there exists an integer $z$ such that $x = y \cdot z$.

Input Format:
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 three integers $n$, $k$, and $d$ ($1 \le n \le 10^9$, $1 \le k,d \le 10^5$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^9$.

Output Format:
For each test case, output $\sum\limits_{i=1}^{n} f(i^k,d)$, modulo $10^9+7$.

Tags:
['dp', 'math', 'number theory']

Time Limit: 4000 ms
Memory Limit: 256 MB
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 $i$ and $j$ ($1 \leq i, j \leq |a|$; $i \neq j$), note that $|a|$ denotes the current size of the array $a$.    2. Append $\lfloor \frac{a_i+a_j}{2} \rfloor$$^{\text{∗}}$ to the end of the array.    3. Remove elements $a_i$ and $a_j$ from the array and concatenate the remaining parts of the array. 

For example, suppose that $a=[5,4,3,2,1,1]$. If we choose $i=1$ and $j=5$, the resulting array will be $a=[4,3,2,1,3]$. If we choose $i=4$ and $j=3$, the resulting array will be $a=[5,4,1,1,2]$.

After all operations, the array will consist of a single element $x$. Find the maximum possible value of $x$ if Pak Chanek performs the operations optimally.

$^{\text{∗}}$$\lfloor x \rfloor$ denotes the floor function of $x$, which is the greatest integer that is less than or equal to $x$. For example, $\lfloor 6 \rfloor = 6$, $\lfloor 2.5 \rfloor=2$, $\lfloor -3.6 \rfloor=-4$ and $\lfloor \pi \rfloor=3$

Input Format:
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$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array $a$.

Do note that the sum of $n$ over all test cases is not bounded.

Output Format:
For each test case, output a single integer: the maximum possible value of $x$ after all numbers have been picked.

Tags:
['data structures', 'greedy', 'math', 'sortings']

Time Limit: 1000 ms
Memory Limit: 256 MB
You are given an array $a$ of $n$ positive integers and an integer $x$. You can do the following two-step operation any (possibly zero) number of times:

  1. Choose an index $i$ ($1 \leq i \leq n$).    2. Increase $a_i$ by $x$, in other words $a_i := a_i + x$. 

Find the maximum value of the $\operatorname{MEX}$ of $a$ if you perform the operations optimally.

The $\operatorname{MEX}$ (minimum excluded value) of an array is the smallest non-negative integer that is not in the array. For example:

  * The $\operatorname{MEX}$ of $[2,2,1]$ is $0$ because $0$ is not in the array.    * The $\operatorname{MEX}$ of $[3,1,0,1]$ is $2$ because $0$ and $1$ are in the array but $2$ is not.    * The $\operatorname{MEX}$ of $[0,3,1,2]$ is $4$ because $0$, $1$, $2$ and $3$ are in the array but $4$ is not.

Input Format:
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 two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$; $1 \le x \le 10^9$) — the length of the array and the integer to be used in the operation.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the given array.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output Format:
For each test case, output a single integer: the maximum $\operatorname{MEX}$ of $a$ if you perform the operations optimally.

Tags:
['brute force', 'greedy', 'math', 'number theory']

Time Limit: 1000 ms
Memory Limit: 256 MB
This is the easy version of the problem. In the two versions, the constraints on $q$ and the time limit are different. In this version, $q=0$. You can make hacks only if all the versions of the problem are solved.

A team consisting of $n$ members, numbered from $1$ to $n$, is set to present a slide show at a large meeting. The slide show contains $m$ slides.

There is an array $a$ of length $n$. Initially, the members are standing in a line in the order of $a_1, a_2, \ldots, a_n$ from front to back. The slide show will be presented in order from slide $1$ to slide $m$. Each section will be presented by the member at the front of the line. After each slide is presented, you can move the member at the front of the line to any position in the lineup (without changing the order of the rest of the members). For example, suppose the line of members is $[\color{red}{3},1,2,4]$. After member $3$ presents the current slide, you can change the line of members into either $[\color{red}{3},1,2,4]$, $[1,\color{red}{3},2,4]$, $[1,2,\color{red}{3},4]$ or $[1,2,4,\color{red}{3}]$.

There is also an array $b$ of length $m$. The slide show is considered good if it is possible to make member $b_i$ present slide $i$ for all $i$ from $1$ to $m$ under these constraints.

However, your annoying boss wants to make $q$ updates to the array $b$. In the $i$-th update, he will choose a slide $s_i$ and a member $t_i$ and set $b_{s_i} := t_i$. Note that these updates are persistent, that is changes made to the array $b$ will apply when processing future updates.

For each of the $q+1$ states of array $b$, the initial state and after each of the $q$ updates, determine if the slideshow is good.

Input Format:
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 three integers $n$, $m$ and $q$ ($1 \le n, m \le 2 \cdot 10^5$; $q=0$) — the number of members, the number of sections and the number of updates.

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le n$) — the initial order of the members from front to back. It is guaranteed that each integer from $1$ to $n$ appears exactly once in $a$.

The third line of each test case contains $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \le b_i \le n$) — the members who should present each section.

It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$ respectively.

Output Format:
For each test case, output $q+1$ lines corresponding to the $q+1$ states of the array $b$. Output "YA" if the slide show is good, and "TIDAK" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yA", "Ya", "ya", and "YA" will be recognized as positive responses.

Tags:
['constructive algorithms', 'greedy']

Time Limit: 2000 ms
Memory Limit: 256 MB