Alice and Bob are playing a card game. The game consists of $$$3$$$ rounds, in each round both players score some points (from $$$0$$$ to $$$k$$$), and for each round, Alice's score differs from Bob's score. The player who scores more points in a round is considered the winner of that round.
In the first round, Alice scored $$$a_1$$$ points, and Bob scored $$$b_1$$$. In the second round, Alice scored $$$a_2$$$ points, and Bob scored $$$b_2$$$.
The winner of the game is the one who has the higher total score. If Alice's total score equals Bob's total score, the player who won more rounds is declared the winner. Alice wants to understand if Bob has a chance to win, or if she will definitely win regardless of the results of the $$$3$$$-rd round. Help her determine this!
Please note that in each round, a player can score at least $$$0$$$ and at most $$$k$$$ points. Additionally, for each round, Alice's score differs from Bob's score.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of three lines:
For each test case, output NO if Alice will win regardless of the results of the third round, or YES if Bob has a chance to win.
562 31 453 13 133 13 1100 110 043 13 1
YESYESNOYESNO
In the first example, Bob will win if, for example, Alice scores $$$3$$$ points in the last round, and Bob scores $$$2$$$.
In the second example, Bob will win if Alice scores $$$0$$$ points in the last round, and Bob scores $$$5$$$.
You have two towers made of blocks, standing next to each other. Initially, the height of the first tower is $$$a$$$, and the height of the second tower is $$$b$$$.
In one action, you can:
Your goal is to make the height of the first tower equal to $$$c$$$, and the height of the second tower equal to $$$d$$$. What is the minimum number of actions you need to perform?
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of one line containing $$$4$$$ integers $$$a, b, c, d$$$ ($$$1 \le a \le c \le 10^8$$$; $$$1 \le b \le d \le 10^8$$$).
For each test case, output one integer — the minimum number of actions that you have to perform.
51 2 3 51 1 1 12 6 3 83 3 6 42 4 7 7
40335
In the first example, you can first place a block on the first tower, making the heights of both towers equal to $$$2$$$. Then, you can place one block on each tower, raising their heights to $$$3$$$. After that, you can place two blocks on the second tower, increasing its height to $$$5$$$. Thus, in $$$4$$$ moves, you can make the height of the first tower equal to $$$3$$$ and the second tower equal to $$$5$$$.
You need to construct a field for the game "Minesweeper" consisting of $$$2$$$ rows and several columns. Each cell must either be empty or contain a mine. We say that two cells are neighboring if they share a side and/or a corner.
The field you are constructing must satisfy the following constraints:
Construct such a field or report that it is impossible.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
Each test case consists of one line containing one integer $$$k$$$ ($$$1 \le k \le 100$$$) — the required number of empty cells which have a neighboring cell with a mine.
For each test case, output the answer as follows:
5148109
YES 1 * . NO YES 5 *.... ...*. YES 6 .*..*. ...... NO
The median of the sequence $$$[s_1, s_2, \dots, s_k]$$$ is defined as the element that appears at position $$$\lfloor \frac{k+1}{2} \rfloor$$$ when the sequence is sorted in non-decreasing order. For example, the median of the sequence $$$[4, 5, 6, 1, 2, 2]$$$ is $$$2$$$; the median of the sequence $$$[3, 6, 3, 4, 5]$$$ is $$$4$$$.
You are given two arrays $$$[a_1, a_2, \dots, a_n]$$$ and $$$[b_1, b_2, \dots, b_m]$$$, sorted in non-decreasing order. Both arrays have odd lengths.
In one operation, you can do the following:
Your task is to determine whether it is possible to make the arrays equal.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of three lines:
Additional constraints on the input:
For each test case, output YES if it is possible to make the arrays equal, or NO if it is not possible.
35 31 2 3 4 51 3 73 511 17 1919 20 26 29 371 7111 2 7 9 11 15 17
YESNOYES
In the first example, the arrays can be made equal by applying the following sequence of operations:
An array $$$a$$$ is called a subsequence of an array $$$b$$$ if some elements can be removed from array $$$b$$$ (possibly all, possibly none) to obtain the array $$$a$$$.
You are given an array $$$a = [a_1, a_2, \dots, a_n]$$$. We call an array $$$b = [b_1, b_2, \dots, b_m]$$$ beautiful if:
You have to process $$$q$$$ queries. In the $$$i$$$-th query, a single integer $$$x_i$$$ is given. Your task is as follows:
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
The third line contains $$$q$$$ integers $$$x_1, x_2, \dots, x_q$$$ ($$$1 \le x_i \le 10^{18}$$$).
For each query, print a single integer — the answer to it.
5 164 1 1 5 91 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4 3 2 1 0 1 2 3 4 5 6 7 8 9 -1 -1
Let's call an integer sequence self-produced if for every $$$i$$$ ($$$1 \le i \le n$$$) at least one of the following conditions holds:
Note that $$$0$$$ at the beginning/end of the sequence is also considered valid.
You are given an integer array $$$a$$$ of size $$$n$$$. Your task is to calculate the number of self-produced subsequences of the array $$$a$$$. Since the answer might be large, print it modulo $$$998244353$$$. Two subsequences are different if the indices of chosen elements are different.
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 second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$).
Additional constraint on the input: the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer — the number of self-produced subsequences of the array $$$a$$$ taken modulo $$$998244353$$$.
531 1 220 050 1 0 1 061 0 2 2 1 1112 0 3 1 0 0 2 3 0 3 2
2412841
On a field of size $$$n \times m$$$, there is a robot located at point $$$(0, 0)$$$, whose task is to reach point $$$(n, m)$$$. The robot moves in steps: at each step, it can move one unit to the right or one unit up. In other words, if it is currently at point $$$(i, j)$$$, it can move to either $$$(i + 1, j)$$$ or $$$(i, j + 1)$$$ in one step.
You do not know the exact route of the robot, but you need to intercept it. For this purpose, you have a jammer with power $$$r$$$, which you can place at any integer point $$$(x, y)$$$ on the field ($$$0 \le x \le n$$$; $$$0 \le y \le m$$$).
The robot is considered to be intercepted if at some point during its movement it is within a distance of no more than $$$r$$$ from the jammer. In other words, if there exists a point $$$(i, j)$$$ on the robot's path such that $$$\sqrt{(i - x)^2 + (j - y)^2} \le r$$$.
But there is a problem: if you place the jammer too close to the starting or the ending point of the robot's route, it will be noticed, and your plan will be compromised. Thus, you want to position the jammer so that it covers neither the point $$$(0, 0)$$$ nor the point $$$(n, m)$$$ (i. e., the distance to each of them must be strictly greater than $$$r$$$).
Calculate the number of suitable points for placing the jammer. A point is suitable if it is not too close to the ends of the route, but at the same time, the robot will be intercepted regardless of the route it takes.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The following are the $$$t$$$ test cases.
The first and only line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$r$$$ ($$$n, m \ge 1$$$; $$$n \cdot m \le 10^9$$$; $$$1 \le r \le n + m$$$) — the dimensions of the field and the power of the jammer.
For each test case, output a single integer — the number of points suitable for placing the jammer.
61 1 110 5 33 6 34 2 31000000000 1 21 1000000000 499999999
0166019999999924
One possible placement of the jammer for the second test case is illustrated in the statement.
The MEX of a sequence of non-negative integers $$$[s_1, s_2, \dots, s_n]$$$ is the smallest non-negative integer that does not appear in this sequence.
Given an array $$$[a_1, a_2, \dots, a_n]$$$, where each element is an integer from $$$-1$$$ to $$$n$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$, calculate $$$f([a_1, a_2, \dots, a_i])$$$, where $$$f(s)$$$ for an array $$$s$$$ is defined as follows:
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-1 \le a_i \le n$$$).
An additional constraint on the input: the array $$$a$$$ contains no more than $$$300$$$ elements equal to $$$-1$$$.
For each $$$i$$$ from $$$1$$$ to $$$n$$$, output a single integer — $$$f([a_1, a_2, \dots, a_i])$$$, taken modulo $$$998244353$$$.
5-1 1 -1 3 -1
1 2 24 26 248
73 5 -1 -1 -1 -1 1
0 0 1 17 223 2645 4906
103 8 5 1 0 0 7 2 2 8
0 0 0 0 2 2 2 4 4 4
Consider $$$i=3$$$ in the first example. We need to calculate $$$f([-1, 1, -1])$$$. There are $$$36$$$ different arrays that can be obtained by replacing each element $$$-1$$$ with an integer from $$$0$$$ to $$$5$$$. For $$$25$$$ of them (those that do not contain $$$0$$$), the MEX is $$$0$$$. Let's consider the remaining $$$11$$$:
The sum of these values is $$$24$$$.
If we consider $$$i=4$$$, then we need to append $$$3$$$ to each of these arrays. This will increase the MEX of two arrays by $$$2$$$, so for $$$i=4$$$, the answer is $$$26$$$.
You are given three arrays:
We perform the following process on these arrays. The process consists of $$$m$$$ stages. During the $$$i$$$-th stage, the following occurs:
An array of $$$m$$$ numbers from $$$0$$$ to $$$n$$$ is called achievable if it can be obtained as a result of this process as the array $$$b$$$.
Your task is to count the number of achievable arrays.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^4$$$).
The second line contains $$$m$$$ integers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le 50$$$).
Print one integer — the number of achievable arrays, taken modulo $$$998244353$$$.
4 34 2 3
21
2 41 2 3 4
51
1 247 34
3