You are given a graph consisting of $$$n$$$ vertices numbered with integers from $$$1$$$ to $$$n$$$, connected by $$$n+m$$$ edges. The first $$$n$$$ edges connect neighboring vertices, meaning the $$$i$$$-th edge connects the $$$i$$$-th and $$$(i+1)$$$-th vertices, and the $$$n$$$-th edge connects the $$$n$$$-th and $$$1$$$-st vertices. In some vertices, there are $$$n-2$$$ tokens numbered with integers from $$$1$$$ to $$$n-2$$$, and no vertex can have more than one token.
In one move, you are allowed to move any token to a vertex connected by an edge to its current vertex, provided that there is currently no token in that vertex. For each token, you know which vertex it should end up in after all moves are completed.
Your task is to determine the sequence of moves so that the tokens end up in the required positions. Note that minimizing the number of moves is not required.
Each test consists of several sets of input data. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of sets of input data. The description of the sets of input data follows.
In the first line of each set of input data, two integers $$$n$$$ and $$$m$$$ ($$$4 \le n \le 100$$$, $$$1 \le m \le 2\,000$$$) are given — the number of vertices and additional edges, respectively.
The second line contains $$$n-2$$$ integers $$$a_i$$$ ($$$1 \le a_i \le n$$$, $$$a_i \ne a_j$$$ for $$$i \ne j$$$), where the $$$i$$$-th number indicates the initial position of the $$$i$$$-th token.
The third line contains $$$n-2$$$ integers $$$b_i$$$ ($$$1 \le b_i \le n$$$, $$$b_i \ne b_j$$$ for $$$i \ne j$$$), where the $$$i$$$-th number indicates the required position of the $$$i$$$-th token.
In the following $$$m$$$ lines, two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$) are given — the numbers of the vertices connected by an edge. It is guaranteed that the resulting graph does not contain multiple edges or self-loops.
It is guaranteed that the sum of $$$n$$$ across all sets of input data does not exceed $$$100$$$.
For each set of input data, output a single integer $$$k$$$ ($$$k \ge 0$$$) in the first line — the number of moves. In the following $$$k$$$ lines, output two integers $$$c_i$$$ and $$$p_i$$$ ($$$1 \le c_i \le n - 2$$$, $$$1 \le p_i \le n$$$) — the token number and the vertex to which it should be moved on the $$$i$$$-th move, respectively.
The total number of moves across all sets of input data must not exceed $$$2 \cdot 10^6$$$. It is guaranteed that such an answer always exists.
14 11 32 12 4
3 2 4 1 2 2 1
As is known, the airline "Trouble" often loses luggage, and concerned journalists decided to calculate the maximum number of luggage pieces that may not return to travelers.
The airline "Trouble" operates flights between $$$n$$$ airports, numbered from $$$1$$$ to $$$n$$$. The journalists' experiment will last for $$$m$$$ days. It is known that at midnight before the first day of the experiment, there were $$$s_j$$$ lost pieces of luggage in the $$$j$$$-th airport. On the $$$i$$$-th day, the following occurs:
For each $$$k$$$ from $$$1$$$ to $$$m$$$, the journalists want to know the maximum number of lost pieces of luggage that may be unfound during the checks over the first $$$k$$$ days. Note that for each $$$k$$$, these values are calculated independently.
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 two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 12$$$, $$$1 \le m \le 2000$$$) — the number of airports and the number of days of the experiment.
The second line of each test case contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$0 \le s_i \le 10^8$$$) — the initial number of lost pieces of luggage in each airport.
Next, the descriptions for each of the $$$m$$$ days follow in order.
The first line of the description of the $$$i$$$-th day contains $$$n$$$ integers $$$a_{i,1}, a_{i,2}, \ldots, a_{i,n}$$$ ($$$0 \le a_{i, j} \le 10^8$$$) — the maximum number of lost pieces of luggage that can be transported to the previous airport for each airport.
The second line of the description of the $$$i$$$-th day contains $$$n$$$ integers $$$b_{i,1}, \ldots, b_{i,n}$$$ ($$$0 \le b_{i, j} \le 10^8$$$) — the minimum number of lost pieces of luggage that will be found on the $$$i$$$-th day in each airport.
The third line of the description of the $$$i$$$-th day contains $$$n$$$ integers $$$c_{i,1}, \ldots, c_{i,n}$$$ ($$$0 \le c_{i, j} \le 10^8$$$) — the maximum number of lost pieces of luggage that can be transported to the next airport for each airport.
It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2000$$$.
For each test case, output $$$m$$$ integers — the maximum number of unfound pieces of luggage for each number of days from $$$1$$$ to $$$m$$$.
25 31 1 1 1 10 0 1 0 00 1 0 0 11 0 0 1 00 1 0 0 09 0 9 9 90 1 0 0 00 0 0 0 09 0 9 0 00 0 0 0 03 10 100000000 50 100000000 50 100000000 50 100000000 5
5 4 2 100000005
In the first test case:
The found luggage is marked in green. In the second test case, all pieces of luggage may remain in their original airports, and the inspection won't find any lost suitcases. Therefore, the answer is $$$10^9 + 5$$$.
Boy Vasya loves to travel very much. In particular, flying in airplanes brings him extraordinary pleasure. He was about to fly to another city, but the runway was heavily covered with snow and needed to be cleared.
The runway can be represented as $$$n$$$ consecutive sections numbered from $$$1$$$ to $$$n$$$. The snowstorm was quite strong, but it has already stopped, so Vasya managed to calculate that the $$$i$$$-th section is covered with $$$a_i$$$ meters of snow. For such situations, the airport has a snowplow that works in a rather unusual way. In one minute, the snowplow can do the following:
Formally, one can choose $$$1 \le l \le r \le n$$$ ($$$r - l + 1 \le d$$$). After that, $$$c = \max \{ a_l, a_{l + 1}, \ldots , a_r \}$$$ is calculated, and if $$$c \gt 0$$$, then for all $$$i \colon l \le i \le r$$$ such that $$$a_i = c$$$, the value of $$$a_i$$$ is decreased by one.
Vasya has been preparing for the flight for a long time and wants to understand how much time he has left to wait until all sections are completely cleared of snow. In other words, it is required to calculate the minimum number of minutes that the snowplow will need to achieve $$$a_i = 0$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 5 \cdot 10^5, 1 \le d \le n$$$) — the number of sections on the runway and the maximum length of the segment that the snowplow can choose.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of meters of snow on the $$$i$$$-th section.
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 single integer — the minimum number of minutes required for the snowplow to achieve $$$a_i = 0$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$.
25 21 5 2 1 23 11000000000 1000000000 1000000000
8 3000000000
In the first test case, there is an optimal sequence of operations. First, select the segment $$$[2, 3]$$$ four times. After three operations, $$$a_2$$$ will turn into $$$2$$$, and the array $$$a$$$ will look like $$$[1, 2, 2, 1, 2]$$$. After the fourth operation, the array $$$a$$$ will become $$$[1, 1, 1, 1, 2]$$$. Next, the array can be transformed into zeros by selecting the segments $$$[1, 2]$$$, $$$[3, 3]$$$, $$$[5, 5]$$$, and $$$[4, 5]$$$ (in that exact order).
In the second test case, $$$d = 1$$$, which means that each section is cleared independently of the others, and the answer is equal to the sum of all $$$a_i$$$.
Sasha wants to buy an apartment on a street where the houses are numbered from $$$1$$$ to $$$10^9$$$ from left to right.
There are $$$n$$$ bars on this street, located in houses with numbers $$$a_1, a_2, \ldots, a_n$$$. Note that there might be multiple bars in the same house, and in this case, these bars are considered distinct.
Sasha is afraid that by the time he buys the apartment, some bars may close, but no more than $$$k$$$ bars can close.
For any house with number $$$x$$$, define $$$f(x)$$$ as the sum of $$$|x - y|$$$ over all open bars $$$y$$$ (that is, after closing some bars).
Sasha can potentially buy an apartment in a house with number $$$x$$$ (where $$$1 \le x \le 10^9$$$) if and only if it is possible to close at most $$$k$$$ bars so that after that $$$f(x)$$$ becomes minimal among all houses.
Determine how many different houses Sasha can potentially buy an apartment in.
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 $$$k$$$ ($$$1 \leq n \leq 10^5, 0 \leq k \lt n$$$) — the number of bars and the maximum number of bars that can close.
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 house numbers where the bars are located.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output a single integer — the number of houses where Sasha can buy an apartment.
44 01 2 3 45 27 6 6 7 13 16 7 96 25 1 9 10 13 2
2 2 4 9
In the first test case, none of the bars can close, so only houses numbered $$$2$$$ and $$$3$$$ are suitable. For the house numbered $$$2$$$, the sum of distances is $$$|2 - 1| + |2 - 2| + |2 - 3| + |2 - 4| = 4$$$, and for the house numbered $$$3$$$, the sum of distances is $$$|3 - 1| + |3 - 2| + |3 - 3| + |3 - 4| = 4$$$. However, for the house numbered $$$1$$$, the sum of distances will be $$$|1 - 1| + |1 - 2| + |1 - 3| + |1 - 4| = 6$$$, so the house numbered $$$1$$$ is not suitable. It can also be proven that Sasha cannot buy apartments in other houses.
In the second test case, the suitable houses are numbered $$$6$$$ and $$$7$$$. For Sasha to choose the house numbered $$$6$$$, it is sufficient that none of the bars close. For Sasha to choose the house numbered $$$7$$$, the bars in houses $$$1$$$ and $$$6$$$ can close. Then the bars will be located in houses numbered $$$6$$$, $$$7$$$, and $$$7$$$.
Every airport has a baggage claim area, and Balbesovo Airport is no exception. At some point, one of the administrators at Sheremetyevo came up with an unusual idea: to change the traditional shape of the baggage claim conveyor from a carousel to a more complex form.
Suppose that the baggage claim area is represented as a rectangular grid of size $$$n \times m$$$. The administration proposed that the path of the conveyor should pass through the cells $$$p_1, p_2, \ldots, p_{2k+1}$$$, where $$$p_i = (x_i, y_i)$$$.
For each cell $$$p_i$$$ and the next cell $$$p_{i+1}$$$ (where $$$1 \leq i \leq 2k$$$), these cells must share a common side. Additionally, the path must be simple, meaning that for no pair of indices $$$i \neq j$$$ should the cells $$$p_i$$$ and $$$p_j$$$ coincide.
Unfortunately, the route plan was accidentally spoiled by spilled coffee, and only the cells with odd indices of the path were preserved: $$$p_1, p_3, p_5, \ldots, p_{2k+1}$$$. Your task is to determine the number of ways to restore the original complete path $$$p_1, p_2, \ldots, p_{2k+1}$$$ given these $$$k+1$$$ cells.
Since the answer can be very large, output it modulo $$$10^9+7$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 3 \cdot 10^4$$$). The description of the test cases follows.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 1000$$$, $$$n \cdot m \ge 3$$$, $$$1 \le k \le \left\lfloor \frac12 (n m - 1) \right\rfloor$$$) — the dimensions of the grid and a parameter defining the length of the path.
Next, there are $$$k+1$$$ lines, the $$$i$$$-th of which contains two integers $$$x_{2i-1}$$$ and $$$y_{2i-1}$$$ ($$$1 \le x_{2i-1} \le n$$$, $$$1 \le y_{2i-1} \le m$$$) — the coordinates of the cell $$$p_{2i-1}$$$ that lies on the path.
It is guaranteed that all pairs $$$(x_{2i-1}, y_{2i-1})$$$ are distinct.
It is guaranteed that the sum $$$n \cdot m$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output a single integer — the number of ways to restore the original complete path modulo $$$10^9+7$$$.
52 4 21 12 22 41 4 11 11 45 5 112 53 44 55 44 35 24 13 22 11 22 31 43 4 41 22 13 22 33 43 3 22 21 11 3
2 0 2 5 1
In the first test case, there are two possible paths:
In the second test case, there is no suitable path, as the cells $$$(1,1)$$$ and $$$(1,4)$$$ do not have a common neighboring cell.
The boarding process for various flights can occur in different ways: either by bus or through a telescopic jet bridge. Every day, exactly one flight is made from St. Petersburg to Minsk, and Vadim decided to demonstrate to the students that he always knows in advance how the boarding will take place.
Vadim made a bet with $$$n$$$ students, and with the $$$i$$$-th student, he made a bet on day $$$a_i$$$. Vadim wins the bet if he correctly predicts the boarding process on both day $$$a_i+1$$$ and day $$$a_i+2$$$.
Although Vadim does not know in advance how the boarding will occur, he really wants to win the bet at least with one student and convince him of his predictive abilities. Check if there exists a strategy for Vadim that allows him to guarantee success.
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$$$ ($$$1 \le n \le 10^5$$$) — the number of students Vadim made bets with.
The second line of each test case contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the days on which Vadim made bets with the students.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output "Yes" (without quotes) if Vadim can guarantee convincing at least one student, 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.
541 1 1 132 2 252 4 3 2 486 3 1 1 5 1 2 611000000000
Yes No Yes No No
In the first test case, Vadim needs to make at least one correct prediction about the boarding process on the second and third days. There are a total of $$$4$$$ possible boarding scenarios for these days, so Vadim can give all $$$4$$$ students different predictions and guarantee that at least one of them will be correct.
In the second test case, Vadim only made bets with three students and cannot guarantee that he will provide at least one of them with a correct prediction.
Some teachers work at the educational center "Sirius" while simultaneously studying at the university. In this case, the trip does not exempt them from completing their homework, so they do their homework right on the plane. Artem is one of those teachers, and he was assigned the following homework at the university.
With an arbitrary string $$$a$$$ of even length $$$m$$$, he can perform the following operation. Artem splits the string $$$a$$$ into two halves $$$x$$$ and $$$y$$$ of equal length, after which he performs exactly one of three actions:
Unfortunately, Artem fell asleep on the plane, so you will have to complete his homework. Artem has two binary strings $$$s$$$ and $$$t$$$ of length $$$n$$$, each consisting of $$$n$$$ characters 0 or 1. Determine whether it is possible to make string $$$s$$$ equal to string $$$t$$$ with an arbitrary number of operations.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the strings $$$s$$$ and $$$t$$$.
The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting only of characters 0 and 1.
The third line of each test case contains the string $$$t$$$ of length $$$n$$$, consisting only of characters 0 and 1.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output "Yes" (without quotes) if it is possible to make string $$$s$$$ equal to string $$$t$$$, and "No" otherwise.
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
380000100110101001800000000000010016010110100010
Yes No Yes
In the first test case, the string 00001001 can be transformed into the string 10101001 in two operations. The sequence of actions is illustrated in the figure below:
In the second test case, the string 00000000 cannot be transformed into any string other than 00000000, as no non-zero elements can be formed during any operation.
We call a phone number a beautiful if it is a string of $$$10$$$ digits, where the $$$i$$$-th digit from the left is at least $$$10 - i$$$. That is, the first digit must be at least $$$9$$$, the second at least $$$8$$$, $$$\ldots$$$, with the last digit being at least $$$0$$$.
For example, 9988776655 is a beautiful phone number, while 9099999999 is not, since the second digit, which is $$$0$$$, is less than $$$8$$$.
Vadim has a beautiful phone number. He wants to rearrange its digits in such a way that the result is the smallest possible beautiful phone number. Help Vadim solve this problem.
Please note that the phone numbers are compared as integers.
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 a single string $$$s$$$ of length $$$10$$$, consisting of digits. It is guaranteed that $$$s$$$ is a beautiful phone number.
For each test case, output a single string of length $$$10$$$ — the smallest possible beautiful phone number that Vadim can obtain.
49999999999998877665599887766509899999999
9999999999 9876556789 9876567890 9899999999
In the first test case, for the first phone number 9999999999, regardless of the rearrangement of digits, the same phone number is obtained.
In the second test case, for the phone number 9988776655, it can be proven that 9876556789 is the smallest phone number that can be obtained by rearranging the digits.
You were flying in an airplane over the Vitebsk region and suddenly realized that you missed the beaver. You jumped out of the plane with a parachute and landed at point $$$A = (x_1, y_1)$$$, knowing for sure that your faithful friend the beaver is at point $$$B = (x_2, y_2)$$$.
There is also a lake in the forest, which is a circle with radius $$$r$$$, centered at the origin $$$(0, 0)$$$. You can move to any point in the forest (including swimming across the lake) at a speed of $$$1$$$, while along the lake, the beaver has built a dam, which allows you to move at a speed of $$$v$$$.
You are interested in the minimum amount of time it will take you to reach the beaver.
The first line contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case is described by a single line containing the integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$, $$$r$$$, and $$$v$$$ ($$$|x_i|, |y_i| \le 10^9$$$, $$$1 \le r, v \le 10^9$$$). It is guaranteed that $$$x_1^2 + y_1^2 \ge r^2$$$ and $$$x_2^2 + y_2^2 \ge r^2$$$.
For each test case, output a single number — the minimum time it takes to reach the beaver.
The answer will be considered correct if the relative or absolute error does not exceed $$$10^{-6}$$$.
3-4 0 4 0 3 3-4 0 4 0 3 1000000000-1 10 1 10 8 1000
5.056391787888 2.000000009425 2.000000000000
There is a directed graph with $$$n$$$ vertices and $$$m$$$ edges, as well as $$$k$$$ arrays $$$a_1, a_2, \ldots, a_k$$$.
A good path from vertex $$$1$$$ to vertex $$$n$$$ of length $$$s$$$ is defined as a sequence of vertices $$$p_1, p_2, \ldots, p_s$$$ ($$$1 \le s \le n$$$) that satisfies the following conditions:
Your task is to compute the number of good paths modulo $$$10^9+7$$$.
Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The following describes the test cases.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$1 \le m, k \le 3 \cdot 10^5$$$) — the number of vertices and edges in the graph and the number of arrays.
Next, there are $$$m$$$ lines, the $$$i$$$-th of which contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i \lt v_i \le n$$$) — the start and end of the $$$i$$$-th edge.
Next, there are $$$k$$$ lines, the $$$i$$$-th of which contains an integer $$$l_i$$$ and $$$l_i$$$ integers $$$a_{i,1}, \ldots, a_{i,l_i}$$$ ($$$1 \le l_i \le n$$$, $$$1 \le a_1 \lt a_2 \lt \ldots \lt a_{l_i} \le n$$$) — the length of the array $$$a_i$$$ and its elements.
It is guaranteed that the sum of $$$n$$$, the sum of $$$m$$$, and the sum of $$$k$$$ across all test cases do not exceed $$$3 \cdot 10^5$$$.
It is guaranteed that the sum of $$$l_i$$$ across all test cases does not exceed $$$3 \cdot 10^5$$$.
For each test case, output a single integer — the number of good paths modulo $$$10^9 + 7$$$.
35 7 41 22 33 44 51 32 43 52 1 22 2 32 3 42 4 55 7 31 22 33 44 51 32 43 53 1 2 33 2 3 43 3 4 56 9 41 22 33 44 55 61 32 43 54 63 1 2 33 2 3 43 3 4 53 4 5 6
1 2 3
In the first example, the only good path is $$$1 \to 3 \to 5$$$.
In the second example, the only good paths are $$$1 \to 2 \to 4 \to 5$$$ and $$$1 \to 3 \to 5$$$.
In the third example, the good paths are $$$1 \to 2 \to 4 \to 6$$$, $$$1 \to 3 \to 4 \to 6$$$, and $$$1 \to 3 \to 5 \to 6$$$.
Vadim has long dreamed of finding a well-paid job, and then he learned that the airline "Beda" is looking for a web development engineer. However, it is rumored that this company gives very difficult tasks during interviews, so Vadim decided to send his student on a reconnaissance mission.
It turned out that during the interview, candidates are offered to solve a puzzle. On one table of size $$$n_1 \times m_1$$$, there are holes drilled, and on another table of size $$$n_2 \times m_2$$$, there are figures that represent prisms with a special sensor on the bottom.
The candidate's task is to fill each hole with one of the figures lying on the table. The additional complexity is that each hole must be completely filled, meaning it must match the shape of the figure placed in it. The correctness of the candidate's solution is checked automatically using special sensors, so the figures cannot be turned upside down. It is allowed not to use some of the figures.
The student was unable to complete the task on his own, but he managed to take two photographs of the tables from the task. Now Vadim has photographs of the task, but he, like his student, also could not complete the task. Therefore, Vadim began to suspect whether the task can be solved at all.
To verify his hypothesis, he sent you the photographs of the task and asked for your help.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 1\,000$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a pair of numbers $$$n_1$$$ and $$$m_1$$$ ($$$1 \le n_1, m_1 \le 1\,000$$$) — the height and width of the table with holes.
The next $$$n_1$$$ lines consist of $$$m_1$$$ characters "." or "N" and describe the configuration of the first table. A hole is considered to be a connected set of cells containing the symbol "N".
Next, in the test case is a pair of numbers $$$n_2$$$ and $$$m_2$$$ ($$$1 \le n_2, m_2 \le 1\,000$$$) — the height and width of the table with figures.
The next $$$n_2$$$ lines consist of $$$m_2$$$ characters "." or "F" and describe the configuration of the second table. A figure is considered to be a connected set of cells containing the symbol "F".
It is guaranteed that the sum of $$$n_1 \cdot m_1$$$ and the sum of $$$n_2 \cdot m_2$$$ across all test cases does not exceed $$$1\,000$$$. It is also guaranteed that each figure and each hole fit within a $$$7 \times 7$$$ square.
For each test case, output "Yes" on a separate line if the task can be solved, and "No" otherwise. The letters of the words "Yes" and "No" can be output in any case.
33 3N.NN..NN.3 4F.F....F.FFF3 3N.NN..NN.3 4FFF...F.F..F3 1N.N1 1F
Yes No No
The Bermuda Triangle — a mysterious area in the Atlantic Ocean where, according to rumors, ships and airplanes disappear without a trace. Some blame magnetic anomalies, others — portals to other worlds, but the truth remains hidden in a fog of mysteries.
A regular passenger flight 814 was traveling from Miami to Nassau on a clear sunny day. Nothing foreshadowed trouble until the plane entered a zone of strange flickering fog. Radio communication was interrupted, the instruments spun wildly, and flashes of unearthly light flickered outside the windows.
For simplicity, we will assume that the Bermuda Triangle and the airplane are on a plane, and the vertices of the triangle have coordinates $$$(0, 0)$$$, $$$(0, n)$$$, and $$$(n, 0)$$$. Initially, the airplane is located at the point $$$(x, y)$$$ strictly inside the Bermuda Triangle and is moving with a velocity vector $$$(v_x, v_y)$$$. All instruments have failed, so the crew cannot control the airplane.
The airplane can escape from the triangle if it ever reaches exactly one of the vertices of the triangle. However, if at any moment (possibly non-integer) the airplane hits the boundary of the triangle (but not at a vertex), its velocity vector is immediately reflected relative to that side$$$^\dagger$$$, and the airplane continues to move in the new direction.
Determine whether the airplane can ever escape from the Bermuda Triangle (i.e., reach exactly one of its vertices). If this is possible, also calculate how many times before that moment the airplane will hit the boundary of the triangle (each touch of the boundary, even at the same point, counts; crossing a vertex does not count).
$$$^\dagger$$$ Reflection occurs according to the usual laws of physics. The angle of incidence equals the angle of reflection.
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 $$$n$$$, $$$x$$$, $$$y$$$, $$$v_x$$$, and $$$v_y$$$ ($$$3 \le n \le 10^9$$$, $$$1 \le x, y$$$, $$$x+y \lt n$$$, $$$1 \le v_x, v_y \le 10^9$$$) — numbers describing the vertices of the triangle, the initial coordinates of the airplane, and the initial velocity vector.
For each test case, output a single integer — the number of times the airplane will hit the boundary of the triangle before it escapes. If the airplane never escapes from the triangle, output $$$-1$$$.
66 2 2 5 26 2 2 20 84 1 2 1 14 1 1 1 24 1 1 2 16 2 3 2 3
2 2 -1 -1 -1 5
An illustration for the first test case is provided below:
In the second test case, the answer is the same as in the first, as all initial data, except for the speed, are the same, but the airplanes are initially moving in the same direction.
In the third test case, the answer is $$$-1$$$, as the airplane will move exclusively along the segments marked in green. An illustration is provided below:
Airplane-airplane-airplane-airplane-airplane. How can I write the problem statement about you? How can I fit you into a problem where there are no airplanes in sight? Airplane-airplane-airplane.
It is not difficult to understand that any airplane can be represented as a triple of numbers $$$(a,b,c)$$$. We will say that the airplane satisfies the quality certificate $$$p$$$ if the following conditions are met:
For a prime number $$$p$$$, you need to find any triple of numbers $$$(a, b, c)$$$ that satisfies the quality certificate $$$p$$$, or state that such a triple does not exist.
The first line contains the number $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.
Each test case is described by a single line containing a single integer prime number $$$p$$$ ($$$3 \le p \le 10^9$$$).
For each test case, output either a suitable triple $$$(a, b, c)$$$ or $$$-1$$$ if such a triple does not exist.
9371113223396716127104652716769023
-1 4 2 1 8 4 10 3 1 9 140 16 67 228 3303 436 228 6453 9446 12228 402737 631562 2045228 1664119 13059676