A wonderful performance is about to begin on the stage set up by cold_beans...
The stage is a 2D Euclidean plane. Character A initially stands at the center of the stage, which is the origin $$$(0, 0)$$$. There are $$$n$$$ spotlights above the stage. Each spotlight projects a circular illuminated area on the plane with its center at $$$(x_i, y_i)$$$ and a radius of $$$\sqrt{x_i^2 + y_i^2}$$$. The boundary of the circle is included in the illuminated area.
To show the tension of the performance, A wants to always stay within the illuminated areas of all spotlights during the performance, and reach the farthest possible point from the center of the stage.
Please help A find the maximum distance from the center of the stage to a point she can reach under the above conditions.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of test cases.
For each test case:
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of spotlights.
Each of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^5 \le x_i, y_i \le 10^5$$$, not both zero) — the coordinates of the center of the illuminated area of a spotlight.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \times 10^5$$$.
It is guaranteed that no two spotlights share the same center, and no three spotlight centers are collinear.
For each test case, output a single real number $$$d$$$ on a new line — the maximum distance from the center of the stage to a point A can reach.
Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$.
220 11 041 1-1 11 -1-1 -1
1.414213562 0.000000000

The figure above illustrates the illuminated areas of the spotlights in the first testcase. In the first test case, the two spotlights project circles passing through the origin, centered at $$$(0, 1)$$$ and $$$(1, 0)$$$. It can be seen that the farthest point A can reach is $$$(1, 1)$$$, so the answer is $$$d = \sqrt{2} \approx 1.41421356$$$.
In the second testcase, there are no intersecting areas for the illuminated regions other than the origin. Therefore, the farthest point A can reach is the origin $$$(0, 0)$$$, and the answer is $$$0$$$.
Constructive Kingdom is still chasing Little T...
Define the prefix $$$\max$$$ sequence $$$x$$$ of a sequence $$$a$$$ of length $$$n$$$ as $$$x_i = \max\{a_j : 1 \le j \le i\}$$$, and the prefix $$$\min$$$ sequence $$$y$$$ as $$$y_i = \min\{a_j : 1 \le j \le i\}$$$.
Given $$$n$$$ and $$$k$$$, please construct two sequences $$$a$$$ and $$$b$$$, both of length $$$n$$$, that satisfy the following conditions. If no such two sequences exist, report that there is no solution:
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^5$$$), indicating the number of test cases.
Each test case consists of a single line containing two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^5, 0 \le k \le 10^{10}$$$), representing the length of the sequences and the required sum of differences between the prefix $$$\max$$$ and $$$\min$$$.
It is guaranteed that $$$\sum n \le 3 \times 10^5$$$ over all test cases.
For each test case, if there exist two sequences satisfying the conditions, output two lines.
The first line should contain $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, representing your constructed sequence $$$a$$$.
The second line should contain $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$, representing your constructed sequence $$$b$$$.
If no such two sequences exist, output a single line containing the integer $$$-1$$$.
If there are multiple valid answers, you may output any of them.
32 12 05 12
1 2 2 1 -1 1 3 4 2 5 1 2 4 5 3
For the 3rd testcase, let's verify if a hypothetical sequence $$$b = \{1, 2, 4, 5, 3\}$$$ satisfies the conditions:
Additional Notes
A permutation of $$$1$$$ to $$$n$$$ is a sequence of length $$$n$$$ in which every integer from $$$1$$$ to $$$n$$$ appears exactly once.
Pheonix has arrived in outer space. There are $$$n$$$ galaxies, numbered $$$1$$$, $$$2$$$, $$$\ldots$$$, $$$n$$$. These galaxies are connected by $$$n - 1$$$ bidirectional wormhole channels, and any galaxy can be reached from any other galaxy via these wormholes.
Each galaxy contains some stars, and the number of stars in the $$$i$$$-th galaxy is $$$s_i$$$.
Pheonix will make $$$q$$$ wormhole trips between galaxies. During a single trip, Pheonix will not visit any galaxy more than once.
Pheonix has limited knowledge of astronomy, but his mathematical observation skills are keen. For each trip, he wants to ask Little T the following questions:
Please help Little T answer these questions.
The first line contains a single integer $$$T$$$ ($$$ 1 \le T \le 10^5$$$), representing the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 10^5, 1 \le q \le 10^5$$$), representing the number of galaxies and the number of trips Pheonix makes.
The next line contains $$$n$$$ integers $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_n$$$ ($$$1 \le s_i \le n$$$), representing the number of stars each galaxy has respectively.
Each of the following $$$n - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n, u \ne v$$$), representing a wormhole channel connecting $$$u$$$ and $$$v$$$.
Each of the next $$$q$$$ lines contains $$$3$$$ integers $$$x$$$, $$$y$$$, and $$$k$$$ ($$$1 \le x, y \le n, 2 \le k \le n, x \ne y$$$), representing the starting and ending galaxies of a trip, and the query parameter.
It is guaranteed that $$$\sum n, \sum q, \sum k \le 3 \times 10^5$$$ over all test cases. It is also guaranteed that the wormhole channels in each test case allow reaching any galaxy from any other galaxy.
For each test case, output $$$q$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th query:
26 41 2 2 1 2 31 22 32 44 55 63 6 21 4 31 6 21 5 37 51 2 1 3 2 2 41 21 32 42 53 66 74 5 24 7 35 6 43 1 27 5 2
2 1 -1 1 2 2 -1 1 2 1 -1

The figure above shows the wormhole connections and the number of stars for the 1st test case.
The 1st query asks about the path from galaxy $$$3$$$ to galaxy $$$6$$$, with the parameter $$$2$$$. The visited galaxies are $$$3 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 6$$$, and the numbers of stars are $$$S = \{2, 2, 1, 2, 3\}$$$. The star number that satisfies having a frequency strictly greater than the threshold $$$\frac{|S|}{k} = 2.5$$$ is $$$2$$$.
This problem shares the same background as Problem E Right & Left, and the two problems are closely related. It is recommended to read the text of the other problem first before attempting either of them.
This is an interactive problem.
Little T is having trouble with the subway map of City T...
Specifically, this city is located on both sides of River E. The north bank has $$$n$$$ subway stations $$$N_1$$$, $$$N_2$$$, $$$\ldots$$$, $$$N_n$$$, and the south bank has $$$n$$$ subway stations $$$S_1$$$, $$$S_2$$$, $$$\ldots$$$, $$$S_n$$$.
City T has a total of $$$n - 1$$$ subway lines, each of which is a loop line. The $$$i$$$-th loop line connects the subway stations $$$N_i - N_{i + 1} - S_{i + 1} - S_i - N_i$$$. However, these subway loop lines operate in a single direction. It might be $$$N_i \leftarrow N_{i + 1} \leftarrow S_{i + 1} \leftarrow S_i \leftarrow N_i$$$ or $$$N_i \rightarrow N_{i + 1} \rightarrow S_{i + 1} \rightarrow S_i \rightarrow N_i$$$.
Each loop line has a price list $$$u_i$$$, $$$d_i$$$, $$$l_i$$$, $$$r_i$$$, respectively representing the price of traveling one subway station between the 4 adjacent stations ($$$N_i - N_{i + 1}$$$, $$$S_i - S_{i + 1}$$$, $$$N_i - S_i$$$, and $$$N_{i + 1} - S_{i + 1}$$$). Note that the direction of traveling one subway station depends on the operating direction of the subway, which might be $$$N_i \rightarrow N_{i + 1}$$$ or $$$N_{i} \leftarrow N_{i + 1}$$$.
Unfortunately, a space-time black hole swallowed the operating directions and prices of these loop lines on the price list. Little T plans to seek Big K's help to find out the operating directions of these subways.
Big K knows the true operating directions of the subways. However, Little T can arbitrarily re-assign a set of prices for the four adjacent station edges of each loop line; Big K will answer Little T's queries based on these assigned prices.
Little T can ask him up to $$$3\,500$$$ questions:
After asking these questions, Little T needs to confirm the operating direction of each subway line with Big K.
Please help Little T solve this problem.
Please note that the directions of the subway lines are predetermined and they will not change during the interaction process. In other words, the interactor is not adaptive.
Each test case in this problem contains only one set of test data.
The first line of input contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$), representing the parameter, where there are $$$2n$$$ subway stations and $$$n - 1$$$ loop lines in total.
You first need to output $$$n - 1$$$ lines, where the $$$i$$$-th line outputs $$$4$$$ integers $$$u_i$$$, $$$d_i$$$, $$$l_i$$$, $$$r_i$$$, respectively representing the moving prices between the four adjacent stations $$$N_i - N_{i + 1}$$$, $$$S_i - S_{i + 1}$$$, $$$N_i - S_i$$$, and $$$N_{i + 1} - S_{i + 1}$$$ on the $$$i$$$-th loop line. You need to ensure that these four integers are between $$$[0, 10^9]$$$.
Then you will directly start the interaction. For each interaction, you can ask the interactor questions in the following format:
If you have already obtained the subway directions, please output the answer in the following format:
After completing the output of the answer, you should exit safely.
Every output needs to include a newline and flush the buffer, otherwise you might get unexpected results.
To flush the buffer, you can:
3 10 12
10 3 1 2 10 10 1 1 ? N 1 N 2 ? N 2 N 3 ! OI

The figure above shows the operating directions of the subways and Little T's price labels.
Please note that the interaction process in the sample is for reference only. The actual interaction process is not unique, and the interaction process in this example is not necessarily feasible or optimal. The sample for this problem will not appear in the additional files.
This problem shares the same background as Problem D Left & Right, and the two problems are closely related. It is recommended to read the text of the other problem first before attempting either of them.
This is not an interactive problem.
Little T is having trouble with the subway map of City T...
Specifically, this city is located on both sides of River E. The north bank has $$$n$$$ subway stations $$$N_1$$$, $$$N_2$$$, $$$\ldots$$$, $$$N_n$$$, and the south bank has $$$n$$$ subway stations $$$S_1$$$, $$$S_2$$$, $$$\ldots$$$, $$$S_n$$$.
City T has a total of $$$n - 1$$$ subway lines, each of which is a loop line. The $$$i$$$-th loop line connects the subway stations $$$N_i - N_{i + 1} - S_{i + 1} - S_i - N_i$$$. However, these subway loop lines operate in a single direction. It might be $$$N_i \leftarrow N_{i + 1} \leftarrow S_{i + 1} \leftarrow S_i \leftarrow N_i$$$ or $$$N_i \rightarrow N_{i + 1} \rightarrow S_{i + 1} \rightarrow S_i \rightarrow N_i$$$.
Each loop line has a price list $$$u_i$$$, $$$d_i$$$, $$$l_i$$$, $$$r_i$$$, respectively representing the price of traveling one subway station between the 4 adjacent stations ($$$N_i - N_{i + 1}$$$, $$$S_i - S_{i + 1}$$$, $$$N_i - S_i$$$, and $$$N_{i + 1} - S_{i + 1}$$$). Note that the direction of traveling one subway station depends on the operating direction of the subway, which might be $$$N_i \rightarrow N_{i + 1}$$$ or $$$N_{i} \leftarrow N_{i + 1}$$$.
Fortunately, a space-time white hole spat out the operating directions and prices of these loop lines on the price lists. Big K plans to seek Little T's help to get the prices for some subway trips.
As a person from another space-time, Big K will tell Little T the operating directions and price lists of these loop lines. Then Little T needs to answer $$$q$$$ questions:
Please help Little T solve this problem.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$), representing the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 10^5, 1 \le q \le 10^5$$$), representing the parameter for the number of cities and subway lines, and the number of queries.
Each of the following $$$n - 1$$$ lines contains $$$4$$$ integers $$$u_i$$$, $$$d_i$$$, $$$l_i$$$, $$$r_i$$$ ($$$0 \le u_i, d_i, l_i, r_i \le 10^9$$$), respectively representing the moving prices between the four adjacent stations $$$N_i - N_{i + 1}$$$, $$$S_i - S_{i + 1}$$$, $$$N_i - S_i$$$, and $$$N_{i + 1} - S_{i + 1}$$$ on the $$$i$$$-th loop line.
Then, a line containing a string $$$S$$$ of length $$$n - 1$$$ is given, where the $$$i$$$-th character $$$S_i \in \{\mathtt{I}, \mathtt{O}\}$$$. If $$$S_i = \mathtt{I}$$$, it indicates the direction of the $$$i$$$-th loop line is $$$N_i \leftarrow N_{i + 1} \leftarrow S_{i + 1} \leftarrow S_i \leftarrow N_i$$$. If $$$S_i = \mathtt{O}$$$, it indicates the direction of the $$$i$$$-th loop line is $$$N_i \rightarrow N_{i + 1} \rightarrow S_{i + 1} \rightarrow S_i \rightarrow N_i$$$.
Each of the next $$$q$$$ lines contains $$$5$$$ elements $$$S_x$$$, $$$id_x$$$, $$$S_y$$$, $$$id_y$$$ ($$$S_x, S_y \in \{\mathtt{N}, \mathtt{S}\}$$$, $$$id_x, id_y \in \{m \in \mathbb{N} : 1 \le m \le n\}$$$), indicating that Big K asks Little T how much subway fare must be paid at least between the $$$id_x$$$-th city $$$(S_x)_{id_x}$$$ located on the $$$S_x$$$ bank and the $$$id_y$$$-th city $$$(S_y)_{id_y}$$$ located on the $$$S_y$$$ bank.
It is guaranteed that $$$\sum n \le 3 \times 10^5$$$ and $$$\sum q \le 3 \times 10^5$$$ over all test cases.
For each test case, output $$$q$$$ lines. The $$$i$$$-th line should contain an integer $$$d$$$ representing the answer to the $$$i$$$-th query received by Little T, i.e., the minimum required subway fare from $$$(S_x)_{id_x}$$$ to $$$(S_y)_{id_y}$$$.
33 510 3 1 210 10 1 1OIN 1 N 2N 2 N 3N 2 S 2S 2 N 2N 1 N 16 15 1 7 32 6 3 46 8 1 710 0 7 84 5 4 9IOIOIN 4 S 46 14 5 7 65 0 9 11 5 1 510 4 7 12 1 3 3OIOIOS 6 S 4
10 12 1 14 0 14 17

The figure above shows the operating directions of the subways and the price lists.
Little T came to City T, and she is going to a Livehouse for a performance.
City T can be represented by an infinite Euclidean 2D plane. The positive direction of the $$$y$$$-axis represents due north (N), the positive direction of the $$$x$$$-axis represents due east (E), the negative direction of the $$$y$$$-axis represents due south (S), and the negative direction of the $$$x$$$-axis represents due west (W).
Little T is initially standing at position $$$(x_{t}, y_{t})$$$, initially facing one of the four directions: due east, south, west, or north. The Livehouse she wants to go to is located at $$$(x_l, y_l)$$$.
For each move, she can choose one of the following two options:
Please calculate, under the above conditions, what is the minimum number of right turns Little T needs to make to reach the Livehouse.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$), representing the number of test cases.
For each test case, one line contains 5 elements $$$x_t$$$, $$$y_t$$$, $$$dir$$$, $$$x_l$$$, $$$y_l$$$ ($$$x_t, y_t, x_l, y_l \in \{n \in \mathbb{Z} : -10^9 \le n\le 10^9\}$$$, $$$dir \in \{\text{N}, \text{E}, \text{S}, \text{W}\}$$$), respectively representing Little T's location, the initial direction Little T is facing, and the location of the Livehouse.
For each test case, output a single line with an integer representing the minimum number of right turns Little T needs to make to reach the Livehouse under the above conditions.
80 0 E 3 -21 1 N 0 110 10 E 10 10-9 2 E 3 20 -7 E -1 -40 6 E -4 610 -9 S 10 91 -3 N -1 0
1 3 0 0 3 2 2 3
For the 1st test case, first walk $$$3$$$ steps east to reach $$$(3,0)$$$, then turn right to face south, and walk $$$2$$$ steps south to $$$(3, -2)$$$.
For the 2nd test case, first turn right three times to face west, then walk $$$1$$$ step to reach $$$(0, 1)$$$.
For the 3rd test case, the starting point and the ending point coincide, so no right turn is needed.
This problem has no relation with Problem H Morrow by Morrow.
TSUCE (Time-Space Union of Coding Experts) is preparing to host the TSUCE Programming Duel Cup, an algorithmic programming 1v1 duel between two players!
The competition format is as follows. Please note the meanings of $$$n$$$ and $$$m$$$:
Unfortunately, the scorekeeper Little T's database broke down. He only remembers the scores of all $$$k$$$ matches, but he forgot $$$n$$$ and $$$m$$$ related to the format.
Please help him determine whether there exists a valid pair of positive integers $$$n$$$ and $$$m$$$ such that all these scores are valid under this format.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$), representing the number of test cases.
The first line of each test case contains an integer $$$k$$$ ($$$1 \le k \le 10^5$$$), representing the number of recorded matches.
Each of the following $$$k$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{18}, |a - b| \ge 2$$$), representing the score of a match recorded in Little T's database.
It is guaranteed that $$$\sum k \le 3 \times 10^5$$$ over all test cases.
For each test case, if there exists a valid pair of positive integers $$$n$$$ and $$$m$$$ such that all these scores are valid under this format, output a string YES on a single line; otherwise, output a string NO on a single line.
Note that the evaluation is case-insensitive for YES and NO. In other words, when the answer is positive, outputs like yes, YES, Yes, YeS will all be considered correct.
6316 1410 1619 22211 1619 2252 1316 129 1313 1020 2225 75 930 55 211 726 99 6
YES YES YES NO YES YES
For the 3rd test case, we can find that $$$n = 12$$$, $$$m = 3$$$ is a valid solution. The matches will go through the following processes:
This problem has no relation with Problem G CS:Go Over.
Little T is preparing some classic problems $$$\ldots$$$
Given a permutation $$$p = \{p_1, p_2, \ldots, p_n\}$$$ of length $$$n$$$, Little T will perform exactly one operation $$$(i, j)$$$:
For all different valid operations $$$(i, j)$$$, Little T needs to calculate the sum of the orders of the permutations represented by the permutation after the swap.
Since the answer can be very large, Little T needs to calculate the answer modulo $$$998\,244\,353$$$.
Please help Little T calculate this problem.
The hints section of the problem provides related information about permutations.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$), representing the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$), representing the length of the permutation.
The next line contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_n$$$ ($$$1 \le p_i \le n$$$), representing the given permutation.
It is guaranteed that $$$\sum n \le 3 \times 10^5$$$ over all test cases, and the input in each test case is guaranteed to be a valid permutation.
For each test case, output a single line with an integer representing the sum of the orders of the permutations represented by the permutation after the swap for all different valid operations $$$(i, j)$$$, modulo $$$998\,244\,353$$$.
232 3 142 1 4 3
6 20
For the 1st test case, there are $$$3$$$ different ways to swap:
Therefore, the answer is $$$6$$$.
Additional notes
A permutation sequence of $$$1$$$ to $$$n$$$ is a sequence of length $$$n$$$ in which each integer from $$$1$$$ to $$$n$$$ appears exactly once. The length of this permutation sequence is also $$$n$$$.
Let $$$S = \{1, 2, \ldots, n\}$$$. A permutation mapping from $$$1$$$ to $$$n$$$ refers to a bijection from $$$S$$$ to $$$S$$$.
A permutation sequence $$$p = \{p_1, p_2, \ldots, p_n \}$$$ of length $$$n$$$ can represent a permutation mapping $$$p(n)$$$, that is, $$$p(i) = p_i$$$.
For example, $$$p = \{2, 3, 1\}$$$ in the 1st test case represents the permutation mapping $$$p(n): \{1, 2, 3\} \rightarrow \{1, 2, 3\}$$$, where $$$$$$ p(1) = 2, p(2) = 3, p(3) = 1. $$$$$$
The identity permutation of length $$$n$$$, $$$\text{id}_n: \{1, 2, \ldots, n\} \rightarrow \{1, 2, \ldots, n\}$$$, is defined as $$$\text{id}_n(i) = i$$$. For example, an identity permutation of length 4, $$$\text{id}_4$$$, has: $$$$$$ \text{id}_4(1) = 1, \text{id}_4(2) = 2, \text{id}_4(3) = 3, \text{id}_4(4) = 4. $$$$$$
The composition $$$p \circ q$$$ of two permutations $$$p$$$ and $$$q$$$ represents the permutation where $$$p \circ q(i) = p(q(i))$$$.
The power $$$p^m$$$ (where $$$m$$$ is a non-negative integer) of a permutation of length $$$n$$$ is defined as $$$$$$ p^m = \begin{cases} p \circ p^{m - 1}, &m \ge 1;\\ \text{id}_n, & m = 0. \end{cases} $$$$$$
The order $$$\text{ord}(p)$$$ of a permutation of length $$$n$$$ is defined as the smallest positive integer $$$k$$$ such that $$$p^{k} = \text{id}_n$$$.
Nailong is addicted to Stardew Valley during his holidays. To complete all achievements, he needs a lot of gold coins to purchase the Gold Clock, so he is currently in desperate need of gold coins.
In the game Stardew Valley, players can grow different crops. By growing crops, the player Nailong can earn the gold coins he needs.
It is now the morning of the $$$1$$$st day of Spring, and Spring lasts for $$$k$$$ days in total. Nailong has some arable plots of land, which are initially empty. He has $$$10^{10^{100}}$$$ gold coins on hand, and now he starts his farm work for the Spring.
Pierre's General Store sells $$$n$$$ types of single-harvest crop seeds and $$$m$$$ types of multi-harvest crop seeds. Their definitions are as follows:
Because Nailong is quite lazy, he will choose to plant at most one type of crop throughout the entire Spring.
Nailong can perform the following operations any number of times each day:
Since all arable plots are equivalent, he wants to know the maximum profit in gold coins that each plot of land can bring him by the end of Spring.
Note that if it is impossible to make a profit no matter what, Nailong can choose to do nothing and gain a profit of $$$0$$$ gold coins by the end of Spring.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$), representing the number of test cases.
The first line of each test case contains 3 integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n + m \le 10^5, n \ge 0, m \ge 0, 2 \le k \le 10^9$$$), representing the number of types of the two kinds of seeds and the number of days Spring lasts.
Each of the following $$$n$$$ lines contains 3 integers $$$p$$$, $$$q$$$, and $$$t$$$ ($$$0 \le p , q\le 10^9, 1 \le t \le k - 1$$$), representing the seed price, mature crop selling price, and maturation time of a single-harvest crop.
Each of the following $$$m$$$ lines contains 4 integers $$$p$$$, $$$q$$$, $$$t$$$, and $$$s$$$ ($$$0 \le p , q\le 10^9, 1 \le t, s \le k - 1$$$), representing the seed price, mature crop selling price, maturation time, and harvest cycle of a multi-harvest crop.
It is guaranteed that $$$\sum (n + m) \le 3 \times 10^5$$$ over all test cases.
For each test case, output a single line with an integer representing the maximum profit in gold coins that each plot of land can bring him by the end of Spring.
32 1 1020 50 35 7 130 15 2 20 2 710 4 2 125 9 1 21 1 510 8 25 1 4 1
90 10 0
For the 1st test case, we have the following crops:
| Crop | Type | Seed Price | Crop Selling Price | Maturation Time | Harvest Cycle |
| A | Single-harvest | 20 | 50 | 3 | N/A |
| B | Single-harvest | 5 | 7 | 1 | N/A |
| C | Multi-harvest | 30 | 15 | 2 | 2 |
We consider choosing Crop A. A feasible plan is as follows:
| Day | Action | Daily Balance |
| 1 | Buy 3 units of Crop A seeds, and plant 1 unit of Crop A | -60 |
| 4 | Harvest and sell 1 harvestable unit of Crop A, and plant 1 unit of Crop A | 50 |
| 7 | Harvest and sell 1 harvestable unit of Crop A, and plant 1 unit of Crop A | 50 |
| 10 | Harvest and sell 1 harvestable unit of Crop A | 50 |
The total profit is $$$-60+50+50+50 = 90$$$ gold coins.
Nailong is killing monsters in the game. This is a turn-based game, and he encounters $$$n$$$ monsters with health points of $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ respectively.
Each turn, Nailong can cast one of the following skills once:
When a monster takes damage, an equal amount of health points will be deducted. If its health points are less than or equal to $$$0$$$, the monster will be killed. Nailong wins the battle when all $$$n$$$ monsters are killed.
Please help Nailong plan his skill usage to minimize the mana consumed while winning the battle, and calculate the minimum mana required.
Each test case in this problem contains only one set of test data.
The first line contains 5 integers $$$n$$$, $$$x$$$, $$$y$$$, $$$a$$$, $$$b$$$ ($$$1 \le n, x, y, a, b \le 2 \times 10^6$$$), respectively representing the number of monsters, the damage of Fireball and Flame Strike, and their mana consumption.
The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 10^7$$$), representing the health points of the monsters.
Output a single line with an integer, representing the minimum mana Nailong needs to consume to win the battle.
4 10 8 5 79 17 23 40
31
5 3 1 2 51 2 3 4 10
17
For the first sample, A feasible skill usage plan for Nailong is to use Flamestrike 7 times, and then use Fireball once on the last monster.
This way, the other monsters take $$$7 \times 3 = 21$$$ damage, and the last monster takes $$$10 + 7 \times 3 = 31$$$ damage, so they are all killed.
The mana consumption is $$$7 \times 4 + 6 \times 1 = 34$$$ points, and it can be proven that this is optimal.
Maddy is still purging Baddy's evil legion...
The game is played on an infinite Chinese Chess (Xiangqi) board, which is formed by the intersection of infinitely many horizontal and vertical lines. Each intersection can hold one chess piece. For ease of description, we abstract it as a 2D Cartesian coordinate system to represent the positions of the pieces.
Baddy controls $$$n$$$ black pawn pieces and one black general piece. These pieces are fixed at their initial positions during the game and will not move. The black pawns are deployed at the intersections $$$(x_1, y_1)$$$, $$$(x_2, y_2)$$$, $$$\ldots$$$, $$$(x_n, y_n)$$$, and the black general is located at $$$(x_\text{K}, y_\text{K})$$$.
Now Maddy controls a red cannon piece. She can deploy the red cannon anywhere on the board. The red cannon follows the movement rules of Chinese Chess. Specifically:
After deploying the red cannon, Maddy can continuously make an infinite number of moves following the rules above.
Maddy now wants to know: is there a valid deployment strategy and a sequence of moves for the red cannon that can capture the black general? Please help her.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$), representing the number of test cases.
The first line of each test case contains 3 integers $$$n$$$, $$$x_\text{K}$$$, and $$$y_\text{K}$$$ ($$$0 \le n \le 10^5, -10^9 \le x_\text{K}, y_\text{K} \le 10^9$$$), representing the number of black pawns and the coordinates of the black general.
Each of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$), representing the position of a black pawn.
It is guaranteed that $$$\sum n \le 3 \times 10^5$$$ over all test cases.
For each test case, if there is a valid deployment strategy and a sequence of moves for the red cannon to capture the black general, output a string YES on a single line; otherwise, output a string NO on a single line.
Note that the evaluation is case-insensitive for YES and NO. In other words, when the answer is positive, outputs like yes, YES, Yes, YeS will all be considered correct.
30 0 01 1 10 14 1 00 12 11 11 2
NO YES NO
The figure below shows the positions of the black pieces for the 2nd test case and one possible deployment position for Maddy's red cannon. By deploying it at $$$(-2, -1)$$$, she can directly capture the black general.
The figure below shows the positions of the black pieces for the 3rd test case.

Please note that for demonstration purposes, the sample figures show the board boundaries, but in fact, the problem description has pointed out that the board is infinite.
Here in the picture, Chinese character "将" means general, "卒" means pawn, "炮" means cannon.
TSUCE's final exams are over! The grading teacher, Big K, looked at Little T's horrible exam paper.
Therefore, he decided to use the following tricks to save Little T, who scored $$$x$$$ points:
Please help Big K find a valid way to use these tricks so that Little T can obtain the maximum possible score.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 3 \times 10^5$$$), representing the number of test cases.
Each test case consists of a single line containing 5 integers $$$x$$$, $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, $$$a_4$$$ ($$$1 \le x \le 100, 0 \le a_1, a_2, a_3, a_4 \le 400$$$), representing Little T's initial score and the maximum number of times Big K can use each trick.
For each test case, output a single line with an integer representing the maximum score Little T can obtain.
71 1 1 1 150 2 1 1 299 0 1 2 110 2 0 0 3100 400 400 400 40075 1 7 3 01 3 7 4 3
70 118 148 71 98703086085238798121046930830507710 168 232
For the 1st test case, Little T initially scored $$$1$$$ point, and Big K can use each trick at most once. Big K can adopt the following strategy: