The MITIT Winter 2025-26 contest takes place on December 6-7, 2025.
This is an interactive problem.
Busy Beaver has a secret array $$$a_1, \dots, a_N$$$, where $$$1 \leq a_i \leq 10^9$$$ for all $$$i$$$ and every two elements are coprime. (Two integers are coprime if the only positive integer dividing both is $$$1$$$.)
You may ask up to $$$100$$$ queries of the following form:
Let $$$Q$$$ be the maximum number of queries you use to determine Busy Beaver's array. For full points, you must have $$$Q \leq \mathbf{67}$$$.
Each test contains multiple test cases. The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) — the number of test cases.
The first line of each test case contains an integer $$$N$$$ ($$$5 \leq N \leq 100$$$). After reading this line, you should begin the interaction.
For each test case, begin by reading $$$N$$$.
To make a query, output "$$$\texttt{?}\;i\;j$$$" ($$$1 \leq i, j \leq n$$$; $$$i \neq j$$$) without quotes. Afterwards, you should read in a single integer — the product $$$a_i \times a_j$$$. You can make at most $$$100$$$ such queries in a single test case.
If you receive the integer $$$-1$$$ instead of an answer, it means your program has made an invalid query, has exceeded the limit of $$$100$$$ queries, or has given an incorrect answer on some previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
When you are ready to give the final answer, output "$$$\texttt{!}\;a_1\;\dots\;a_N$$$" ($$$1 \leq a_i \leq 10^9$$$) without quotes — Busy Beaver's array. Giving this answer does not count towards the limit of $$$100$$$ queries. Afterwards, your program must continue to solve the remaining test cases, or exit if all test cases have been solved.
After printing a query do not forget to output end of line and flush the output. To do this, use:
2 5 77 30 85 5 69
? 1 2 ? 3 4 ? 4 5 ! 7 11 6 5 17 ? 1 5 ! 1 40 61 41 69
During an actual run the solution does not know the hidden array; it is shown here only to justify the sample.
In the first test case, the judge prints 5, so $$$N=5$$$. Its hidden array is $$$[7,11,6,5,17]$$$.
In the second test case, the judge prints 5. Its hidden array is $$$[1,40,61,41,69]$$$.
The program asks ? 1 5 and receives 69 from $$$1\times 69$$$. It then outputs ! 1 40 61 41 69, which matches the judge's array.
This illustrates one valid interaction sequence; any correct determination of the array using allowed queries is acceptable.
Busy Beaver has $$$X$$$ cards with the letter $$$\texttt{M}$$$, $$$Y$$$ cards with the letter $$$\texttt{I}$$$, and $$$Z$$$ cards with the letter $$$\texttt{T}$$$.
He wants to arrange these $$$X+Y+Z$$$ cards into a row following some constraints:
Determine if he can do this. If it is possible, output an example.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 50$$$) — the number of test cases.
The only line of each test case contains three integers $$$X$$$, $$$Y$$$, and $$$Z$$$ ($$$0 \leq X, Y, Z \leq 10^5$$$). There is at least one card in each test case ($$$X+Y+Z \gt 0$$$).
The combined sum of $$$X+Y+Z$$$ across all test cases does not exceed $$$3 \cdot 10^5$$$.
For each test case, if Busy Beaver cannot arrange all $$$X+Y+Z$$$ cards, output NO.
Otherwise, output YES. Then, output one line — a string of length $$$X+Y+Z$$$ consisting of characters $$$\texttt{M}$$$, $$$\texttt{I}$$$, and $$$\texttt{T}$$$, satisfying the constraints in the statement.
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. You can also output the string in any case.
21 1 13 0 0
YESITMNO
In the first test case, there are $$$4$$$ possible combinations that will work: $$$\texttt{ITM}$$$, $$$\texttt{IMT}$$$, $$$\texttt{MTI}$$$, $$$\texttt{TMI}$$$. $$$\texttt{ITM}$$$ is one of them. It does not have equal adjacent cards, and there is no $$$\texttt{MIT}$$$ or $$$\texttt{TIM}$$$.
In the second test case, there is only one possible construction: $$$\texttt{MMM}$$$, but it is not valid, as there are adjacent $$$\texttt{M}$$$s.
Deep in Busy Beaver's robotics lab sits an experimental Busy Beaver machine. Given a positive integer $$$X$$$ written in base $$$B$$$, it attempts to produce two positive integers $$$Y$$$ and $$$Z$$$ such that $$$X + Y = Z$$$, and the base-$$$B$$$ representations of $$$Y$$$ and $$$Z$$$ contain exactly the same multiset of digits.
The machine never produces leading zeroes and never outputs numbers with $$$2 \cdot 10^5$$$ or more digits. It has recently stopped functioning, so your task is to determine whether such $$$Y$$$ and $$$Z$$$ exist, and to output them if they do. You are given the digits of $$$X$$$ in base $$$B$$$ without leading zeroes.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$), the number of test cases.
Each test case consists of two lines. The first line of each test case contains two integers $$$N$$$ and $$$B$$$ ($$$1 \le N \le 10^5$$$; $$$2 \le B \le 10^5$$$).
The second line of each test case contains $$$N$$$ integers $$$a_1, a_2, \ldots, a_N$$$ ($$$0 \le a_i \le B-1$$$; $$$a_1 \ne 0$$$), representing the digits of $$$X$$$ in base $$$B$$$: $$$$$$ X = a_1 B^{N-1} + a_2 B^{N-2} + \cdots + a_N. $$$$$$
The sum of $$$N$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, if no valid solution exists, output a single line containing NO.
Otherwise, output YES on the first line. On the second line output an integer $$$M$$$ ($$$1 \le M \le 2 \cdot 10^5$$$), the number of digits in both $$$Y$$$ and $$$Z$$$.
On the next line output $$$M$$$ digits $$$p_1, p_2, \ldots, p_M$$$ ($$$0 \le p_i \le B-1$$$; $$$p_1 \ne 0$$$), representing $$$$$$ Y = p_1 B^{M-1} + p_2 B^{M-2} + \cdots + p_M. $$$$$$ On the following line output $$$M$$$ digits $$$q_1, q_2, \ldots, q_M$$$ ($$$0 \le q_i \le B-1$$$; $$$q_1 \ne 0$$$), representing $$$$$$ Z = q_1 B^{M-1} + q_2 B^{M-2} + \cdots + q_M. $$$$$$ The digit sequences $$$(p_1, \ldots, p_M)$$$ and $$$(q_1, \ldots, q_M)$$$ must use exactly the same multiset of digits, and the integers they represent must satisfy $$$X + Y = Z$$$. You may print YES and NO in any mixture of uppercase and lowercase letters.
32 103 64 51 4 3 45 124 8 8 3 1
YES 2 1 5 5 1 YES 4 1 4 3 2 3 4 2 1 NO
In the first test case, with $$$B = 10$$$ and $$$X = 36$$$, a valid solution is $$$Y = 15$$$ and $$$Z = 51$$$, since $$$51 = 36 + 15$$$ and both numbers use the digits $$$\{1,5\}$$$.
In the second test case, with $$$B = 5$$$ and $$$X$$$ given by digits $$$(1, 4, 3, 4)_5$$$, $$$$$$ X = 1 \cdot 5^3 + 4 \cdot 5^2 + 3 \cdot 5^1 + 4 = 244. $$$$$$ One valid pair is $$$$$$ Y = (1, 4, 3, 2)_5 = 242, \qquad Z = (3, 4, 2, 1)_5 = 486, $$$$$$ which share the digit multiset $$$\{1,2,3,4\}$$$ and satisfy $$$X + Y = Z$$$.
Busy Beaver is hosting an upcoming exam for his students in the MITIT exam room. Due to last-minute preparation and bad testing, the students will need to come up to him to complain about things like bad difficulty distributions, server issues, misleading statements, and awful flavortexts without disturbing other students, so he needs to ensure that the seats are well separated.
The room has $$$N$$$ seats at points $$$P_i = (x_i,y_i)$$$, with Busy Beaver's desk located at $$$O = (0,0)$$$. He wants to choose a nonempty subset of the seats satisfying the following condition:
How many nonempty subsets satisfy this criterion? Since the answer may be enormous, output it modulo $$$998\,244\,353$$$.
The first line contains a single integer $$$N$$$ ($$$1 \le N \le 500$$$).
The $$$i$$$-th of the next $$$N$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i,y_i \le 10^9$$$).
All $$$N$$$ points in the input are distinct and not equal to $$$(0,0)$$$.
Output a single integer — the number of valid nonempty subsets modulo $$$998\,244\,353$$$.
There are four subtasks for this problem.
21 22 1
2
31 22 11 -3
5
In the first sample, the two desks are $$$\sqrt{2}$$$ apart and $$$\sqrt{5}$$$ away from the origin, so either one or the other can be used.
In the second sample, the third desk is $$$\sqrt{10}$$$ away from the origin and $$$\sqrt{17}$$$ away from the closest other desk, so the third desk can always be used. The valid subsets are: $$$$$$ \{\text{desk }1\}, \{\text{desk }2\}, \{\text{desk }3\}, \{\text{desk }1, \text{desk }3\}, \{\text{desk }2, \text{desk }3\}. $$$$$$
Busy Beaver has finally rage-quit Minesweeper and picked up Mahjong Connect instead. He has $$$N$$$ mahjong tiles at distinct locations on the Cartesian plane. Each tile $$$i$$$ has integer coordinates $$$(x_i, y_i)$$$ and a type $$$t_i$$$ with $$$1 \le t_i \le M$$$.
Two distinct tiles $$$i$$$ and $$$j$$$ match if and only if all of the following hold:
A perfect matching is a partition of the $$$N$$$ tiles into $$$N/2$$$ disjoint pairs such that every pair is a valid match under the rules above. Determine whether a perfect matching exists. If it does, output any one perfect matching; otherwise, report that no perfect matching exists.
The first line contains two integers $$$N$$$ and $$$M$$$ ($$$2\le N\le 3\cdot 10^5$$$, $$$1\le M\le 3\cdot 10^5$$$, $$$N$$$ is even).
The next $$$N$$$ lines describe the tiles. The $$$i$$$-th of these lines contains three integers $$$x_i$$$, $$$y_i$$$ and $$$t_i$$$ ($$$|x_i|,|y_i|\le 10^9$$$, $$$1\le t_i\le M$$$).
It is guaranteed that the pairs $$$(x_i,y_i)$$$ are distinct.
If no perfect matching exists, print a single line containing NO.
Otherwise, print a single line containing YES. Then print $$$N/2$$$ lines, each containing two integers $$$i$$$ and $$$j$$$ ($$$1\le i,j\le N$$$, $$$i\neq j$$$), indicating that tiles $$$i$$$ and $$$j$$$ form a matched pair.
Each index from $$$1$$$ to $$$N$$$ must appear in exactly one pair. The pairs may be printed in any order, and within each pair, the order of $$$i$$$ and $$$j$$$ does not matter.
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.
4 2-1 0 11 0 10 -1 20 1 2
YES 1 2 3 4
4 2-1 0 11 0 10 0 20 1 2
NO
22 31 1 21 2 21 3 21 4 12 3 23 2 13 1 24 3 25 4 15 3 15 2 15 1 17 1 37 2 37 3 37 4 39 4 310 4 311 4 310 3 110 2 110 1 3
YES 1 7 2 3 4 9 5 8 6 11 10 12 13 22 14 15 16 17 18 19 20 21
In the first test case, we can pair up the tiles at $$$(-1,0),(1,0)$$$ and $$$(0,-1),(0,1)$$$, respectively.
In the second test case, we cannot do the same thing because the tile at $$$(0,0)$$$ blocks the connection between $$$(-1,0)$$$ and $$$(1,0)$$$.
The visualization of the third test case is as follows (different colors represent different types of tiles):
Note again that, if the answer is YES, any valid pairing with any order will be accepted. For instance, for the first sample, the following output is also acceptable:
YES
4 3
1 2
Busy Beaver recently learned about the Collatz Conjecture! He has written down a sequence of $$$N$$$ positive integers $$$a_1, a_2, \ldots , a_N$$$ on a blackboard to experiment with and further his understanding of the conjecture. He also notices a counter left on a table and comes up with the following game to play.
The counter initially starts at the number $$$1$$$. A move consists of picking a number on the blackboard and replacing it:
Busy Beaver wants to play this game for as long as possible. Help him determine the maximum number of moves he can perform before he runs out of moves!
The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 500$$$).
The first line of each test case contains a single integer $$$N$$$ ($$$1 \le N \le 500$$$), the number of positive integers on the blackboard.
The second line of each test case contains $$$N$$$ positive integers $$$a_1, a_2, \ldots , a_N$$$ ($$$1 \le a_i \le 10^6$$$). It can be shown that any Collatz sequence started on a number at most $$$10^6$$$ will reach $$$1$$$ after at most $$$524$$$ moves. Additionally, it can also be shown that Busy Beaver will eventually run out of moves and that he never writes a number larger than $$$10^{18}$$$ on the blackboard.
The sum of $$$N$$$ across all test cases does not exceed $$$500$$$.
For each test case, output a single integer — the maximum number of moves that Busy Beaver can perform.
61352 4 6 8 1064 5 6 6 5 426837799 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 193 1 4 1 5 9 2 6 510123456 678910 111213 141516 171819 202122 232425 262728 293031 323334
40141643460
In the first test case, Busy Beaver only has one number on the blackboard which is the number $$$3$$$.
In the second test case, Busy Beaver cannot make any move since there are no odd numbers on the blackboard.
Busy Beaver has arranged $$$N$$$ logs in a line to form the base of his dam. Each log has an integer quality value between $$$-2$$$ and $$$2$$$. From time to time, some logs are replaced. He occasionally wants to know if there is a contiguous segment of logs whose total quality equals a given nonzero number $$$X$$$, and may also want to know the segment. Help Busy Beaver process all updates and queries efficiently.
The first line of input contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of testcases.
The first line of each test case contains two integers $$$N$$$ and $$$Q$$$ ($$$1 \le N,Q \le 2\cdot 10^5$$$) — the size of the array and the number of queries, respectively.
The second line of each test case contains $$$N$$$ integers $$$a_1, a_2, \dots, a_N$$$ ($$$-2 \le a_i \le 2$$$) — the qualities of the logs.
The next $$$Q$$$ lines of each test case are of two forms:
There is at least one query of the second type.
The sum of $$$N$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
The sum of $$$Q$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each query of the second type, if a valid contiguous segment exists, print YES on the first line, followed by the left and right indices of that segment $$$l$$$ and $$$r$$$ on the next line ($$$1 \le l \le r \le N$$$). If no such segment exists, print NO on a single line.
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.
There are four subtasks in this problem. You can receive $$$50\%$$$ of the points for each subtask if the YES/NO answers are correct, but the indices are incorrect. To obtain these partial points, you must still output integers $$$l$$$ and $$$r$$$ between $$$1$$$ and $$$N$$$ after all YES answers.
45 5-1 2 0 -2 11 2 12 11 4 22 32 -24 3-1 -1 -1 -11 4 12 -12 -46 61 -1 1 -1 1 -11 3 02 12 -22 31 3 22 16 30 0 0 0 0 02 21 1 12 1
YES2 2YES3 5NOYES2 2NOYES1 1YES2 4NOYES1 1NOYES1 1
For the first test case:
For the second test case:
Busy Beaver has $$$N$$$ favorite snack spots along the Charles River, labeled $$$1, 2, \dots, N$$$. Each day, he wishes to enjoy a snack at spot $$$i$$$ during time $$$i$$$. What a perfectly optimized routine!
Unfortunately, the geese have other plans. For each index $$$i$$$, a goose occupies spot $$$a_i$$$ at time $$$i$$$. Busy Beaver absolutely refuses to visit the same spot as a goose, so his final schedule $$$p_1,p_2,\dots,p_N$$$ must be a permutation of $$$1,2,\dots,N$$$ that satisfies $$$p_i \neq a_i$$$ for every $$$1 \le i \le N$$$.
Busy Beaver also wants to keep his life predictable. Among all valid schedules $$$p$$$, determine the minimum possible number of inversions$$$^{\text{∗}}$$$ $$$p$$$ can have. If no valid schedule exists, output $$$-1$$$.
$$$^{\text{∗}}$$$Recall that the number of inversions in $$$p$$$ is defined as the number of pairs $$$(i,j)$$$ with $$$1 \le i \lt j \le N$$$ and $$$p_i \gt p_j$$$.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 3 \cdot 10^5$$$) representing the number of test cases.
The first line of each test case contains a single integer $$$N$$$ ($$$1 \le N \le 3\cdot 10^5$$$).
The second line of each test case contains $$$N$$$ integers $$$a_1,a_2,\dots,a_N$$$ ($$$1 \le a_i \le N$$$).
The sum of $$$N$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.
For each test case, print a single integer: the minimum possible inversion count among all permutations $$$p$$$ satisfying $$$p_i \ne a_i$$$ for all $$$i$$$. If no valid schedule exists, print $$$-1$$$.
432 3 141 2 3 451 1 1 1 1101 1 1 1 1 10 10 10 10 10
02-19
In the first test case, no position satisfies $$$a_i=i$$$, so Beaver can use his original routine $$$p=[1,2,3]$$$, which has $$$0$$$ inversions.
In the second test case, a valid schedule is $$$p=[2,1,4,3]$$$, which has exactly $$$2$$$ inversions.
In the third test case, spot $$$1$$$ is occupied throughout the day, so that poor Busy Beaver fails to schedule. What a pity!
This is an interactive problem.
Busy Beaver has a secret array $$$a_1,a_2,\dots,a_N$$$ of distinct positive integers between $$$1$$$ and $$$10^9$$$. For $$$1 \le l \le r \le N$$$, Busy Beaver defines $$$f(l,r)$$$ to be equal to $$$\min(a_l,a_{l+1},\dots,a_r)$$$.
Busy Beaver allows you to ask some queries to uncover information about the array. In a query, you can specify $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le N$$$), and Busy Beaver will tell you the value of $$$f(l,r)$$$ for a cost of $$$\frac{1}{r-l+1}$$$. You must ensure that the total cost of all queries is at most $$$1$$$.
After making all your queries, you report to Busy Beaver a list of pairs $$$(l,r)$$$ for which you determined the value of $$$f(l,r)$$$. If any of your answers are wrong, Busy Beaver will be displeased and award you $$$0$$$ points. Otherwise, your score will depend on the fraction of the $$$\frac{N(N+1)}{2}$$$ pairs $$$(l,r)$$$ with $$$1 \le l \le r \le N$$$ where you determined a value for $$$f(l,r)$$$ (see the Scoring section for more details).
To reduce the size of the output, you report your knowledge using $$$k$$$ tuples of the form $$$(l_{min},l_{max},r_{min},r_{max},v)$$$, where $$$1 \le l_{min} \le l_{max} \le r_{min} \le r_{max} \le N$$$ and $$$1 \le v \le 10^9$$$. Each tuple declares that $$$f(l,r) = v$$$ for all $$$l_{min} \le l \le l_{max}$$$ and $$$r_{min} \le r \le r_{max}$$$. Any pairs $$$(l,r)$$$ that do not correspond to any tuple are treated as unspecified. It is allowed to have multiple tuples that describe the same pair $$$(l,r)$$$, but you will receive $$$0$$$ points if these tuples indicate inconsistent values.
The first line of input contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$), the length of Busy Beaver's secret array.
You may repeatedly ask queries by outputting a line of the form "? l r", where $$$1 \le l \le r \le N$$$. Then, the judge will respond with a single integer, denoting the value of $$$f(l,r)$$$. If you exceed a total cost of $$$1$$$, the judge will instead respond with $$$-1$$$, and you should terminate your program immediately to receive a Wrong Answer verdict.
After you are finished with your queries, first output a line of the form "! k" ($$$0 \le k \le 2N$$$), representing that you will describe your knowledge of $$$f$$$ using $$$k$$$ tuples $$$(l_{min},l_{max},r_{min},r_{max},v)$$$.
Then, the next $$$k$$$ lines should each contain $$$5$$$ space-separated integers $$$l_{min}$$$, $$$l_{max}$$$, $$$r_{min}$$$, $$$r_{max}$$$, and $$$v$$$, specifying a tuple.
The interactor is not adaptive, meaning that Busy Beaver will not change the entries of his secret array $$$a$$$ in response to your queries.
For all test cases used for scoring, $$$N = 10^5$$$.
If you exceed a cost of $$$1$$$ or any of the values you claim for $$$f(l,r)$$$ are incorrect, you will receive $$$0$$$ points and a Wrong Answer verdict.
Otherwise, let $$$x$$$ be the fraction of the $$$\frac{N(N+1)}{2}$$$ values of $$$f(l,r)$$$ that you specified a value for. Your score for the test case will be equal to $$$$$$ \left\lfloor \min\left(100,100 \cdot \frac{x}{0.8}\right) \right\rfloor. $$$$$$ In particular, if $$$x \ge 0.8$$$, then you will receive full points for the test case.
Your final score will be the minimum score over all test cases.
6 31 26 53
? 1 3 ? 1 6 ? 5 6 ! 4 1 1 3 3 31 1 4 4 6 26 2 3 5 5 26 5 5 6 6 53
Note that the sample does not satisfy $$$N = 10^5$$$, so it will not be included in the actual test cases. It is provided only to illustrate the interaction format.
In the sample, Busy Beaver's secret array is $$$a = [31,41,59,26,53,58]$$$. You decide to make the following queries:
Note that the total cost of all your queries is $$$\frac13+\frac16+\frac12 = 1$$$, which does not exceed $$$1$$$ as required.
From this information, you report to Busy Beaver the following values of $$$f(l,r)$$$ you have deduced: