Busy Beaver calls an integer timely if its decimal representation has $$$2025$$$ as a contiguous substring.
Given an integer $$$N$$$, output any $$$N$$$-digit positive integer $$$X$$$ such that $$$X$$$ is timely and a perfect square. It can be shown that such an integer always exists.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 997$$$) — the number of testcases.
The only line of each test case contains a single integer $$$N$$$ ($$$4 \leq N \leq 1000$$$) — the number of digits of $$$X$$$.
For each test case, output an $$$N$$$-digit positive integer $$$X$$$ such that $$$X$$$ is timely and a perfect square.
34512
2025 42025 395720257969
In the first test case, $$$2025 = 45^2$$$.
In the second test case, $$$42025 = 205^2$$$.
In the third test case, $$$395720257969 = 629063^2$$$.
Busy Beaver has a collection of $$$N$$$ sticks with integer lengths $$$a_1, a_2, \dots, a_N$$$ and wants to make a kite. To do so, he needs to choose four different sticks from his collection with lengths $$$a$$$, $$$a$$$, $$$b$$$, $$$b$$$ for some integers $$$a$$$ and $$$b$$$ (not necessarily distinct).
It might not be possible for Busy Beaver to make a kite using his current collection, but he is able to modify the sticks. In an operation, Busy Beaver can take a stick and extend its length by $$$1$$$. Compute the minimum number of operations required to construct a kite of any size. It can be shown that it's always possible to make a kite after a finite number of operations.
Each test contains multiple test cases. The first line of input contains a single integer $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, the number of test cases. The description of each test case follows.
The first line of each test case contains a single positive integer $$$N$$$ ($$$4 \leq N \leq 2 \cdot 10^5$$$) — the number of sticks in Busy Beaver's collection.
The second line contains $$$N$$$ space separated integers $$$a_1, a_2, \dots, a_N$$$ ($$$1 \leq a_i \leq 10^9$$$) — the lengths of the sticks.
It is guaranteed that the sum of $$$N$$$ across all test cases is no more than $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the minimum number of operations that Busy Beaver needs before he can make a kite.
There are two subtasks for this problem.
541 9 9 9513 9 20 9 2055 4 3 2 171 6 9 10 11 14 19101 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
8 0 2 4 909
In the first test case, there are four sticks, all of which are length $$$9$$$ except for one that is length $$$1$$$. The optimal way to create a kite is to apply the operation $$$8$$$ times to the stick of length $$$1$$$. We will then have four sticks of length $$$9$$$, which we can use to make a kite.
In the second test case, there are five sticks. We do not need to apply any operations because we already have four sticks of lengths $$$9$$$, $$$9$$$, $$$20$$$, $$$20$$$, so the answer is $$$0$$$.
In the third test case, it can be shown that the minimum number of operations needed is $$$2$$$. One way to make a kite with $$$2$$$ operations would be to extend the sticks of length $$$1$$$ and $$$3$$$ so that our collection of sticks has lengths $$$5$$$, $$$4$$$, $$$4$$$, $$$2$$$, $$$2$$$. The last four sticks can then form a kite.
It's dinner time, and Busy Beaver has to feed his baby beavers.
Busy Beaver has $$$N$$$ baby beavers, numbered from $$$1$$$ to $$$N$$$. The older baby beavers have bigger indices than the younger ones; for example, beaver $$$1$$$ is the youngest while beaver $$$N$$$ is the oldest.
Busy Beaver also has $$$2N$$$ dishes, which are numbered from $$$1$$$ to $$$2N$$$. If a beaver eats dish $$$i$$$, its satisfaction will increase by $$$i$$$. Each beaver starts with $$$0$$$ satisfaction.
Now, Busy Beaver wants to distribute the dishes amongst his baby beavers subject to the following constraints:
Determine if there exists a way to feed all $$$N$$$ beavers that respects these constraints. Additionally, if the task is possible, print any valid assignment of dishes to beavers.
Each test contains multiple test cases. The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains an integer $$$N$$$ ($$$1 \le N \le 10^5$$$) — the number of baby beavers.
The second line of each test case contains a string $$$c$$$ of length $$$N$$$, where each of the characters $$$c_i$$$ is either 'O' or 'E'. If $$$c_i$$$ is 'O', the beaver $$$i$$$ wants its satisfaction to be an odd number. If $$$c_i$$$ is 'E', the beaver $$$i$$$ wants its satisfaction to be an even number.
It is guaranteed that the sum of $$$N$$$ across all test cases is no more than $$$10^5$$$.
For each test case, if it is possible to feed the beavers, output "YES" (without quotes) on the first line. Next, print $$$N$$$ lines describing how to feed each beaver. The $$$i$$$-th of these lines should contain two integers, which denote the indices of the two dishes that will be given to beaver $$$i$$$.
If it is impossible to feed the beavers, output "NO" (without quotes).
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
There are two subtasks for this problem.
34OEEO7OEOEOEO6OOOOOO
YES 2 3 5 1 4 8 7 6 NO YES 1 12 2 11 3 10 4 9 5 8 6 7
In the first test case, one possible way to feed the beavers is as follows:
The satisfaction of the four beavers in increasing order of age are $$$[5, 6, 12, 13]$$$. It can be checked that this assignment satisfies the conditions.
In the second test case, it can be shown that the task is impossible.
Busy Beaver wants to have a tour in Beaverland! Beaverland consists of $$$N$$$ cities and $$$M$$$ bidirectional roads between them. It is guaranteed that it is possible to travel between any pair of cities along the $$$M$$$ roads, and that all roads have length $$$1$$$.
So far, Busy Beaver has planned out his tour, and wishes to visit the cities $$$x_1, x_2, \dots, x_K$$$. He views his tour to be interesting if $$$$$$\mathrm{dist}(1,x_1) \lt \mathrm{dist}(1,x_2) \lt \dots \lt \mathrm{dist}(1,x_K)$$$$$$ where $$$\mathrm{dist}(x, y)$$$ for two cities $$$x, y$$$ is equal to the length of the shortest path connecting the two cities.
However, it might not be the case that Busy Beaver's tour is currently interesting! To fix this, he can add up to $$$5 \cdot 10^5$$$ more roads between any pairs of cities. Each of the added roads is also bidirectional and has length $$$1$$$.
Determine whether it is possible to make Busy Beaver's tour interesting by adding some roads (possibly none). Additionally, if it is possible, provide any valid construction.
Each test contains multiple test cases. The first line of input contains a single integer $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, the number of test cases. The description of each test case follows.
The first line of each test case contains three integers $$$N,M,K$$$ ($$$1 \le K \le N, N-1 \le M \le 2 \cdot 10^5$$$) — the total number of cities, roads, and the number of cities in Busy Beaver's tour, respectively.
The next line contains $$$K$$$ integers $$$x_1,x_2, \dots, x_K$$$ ($$$1 \le x_i \le N$$$, $$$x_i$$$ distinct) — the cities that Busy Beaver plans to visit.
The $$$i$$$-th of the next $$$M$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le N$$$, $$$u_i \neq v_i$$$) — indicating that there is a road between cities $$$u_i$$$ and $$$v_i$$$. It is guaranteed that there is at most $$$1$$$ edge between any two distinct cities.
The sum of $$$N$$$, the sum of $$$M$$$, and the sum of $$$K$$$ over all test cases all do not exceed $$$2 \cdot 10^5$$$.
For each test case, if it is possible to make the tour interesting, the first line of output should contain an integer $$$L$$$ ($$$0 \leq L \leq 5 \cdot 10^5$$$) — the number of added roads. Each of the next $$$L$$$ lines of output should then contain two integers $$$u_i,v_i$$$ ($$$1 \leq u_i , v_i \leq N$$$, $$$u_i \neq v_i$$$) representing a road to be added.
If there are multiple solutions, print any of them. Otherwise, if there is no solution, print a single integer $$$-1$$$ instead.
Due to judging constraints, you may use at most $$$5 \cdot 10^5$$$ roads in total, over all test cases. It can be shown that this is enough to solve the problem.
43 3 21 21 21 32 33 3 31 2 31 21 32 35 5 23 51 22 31 44 52 46 6 51 2 3 4 51 22 33 44 55 64 6
1 1 2 -1 1 1 3 0
In the first test case, adding a road between cities $$$1, 2$$$ causes $$$dist(1,1) = 0, dist(1,2) = 1$$$, making the tour interesting.
In the second test case, it can be shown that the task is impossible.
In the third test case, by adding a road between cities $$$1, 3$$$ we have $$$dist(1,3) = 1, dist(1,5) = 2$$$, making the tour interesting.
In the fourth test case, the tour is already interesting, and no roads need to be added.
This is an interactive problem.
Busy Beaver and Lazy Lemur are playing a game on a binary string $$$s$$$ that is initially not sorted. In this game, they take turns choosing some subsequence$$$^{\text{∗}}$$$ that isn't sorted, and sort it in place. Formally, they select indices $$$b_1 \lt b_2 \lt \dots \lt b_k$$$ such that the string $$$s_{b_1}s_{b_2}\dots s_{b_k}$$$ is not sorted, and sort only these characters of the original string.
It can be shown that no matter how the two players move, the string will become sorted after a finite number of turns. When this happens, the player who made the final move loses, and the other player wins.
Busy Beaver needs your help to beat Lazy Lemur. Given the starting string, determine whether or not Busy Beaver should choose to go first or second, then make a series of moves that wins against the judge.
$$$^{\text{∗}}$$$A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by the deletion of several (possibly, zero or all) elements.
Each test contains multiple test cases. The first line of input contains a single integer $$$T$$$ $$$(1 \leq T \leq 100)$$$, the number of test cases. The description of each test case follows.
The first line of each test case contains the string $$$s$$$ ($$$2 \leq |s| \leq 400$$$), consisting of characters '0' and/or '1'. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$400$$$.
Afterwards, output a string that is either First or Second (case-insensitive), representing whether you wish to move first or second, respectively.
Then, your program will play against the judge.
Once the string becomes sorted, one of two events will happen:
Each time your program makes a move, do not forget to output the end of line and flush the output. Otherwise, you will get an Idleness limit exceeded verdict. To do this, use:
If, at any interaction step, you read $$$-1$$$ instead of valid data, your solution must exit immediately. This means that your solution will receive a Wrong answer verdict 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.
3 100 001 0101 0011 1100 0110 0011
First 2 1 2 Second First 2 2 3 3 1 3 4
In the first test case, the starting string $$$s$$$ is 100. Busy Beaver chooses to move first, and sorts the subsequence $$$s_1s_2$$$: 100 $$$\to$$$ 010. From this position, Lazy Lemur is forced to sort the string, i.e. by sorting the subsequence $$$s_2s_3$$$: 010 $$$\to$$$ 001.
In the second test case, the starting string $$$s$$$ is 0101. Busy Beaver chooses to move second. Lazy Lemur may choose any of the subsequences $$$s_2s_3$$$, $$$s_1s_2s_3$$$, $$$s_2s_3s_4$$$, $$$s_1s_2s_3s_4$$$ but all of these result in the string becoming sorted: 0101 $$$\to$$$ 0011.
In the third test case, the starting string $$$s$$$ is 1100. Busy Beaver chooses to move first, and sorts the subsequence $$$s_2s_3$$$: 1100 $$$\to$$$ 1010. Then, Lazy Lemur chooses to sort the subsequence $$$s_1s_2$$$: 1010 $$$\to$$$ 0110. Then, Busy Beaver chooses to sort the subsequence $$$s_1s_3s_4$$$: 0110 $$$\to$$$ 0101. Finally, Lazy Lemur chooses to sort the subsequence $$$s_2s_3$$$: 0101 $$$\to$$$ 0011. Because Lazy Lemur sorted the string, Busy Beaver wins.