Shaban is moving from Earth to Mars, where the laws of physics are a little unusual.
On Earth, when several weights are placed on the same side of a balance scale, their weights are added together. For example, weights $$$2$$$ and $$$5$$$ have total weight $$$2 + 5 = 7$$$.
On Mars, however, weights are multiplied instead of added. Thus weights $$$2$$$ and $$$5$$$ have total weight $$$2 \cdot 5 = 10$$$.
![]() |
Shaban wants to take a collection of balance weights with positive integer values to Mars. For every vegetable whose weight is an integer from $$$1$$$ to $$$m$$$, inclusive, he must be able to determine its exact weight by placing a non-empty subset of his weights on the empty side of the balance. On Mars, this means that the product of the chosen weights must be equal to the vegetable's weight.
Multiple carried weights may have the same value.
Your task is to find the minimum number of weights Shaban needs to take.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case begins with a line containing one integer $$$m$$$ ($$$1 \le m \le 10^6$$$).
For each test case, print one integer — the minimum number of weights Shaban needs to take so that every integer weight from $$$1$$$ to $$$m$$$ can be represented as the product of a non-empty subset of his weights.
269
57
For $$$m = 6$$$, one optimal collection is $$$\{1, 2, 3, 4, 5\}$$$. The weight $$$1$$$ is necessary because the chosen subset must be non-empty. The weights $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, and $$$5$$$ are represented directly, and $$$6 = 2 \cdot 3$$$.
For $$$m = 9$$$, one optimal collection is $$$\{1, 2, 3, 4, 5, 7, 9\}$$$. In particular, $$$8 = 2 \cdot 4$$$ and $$$9$$$ is represented directly.
While 3atori and Habbab battle it out in CS2 and PUBG, this problem is all yours.
You are given a string $$$s$$$ of length $$$n$$$ and an even integer $$$k$$$.
Consider the $$$n$$$ suffixes of $$$s$$$, one suffix for each starting position. Choose exactly $$$k$$$ of these suffixes. The score of the chosen set is the number of distinct non-empty strings $$$p$$$ such that $$$p$$$ is a prefix of at least $$$\frac{k}{2}$$$ chosen suffixes.
Compute the sum of scores over all ways to choose exactly $$$k$$$ suffixes. Since the answer can be large, print it modulo $$$10^9 + 7$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of a test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 10^6$$$, $$$k$$$ is even).
The second line contains a string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, print one integer — the sum of scores over all choices of exactly $$$k$$$ suffixes, modulo $$$10^9 + 7$$$.
32 2ab3 2aba6 4abcaec
31112
In the first test case, the two suffixes are $$$\texttt{ab}$$$ and $$$\texttt{b}$$$. Since $$$k=2$$$, both suffixes must be chosen, and a string is counted if it is a prefix of at least one chosen suffix.
The counted strings are $$$\texttt{a}$$$, $$$\texttt{ab}$$$, and $$$\texttt{b}$$$, so the answer is $$$3$$$.
In the second test case, the suffixes are $$$\texttt{aba}$$$, $$$\texttt{ba}$$$, and $$$\texttt{a}$$$. We choose two suffixes, and again a string is counted if it is a prefix of at least one chosen suffix.
If we choose $$$\texttt{aba}$$$ and $$$\texttt{ba}$$$, the score is $$$5$$$. If we choose $$$\texttt{aba}$$$ and $$$\texttt{a}$$$, the score is $$$3$$$. If we choose $$$\texttt{ba}$$$ and $$$\texttt{a}$$$, the score is $$$3$$$. Therefore the total answer is $$$5+3+3=11$$$.
As every contestant knows, the head of the 7asa7ees gang caused unforgettable chaos in HIAST CPC 2024.
Since that day, the 3ara3eer gang devoted their lives to stopping the 7asa7ees from causing more trouble for the contestants. They trained in secret rooms, guarded old archives, and watched every problemsetting meeting from the shadows.
This year, destiny brought them to the same table again.
The head of the 7asa7ees, Fofo, entered the problemsetting room with a calm smile, holding a mysterious scroll covered with strange symbols. With great confidence, Fofo suggested a 7as7ous problem.
The room became silent.
Bisseh, the head of the 3ara3eer, stood up and rejected the idea at once. The air grew heavy. Papers flew from the table. The lights flickered. Fofo's smile disappeared.
A battle began.
Bisseh fought bravely, but Fofo was a true 7as7oos. With terrifying speed, Fofo defeated Bisseh and left him fallen among the broken chairs of the problemsetting room.
Then Al-Coach Habbab stepped forward.
Everyone knew Al-Coach Habbab had strong muscles. He believed he could take revenge for his leader, and for a moment, even Fofo looked worried. Habbab charged forward, shaking the whole hall with every step.
But Fofo raised one hand and whispered the forbidden spell: $$$$$$\texttt{7as}$$$$$$
The spell struck Al-Coach Habbab directly, and he fell before reaching Fofo.
Far away, 3atori, Anous, and Moufless saw the sky turning dark above the battlefield. Without hesitation, they climbed aboard their Jamalocopter and went straight to the fight area.
What happened next was remembered as one of the wildest battles in problemsetting history. The Jamalocopter roared through smoke and lightning. Moufless held the route steady through the storm. Anous dodged cursed statements. 3atori broke through waves of 7as7ous energy. Fofo answered every attack with another spell, another trap, another impossible twist.
At last, 3atori was cornered. His strength was fading. Fofo prepared the final strike.
Just before everything ended, 3atori raised his hand and cast the ancient spell: $$$$$$\texttt{3rr}$$$$$$
The battlefield shook.
Fofo was defeated.
But the story did not end there.
Sneakily, the 3ambaloos entered the fight area while nobody was watching. They moved Fofo to the hospital, where he is now healing and preparing for another battle.
To be continued.
The next battle is coming, and only one spell can be written on your banner.
The input contains one line:
$$$$$$\texttt{What will you write on your banner?}$$$$$$
This line is a message from the battlefield and does not affect the answer.
Print exactly one of the following strings:
What will you write on your banner?
3rr
The sample chooses 3rr. Printing 7as would also be accepted.
Habbab thinks that this problem is very easy, so are you going to be '3rrar' and run away from us without solving it, or 'lesa al-amana momkenah'?
You are given a binary array $$$a$$$ of length $$$n$$$, and $$$q$$$ queries. Each query provides a range $$$[l, r]$$$, corresponding to the subarray $$$b = a_l, a_{l+1}, \dots, a_r$$$ of length $$$m = r - l + 1$$$.
For each query, calculate the number of good cyclic shifts$$$^\dagger$$$ of $$$b$$$.
A binary array $$$c$$$ of length $$$m$$$ is considered good if the following process finishes with $$$x = 0$$$:
$$$^\dagger$$$ A cyclic shift of $$$b$$$ is formed by moving its first $$$k$$$ elements to the end ($$$0 \le k \lt m$$$), resulting in the array $$$b_{k+1}, \dots, b_m, b_1, \dots, b_k$$$. All $$$m$$$ possible shifts are counted independently for each query, even if they result in identical arrays.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case begins with a line containing two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the length of the array and the number of queries.
The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$).
Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$), describing a query.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For every query, print one integer — the number of good cyclic shifts of the subarray in that query.
25 41 0 1 0 11 52 41 14 56 40 0 0 1 1 01 61 34 53 6
21014323
Consider the first test case.
It is a well-known fact in the problemsetting room: Fofo absolutely despises trees, and Jamal harbors an intense hatred for grids. Naturally, the room was left in stunned silence when Fofo, with a mischievous grin, unexpectedly proposed a tree problem.
Before the ink could even dry, Jamal narrowed his eyes and hit him with a swift, merciless $$$\texttt{3rr}$$$.
"Project it onto a grid," Jamal demanded.
After a fierce clash of wills, a compromise was born. What lies before you is the ultimate cocktail of Jamal and Fofo's $$$\texttt{7as7aseh}$$$—a grid problem haunted by the ghost of a tree.
Consider an $$$n \times m$$$ grid. A path is a sequence of cells moving exclusively down or to the right, starting and ending at distinct positions. The length of a path is the total number of cells it traverses.
Your challenge is to survive their $$$\texttt{7as7aseh}$$$ by filling the grid with positive integers such that it satisfies one core property: for every path of length $$$L$$$, at least two cells along that path must contain values divisible by $$$L$$$.
If their combined trap is too strong and no such valid grid exists, report that it is impossible.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 300$$$) — the number of rows and columns.
It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$90000$$$.
For each test case, print NO if it is impossible to construct a valid grid.
Otherwise, print YES, followed by $$$n$$$ lines. Each of these lines must contain $$$m$$$ integers, the values in the grid. Every value must be between $$$1$$$ and $$$10^9$$$, inclusive.
You may print YES and NO in any case. If there are several valid grids, print any of them.
31 11 32 2
YES 1000000000 YES 6 6 6 YES 12 6 6 12
The provided sample illustrates just one possible valid configuration.
In the first test case, there does not exist any path starting and ending at distinct positions. Hence, any grid works.
You are given a connected undirected graph with $$$n$$$ vertices. The vertices contain the values $$$1, 2, \ldots, n$$$, each value exactly once.
In one operation, you may choose an edge $$$(u, v)$$$ and swap the values on vertices $$$u$$$ and $$$v$$$ if and only if the two values differ by exactly $$$1$$$.
You are given the initial values $$$a_1, a_2, \ldots, a_n$$$ and the target values $$$b_1, b_2, \ldots, b_n$$$. Determine whether it is possible to obtain the target values after applying zero or more operations.
Note that the input and output sizes are large, so using fast I/O is recommended.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each test case begins with a line containing two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$n - 1 \le m \le \frac{n(n-1)}{2}$$$) — the number of vertices and edges.
Each of the next $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$), denoting an undirected edge. The graph is connected and contains no multiple edges.
The next line contains a permutation $$$a_1, a_2, \ldots, a_n$$$ of $$$1, 2, \ldots, n$$$.
The next line contains a permutation $$$b_1, b_2, \ldots, b_n$$$ of $$$1, 2, \ldots, n$$$.
It is guaranteed that the sum of $$$n^2$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, if the target values cannot be obtained, print NO.
Otherwise, print YES. Then print an integer $$$k$$$ ($$$0 \le k \le n^2$$$) – the number of swaps. Each of the next $$$k$$$ lines must contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$), meaning that you swap the values on vertices $$$u$$$ and $$$v$$$ at this step. For every printed swap, vertices $$$u$$$ and $$$v$$$ must be connected by an edge, and their values immediately before the swap must differ by exactly $$$1$$$. After all printed swaps, the values must be equal to the target permutation.
It is guaranteed that if a solution exists, then there exists one with at most $$$n^2$$$ swaps.
You may print YES and NO in any case. For example, yes, Yes, and YES are all accepted.
4 3 2 1 2 2 3 2 1 3 1 2 3 3 2 1 2 2 3 1 2 3 3 2 1 4 6 1 2 1 3 1 4 2 3 2 4 3 4 1 4 2 3 3 2 4 1 5 4 1 2 1 3 1 4 1 5 1 2 3 4 5 5 1 2 3 4
YES 1 2 1 NO YES 4 3 4 1 4 3 2 1 2 YES 4 1 2 1 3 1 4 1 5
In the first test case, the initial values are $$$(2,1,3)$$$. The values on vertices $$$1$$$ and $$$2$$$ differ by $$$1$$$, and vertices $$$1$$$ and $$$2$$$ are connected by an edge, so we can swap them and obtain $$$(1,2,3)$$$.
In the second test case, it can be shown that the target values cannot be obtained.
In the third test case, one valid sequence of swaps is shown in the sample output.
In the fourth test case, the graph is a star centered at vertex $$$1$$$. Starting from $$$(1,2,3,4,5)$$$, perform the swaps along edges $$$(1,2)$$$, then $$$(1,3)$$$, then $$$(1,4)$$$, then $$$(1,5)$$$. The values after these swaps are $$$(5,1,2,3,4)$$$, which is the target permutation.
Anas has an array $$$a$$$ of an even length $$$n$$$. The array can be partitioned into $$$\frac{n}{2}$$$ pairs such that the two elements in every pair are opposites: one is equal to $$$x$$$ and the other is equal to $$$-x$$$.
Anas removes exactly one element from the array and gives the remaining $$$n-1$$$ elements to Shaban. Determine the value of the removed element.
The order of the remaining elements may be arbitrary.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains an even integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the original array.
The second line contains $$$n-1$$$ integers $$$b_1,b_2,\ldots,b_{n-1}$$$ ($$$-10^4 \le b_i \le 10^4$$$) — the elements remaining after Anas removed one element.
It is guaranteed that the given elements were obtained by removing exactly one element from an array that can be partitioned into pairs of opposite elements. The removed element is also between $$$-10^4$$$ and $$$10^4$$$, inclusive.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print one integer — the value of the removed element.
4 2 7 4 5 -5 -9 6 1 -1 4 -4 -123 8 10000 -10000 2 -2 2 -2 42
-7 9 123 -42
In the first test case, the original array was $$$[7,-7]$$$.
In the second test case, adding $$$9$$$ gives the array $$$[5,-5,-9,9]$$$, which can be partitioned into the pairs $$$(5,-5)$$$ and $$$(-9,9)$$$.
You may reorder the elements of $$$a$$$ arbitrarily. Let $$$b$$$ be the array obtained after reordering. The array $$$w$$$ is not reordered: $$$w_i$$$ always belongs to position $$$i$$$.
A position $$$i$$$ ($$$1 \le i \le n$$$) is called good if $$$b_i \le i$$$. The score of $$$b$$$ is the sum of weights of all good positions. In other words, for every good position $$$i$$$, add $$$w_i$$$ to the score.
Find the maximum possible score.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the arrays.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
The third line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print one integer — the maximum possible score.
2 5 2 4 1 7 2 5 3 9 4 8 4 10 10 10 10 1 2 3 4
26 0
In the first sample, one optimal reordered array is $$$b=[1,7,2,2,4]$$$. Positions $$$1$$$, $$$3$$$, $$$4$$$, and $$$5$$$ are good, so the score is $$$5+9+4+8=26$$$. In the second sample, every element of $$$a$$$ is greater than every valid position index, so no position can be good and the answer is $$$0$$$.
You are given two strings $$$s$$$ and $$$t$$$. Initially, the current string is equal to $$$s$$$.
In one operation, you may do exactly one of the following:
The inserted string may be chosen arbitrarily, and its length does not matter.
Find the minimum number of operations needed to make the current string equal to $$$t$$$.
The first line contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases.
Each of the next $$$q$$$ lines contains two strings $$$s$$$ and $$$t$$$ ($$$1 \le |s|, |t| \le 10^6$$$). The strings consist only of lowercase English letters.
It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^6$$$, and the sum of $$$|t|$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, print one integer — the minimum number of operations needed to make $$$s$$$ equal to $$$t$$$.
7 abc abc abc bc abc ab ac abc abc b abc de ab axyb
0 1 1 1 2 2 1
In the first test case, the strings are already equal.
In the second test case, remove the prefix $$$\texttt{a}$$$ from $$$\texttt{abc}$$$.
In the fourth test case, insert $$$\texttt{b}$$$ between $$$\texttt{a}$$$ and $$$\texttt{c}$$$.
In the fifth test case, one operation is not enough. We can remove the prefix $$$\texttt{a}$$$ and then remove the suffix $$$\texttt{c}$$$.
You are given a tree with $$$n$$$ vertices. Vertex $$$i$$$ initially contains $$$a_i$$$ integer units of value.
For an edge $$$(u, v)$$$ with cost $$$w$$$, moving one unit of value from $$$u$$$ to $$$v$$$ costs $$$w$$$, and moving one unit from $$$v$$$ to $$$u$$$ also costs $$$w$$$. You may perform any number of such transfers. The final values of all vertices must be integers, and the total amount of value is preserved.
Let the final values be $$$b_1, b_2, \ldots, b_n$$$. Your primary goal is to minimize the difference between the maximum and minimum final values. Formally, you must minimize
$$$$$$\max(b_1, b_2, \dots, b_n) - \min(b_1, b_2, \dots, b_n)$$$$$$
Among all ways to obtain this minimum possible difference, find the minimum possible total transfer cost.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case begins with a line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of vertices.
The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^4$$$) — the initial values of the vertices.
Each of the next $$$n-1$$$ lines contains three integers $$$u$$$, $$$v$$$, and $$$w$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$, $$$1 \le w \le 10^4$$$), denoting an edge between vertices $$$u$$$ and $$$v$$$ with cost $$$w$$$ per moved unit.
The given edges form a tree. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, print one integer — the minimum total transfer cost among all final configurations with minimum possible value difference.
421 31 2 531 1 51 2 42 3 7410 1 1 11 2 11 3 101 4 10056 6 6 6 61 2 32 3 43 4 54 5 6
5182220
In the first test case, the total value is $$$4$$$, so both vertices must end with value $$$2$$$. One unit is moved through the only edge, for a cost of $$$5$$$.
In the second test case, the total value is $$$7$$$. The minimum possible difference is $$$1$$$, and the final values must be two vertices with value $$$2$$$ and one vertex with value $$$3$$$. It is optimal to leave vertex $$$3$$$ with value $$$3$$$, move one unit from vertex $$$3$$$ to vertex $$$2$$$, and then move one unit from vertex $$$2$$$ to vertex $$$1$$$, for a total cost of $$$18$$$.
In the third test case, the only optimal choice is to make the center vertex have value $$$4$$$ and the leaves have value $$$3$$$.
In the fourth test case, all values are already equal, so the answer is $$$0$$$.
You are given an array $$$a_1, a_2, \ldots, a_n$$$ and an integer $$$k$$$.
For every subarray $$$[l,r]$$$ ($$$1 \le l \le r \le n$$$), define $$$$$$ f(l,r)=\left[\sum_{i=l}^{r-1} a_i \oplus a_{i+1}\right]-a_l \oplus a_r $$$$$$ Here $$$\oplus$$$ denotes the bitwise XOR operation. If $$$l=r$$$, the sum is empty and is defined to be $$$0$$$.
Count the number of subarrays $$$[l,r]$$$ such that $$$f(l,r)=k$$$.
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 two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le k \lt 2^{30}$$$) — the length of the array and the required value of $$$f(l,r)$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0 \le a_i \lt 2^{30}$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print one integer — the number of subarrays $$$[l,r]$$$ for which $$$f(l,r)=k$$$.
6 1 0 7 3 0 1 2 3 3 2 1 2 3 4 6 0 3 5 6 5 1 0 1 0 1 0 4 4 0 3 0 3
1 5 1 1 0 0
In the first test case, the only subarray is $$$[1,1]$$$. Both the empty sum and $$$a_1 \oplus a_1$$$ are zero, so its value is zero.
In the second test case, all three subarrays of length one and both subarrays of length two have value zero. The subarray $$$[1,3]$$$ has value $$$$$$ (1 \oplus 2)+(2 \oplus 3)-(1 \oplus 3)=3+1-2=2. $$$$$$ Therefore, the answer is $$$5$$$.
While wandering through the desert, Ammar and his camel discover a sealed cave. A short chant opens the door, but there is still no water inside. Instead, Ammar finds the Bassami Water Puzzle.
The puzzle has an ordered box $$$v$$$. The box starts empty and can hold at most $$$m$$$ stones. Ammar then receives $$$n$$$ stones one by one.
The $$$i$$$-th stone is described by two values, $$$id_i$$$ and $$$state_i$$$:
The same identifier may appear more than once in the input. The box, however, never contains two stones with the same identifier.
For each incoming stone, apply the first rule below that matches the current box:
The first stone is the one closest to the front of the box. The back is the opposite end.
There are also $$$k$$$ curse moments. Immediately after processing the $$$c_j$$$-th stone for every $$$j$$$, the curse reverses the whole current order of the box.
After all stones and curses are handled, output the final contents of the box from front to back.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case starts with a line containing three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n,m \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$) — the number of processed stones, the capacity of the box, and the number of curse moments.
Each of the next $$$n$$$ lines contains two integers $$$id_i$$$ and $$$state_i$$$ ($$$1 \le id_i \le 10^9$$$, $$$state_i \in \{0,1\}$$$) — the identifier and state of the $$$i$$$-th stone.
After the stones, for $$$k \gt 0$$$, one more line contains $$$k$$$ distinct integers $$$c_1,c_2,\ldots,c_k$$$ ($$$1 \le c_1 \lt c_2 \lt \ldots \lt c_k \le n$$$). These are the processing steps followed by a curse. For $$$k=0$$$, this line is not present.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print two lines.
The first line contains one integer — the final number of stones in the box.
The second line contains the identifiers of the stones in the box from front to back, separated by spaces. For an empty box, print an empty second line.
2 6 3 2 1 1 2 1 3 0 4 1 5 1 6 0 3 5 4 2 0 1 0 2 1 1 1 3 0
3 5 4 1 2 2 1
In the first sample test case, the first three stones make the box $$$[1,2,3]$$$. The first curse reverses it to $$$[3,2,1]$$$.
Stone $$$4$$$ removes the first broken stone, so the box becomes $$$[2,1,4]$$$. Stone $$$5$$$ is unbroken; the full box has no broken stones, so the first stone is removed and the box becomes $$$[1,4,5]$$$. The second curse reverses it to $$$[5,4,1]$$$. Stone $$$6$$$ is broken, while the full box contains only unbroken stones, so stone $$$6$$$ is ignored.
You are given a set of $$$n$$$ red points and $$$m$$$ blue points in the Euclidean plane. No three points, ignoring their colors, are collinear.
A subset of at least three red points is called good if its points form a strictly convex polygon (i.e., every point in the subset is a vertex of its own convex hull).
Let $$$P$$$ be the convex polygon defined by a good subset. A good subset is valid if the interior of $$$P$$$ contains an odd number of blue points. Calculate the total number of valid good subsets, modulo $$$2$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each test case starts with a line containing two integers $$$n$$$ and $$$m$$$ ($$$0 \le n, m \le 1500$$$) — the number of red and blue points.
Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) — the coordinates of a red point.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) — the coordinates of a blue point.
Over all test cases, the total number of red points is at most $$$1500$$$, and the total number of blue points is at most $$$1500$$$.
No three points in one test case, ignoring their colors, are collinear.
For each test case, print one integer — the required number of valid good red subsets, modulo $$$2$$$.
43 10 04 00 41 14 10 04 00 41 11 24 10 05 06 4-1 32 22 30 03 10 12 35 5
1010
In the first test case, the only valid good subset is the set of all three red points, and its triangle contains the blue point.
In the second test case, the extra red point changes which red subsets are valid good. The number of valid good polygons containing an odd number of blue points is even, so the answer is $$$0$$$.
In the last test case, fewer than three red points are given, so there are no valid good subsets.
You are given an array $$$a$$$ of length $$$n$$$. You may color every position of the array either black or white. Let $$$D_B$$$ be the number of distinct values that appear in at least one black position, and let $$$D_W$$$ be the number of distinct values that appear in at least one white position.
Your task is to determine whether there exists a coloring such that $$$D_B = D_W$$$.
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 2 \cdot 10^5$$$) — the length of the array.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print YES if there exists a coloring such that $$$D_B = D_W$$$. Otherwise, print NO.
You may print each letter in any case.
5 1 1 4 1 2 3 4 6 1 1 2 3 4 5 3 2 2 2 7 1 2 1 3 4 5 6
NO YES YES YES YES
The colorings mentioned below are only explanations for the sample answers. They should not be printed.
In the first test case, the only value would appear in exactly one color, so the two numbers of distinct values cannot be equal.
In the second test case, there are $$$4$$$ distinct values. For example, values $$$1$$$ and $$$2$$$ can be colored black, and values $$$3$$$ and $$$4$$$ can be colored white. Then $$$D_B=D_W=2$$$.
In the third test case, there are $$$5$$$ distinct values and the value $$$1$$$ appears twice. For example, color the first occurrence of $$$1$$$ black, the second occurrence of $$$1$$$ white, values $$$2$$$ and $$$3$$$ black, and values $$$4$$$ and $$$5$$$ white. Then both colors contain exactly $$$3$$$ distinct values.
In the fourth test case, all positions contain value $$$2$$$. Since there is more than one occurrence, at least one occurrence can be colored black and at least one occurrence can be colored white. Then $$$D_B=D_W=1$$$.