Wandering past the fresh produce, Busy Beaver's attention is captured by the local dairy vendor with a peculiar board game at his stall.
There is a circular board with $$$N$$$ squares numbered from $$$0$$$ to $$$N-1$$$. Busy Beaver plays a game on this board with an $$$N$$$ sided die labelled from $$$0$$$ to $$$N-1$$$. If he is on square $$$s$$$ and moves by $$$t$$$ steps, he will land directly on the square $$$s+t \pmod N$$$.
There is also one magical portal on the board, such that if the player lands exactly on square $$$X$$$, they are instantly teleported to square $$$Y$$$.
Busy Beaver rolls the die $$$K$$$ times and obtains the sequence $$$a_1, a_2, \dots, a_K$$$. From his initial square, Busy Beaver will move by $$$a_1$$$ steps, then by $$$a_2$$$ steps, and so on until he has completed all $$$K$$$ moves, where he moves by $$$a_i$$$ on the $$$i$$$-th move.
For each possible initial square from $$$0$$$ to $$$N-1$$$ (inclusive, except square $$$X$$$), determine the square that Busy Beaver lands on after all $$$K$$$ moves are completed (including any teleports).
The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 2 \cdot 10^3$$$).
The first line of each test case contains four integers $$$N$$$, $$$K$$$, $$$X$$$, and $$$Y$$$ ($$$2 \le N \le 5 \cdot 10^5$$$, $$$1 \le K \le 5 \cdot 10^5$$$, $$$0 \le X, Y \lt N$$$, $$$X \ne Y$$$).
The second line of each test case contains $$$K$$$ integers $$$a_1, a_2, \dots, a_K$$$ ($$$0 \le a_i \lt N$$$).
The sum of $$$N$$$ across all test cases does not exceed $$$5 \cdot 10^5$$$.
The sum of $$$K$$$ across all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, output $$$N-1$$$ integers representing the square that Busy Beaver would land on if he started on square $$$i$$$, for all $$$0 \le i \lt N$$$ except for $$$i = X$$$.
There are two subtasks for this problem.
35 1 0 115 3 0 11 2 320 10 3 14 15 9 2 6 5 3 5 8 9
2 3 4 12 4 4 16 7 6 6 11 10 11 14 15 16 17 18 17 18 17 2 1 4 1
In the first sample test case, there are $$$5$$$ squares on the board and one die roll that rolls $$$1$$$. The portal teleports the player from square $$$0$$$ to square $$$1$$$. For each of the starting squares, here is the sequence of events:
In the second sample test case, there are $$$5$$$ squares on the board and three die rolls that roll $$$1,2,3$$$ respectively. The portal teleports the player from square $$$0$$$ to square $$$1$$$. For each of the starting squares, here is the sequence of events:
Busy Beaver is causing chaos at the farmers' market again! This time, he is starting a food fight among the stalls.
The stalls are numbered from $$$1$$$ to $$$N$$$ and are connected by $$$N-1$$$ roads, forming a tree. In other words, it is possible to travel from any stall to any other stall by following the roads, and there is exactly one simple path between any two stalls.
Busy Beaver assigns each stall to either Team Potato or Team Tomato as follows:
Your task is to count the number of possible team assignments. Note that different minimum-length routes may produce the same final assignment; such assignments should be counted only once. Since the answer may be enormous, output it modulo $$$10^9+7$$$.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$N$$$ ($$$2 \le N \le 10^5$$$).
Each of the next $$$N-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le N$$$, $$$u \neq v$$$), indicating that there is a road between stalls $$$u$$$ and $$$v$$$.
The sum of $$$N$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer: the number of possible final team assignments modulo $$$10^9+7$$$.
There are two subtasks for this problem.
441 22 32 471 21 31 41 51 61 771 21 32 42 53 63 771 21 31 42 52 62 7
220812
The sample contains $$$4$$$ test cases:
In the first test case, one possible team assignment is shown below.
One minimum-length route is: $$$$$$ 1 \to 2 \to 3 \to 2 \to 4 \to 2 \to 1. $$$$$$
Its total length is $$$6$$$, which is the smallest possible for a route that starts at stall $$$1$$$, visits every stall, and returns to stall $$$1$$$.
The stalls are then assigned in the order in which they are first visited:
The other possible team assignment is obtained by visiting stall $$$4$$$ before stall $$$3$$$, which swaps their teams. Therefore, the total number of possible team assignments is $$$2$$$.
Busy Beaver loves spending his afternoons at MIT's Banana Lounge. He decides to help out by stacking banana boxes! He needs to collect the inventory across $$$N$$$ consecutive rooms, arranged in a single row and numbered $$$1$$$ to $$$N$$$ from left to right. Due to the quirky architecture of MIT's buildings, each room $$$i$$$ has a specific ceiling clearance height, $$$h_i$$$.
Busy Beaver needs to select one room $$$k$$$ ($$$1 \le k \le N$$$) to serve as the Main Hub. Then, $$$N$$$ of his friends, one from each room, each carry a vertical stack of banana boxes from their starting room $$$i$$$ directly to the hub room $$$k$$$. Since they must walk in a straight line, the maximum number of boxes they can carry is limited by the minimum clearance on their path.
Formally, the number of banana boxes delivered by the friend starting at room $$$i$$$ to the hub room $$$k$$$ is:
What is the maximum total number of banana boxes Busy Beaver can gather at the Main Hub after choosing the optimal hub location $$$k$$$ and performing at most one ceiling renovation?
The first line contains a single integer $$$T$$$ ($$$1 \le T \leq 10^5$$$) — the number of test cases.
The first line of each test case contains a single integer $$$N$$$ ($$$2 \leq N \leq 10^6$$$).
The next line of each test case contains $$$N$$$ space-separated integers $$$h_1,h_2,\dots,h_N$$$ ($$$1 \leq h_i \leq 10^9$$$).
The sum of $$$N$$$ across all test cases does not exceed $$$10^6$$$.
For each test case, output one line containing one integer: the answer for the test case.
There are two subtasks for this problem.
251 10 1 10 1510 10 10 10 10
3250
In the first sample case, the best option is to choose hub $$$k = 2$$$ and renovate $$$h_3$$$ to at least $$$10$$$, allowing the middle three friends to all carry $$$10$$$, for a total of $$$32$$$.
In the second sample case, no renovation can increase the number of banana boxes, so the answer is $$$50$$$.
Busy Beaver is at the farmers' market! There are $$$N$$$ stalls, numbered from $$$1$$$ to $$$N$$$. There are also $$$M$$$ directed paths between stalls. The $$$i$$$-th path goes from stall $$$a_i$$$ to stall $$$b_i$$$, where $$$a_i\ne b_i$$$. It is guaranteed that no paths leave stall $$$N$$$, at least one path leaves every stall other than stall $$$N$$$, no two paths have the same starting and ending stalls, and for every path going from stall $$$r_1\ne N$$$ to $$$r_2\ne N$$$, there is another path going from $$$r_2$$$ to $$$r_1$$$. Each path $$$i$$$ that does not end at stall $$$N$$$ has a unique successor path $$$s_i$$$. It is guaranteed that path $$$s_i$$$ can be used after path $$$i$$$. In other words, $$$a_{s_i} = b_i$$$. Each stall also has an integer counter $$$x_i$$$.
Busy Beaver chooses a stall to start his shopping. First, Busy Beaver travels along any path leaving his starting stall. Then, every minute, supposing Busy Beaver has just traveled along path $$$p$$$ from $$$a_p$$$ to $$$b_p$$$, he performs the following two actions:
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases.
The first line of each test case contains two space-separated integers $$$N$$$ and $$$M$$$ ($$$2 \le N \le 2\cdot 10^5$$$, $$$1 \le M \le 4\cdot 10^5$$$) — the total number of stalls and the number of directed paths in the farmers' market.
The $$$i$$$-th of the next $$$M$$$ lines of each test case contains three space-separated integers $$$a_i$$$, $$$b_i$$$, and $$$s_i$$$ ($$$1 \le a_i, b_i \le N$$$, $$$a_i \neq b_i$$$, $$$1 \le s_i \le M$$$) — indicating that the $$$i$$$-th path goes from stall $$$a_i$$$ to stall $$$b_i$$$, and its unique successor path is $$$s_i$$$. If $$$b_i=N$$$, then $$$s_i=-1$$$, indicating the path has no successor.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$2\cdot 10^5$$$ and the sum of $$$M$$$ over all test cases does not exceed $$$4 \cdot 10^5$$$.
For each test case, if there exists a value for $$$K$$$, initial values for all $$$x_i$$$, and a starting stall such that Busy Beaver can stay in the market forever without ever reaching stall $$$N$$$, print "YES". Otherwise, print "NO".
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.
25 91 2 32 1 72 3 53 2 23 1 91 3 41 4 84 1 11 5 -14 91 2 82 1 72 3 93 2 83 1 71 3 91 4 -12 4 -13 4 -1
YESNO
The market for test case $$$1$$$ is shown below. The stalls are circled and the paths are in blue. It is possible for Busy Beaver to stay in the market forever. A solution is to set $$$K=2$$$, $$$x=[0,0,0,0,0]$$$, and initially put Busy Beaver at stall $$$1$$$. Busy Beaver will then travel along the closed path through the stalls $$$1\rightarrow 2\rightarrow 3\rightarrow 1\rightarrow 4\rightarrow 1$$$, repeating forever. When Busy Beaver reaches stall $$$1$$$ with path $$$5$$$, $$$x_1$$$ becomes odd, and when Busy Beaver reaches stall $$$1$$$ with path $$$8$$$, $$$x_1$$$ becomes even. This ensures that Busy Beaver is never forced to take path $$$9$$$ (which leads to stall $$$N$$$).
The market for test case $$$2$$$ is shown below. It can be shown that it is impossible for Busy Beaver to stay in the market forever.
While visiting the farmers' market, Busy Beaver stops to watch a street magician. The magician presents a row of $$$N$$$ boxes, holding $$$M$$$-bit nonnegative integers $$$a_1, a_2, \dots, a_N$$$, where $$$0 \le a_i \lt 2^M$$$ for all $$$1 \le i \le N$$$.
The magician magically sorts the boxes into non-decreasing order by a series of magic swaps. In a single magic swap, the magician chooses an index $$$i$$$ ($$$1 \le i \lt N$$$) such that the binary representations of $$$a_i$$$ and $$$a_{i+1}$$$ differ by exactly one bit, and swaps $$$a_i$$$ and $$$a_{i+1}$$$.
Watching the performance, Busy Beaver wonders about the limits of this trick. Out of all $$$2^{MN}$$$ possible initial values of $$$a_1, a_2, \dots, a_N$$$ in the boxes, how many of them can be sorted into non-decreasing order using magic swaps? Since this number may be large, Busy Beaver is content with finding it modulo $$$10^9+7$$$.
The first and only line of input contains two integers $$$N$$$ and $$$M$$$ ($$$1 \le N,M \le 50$$$).
Output a single integer: the number of sequences that can be sorted using magic swaps, modulo $$$10^9+7$$$.
There are five subtasks for this problem.
3 2
44
50 1
898961331
10 10
649370314
In the first sample, one sequence that can be sorted using magic swaps is $$$[a_1,a_2,a_3] = [3,1,2]$$$, as follows: