Last Christmas, your friend Fernando gifted you a string $$$s$$$ consisting only of the characters $$$\mathtt{Y}$$$ and $$$\mathtt{N}$$$, representing "Yes" and "No", respectively.
You can repeatedly apply the following operation on $$$s$$$:
Formally, in each operation, you can choose an index $$$i$$$ ($$$1 \leq i \leq |s|-1$$$), remove the characters $$$s_i$$$ and $$$s_{i+1}$$$, then insert:
Note that after each operation, the length of $$$s$$$ decreases by $$$1$$$.
Unfortunately, Fernando does not want you to combine "Yes OR Yes", as he has experienced trauma relating to a certain song.
Determine whether it is possible to reduce $$$s$$$ to a single character by repeatedly applying the operation above, without ever combining two $$$\mathtt{Y}$$$'s.
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 the string $$$s$$$ ($$$2\le |s|\le 100$$$). It is guaranteed that $$$s_i = \mathtt{Y}$$$ or $$$\mathtt{N}$$$.
For each test case, print "YES" if the string can be reduced to a single character by repeatedly applying the described operation, and "NO" 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.
7YYNNNNYYYYNYNNNNNYYYYYYYNNNNN
NOYESYESNOYESNOYES
In the first test case, you cannot combine $$$s_1$$$ and $$$s_2$$$ since they are both $$$\mathtt{Y}$$$. Thus, the answer is NO.
In the third test case, the following is a valid sequence of operations: $$$\mathtt{\underline{NN}Y}\to\mathtt{\underline{NY}}\to\mathtt{Y}$$$. Thus, the answer is YES.
In the fourth test case, there are two possibilities for the first operation: $$$\mathtt{YY\underline{YN}Y}\to \mathtt{YYYY}$$$ or $$$\mathtt{YYY\underline{NY}}\to \mathtt{YYYY}$$$. However, in either case, it is not possible to perform any more operations without combining two $$$\mathtt{Y}$$$'s. Thus, the answer is NO.
In the fifth test case, the following is a valid sequence of operations: $$$\mathtt{N\underline{NN}NN}\to\mathtt{\underline{NN}NN}\to\mathtt{N\underline{NN}}\to\mathtt{\underline{NN}}\to\mathtt{N}$$$. Thus, the answer is YES.
A string $$$w$$$ consisting of lowercase Latin letters is called suspicious if and only if all of the following conditions hold:
After watching you finish a string task, your friend Aka has gifted you a string $$$r$$$ consisting only of letters $$$\mathtt{s}$$$ and $$$\mathtt{u}$$$. You can perform the following operation on $$$r$$$:
Determine the minimum number of operations needed to make $$$r$$$ suspicious. It can be shown that, under the given constraints, it is always possible to transform $$$r$$$ into a suspicious string.
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 the string $$$r$$$ ($$$3\le |r|\le 2\cdot 10^5$$$). It is guaranteed that $$$r_i = \mathtt{s}$$$ or $$$\mathtt{u}$$$.
It is guaranteed that the sum of $$$|r|$$$ over all test cases does not exceed $$$2\cdot 10 ^ 5$$$.
For each test case, output a single integer — the minimum number of operations needed to make $$$r$$$ suspicious.
9susuuuusssssuusuuusuuuuuuussssssssssuuussssusuusuuusuuuuuuuuuuu
030331126
In the first test case, the string $$$\mathtt{sus}$$$ is already suspicious because $$$\mathtt{s}$$$ appears twice in the string and the two nearest $$$\mathtt{s}$$$ to the only $$$\mathtt{u}$$$ are both $$$1$$$ character away: $$$\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}$$$.
In the second test case, it is optimal to perform the operation on indices $$$1$$$, $$$3$$$, and $$$4$$$. After that, the string $$$s$$$ becomes $$$\texttt{suss}$$$. The string $$$\mathtt{suss}$$$ is suspicious because $$$\mathtt{s}$$$ appears $$$3$$$ times in the string and the two nearest $$$\mathtt{s}$$$ to the only $$$\mathtt{u}$$$ are both $$$1$$$ character away: $$$\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}\mathtt{s}$$$.
In the third test case, the condition on $$$\mathtt{u}$$$ is vacuously true because there is no $$$\mathtt{u}$$$ in the string $$$\mathtt{sssss}$$$. Thus, the given string is already suspicious.
In the sixth test case, the initial string $$$\mathtt{usssssss}$$$ is not suspicious because the two nearest $$$\mathtt{s}$$$ to the only $$$\mathtt{u}$$$ are one and two characters away, respectively: $$$\underline{\mathtt{u}}\color{red}{\mathtt{ss}}\mathtt{sssss}$$$.
There are $$$n$$$ children standing in a line, where the niceness of the $$$i$$$-th child is $$$a_i$$$. Santa is deciding which children belong on the nice list and which belong on the naughty list.
An integer $$$X$$$ is initially set to $$$0$$$. Santa will perform the following operation exactly $$$n-1$$$ times:
Note that after all operations, exactly one child remains unassigned to a list.
Determine the maximum possible value of $$$X$$$ that Santa can obtain after all $$$n-1$$$ operations.
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$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of children.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9\le a_i\le 10^9$$$) — the niceness of each child.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10 ^ 5$$$.
For each test case, print a single integer — the maximum possible value of $$$X$$$ that Santa can obtain after all $$$n-1$$$ operations.
722 -341 4 3 44-4 2 3 -65-2 -3 4 10 -95-12345678 -1000000000 -999999999 1000000000 -9999999992-7 157 -6 -1 -8 -8
384152987654321-129
In the first test case, Santa will perform exactly one operation. If he chooses the first child, he will add $$$a_1=2$$$ to $$$X$$$ to get $$$X=2$$$; if he chooses the second child, he will subtract $$$a_2=-3$$$ from $$$X$$$ to get $$$X=3$$$. Thus, the answer is $$$3$$$.
In the second test case, it is optimal to select the first child in all three operations. The value of $$$X$$$ will be $$$1+4+3=8$$$.
In the third test case, below is an optimal sequence of operations:
| # | Type | Niceness of remaining children | $$$X$$$ after operation |
| 0 | — | $$$[-4, 2, 3, -6]$$$ | $$$0$$$ |
| 1 | First | $$$[2, 3, -6]$$$ | $$$-4$$$ |
| 2 | First | $$$[3, -6]$$$ | $$$-2$$$ |
| 3 | Second | $$$[3]$$$ | $$$4$$$ |
In the fourth test case, below is an optimal sequence of operations:
| # | Type | Niceness of remaining children | $$$X$$$ after operation |
| 0 | — | $$$[-2, -3, 4, 10, -9]$$$ | $$$0$$$ |
| 1 | Second | $$$[-2, 4, 10, -9]$$$ | $$$3$$$ |
| 2 | First | $$$[4, 10, -9]$$$ | $$$1$$$ |
| 3 | First | $$$[10, -9]$$$ | $$$5$$$ |
| 4 | First | $$$[-9]$$$ | $$$15$$$ |
Franklin is plotting a Christmas attack where he casts the spell Mass Hysteria on a village of elves.
There are $$$n$$$ elves numbered $$$1$$$ to $$$n$$$, where elf $$$i$$$ has a health value of $$$h_i$$$ and an attack value of $$$a_i$$$. Initially, $$$h_i=a_i$$$ for all $$$i$$$, and all $$$a_i$$$ are distinct. Elf $$$i$$$ is alive if and only if its health is positive (i.e., $$$h_i \gt 0$$$).
When Franklin casts Mass Hysteria, the following process is repeated:
The process will repeat until it is impossible to choose a valid pair of elves. It can be shown that Mass Hysteria terminates after at most $$$n$$$ iterations.
Given an integer $$$m$$$, construct a valid sequence of attacks such that exactly $$$m$$$ elves are alive when the process ends; or determine that no such sequence exists.
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$$$ and $$$m$$$ ($$$2\le n\le 2\cdot 10^5, 0\le m\le n$$$) — the number of elves in the village and the number of elves to be left alive.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$) — the initial attack and health values of the elves.
It is guaranteed that all $$$a_i$$$ are distinct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10 ^ 5$$$.
For each test case, if it is impossible for exactly $$$m$$$ elves to remain alive, print $$$-1$$$.
Otherwise, output a valid sequence of attacks as follows:
The sequence must satisfy all of the following conditions:
If there are multiple answers, you may output any of them. Any valid sequence satisfying the above conditions will be accepted.
74 21 4 2 32 26 73 01 2 33 11 2 33 21 2 34 12 3 4 56 0998244353 1000000000 314159265 676767677 999999999 987654321
23 12 4-123 21 321 23 2-121 44 243 12 56 14 2
In the first test case, one possible sequence of attacks is shown below:
| # | $$$x$$$ | $$$y$$$ | Health values after attack | Elves that have attacked |
| 0 | — | — | $$$[1, 4, 2, 3]$$$ | $$$[]$$$ |
| 1 | $$$3$$$ | $$$1$$$ | $$$[-1, 4, 1, 3]$$$ | $$$[3]$$$ |
| 2 | $$$2$$$ | $$$4$$$ | $$$[-1, 1, 1, -1]$$$ | $$$[2, 3]$$$ |
After $$$2$$$ iterations, only elves $$$2$$$ and $$$3$$$ are alive. Since both of them have already attacked, no further valid attack is possible, and Mass Hysteria terminates.
In the second test case, the only possible choices for $$$(x,y)$$$ in the first iteration are $$$(1,2)$$$ or $$$(2,1)$$$. In either case, elf $$$1$$$ ends up with $$$-1$$$ health, so it is impossible for both elves to remain alive at the end. Note that Mass Hysteria will last at least one iteration as there exists a valid $$$(x,y)$$$ for the first iteration.
In the sixth test case, only elf $$$3$$$ is alive after all attacks. Even though elf $$$3$$$ has not attacked before, Mass Hysteria terminates since there is no other elf it can attack.
This is an interactive problem.
While procrastinating at work, Dilhan the elf stumbled upon two arrays $$$a$$$ and $$$b$$$. Initially, both of them consist of a single integer $$$2^k$$$ (i.e., $$$a=b=[2^k]$$$), where $$$k$$$ is a non-negative integer.
Dilhan then applied the following two types of operations an arbitrary number of times (possibly zero), in any order:
After performing these operations, Dilhan discards $$$b$$$, hides $$$a$$$ from you, and challenges you to a game.
Let $$$n$$$ be the length of the hidden array $$$a$$$. You may make the following query:
Determine the value of the maximum element of $$$a$$$ by making at most $$$300$$$ queries.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of $$$a$$$.
It is guaranteed that $$$1\le a_i\le 2^{30}$$$, and the array $$$a$$$ can be generated by the process described in the statements.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, you are first given an integer $$$n$$$ — the length of the hidden array $$$a$$$. You may then make up to $$$300$$$ queries.
To make a query, print a line in the following format:
After you print a query, the interactor will respond with a single integer — the sum $$$a_l+a_{l+1}+\ldots+a_r$$$.
To report that you have determined the value of the maximum element of $$$a$$$, print your answer in the following format:
Printing the answer does not count as one of the $$$300$$$ queries.
After printing the answer, proceed to the next test case. If the current test case is the last one, terminate the program.
After printing each query do not forget to output the end of line and flush$$$^{\text{∗}}$$$ the output. Otherwise, you will get Idleness limit exceeded verdict.
If, at any interaction step, you read $$$-1$$$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.
The interactor in this problem is not adaptive. In other words, the array $$$a$$$ is fixed before any queries and will not change during the interaction.
Hacks are disabled in this problem.
$$$^{\text{∗}}$$$To flush, use:
4 11 9 4 12 1 1 8 4 4 4 4 8
? 3 8 ? 1 4 ? 5 11 ! 2 ? 1 1 ! 1 ? 1 1 ? 2 2 ? 3 3 ? 4 4 ! 4 ! 1073741824
In the first test case, Dilhan's hidden array $$$a$$$ is $$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$$. It can be generated by the following process:
| # | Type | $$$a$$$ after operation | $$$b$$$ after operation |
| 0 | $$$[4]$$$ | $$$[4]$$$ | |
| 1 | Flatten $$$a$$$ | $$$[\underline 4] \to {[2, 2]}$$$ | $$$[4]$$$ |
| 2 | Flatten $$$b$$$ | $$$[2, 2]$$$ | $$$[\underline 4] \to {[2, 2]}$$$ |
| 3 | Flatten $$$a$$$ | $$$[2, \underline 2] \to {[2, 1, 1]}$$$ | $$$[2, 2]$$$ |
| 4 | Concatenate | $$$[2, 1, 1, 2, 2]$$$ | $$$[2, 1, 1, 2, 2]$$$ |
| 5 | Flatten $$$a$$$ | $$$[\underline 2, 1, 1, 2, 2]\to {[1, 1, 1, 1, 2, 2]}$$$ | $$$[2, 1, 1, 2, 2]$$$ |
| 6 | Concatenate | $$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$$ | $$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$$ |
And the value of the maximum element of $$$a$$$ is $$$2$$$.
In the second test case, the array $$$a$$$ has only one element. By the query, the value of the only element is $$$1$$$, and it must also be the maximum value.
In the third test case, Dilhan's hidden array $$$a$$$ is $$$[4, 4, 4, 4, 4, 4, 4, 4]$$$. It can be generated by the following process:
| # | Type | $$$a$$$ after operation | $$$b$$$ after operation |
| 0 | $$$[4]$$$ | $$$[4]$$$ | |
| 1 | Concatenate | $$$[4, 4]$$$ | $$$[4, 4]$$$ |
| 2 | Concatenate | $$$[4, 4, 4, 4]$$$ | $$$[4, 4, 4, 4]$$$ |
| 3 | Concatenate | $$$[4, 4, 4, 4, 4, 4, 4, 4]$$$ | $$$[4, 4, 4, 4, 4, 4, 4, 4]$$$ |
And the value of the maximum element of $$$a$$$ is $$$4$$$.
In the fourth test case, Dilhan's hidden array $$$a$$$ is $$$[2^{29}, 2^{29}, 2^{30}, 2^{29}, 2^{28}, 2^{28}, 2^{29}, 2^{29}]$$$.
Define the unique ornamental coloring of a rooted tree$$$^{\text{∗}}$$$ as the following vertex coloring:
On his quest to conquer a forest of Christmas trees, Yuuki encountered an ornamentally colored tree $$$T$$$ with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$, rooted at vertex $$$1$$$.
Yuuki considers the tree conquered if and only if at least one of the following conditions holds:
To conquer the tree, Yuuki can apply the following operation on $$$T$$$ an arbitrary number of times (possibly zero):
A possible application of the operation in the first test case. The resulting tree is conquered since all white vertices lie on the path between vertices $$$1$$$ and $$$3$$$. Compute the number of distinct$$$^{\text{‡}}$$$ conquered trees that Yuuki can construct by applying the above operation an arbitrary number of times on $$$T$$$. Since the answer may be large, output it modulo $$$998\,244\,353$$$.
Note that Yuuki cannot stop midway through an operation (in particular, he must recolor the tree before checking if it is conquered). Additionally, Yuuki is allowed to apply the operation even if the tree is already conquered.
$$$^{\text{∗}}$$$A tree is a connected graph without cycles.
$$$^{\text{†}}$$$A subtree of vertex $$$v$$$ is the subgraph of $$$v$$$, all its descendants, and all the edges between them.
$$$^{\text{‡}}$$$Two trees are considered distinct if and only if there exists a pair of vertices such that there is an edge between them in one of the trees, and not in the other.
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$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of vertices in $$$T$$$.
Then $$$n-1$$$ lines follow, the $$$i$$$-th line containing two integers $$$u_i$$$ and $$$v_i$$$ ($$$1\le u_i \lt v_i\le n$$$) — the two vertices that the $$$i$$$-th edge connects.
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 $$$2\cdot 10^5$$$.
For each test case, output a single integer — the number of distinct conquered trees that can be constructed from $$$T$$$, modulo $$$998\,244\,353$$$.
541 21 33 451 21 31 41 551 22 31 44 561 22 32 42 65 6112 106 81 63 75 115 85 94 76 72 6
411682048
In the first test case, below are the four conquered trees that can be constructed and a sequence of operations that constructs each one.
| Illustration | |
| ![]() |
| ![]() |
| ![]() |
| ![]() |
In the second test case, Yuuki cannot apply the operation on $$$T$$$ since there are no white vertices. Additionally, $$$T$$$ is already conquered since there are no white vertices. Thus, the answer is $$$1$$$.
Due to supply chain issues in the North Pole (allegedly caused by a lazy elf), Santa is planning to give out hand-drawn circles as presents this Christmas. Please help him decorate them!
There are $$$2n$$$ equally spaced points around the circle, labeled $$$1,2,\ldots,2n$$$ in clockwise order. Santa has chosen $$$n$$$ chords with distinct endpoints, where chord $$$i$$$ connects the points $$$a_i$$$ and $$$b_i$$$. He draws these chords onto the circle one by one, in order.
After Santa has drawn the first $$$\ell$$$ chords, consider any non-empty subset $$$S$$$ of the $$$\ell$$$ chords and let $$$1\leq c_1 \lt c_2 \lt \cdots \lt c_{|S|}\leq \ell$$$ be their indices. $$$S$$$ is defined to be a chain if and only if chord $$$c_k$$$ intersects chord $$$c_{k+1}$$$ for all $$$1\leq k \lt |S|$$$. Note that $$$S$$$ is always a chain if $$$|S|=1$$$.
Santa does not want any chord to be the odd one out. Therefore, he considers the chords to be tight-knit if and only if every chord appears in an even number of chains, taken over all chains that are subsets of the first $$$\ell$$$ chords.
For each $$$\ell$$$ from $$$1$$$ to $$$n$$$, help Santa determine whether his chords are tight-knit.
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$$$ ($$$2\le n\le 5\cdot 10^5$$$) — the number of chords.
Then $$$n$$$ lines follow, the $$$i$$$-th line containing two integers $$$a_i$$$ and $$$b_i$$$ ($$$1\le a_i \lt b_i\le 2n$$$) — the endpoints of the $$$i$$$-th chord.
It is guaranteed that all endpoints are distinct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.
For each test case, output a string of length $$$n$$$ — the $$$\ell$$$-th character should be $$$\texttt{1}$$$ if the first $$$\ell$$$ chords are tight-knit and $$$\texttt{0}$$$ otherwise.
331 62 34 541 73 84 62 551 64 92 75 103 8
000010001111
In the first test case, no pairs of chords intersect, and thus every chord appears in exactly one chain consisting of itself. Therefore, the chords are not tight-knit for all $$$\ell$$$.
In the second test case, below is an illustration and explanation after the first $$$\ell=1,2,3,4$$$ chords are drawn. Sets of chords are denoted as a set of the indices of the corresponding chords.
| Illustration | |
Chains
| ![]() |
Chains
| ![]() |
Chains
| ![]() |
Chains
| ![]() |
Thus, we output $$$\mathtt{0100}$$$.
Santa realized that hand-drawing circles takes too long, so he has turned to magic to meet his production quotas.
There are three types of presents with distinct values $$$a$$$, $$$b$$$, and $$$c$$$. Initially, Santa has exactly one present of each type.
You are given two integers $$$m$$$ and $$$k$$$, representing Santa's favorite number and the cost of duplication, respectively. Santa can cast the following two types of spells any number of times (possibly zero):
Santa wants to perform a sequence of spells such that the sum of the values of all presents is a multiple of $$$m$$$ after the spells.
Determine the minimum amount of mana Santa needs to achieve this. It can be shown that, under the given constraints, such a sequence of spells always exists.
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 five integers $$$a$$$, $$$b$$$, $$$c$$$, $$$m$$$, and $$$k$$$ ($$$1\leq a \lt b \lt c \lt m\leq 5\cdot 10^5$$$, $$$1\leq k\leq 5\cdot 10^5$$$).
It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.
It is guaranteed that the sum of $$$k$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.
For each test case, output a single integer — the minimum amount of mana Santa needs to make the sum of the values of all presents a multiple of $$$m$$$.
71 2 3 21 43 4 5 12 343 12 14 18 16 7 8 10 3100 103 282 488 221307 2000 5096 12018 5764194093 292793 395323 475619 490151
1001791227351167050242
Let $$$\ell$$$ be the list of values of presents and $$$\operatorname{sum}(\ell)$$$ be the sum of all elements in $$$\ell$$$.
In the first test case, below is an optimal sequence of operations:
| # | Operation | Value | $$$\ell$$$ after operation | $$$\operatorname{sum}(\ell)$$$ | Cost |
| 0 | — | — | $$$[1, 2, 3]$$$ | $$$6$$$ | — |
| 1 | Create | $$$3$$$ | $$$[1, 2, 3, 3]$$$ | $$$9$$$ | $$$3$$$ |
| 2 | Create | $$$3$$$ | $$$[1, 2, 3, 3, 3]$$$ | $$$12$$$ | $$$3$$$ |
| 3 | Duplicate | $$$3$$$ | $$$[1, 2, 3, 3, 3, 3, 3, 3]$$$ | $$$21$$$ | $$$4$$$ |
| $$$21=7\cdot 3$$$ | Total: $$$10$$$ | ||||
In the second test case, it is optimal to not perform any operations because $$$3+4+5=12$$$ is already a multiple of $$$12$$$.
In the third test case, below is an optimal sequence of operations:
| # | Operation | Value | $$$\ell$$$ after operation | $$$\operatorname{sum}(\ell)$$$ | Cost |
| 0 | — | — | $$$[3, 12, 14]$$$ | $$$29$$$ | — |
| 1 | Duplicate | $$$12$$$ | $$$[3, 12, 12, 14]$$$ | $$$41$$$ | $$$1$$$ |
| 2 | Duplicate | $$$14$$$ | $$$[3, 12, 12, 14, 14]$$$ | $$$55$$$ | $$$1$$$ |
| 3 | Create | $$$14$$$ | $$$[3, 12, 12, 14, 14, 14]$$$ | $$$69$$$ | $$$14$$$ |
| 4 | Duplicate | $$$3$$$ | $$$[3, 3, 12, 12, 14, 14, 14]$$$ | $$$72$$$ | $$$1$$$ |
| $$$72=18\cdot 4$$$ | Total: $$$17$$$ | ||||
Now that all the presents have been delivered, the North Pole is finally at peace — and it's time to celebrate with a spectacular New Year's fireworks show!
The North Pole is modeled as the Cartesian plane, with $$$n$$$ cities located at distinct lattice points. You are also given an integer $$$k$$$.
For a proper subset$$$^{\text{∗}}$$$ $$$T$$$ of the cities ($$$T$$$ may be empty), we define its explosiveness as follows:
Compute the sum of the explosiveness of $$$T$$$ over all $$$2^n-1$$$ proper subsets $$$T$$$ of the cities. Since the answer may be large, output it modulo $$$998\,244\,353$$$.
$$$^{\text{∗}}$$$A proper subset is any subset which is not equal to the whole set.
$$$^{\text{†}}$$$The Euclidean distance between two points $$$(x, y)$$$ and $$$(p, q)$$$ is defined as $$$\sqrt{(x - p)^2 + (y - q)^2}$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2\le n\le 31$$$, $$$1\leq k \leq2\cdot 10^4$$$).
Then $$$n$$$ lines follow, the $$$i$$$-th line containing two integers $$$x_i$$$ and $$$y_i$$$ ($$$1\leq x_i, y_i\leq 100$$$) — the $$$x$$$ and $$$y$$$ coordinates of the $$$i$$$-th city, respectively. It is guaranteed that the coordinates of the cities are pairwise distinct.
It is guaranteed that the sum of $$$n^3$$$ over all test cases does not exceed $$$31^3$$$.
For each test case, print a single integer — the sum, modulo $$$998\,244\,353$$$, of the explosiveness over all proper subsets $$$T$$$ of the cities.
43 11 22 12 22 200001 1100 1009 51 11 21 32 12 22 33 13 23 313 2550 5055 5054 5353 5450 5547 5446 5345 5046 4747 4650 4553 4654 47
1638255560112
In the first test case, below are the $$$2^3-1=7$$$ possible placements of fireworks. The numbers assigned to cities not in $$$T$$$ are circled.
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() |
In the second test case, there are $$$2^2-1=3$$$ possible placements of fireworks. For every placement, since $$$(1,1)$$$ and $$$(100,100)$$$ have a Euclidean distance of $$$\sqrt{(100-1)^2+(100-1)^2}=\sqrt{19\,602}\neq\sqrt{20\,000}$$$, none of the cities will have fireworks that are exactly $$$\sqrt{k}$$$ away. Thus, the number $$$1$$$ is assigned to every city without fireworks. Therefore, the explosiveness is $$$1$$$ for every $$$T$$$, and the answer is $$$1+1+1=3$$$.