Busy Beaver arrived to his MIT class late! However, thanks to "MIT time", all classes actually start $$$5$$$ minutes later than the posted time.
Busy Beaver wants to make a generalization of this system. Namely, if someone arrives $$$N$$$ minutes late to an event, then:
The first line contains a single integer $$$T$$$ $$$(1 \leq T \leq 10^5)$$$ — the number of test cases.
The only line of each test case contains a single integer $$$N$$$ ($$$1 \le N \le 10^9$$$) — the number of minutes late to an event the person is.
For each test case, output a single line that consists of either "MIT time" or "MIT^$$$k$$$ time" for some integer $$$k \geq 2$$$, corresponding to the time this person arrives at.
545131261
MIT time MIT time MIT^2 time MIT^4 time MIT time
In the first test case, $$$N = 4$$$, which is at most $$$5$$$, so this is MIT time.
In the second test case, $$$N = 5$$$, which is equal to $$$5$$$, so this is also MIT time.
In the third test case, $$$N = 13$$$, which is not more than $$$25$$$ but more than $$$5$$$, so this is MIT$$$^2$$$ time.
The fourth test case, $$$N = 126$$$, which is not more than $$$5^4=625$$$ but more than $$$5^3 = 125$$$, so this is MIT$$$^4$$$ time.
Busy Beaver is bored in class one day and decides to write several strings. He calls a string repetitive if it is the character $$$\texttt{M}$$$ suffixed with one or more repetitions of $$$\texttt{IT}$$$. For example, the shortest repetitive strings are $$$\texttt{MIT}$$$, $$$\texttt{MITIT}$$$, $$$\texttt{MITITIT}$$$, ....
You are given a string $$$S$$$. Determine whether it can be expressed as the concatenation of one or more repetitive strings.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) — the number of test cases.
The first line of each test case contains a single integer $$$|S|$$$ ($$$3 \leq |S| \leq 2 \cdot 10^5$$$) — the length of $$$S$$$.
The second line of each test case contains the string $$$S$$$ consisting of uppercase Latin characters.
The sum of $$$|S|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single string "YES" or "NO" (without the quotes) denoting if the string $$$S$$$ is a concatenation of repetitive strings.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
65MITIT4MITI15MITITMITMITITIT6MITITM9MITBEAVER5MIIIT
YES NO YES NO NO NO
In the first test case, the entire string $$$\tt{MITIT}$$$ is repetitive.
In the second test case, it can be shown that the string is not a concatenation of repetitive strings.
In the third test case, the string is the following concatenation of repetitive strings: $$$\texttt{MITIT} + \texttt{MIT} + \texttt{MITITIT}$$$.
There are $$$N$$$ cities numbered from $$$1$$$ to $$$N$$$, the $$$i$$$-th of which is at coordinates $$$(x_i, y_i)$$$.
Busy Beaver wants to start at city $$$1$$$, visit every city exactly once, and return to city $$$1$$$.
To go from city $$$i$$$ to city $$$j$$$, it takes $$$|x_i - x_j + y_i - y_j|$$$ seconds. Find the minimum number of seconds for Busy Beaver to complete his trip.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$N$$$ ($$$2 \leq N \leq 2 \cdot 10^5$$$) — the number of cities.
The $$$i$$$-th of the next $$$N$$$ lines of each test case contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \leq x_i, y_i \leq 10^9$$$) — the coordinates of the $$$i$$$-th city.
The sum of $$$N$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the minimum number of seconds needed for Busy Beaver to complete his trip.
350 0-2 01 2-1 30 130 01 43 42-1 98 -4
10 14 8
In the first test case, we can take the path $$$1 \xrightarrow{3\,\text{seconds}} 3 \xrightarrow{1\,\text{second}} 4 \xrightarrow{1\,\text{second}} 5 \xrightarrow{3\,\text{seconds}} 2 \xrightarrow{2\,\text{seconds}} 1$$$ which takes $$$3+1+1+3+2=10$$$ seconds.
The MITIT 2025 Winter Contest has successfully ended with the participation of $$$K$$$ teams, and Busy Beaver has to write a report for the contest.
For the report, Busy Beaver took $$$N$$$ screenshots of the scoreboard during the contest. Each screenshot contains the scores of all $$$K$$$ teams when the screenshot was taken.
Unfortunately, Busy Beaver forgot in which order he took the screenshots! He assumes that if there were no regrades during the contest, each team's score will be nondecreasing over time. Under this assumption, Busy Beaver wants to recover the order of the screenshots.
Determine if there is a valid ordering such that no team's score ever decreases over time, and if it exists, print any such order.
The first line contains two integers $$$N$$$ and $$$K$$$ ($$$2 \leq N \leq 400$$$; $$$1 \leq K \leq 400$$$) — the number of screenshots and teams.
The $$$i$$$-th of the next $$$N$$$ lines contains $$$K$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,k}$$$ ($$$0 \leq a_{i,j} \leq 900$$$), where $$$a_{i, j}$$$ is the score of the $$$j$$$-th team in the $$$i$$$-th screenshot.
If a valid ordering exists, print "YES" (without quotes) on the first line. On the second line, print $$$N$$$ integers $$$b_1, \dots, b_N$$$, where $$$b_i$$$ is the index of the $$$i$$$-th screenshot in the valid ordering. If there are multiple solutions, you can print any of them.
If there is no valid ordering, print "NO" (without quotes).
There are two subtasks for this problem.
3 21 10 00 1
YES 2 3 1
3 30 0 11 0 00 1 0
NO
In the first test case, a valid ordering of the screenshots is:
In the second test case, no valid ordering exists because it is impossible to arrange the screenshots so that all scores for each team are nondecreasing over time.
Busy Beaver has an array of positive integers $$$a_1, \dots, a_N$$$, consisting of positive integers at most $$$N$$$. He needs to perform $$$Q$$$ operations on the array of two types:
Help answer all of Busy Beaver's queries! The input will be generated in such a way that an answer exists for all type $$$\texttt{2}$$$ queries.
The first line contains two positive integers $$$N$$$ and $$$Q$$$ ($$$2 \le N \le 2 \cdot 10^5$$$; $$$1 \le Q \le 2 \cdot 10^5$$$).
The second line contains $$$N$$$ integers $$$a_1, \dots, a_N$$$ ($$$1 \le a_i \le N$$$).
Each of the next $$$Q$$$ lines contains three positive integers: either $$$\texttt{1}\,~x\,~y$$$ or $$$\texttt{2}\,~l\,~r$$$ ($$$1 \le x, y \le N$$$; $$$1 \le l \le r \le N$$$).
Additional constraint on the input: there is at least one type $$$\texttt{2}$$$ query, and every type $$$\texttt{2}$$$ query has an answer.
For each type $$$\tt{2}$$$ query, output a single line containing the answer. If there are multiple possible answers for a query, you may output any of them.
There are three subtasks for this problem.
5 43 5 2 1 52 1 51 4 41 3 12 3 5
4 2
In the first query, the only integer from $$$1$$$ to $$$5$$$ missing from $$$[3, 5, 2, 1, 5]$$$ is $$$4$$$, so $$$4$$$ is the only possible answer.
After the second query, the array becomes $$$[3, 5, 2, 4, 5]$$$.
After the third query, the array becomes $$$[3, 5, 1, 4, 5]$$$.
The last query asks for an integer from $$$1$$$ to $$$5$$$ missing from $$$[1, 4, 5]$$$. Either $$$2$$$ or $$$3$$$ would be acceptable answers to this query.
Busy Beaver is preparing for the MIT Mystery Hunt! He is playing a game on two strings $$$S_1$$$ and $$$S_2$$$, each consisting only of the letters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. He can perform the following operation any number of times (possibly zero) on $$$S_1$$$:
Find the minimum number of operations needed to transform $$$S_1$$$ into $$$S_2$$$, or report that this is impossible.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$) — the number of test cases.
The only line of each test case contains two space-separated strings $$$S_1$$$ and $$$S_2$$$ ($$$1\le |S_1| = |S_2|\le 10^5$$$) consisting of characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$.
The total length of all strings across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print the minimum number of operations you need to transform $$$S_1$$$ into $$$S_2$$$. If this is impossible, output $$$-1$$$.
There are three subtasks for this problem.
1AABBB BABBA
2
1AAAAAABBB BBBAAAAAA
9
In the first test case, we can perform two operations: $$$\color{red}{\texttt{AAB}}\texttt{BB} \to \color{blue}{\texttt{BAA}}\texttt{BB}$$$ and then $$$\texttt{BA}\color{red}{\texttt{ABB}} \to \texttt{BA}\color{blue}{\texttt{BBA}}$$$.
Busy Beaver and Calico Bear are playing a game with an $$$N$$$ by $$$M$$$ grid of nonnegative integers $$$a_{i,j}$$$, where initially no two edge-adjacent numbers are equal.
In a move, a player chooses a positive integer in the grid and decreases it by $$$1$$$, subject to the constraint that after the move, it still holds that no two edge-adjacent numbers are equal and that all numbers are non-negative. If a player has no legal moves on their turn, they lose, and the other player wins.
Busy Beaver moves first, and then the players alternate. Assuming both players play optimally, determine whether or not Busy Beaver has a winning strategy.
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 two positive integers $$$N$$$ and $$$M$$$ ($$$1 \leq N, M, N \cdot M \leq 2.5 \cdot 10^5$$$) — the dimensions of the grid.
The $$$i$$$-th of the next $$$N$$$ lines contains $$$M$$$ space-separated nonnegative integers $$$a_{i,1}, \dots, a_{i,M}$$$ ($$$0 \leq a_{i,j} \leq 10^9$$$), where $$$a_{i,j}$$$ represents the integer in the grid in row $$$i$$$ and column $$$j$$$.
The sum of $$$N \cdot M$$$ over all test cases does not exceed $$$2.5 \cdot 10^5$$$.
For each test case, output "YES" (without quotes) if Busy Beaver wins, and "NO" (without quotes) if Calico Bear wins.
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.
51 111 50 1 2 3 43 30 1 010 3 100 1 02 40 2 4 61 3 5 74 56 7 6 7 67 6 7 6 76 7 6 7 67 6 7 6 7
Yes No Yes No No
In the first test case, Busy Beaver can decrease the $$$1$$$ to a $$$0$$$. Then, Calico Bear has no moves, so Busy Beaver has a winning strategy.
In the second test case, Busy Beaver has no legal moves. Therefore, Calico Bear has a winning strategy.
In the third test case, Busy Beaver first decreases the central $$$3$$$ to a $$$2$$$. Then, regardless of which $$$10$$$ Calico Bear decreases, Busy Beaver can decrease the other one. Therefore, Calico Bear runs out of moves before Busy Beaver does, giving Busy Beaver a winning strategy.
Busy Beaver has discovered that someone has mixed up his toy marbles!
There are $$$N$$$ containers, numbered from $$$1$$$ to $$$N$$$. The $$$i$$$-th container currently contains a single marble of color $$$c_i$$$.
Busy Beaver wants to tidy up his marbles so that the $$$i$$$-th container only contains marbles of color $$$i$$$. To achieve this, he can perform either of the following actions any number of times (possibly zero):
Find a way to organize the marbles using the minimum number of actions.
The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 2 \cdot 10^5$$$) — the number of containers.
The second line contains $$$N$$$ integers $$$c_1, c_2, \dots, c_N$$$ ($$$1 \leq c_i \leq N$$$) — the marble initially in each container.
On the first line, print a single integer $$$K$$$ — the minimum number of actions required.
On the next $$$K$$$ lines, describe the actions in order, one per line. Each action should be in one of the following formats:
If there are multiple ways to achieve the goal in the minimum number of actions, you may print any valid solution.
There are two subtasks for this problem.
42 4 3 1
2 1 2 4 1 1 2
83 6 7 6 3 6 8 3
6 2 6 4 2 6 2 1 8 7 1 7 3 2 3 1 2 3 5
In the first test case, it is able to achieve the goal in two actions:
It is impossible to achieve the goal in less than two actions.
On a rectangular grid, a snake of size $$$k$$$ is defined to be a subset of cells that is formed by taking the first $$$k$$$ numbered cells in the following figure, where cells are numbered along a path with alternating right and down steps:
Additionally, subsets that are rotations, translations, or reflections of these shapes are also considered snakes. A grid is considered good if every connected component consisting of equal values in the grid is a snake.
Busy Beaver has an $$$N \times M$$$ grid with rows numbered $$$0, \dots, N-1$$$ and columns numbered $$$0, \dots, M-1$$$, where each cell $$$(i, j)$$$ in row $$$i$$$, column $$$j$$$ has a value $$$a_{ij}$$$. Since he's afraid of snakes, he wants you to answer $$$Q$$$ of the following queries: given a contiguous subrectangle of the grid, determine whether or not the subgrid is good.
The first line contains 2 integers, $$$N$$$ and $$$M$$$ ($$$1 \leq N, M \leq 1000$$$) — the dimensions of the grid.
Each of the next $$$N$$$ rows contains $$$M$$$ integers, with the $$$j$$$-th element of the $$$i$$$-th row being $$$a_{i,j}$$$ ($$$1 \leq a_{i, j} \leq 10^6$$$) — the number written in the $$$j$$$-th cell of the $$$i$$$-th row.
The next line contains a single integer, $$$Q$$$ ($$$1 \leq Q \leq 5 \cdot 10^5$$$) — the number of queries.
The next $$$Q$$$ lines describe the queries, Each line contains 4 integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ $$$(0 \leq x_1 \leq x_2 \lt N,$$$ $$$ 0 \leq y_1 \leq y_2 \lt M)$$$, representing a query asking whether the rectangular subgrid with top left corner at $$$(x_1, y_1)$$$ and bottom right corner at $$$(x_2, y_2)$$$ is good.
For each query, output "YES" (without quotes) if the corresponding subgrid consists only of snakes, and "NO" (without quotes) otherwise.
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 four subtasks for this problem.
10 9 1 1 2 2 3 3 2 2 1 4 1 1 3 3 2 2 4 4 4 4 1 1 2 2 3 4 4 4 2 2 1 1 3 3 4 4 2 2 3 4 4 2 2 3 3 1 1 3 3 4 4 2 2 3 2 1 1 3 3 4 4 2 4 2 2 1 2 4 4 3 3 4 1 3 3 4 4 2 2 3 4 3 3 1 1 1 1 4 4 4 5 0 1 6 5 5 4 7 8 0 6 2 8 6 0 9 3 8 5 9 8
YES NO NO YES NO
If we color the sample grid with respect to the value in each cell, we get