Tsondu and Tenzing are playing a card game. Tsondu has $$$n$$$ monsters with ability values $$$a_1, a_2, \ldots, a_n$$$ while Tenzing has $$$m$$$ monsters with ability values $$$b_1, b_2, \ldots, b_m$$$.
Tsondu and Tenzing take turns making moves, with Tsondu going first. In each move, the current player chooses two monsters: one on their side and one on the other side. Then, these monsters will fight each other. Suppose the ability values for the chosen monsters are $$$x$$$ and $$$y$$$ respectively, then the ability values of the monsters will become $$$x-y$$$ and $$$y-x$$$ respectively. If the ability value of any monster is smaller than or equal to $$$0$$$, the monster dies.
The game ends when at least one player has no monsters left alive. The winner is the player with at least one monster left alive. If both players have no monsters left alive, the game ends in a draw.
Find the result of the game when both players play optimally.
Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^3$$$) — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n,m \leq 50$$$) — the number of monsters Tsondu and Tenzing have respectively.
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ $$$(1 \leq a_i \leq 10^9$$$) — the ability values of Tsondu's monsters.
The third line of each test case contains $$$m$$$ integers $$$b_1,b_2,\ldots,b_m$$$ $$$(1 \leq b_i \leq 10^9$$$) — the ability values of Tenzing's monsters.
For each test case, output "Tsondu" if Tsondu wins, "Tenzing" if Tenzing wins, and "Draw" if the game ends in a draw. (Output without quotes.)
Note that the output is case-sensitive. For example, if the answer is "Tsondu", the outputs "tsondu", "TSONDU", and "tSonDu" will all be recognized as incorrect outputs.
61 391 2 32 31 21 1 13 21 2 31 13 31 1 12 2 210 101 2 3 3 2 2 1 1 2 23 3 3 3 2 1 1 1 1 110 101 2 3 4 5 6 7 8 9 106 7 8 9 10 11 1 1 1 1
Tsondu Draw Tsondu Tenzing Draw Draw
Consider the first test case. It can be shown that Tsondu has a winning strategy. The following is a possible way that Tsondu can win (note that the players may not be playing optimally in this example):
Tenzing received $$$3n$$$ books from his fans. The books are arranged in $$$3$$$ stacks with $$$n$$$ books in each stack. Each book has a non-negative integer difficulty rating.
Tenzing wants to read some (possibly zero) books. At first, his knowledge is $$$0$$$.
To read the books, Tenzing will choose a non-empty stack, read the book on the top of the stack, and then discard the book. If Tenzing's knowledge is currently $$$u$$$, then his knowledge will become $$$u|v$$$ after reading a book with difficulty rating $$$v$$$. Here $$$|$$$ denotes the bitwise OR operation. Note that Tenzing can stop reading books whenever he wants.
Tenzing's favourite number is $$$x$$$. Can you help Tenzing check if it is possible for his knowledge to become $$$x$$$?
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 test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 10^5$$$, $$$0 \leq x \leq 10^9$$$) — the number of books in each stack and Tenzing's favourite number.
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) — the difficulty rating of the books in the first stack, from top to bottom.
The third line of each test case contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$0 \leq b_i \leq 10^9$$$) — the difficulty rating of the books in the second stack, from top to bottom.
The fourth line of each test case contains $$$n$$$ integers $$$c_1,c_2,\ldots,c_n$$$ ($$$0 \leq c_i \leq 10^9$$$) — the difficulty rating of the books in the third stack, from top to bottom.
It is guaranteed that the sum of $$$n$$$ does not exceed $$$10^5$$$.
For each test case, output "Yes" (without quotes) if Tenzing can make his knowledge equal to $$$x$$$, 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.
35 71 2 3 4 55 4 3 2 11 3 5 7 95 23 2 3 4 55 4 3 2 13 3 5 7 93 01 2 33 2 12 2 2
Yes No Yes
For the first test case, Tenzing can read the following $$$4$$$ books:
After reading all books, Tenzing's knowledge is $$$7$$$.
For the third test case, Tenzing can read $$$0$$$ books to make his final knowledge equals to $$$0$$$.
Tenzing has $$$n$$$ balls arranged in a line. The color of the $$$i$$$-th ball from the left is $$$a_i$$$.
Tenzing can do the following operation any number of times:
Tenzing wants to know the maximum number of balls he can remove.
Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10^3$$$) — the number of test cases. The description of test cases follows.
The first line contains a single integer $$$n$$$ ($$$1\leq n\leq 2\cdot 10^5$$$) — the number of balls.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\leq a_i \leq n$$$) — the color of the balls.
It is guaranteed that sum of $$$n$$$ of all test cases will not exceed $$$2\cdot 10^5$$$.
For each test case, output the maximum number of balls Tenzing can remove.
251 2 2 3 341 2 1 2
4 3
In the first example, Tenzing will choose $$$i=2$$$ and $$$j=3$$$ in the first operation so that $$$a=[1,3,3]$$$. Then Tenzing will choose $$$i=2$$$ and $$$j=3$$$ again in the second operation so that $$$a=[1]$$$. So Tenzing can remove $$$4$$$ balls in total.
In the second example, Tenzing will choose $$$i=1$$$ and $$$j=3$$$ in the first and only operation so that $$$a=[2]$$$. So Tenzing can remove $$$3$$$ balls in total.
Tenzing has $$$n$$$ animal friends. He numbers them from $$$1$$$ to $$$n$$$.
One day Tenzing wants to play with his animal friends. To do so, Tenzing will host several games.
In one game, he will choose a set $$$S$$$ which is a subset of $$$\{1,2,3,...,n\}$$$ and choose an integer $$$t$$$. Then, he will play the game with the animals in $$$S$$$ for $$$t$$$ minutes.
But there are some restrictions:
Tenzing wants to know the maximum total time that he can play with his animal friends. Please find out the maximum total time that Tenzing can play with his animal friends and a way to organize the games that achieves this maximum total time, or report that he can play with his animal friends for an infinite amount of time. Also, Tenzing does not want to host so many games, so he will host at most $$$n^2$$$ games.
The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 100$$$, $$$0 \leq m \leq \frac{n(n-1)}{2}$$$) — the number of animal friends and the number of special restrictions.
The $$$i$$$-th of the following $$$m$$$ lines of input contains three integers $$$u_i$$$, $$$v_i$$$ and $$$y_i$$$ ($$$1\leq u_i \lt v_i\leq n$$$, $$$0\leq y_i\leq 10^9$$$) — describing the $$$i$$$-th special restriction. It is guaranteed that for $$$1 \leq i \lt j \leq m$$$, $$$(u_i,v_i) \neq (u_j,v_j)$$$.
If Tenzing can play with his animal friends for an infinite amount of time, output "inf". (Output without quotes.)
Otherwise, in the first line, output the total time $$$T$$$ ($$$0 \leq t \leq 10^{18}$$$) and the number of games $$$k$$$ ($$$0 \leq k \leq n^2$$$).
In the following $$$k$$$ lines of output, output a binary string $$$s$$$ of length $$$n$$$ and an integer $$$t$$$ ($$$0 \leq t \leq 10^{18}$$$) — representing the set $$$S$$$ and the number of minutes this game will be played. If $$$s_i=\texttt{1}$$$, then $$$i \in S$$$, otherwise if $$$s_i=\texttt{0}$$$, then $$$i \notin S$$$.
Under the constraints of this problem, it can be proven that if Tenzing can only play with his friends for a finite amount of time, then he can only play with them for at most $$$10^{18}$$$ minutes.
5 4 1 3 2 1 4 2 2 3 1 2 5 1
4 4 10000 1 10010 1 10100 1 11110 1
3 0
inf
In the first test case:
If after that, Tenzing host another game with friends $$$\{1,2\}$$$ for $$$1$$$ minute. Then the time of exactly one of friends $$$2$$$ or $$$3$$$ with Tenzing will becomes $$$2$$$ minutes which will not satisfy the $$$3$$$-rd special restriction.
In the second test case, there is no special restrictions. So Tenzing can host a game with friend $$$\{1\}$$$ for an infinite amount of time.
There are $$$n$$$ pairwise-distinct points and a line $$$x+y=k$$$ on a two-dimensional plane. The $$$i$$$-th point is at $$$(x_i,y_i)$$$. All points have non-negative coordinates and are strictly below the line. Alternatively, $$$0 \leq x_i,y_i, x_i+y_i \lt k$$$.
Tenzing wants to erase all the points. He can perform the following two operations:
The blue area of the following picture describes the triangle with $$$a=1,b=1$$$ with cost $$$=1\cdot A$$$.
Help Tenzing find the minimum cost to erase all of the points.
The first line of the input contains three integers $$$n$$$, $$$k$$$ and $$$A$$$ ($$$1\leq n,k\leq 2\cdot 10^5$$$, $$$1\leq A\leq 10^4$$$) — the number of points, the coefficient describing the hypotenuse of the triangle and the coefficient describing the cost of drawing a triangle.
The following $$$n$$$ lines of the input the $$$i$$$-th line contains three integers $$$x_i,y_i,c_i$$$ ($$$0\leq x_i,y_i,x_i+y_i \lt k$$$, $$$1\leq c_i\leq 10^4$$$) — the coordinate of the $$$i$$$-th points and the cost of erasing it using the second operation. It is guaranteed that the coordinates are pairwise distinct.
Output a single integer —the minimum cost needed to erase all of the points.
4 6 1 1 2 1 2 1 1 1 1 1 3 2 6
4
6 7 1 4 2 1 3 3 1 5 1 4 3 2 5 4 1 1 0 6 4
4
10 4 100 0 0 1 0 1 1 0 2 50 0 3 200 1 0 1 1 1 1 1 2 1 2 0 200 2 1 200 3 0 200
355
The picture of the first example:
Tenzing do the following operations:
The picture of the second example:
Tenzing has an undirected tree of $$$n$$$ vertices.
Define the value of a tree with black and white vertices in the following way. The value of an edge is the absolute difference between the number of black nodes in the two components of the tree after deleting the edge. The value of the tree is the sum of values over all edges.
For all $$$k$$$ such that $$$0 \leq k \leq n$$$, Tenzing wants to know the maximum value of the tree when $$$k$$$ vertices are painted black and $$$n-k$$$ vertices are painted white.
The first line of the input contains a single integer $$$n$$$ ($$$1\leq n\leq 5000$$$) — the number of vertices.
The following $$$n-1$$$ lines of the input contains $$$2$$$ integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n, u_i \neq v_i$$$) — indicating an edge between vertices $$$u_i$$$ and $$$v_i$$$. It is guaranteed that the given edges form a tree.
Output $$$n+1$$$ numbers. The $$$i$$$-th number is the answer of $$$k=i-1$$$.
4 1 2 3 2 2 4
0 3 4 5 6
1
0 0
Consider the first example. When $$$k=2$$$, Tenzing can paint vertices $$$1$$$ and $$$2$$$ black then the value of edge $$$(1,2)$$$ is 0, and the values of other edges are all equal to $$$2$$$. So the value of that tree is $$$4$$$.
Tenzing has an array $$$a$$$ of length $$$n$$$ and an integer $$$v$$$.
Tenzing will perform the following operation $$$m$$$ times:
Tenzing wants to know the expected value of $$$\prod_{i=1}^n a_i$$$ after performing the $$$m$$$ operations, 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 the integer $$$x$$$ that $$$0 \le x \lt M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$v$$$ ($$$1\leq n\leq 5000$$$, $$$1\leq m,v\leq 10^9$$$).
The second line of input contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\leq a_i\leq 10^9$$$).
Output the expected value of $$$\prod_{i=1}^n a_i$$$ modulo $$$10^9+7$$$.
2 2 5 2 2
84
5 7 9 9 9 8 2 4
975544726
There are three types of $$$a$$$ after performing all the $$$m$$$ operations :
1. $$$a_1=2,a_2=12$$$ with $$$\frac{1}{4}$$$ probability.
2. $$$a_1=a_2=12$$$ with $$$\frac{1}{4}$$$ probability.
3. $$$a_1=7,a_2=12$$$ with $$$\frac{1}{2}$$$ probability.
So the expected value of $$$a_1\cdot a_2$$$ is $$$\frac{1}{4}\cdot (24+144) + \frac{1}{2}\cdot 84=84$$$.
There are $$$n$$$ uniform random real variables between 0 and 1, inclusive, which are denoted as $$$x_1, x_2, \ldots, x_n$$$.
Tenzing has $$$m$$$ conditions. Each condition has the form of $$$x_i+x_j\le 1$$$ or $$$x_i+x_j\ge 1$$$.
Tenzing wants to know the probability that all the conditions are satisfied, modulo $$$998~244~353$$$.
Formally, let $$$M = 998~244~353$$$. 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 the integer $$$x$$$ that $$$0 \le x \lt M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 20$$$, $$$0\le m\le n^2+n$$$).
Then following $$$m$$$ lines of input contains three integers $$$t$$$, $$$i$$$ and $$$j$$$ ($$$t \in \{0,1\}$$$, $$$1\le i\le j\le n$$$).
It is guaranteed that all conditions are pairwise distinct.
Output the probability that all the conditions are satisfied, modulo $$$M = 998~244~353$$$.
3 2 0 1 2 1 3 3
748683265
3 3 0 1 2 0 1 3 0 2 3
748683265
3 4 0 1 2 0 1 3 1 2 3 1 2 2
935854081
4 4 0 1 2 0 3 4 1 1 3 1 2 4
0
8 12 0 1 2 0 2 3 1 3 4 0 1 4 0 5 6 0 6 7 1 7 8 0 5 8 1 3 7 1 3 8 1 4 7 1 4 8
997687297
In the first test case, the conditions are $$$x_1+x_2 \le 1$$$ and $$$x_3+x_3\ge 1$$$, and the probability that each condition is satisfied is $$$\frac 12$$$, so the probability that they are both satisfied is $$$\frac 12\cdot \frac 12=\frac 14$$$, modulo $$$998~244~353$$$ is equal to $$$748683265$$$.
In the second test case, the answer is $$$\frac 14$$$.
In the third test case, the answer is $$$\frac 1{16}$$$.
In the fourth test case, the sum of all variables must equal $$$2$$$, so the probability is $$$0$$$.
Tenzing has a beautiful necklace. The necklace consists of $$$n$$$ pearls numbered from $$$1$$$ to $$$n$$$ with a string connecting pearls $$$i$$$ and $$$(i \text{ mod } n)+1$$$ for all $$$1 \leq i \leq n$$$.
One day Tenzing wants to cut the necklace into several parts by cutting some strings. But for each connected part of the necklace, there should not be more than $$$k$$$ pearls. The time needed to cut each string may not be the same. Tenzing needs to spend $$$a_i$$$ minutes cutting the string between pearls $$$i$$$ and $$$(i \text{ mod } n)+1$$$.
Tenzing wants to know the minimum time in minutes to cut the necklace such that each connected part will not have more than $$$k$$$ pearls.
Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2\leq n\leq 5\cdot 10^5$$$, $$$1\leq k \lt n$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\leq a_i\leq 10^9$$$).
It is guaranteed that the sum of $$$n$$$ of all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, output the minimum total time in minutes required.
45 21 1 1 1 15 21 2 3 4 56 34 2 5 1 3 310 32 5 6 5 2 1 7 9 7 2
3 7 5 15
In the first test case, the necklace will be cut into $$$3$$$ parts: $$$[1,2][3,4][5]$$$, so the total time is $$$3$$$.
In the second test case, the necklace will be cut into $$$3$$$ parts: $$$[5,1][2][3,4]$$$, Tenzing will cut the strings connecting $$$(1,2), (2,3)$$$ and $$$(4,5)$$$, so the total time is $$$a_1+a_2+a_4=7$$$.