text
stringlengths
0
801
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 only line of each test case contains two integers $n$, $p$ ($1 \le n \le 500$, $10^8 \leq p \leq 10^9$, $p$ is prime) — the number of cities and the modulo.
It is guaranteed that the sum of $n$ over all test cases does not exceed $500$.
For each test case, output $n+1$ integers: the $i$-th integer should be the number of arrays that satisfy the conditions for $k = i-1$.
In the first test case,
* arrays with $1$ good starting city: $[1]$.
In the second test case,
* arrays with $0$ good starting cities: $[1, 1]$; * arrays with $1$ good starting city: $[1, 2]$, $[2, 1]$; * arrays with $2$ good starting cities: $[2, 2]$.
In the third test case,
* arrays with $0$ good starting cities: $[1, 1, 1]$, $[1, 1, 2]$, $[1, 1, 3]$, $[1, 2, 1]$, $[1, 2, 2]$, $[1, 3, 1]$, $
[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).
Your score is the maximum value of a red element plus the number of red elements. Find the maximum score you can get.
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$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$) — the given array.
For each test case, output a single integer: the maximum possible score you can get after coloring some elements red according to the statement.
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([4, 4]) + \text{size}([4, 4]) = 4+2 = 6$. This is the maximum score you can get.
In the third test case, you can color the array as follows: $[\color{red}{3}, 3, \color{red}{3}, 3, \color{red}{4}, 1, 2, \color{red}{3}, 4, \color{red}{5}]$. Your score is $\max([3, 3, 4, 3, 5]) + \text{size}([3, 3, 4, 3, 5]) = 5+5 = 10$. This is the maximum score you can get.
[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.
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$.
For each test case, output a single line with $q$ integers: the $i$-th integer is the answer to the $i$-th query.
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], [3, 6], [3, 7], [5, 6], [5, 7], [6, 7]$. Points $1, 7$ are contained in exactly $5$ segments; points $2, 4, 6$ are contained in exactly $9$ segments; points $3, 5$ are contained in exactly $11$ segments.
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.
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}$).
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}$.
In the first test case, $(0\,|\,2)-(0\,\&\,2)=2-0=2$. So, $a = 0$ is a correct answer.
In the second test case, no value of $a$ satisfies the equation.
In the third test case, $(12\,|\,10)-(12\,\&\,2)=14-0=14$. So, $a = 12$ is a correct answer.
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.
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.