Aboard the spaceship Skeld are you — the ship's commander — along with $$$N$$$ crewmates. The voyage from Earth to Polus was meant to be peaceful... until it wasn't. A series of strange incidents occurs: oxygen runs low, the reactor nearly melts down, the lights flicker, and the doors jam shut. Suspicion spreads — there might be impostors among us.
Moments of crisis were handled with the crewmates' unity, but the tension lingered. Each crewmate now secretly suspects exactly one crewmate of being the impostor. Remarkably, no crewmate is suspected by more than one person. Formally, there exists a permutation $$$P$$$ of length $$$N$$$, where $$$P[i]$$$ is the crewmate whom the $$$i$$$-th crewmate suspects.
Overseeing this chaos from the commander's room, you, however, are not actually concerned with finding the impostors. Rather, your only goal is to determine the hidden permutation $$$P$$$.
Naturally, to achieve this, you may call emergency meetings. In each meeting, you can choose the order in which the crewmates speak.
Given a crewmate speaking, they will accuse the crewmate they suspect. If the speaker has not yet been marked as sus, their accusation is valid, and the accused crewmate becomes sus. However, if the speaker is already sus, their accusation is ignored.
Unfortunately, as the commander, you cannot attend the meetings yourself. Instead, after each meeting, the ship's log reports the sus status of all crewmates as a binary array, where 1 indicates sus and 0 indicates not sus.
Since time is limited, you may hold at most $$$400$$$ emergency meetings. Your task is to determine the hidden permutation $$$P$$$ within this limit.
Your program first reads a single integer $$$N$$$ ($$$2 \le N \le 100$$$) — the number of crewmates.
Then, you may repeatedly perform queries (call emergency meetings). To make a query, print a line in the following format:
Here, $$$(q_1, q_2, \dots, q_N)$$$ is the order in which the crewmates will speak during the meeting. The sequence must be a permutation of length $$$N$$$.
After printing a query, flush the output and read a line containing $$$N$$$ integers:
Here, $$$s_i$$$ indicates the status of the $$$i$$$-th crewmate after the meeting ends:
Each emergency meeting is independent; all crewmates start as not sus.
When you have determined the hidden permutation $$$P$$$, print it in the following format:
Printing the answer does not count as a query. After printing the final answer, your program should immediately terminate. Failure to do so may result in an undefined verdict.
You may perform at most 400 queries. If your program performs more than $$$400$$$ queries or outputs an invalid format, you may receive a Wrong Answer verdict.
The interactor is not adaptive, which means that the hidden permutation does not depend on the queries you make.
After printing a query or an answer, do not forget to output the end of line and flush the output. Otherwise, you may get an Idleness Limit Exceeded verdict. To do this, use:
6 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1
? 1 2 3 4 5 6 ? 2 4 3 1 5 6 ? 6 5 4 3 2 1 ? 3 5 4 2 1 6 ! 4 5 3 6 2 1
For the first emergency meeting, the permutation $$$P$$$ is $$$[4,5,3,6,2,1]$$$ and the accusations go as follows:
Jack is playing a game with his cat, Salmon. On a shelf, Jack has comic books labeled from volume $$$1$$$ to volume $$$N$$$, arranged in some order from left to right. All books are identical in size.
Jack and Salmon will repeat the following sequence of moves exactly $$$M$$$ times (where $$$M$$$ may be zero):
Your task is to determine the lexicographically largest initial arrangement of the books such that, after performing exactly $$$M$$$ sets of moves as described, there exists a sequence of choices for Jack that results in the books being sorted in ascending order from volume $$$1$$$ to volume $$$N$$$ from left to right.
Two different arrangements $$$A$$$ and $$$B$$$ of $$$N$$$ books are compared lexicographically as follows: $$$A$$$ is said to be lexicographically larger than $$$B$$$ if, at the first position $$$i$$$ from left side where they differ, $$$A_i \gt B_i$$$.
Input The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of test cases.
Each test case consists of a single line containing two integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le M \le 10^9$$$) — the number of comic books on the shelf and the number of sets of moves performed, respectively.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, print $$$N$$$ integers — the lexicographically largest initial order of the books that will result in the volumes being arranged as $$$1, 2, \ldots, N$$$ after exactly $$$M$$$ moves if Jack chooses the books optimally.
23 15 2
3 1 2 5 4 1 2 3
In the first test case, Jack can knock down book number $$$3$$$, and Salmon inserts it at the rightmost position, resulting in [ 1 2 3. ]
Another possible initial arrangement is 1 3 2, but the output is lexicographically larger.
The initial arrangement 1 2 3 is not possible: knocking down book $$$1$$$ gives 2 3 1, and knocking down book $$$2$$$ gives 1 3 2.
A mathematician from ancient times left behind a riddle for future generations. Carved into stone lies a challenge about numbers and operations : Any number can be represented using a sequence of $$$+$$$ and $$$-$$$ signs applied to the numbers 1, 2, 3, ...
You, a bright and curious mind from the future, decide to take up this challenge and makes it even more challenging.
Given an integer $$$X$$$, your task is to express it in the form $$$1 \pm 2 \pm 3 \pm 4 \pm \ldots \pm N$$$ so that the result equals $$$X$$$ and $$$N$$$ is the smallest number.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each testcase contains a single line of one integer $$$X$$$ ( $$$|X| \le 2 \cdot 10^5$$$ )
It is guaranteed that the sum $$$|X|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each testcase:
First, print a line with an integer $$$N$$$.
Then print one valid expression in the format $$$1+2-3+4-5 \ldots N$$$. No spaces are allowed, and the sequence must include all numbers from $$$1$$$ to $$$N$$$.
If there are many expressions, output any of them.
50-214-6
31+2-341-2+3-41141+2-3+471+2+3-4+5-6-7
Audrey and Bastian are about to start on an epic dungeon crawl where they'll face $$$R$$$ monsters ($$$1 \le R \le 10^9$$$). Each monster has a health point (HP) value between $$$0$$$ and $$$N$$$ ($$$1 \le N \le 5 \times 10^5$$$).
Game Rules
The battle proceeds in turns, with Audrey going first:
Both players play optimally.
The Setup Phase
Audrey's Preparation: Audrey, being a cunning adventurer, prepares the dungeon in advance. She sets the initial HP of all $$$R$$$ monsters to values $$$a_1, a_2, \ldots, a_R$$$ where $$$0 \le a_i \le N$$$. Audrey configures the monsters such that she is guaranteed to win if the game proceeds with these HP values.
Bastian's Sabotage: Bastian discovers Audrey's scheme and decides to sabotage exactly one monster before the battle begins. He chooses one monster with HP $$$= a_i$$$ where $$$a_i \ge K$$$ and decreases its HP by $$$K$$$, making its new HP equal to $$$a_i - K$$$.
Bastian's goal is to turn the tables and guarantee his own victory. If there's no way for Bastian to choose a monster that guarantees his win, Bastian abandons the dungeon (the game doesn't happen).
You have to determine how many distinct configurations $$$(a_1, a_2, \ldots, a_R)$$$ are possible on the final day (after Bastian's sabotage, if the game proceeds).
Important: Count configurations based on the HP values after Bastian's modification, not the initial values Audrey set.
Two configurations are considered different if they contain different HP values or the same HP values in different orders (e.g., $$$(1, 3, 2) \neq (1, 2, 3)$$$)
The first line contains three integers $$$N$$$, $$$K$$$, and $$$R$$$ — the maximum HP value, the maximum reduction amount, and the number of monsters.
The second line contains $$$N$$$ integers $$$p[1], p[2], \ldots, p[N]$$$ — where $$$p[i]$$$ is the maximum damage that can be dealt to a monster with $$$i$$$ HP.
Output a single integer — the number of possible monster HP configurations on the final day, modulo $$$998244353$$$.
10 3 11 2 1 2 1 3 4 5 4 5
2
10 3 31 2 1 2 1 3 4 5 4 5
194
Sample Input 1
10 3 1
1 2 1 2 1 3 4 5 4 5
Sample Output 1
2
Explanation 1
With $$$R = 1$$$ monster, the possible configurations on the final day are single-monster configurations. The valid final configurations are $$$(3)$$$ and $$$(5)$$$, giving us $$$2$$$ possible configurations.
Sample Input 2
10 3 3
1 2 1 2 1 3 4 5 4 5
Sample Output 2
194
Explanation 2
One example of a valid final day configuration is $$$(1, 7, 2)$$$. This configuration could arise from:
In both cases, the initial configuration guarantees Audrey's win, but after Bastian's sabotage, the final configuration $$$(1, 7, 2)$$$ guarantees Bastian's win. The total number of such valid final configurations is $$$194$$$.
Elena the Ashen Witch has decided to spend some time in a magical country and is now searching for a place to stay. The country consists of $$$N$$$ cities, numbered from $$$1$$$ to $$$N$$$, connected by $$$M$$$ one-way streets. Since flying magic has been banned for intercity travel, Elena must rely on these streets to move from one city to another.
Each street is described by four integers $$$u$$$, $$$v$$$, $$$p$$$, and $$$h$$$ — meaning there is a road leading from city $$$u$$$ to city $$$v$$$ that requires a pass level of $$$p$$$ and takes $$$h$$$ hours to traverse. To use a street, Elena needs a travel pass. If she holds a pass of level $$$p$$$, she can use any streets that require a pass level less than or equal to $$$p$$$. There may be multiple streets from city $$$u$$$ to city $$$v$$$.
Elena has prepared $$$Q$$$ questions for her journey, each falling into one of the following two types:
The first line contains three integers $$$N$$$, $$$M$$$, and $$$Q$$$ ($$$2 \le N \le 100$$$, $$$1 \le M \le 10^4$$$, $$$1 \le Q \le 10^5$$$) — the number of cities, the number of streets, and the number of queries, respectively.
Each of the following $$$M$$$ lines contains four integers $$$u$$$, $$$v$$$, $$$p$$$, and $$$h$$$ ($$$1 \le u, v \le N$$$, $$$u \ne v$$$, $$$1 \le p \le 10^9$$$, $$$1 \le h \le 10^9$$$), indicating that there is a road from city $$$u$$$ to city $$$v$$$ that requires a pass level of $$$p$$$ and takes $$$h$$$ hours to travel.
The next $$$Q$$$ lines describe the queries, each following one of the two formats below:
Output For each query $$$i$$$ ($$$1 \le i \le Q$$$), output the answer to the $$$i$$$-th query.
If the query is of Type 1, print a single integer — the minimum pass level required. If there is no valid answer, print -1.
If the query is of Type 2, print two integers — the city and the minimum pass level required. If it is impossible, print -1 -1. If there is more than one city achieving the minimum pass level, print the one with the lowest number.
5 6 41 2 1 32 3 1 13 4 1 24 5 1 35 1 1 21 3 2 11 1 92 81 1 81 1 5
1 2 1 2 -1
In the first question, Elena decides to stay in city 1. With the pass level $$$1$$$, city $$$5$$$ takes the most time out of other cities with $$$9$$$ hours — still in time.
In the second question, with a pass level $$$1$$$, Elena can travel from city $$$2$$$ to any city in $$$8$$$ hours. City $$$5$$$ also achieves the same time, but the number is higher.
In the third question, with a pass level $$$2$$$, Elena can travel from city $$$1$$$ to city $$$2$$$ in $$$3$$$ hours, to city $$$3$$$ in $$$1$$$ hour, city $$$4$$$ in $$$3$$$ hours, and city $$$5$$$ in $$$6$$$ hours.
In the fourth question, Elena cannot travel from city $$$1$$$ to city $$$5$$$ in less than $$$6$$$ hours with any pass level.
With the quarantine measures lifted, Jack's hometown decides to hold a festival. Jack is still cautious about meeting too many people, so he wants to plan his route through the festival to maximize his happiness using a simple strategy.
The festival has $$$N$$$ stalls, numbered from $$$1$$$ to $$$N$$$. If Jack enters the $$$i$$$-th stall, he meets $$$p_i$$$ people and gains happiness $$$h_i$$$. He walks from stall $$$1$$$ to stall $$$N$$$ in order and does not revisit any stall. At each stall, he can either enter it or walk past it.
It is guaranteed that $$$p_i \ge p_{i+1}$$$ for all $$$i \lt N$$$, since earlier stalls tend to draw larger crowds.
Jack wants to meet at most $$$P$$$ people in total. He also considers only stalls whose happiness exceeds a certain threshold value $$$threshold$$$. The $$$threshold$$$ should be a non-negative integer.
Formally, let $$$ht$$$ be Jack's total happiness and $$$m$$$ be the number of people he has met. Jack will follow the following strategy.
Jack's strategy (pseudo-code):
ht = 0 // initially, the total happiness is zero
m = 0 // initially, he meets zero person
for i = 1 to N:
if h[i] > threshold and m + p[i] <= P:
enter stall i
ht = ht + h[i]
m = m + p[i]
else:
skip stall i
Jack wants to choose the value of $$$threshold$$$ that maximizes his total happiness $$$ht$$$. If multiple thresholds achieve the same maximum happiness, he wants the minimum such threshold.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of test cases.
Each test case consists of:
The first line contains two integers $$$N$$$ and $$$P$$$ ($$$1 \le N \le 2 \cdot 10^5$$$, $$$1 \le P \le 10^{18}$$$) — the number of stalls and the maximum number of people Jack wants to meet.
Each of the next $$$N$$$ lines contains two integers $$$h_i$$$ and $$$p_i$$$ ($$$1 \le h_i \le 10^9$$$, $$$1 \le p_i \le 10^{18}$$$) — the happiness gained and the number of people met at the $$$i$$$-th stall.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
Additionally, for each test case, the sum of all $$$p_i$$$ does not exceed $$$10^{18}$$$ and $$$p_j \ge p_{j+1}$$$ for all $$$j \lt N$$$.
For each test case, print two integers — the maximum total happiness Jack can achieve and the minimum threshold to achieve the total happiness.
24 154 61 53 33 14 144 61 53 33 1
11 0 10 1
In the first test case, Jack can enter every stall without exceeding the maximum number of people he wants to meet. Therefore, the optimal threshold is $$$0$$$.
In the second test case, if the threshold is set to $$$0$$$, Jack will skip stall $$$3$$$, resulting in a total happiness of $$$8$$$. If the threshold is increased to $$$1$$$, he will instead skip stall $$$2$$$ due to the threshold condition, resulting in a total happiness of $$$10$$$, which is the maximum possible. Threshold value $$$2$$$ also resulted in total happiness of $$$10$$$, but it is not minimal.
In a galaxy far, far away, there are $$$N$$$ planets. The $$$i$$$-th planet is located at coordinates $$$(x_i,y_i,z_i)$$$. The planets are connected by a galactic railway system consisting of $$$N-1$$$ bi-directional railways, forming a tree structure.
As an agent of the Galactic Adventure Agency, you are planning a promotional campaign. For this campaign, you must choose two planets to highlight. Wanderers can journey between these two planets in two different ways:
To please both types of tourists, you want to select a pair of planets $$$(u, v)$$$ that maximizes the combined satisfaction value, defined as the sum of the train satisfaction and the rocket satisfaction between them.
Your task is to find this maximum combined satisfaction value.
The first line of input contains one integer $$$N$$$ ($$$2 \le N \le 2 \cdot 10^5$$$) — the number of planets.
Each of the next $$$N-1$$$ lines contains three integers, $$$u$$$, $$$v$$$, and $$$w$$$, — a railway between planet $$$u$$$ and planet $$$v$$$ with a satisfaction score of $$$w$$$ ($$$1\le u,v\le N , u \neq v, |w| \le 10^9$$$). It is guaranteed that these edges form a tree.
Each of the next $$$N$$$ lines contains three integers, $$$x$$$, $$$y$$$, and $$$z$$$ — the coordinates of the planet $$$u$$$ ($$$1\le x,y,z\le 10^{14}$$$).
A line contains one integer — the maximum combined satisfaction value.
If the maximum combined satisfaction value is less than zero, output zero.
51 2 -22 4 53 4 14 5 -58 3 27 6 18 6 23 6 31 1 1
12
For the example, if you choose planet $$$1$$$ and planet $$$4$$$, the train satisfaction is equal to $$$-2+5=3$$$ and the rocket satisfaction is $$$|8-3|+|3-6|+|2-3| = 9$$$, the combined satisfaction is equal to $$$9+3=12$$$, which can be shown to be the maximum.
Life feels dull when you cannot go outside or meet your favorite people. Fortunately, your favorite bands keep releasing new hits this year, such as Ussewa, Wan Koei Tuen, and Thought Crime. Therefore, you decide to work out at home with your playlist!
You have a playlist of $$$N$$$ songs, numbered from $$$1$$$ to $$$N$$$, representing the order in which they are played. Each song $$$i$$$ has a hypeness value $$$A_i$$$.
While exercising, you only want to listen to songs that match a certain pattern of rising excitement. You may choose to skip some songs, keeping the remaining ones in their original order.
Formally, let $$$S = [S_1, S_2, \dots, S_k]$$$ be a subsequence of $$$[1, 2, \dots, N]$$$ representing the indices of unskipped songs. Your task is to find the longest possible subsequence $$$S$$$ such that:
In other words, both the hypeness values and the gaps between them must form strictly increasing sequences. Find the maximum possible length of such a subsequence $$$S$$$.
The first line contains a single integer $$$N$$$ ($$$1 \le N \le 5 \cdot 10^4$$$) — the number of songs in the playlist.
The second line contains $$$N$$$ integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le 10^5$$$) — the hypeness values of the songs.
On the first line, print one integer $$$k$$$ — the number of unskipped songs.
On the second line, print $$$k$$$ integers — the indices of the unskipped songs in ascending order.
If there are multiple valid lists of unskipped songs, you may print any of them.
52 1 3 4 6
3 3 4 5
Other valid lists of unskipped songs include $$$[1, 3, 5]$$$, which correspond to hypeness values $$$[2, 3, 6]$$$, and $$$[2, 3, 5]$$$, which correspond to hypeness values $$$[1, 3, 6]$$$. You may output any of them.
Myth generation has begun !
Ina is given a string $$$S$$$ of length $$$N$$$, consisting only of the characters 'I', 'C', and 'P'.
Her task is to repeatedly extract the substring "ICPC" from $$$S$$$ as many times as possible. Each time she extracts "ICPC", she must choose four characters from $$$S$$$ in order (not necessarily contiguous, but respecting the original order) that form "ICPC". After each extraction, the chosen characters are removed from the string. The remaining characters close the gap and form the new string for the next extraction.
You must help her determine the maximum number of times she can extract "ICPC" and the indices (1-indexed) of the characters removed from the original string $$$S$$$ for each extraction.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each testcase contains one single line of the string $$$S$$$, consisting only of the characters 'I', 'C', and 'P'.
It is guaranteed that the sum of the length of $$$S$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each testcase:
First, print a line with an integer $$$K$$$ — the maximum number of extractions of "ICPC".
Then print $$$K$$$ lines, each containing four integers — the positions of the characters removed during that extraction, based on the original string.
If there are many ways to extract, output any of them.
4PICPPCICPICPCCICIPCICICPPCCPIPCC
1 2 3 5 6 2 1 2 3 7 4 5 6 8 2 2 4 9 11 5 6 10 12 0
At a grand and dazzling dance party, there are $$$N$$$ guests, each with their own dance skill power $$$a_i$$$.
When two guests pair up on the dance floor, their performance score is equal to the square root of the sum of their skill powers. For example, if one guest has a skill power of $$$4$$$ and another has $$$5$$$, their duet would have a performance score of $$$\sqrt{4 + 5} = 3$$$.
As the host of this vivid celebration, you wish to measure the collective joy — the total performance score of every possible pair of guests dancing together exactly once.
Your task is to determine this total score.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 200000$$$) — the number of guests.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1\le a_i \le 10^9$$$) — the dancing skill powers of the guests.
A single real number — the total performance score at the party.
The answer is considered correct if the relative error does not exceed $$$10^{-6}$$$.
57 3 11 2 17
39.009712
All possible pairs and their performance scores are:
Guest $$$1$$$ and guest $$$2$$$: $$$\sqrt{7+3} \approx 3.162277660$$$
Guest $$$1$$$ and guest $$$3$$$: $$$\sqrt{7+11} \approx 4.242640687$$$
Guest $$$1$$$ and guest $$$4$$$: $$$\sqrt{7+2} = 3$$$
Guest $$$1$$$ and guest $$$5$$$: $$$\sqrt{7+17} \approx 4.898979486$$$
Guest $$$2$$$ and guest $$$3$$$: $$$\sqrt{3+11} \approx 3.741657387$$$
Guest $$$2$$$ and guest $$$4$$$: $$$\sqrt{3+2} \approx 2.236067977$$$
Guest $$$2$$$ and guest $$$5$$$: $$$\sqrt{3+17} \approx 4.472135955$$$
Guest $$$3$$$ and guest $$$4$$$: $$$\sqrt{11+2} \approx 3.605551275$$$
Guest $$$3$$$ and guest $$$5$$$: $$$\sqrt{11+17} \approx 5.291502622$$$
Guest $$$4$$$ and guest $$$5$$$: $$$\sqrt{2+17} \approx 4.358898944$$$
Adding them all up gives approximately $$$39.009712$$$.
Welcome to the Kickshot Tournament, part of the prestigious International Cue & Pocket Championship (ICPC) ! This year is a special year because they decide to host the tournament in the virtual world instead of real life !
You are playing on a rectangular pool table of size $$$(R - 1) \times (C - 1)$$$. On every lattice point of the table lies a virtual coin, forming a total of $$$R \times C$$$ coins. The coordinate system is $$$1$$$-indexed, with the coin at row $$$1$$$, column $$$1$$$ positioned at the bottom-left corner. Rows increase upward, and columns increase to the right.
A ball is placed on the coin located at row $$$M$$$, column $$$N$$$, and is shot at a perfect $$$45^\circ$$$ angle in the up-right direction. Initially, for each millisecond, the ball moves one unit upward (toward larger row numbers) and one unit rightward (toward larger column numbers). When the ball hits the top or bottom wall, it flips its vertical direction; when it hits the left or right wall, it flips its horizontal direction. There is no energy loss — the ball continues bouncing perfectly until it lands in one of the four corner pockets.
Each time the ball passes through a coin, that coin immediately disappears from the table. Collecting a coin does not affect the trajectory of the ball. The coin at row $$$M$$$ column $$$N$$$ is immediately collected when shot. The process continues until the ball reaches a corner, where it finally stops.
Your task is to determine how many coins the ball collects in total, including both the starting coin and the final coin at the pocket.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.
For each test case, there is one line that contains four integers $$$M$$$, $$$N$$$, $$$R$$$, and $$$C$$$ $$$(3 \le R,C \le 10^9, 1 \le M \lt R, 1 \le N \lt C, (M,N) \neq (1,1))$$$ indicating the starting position of the ball and the size of the table.
For each test case, output one line that contains a single integer $$$X$$$ — the number of coins the ball collects.
If the ball never reaches any of the corners, output $$$-1$$$.
33 4 6 82 3 6 74 3 7 10
175-1
The first testcase can be visualized as follows:
The ball path.
A mega-scale project to convert laser light into usable energy for general purposes has begun in the almost infinite experiment area with laser-amplifying glass panes.
The experiment was conducted by placing a laser emitter in one room. After that, the $$$N$$$ laser receivers were placed in room coordinates $$$(x_i,y_i)$$$; each room has a glass pane on the vertical and horizontal side which is shared between adjacent rooms.
The room coordinate in the experiment area with a glass pane on each side Furthermore, the administrator of the project has provided 1 L-shaped reflector to change the trajectory of the laser from horizontal to vertical or vice versa. You want to run $$$Q$$$ simulation tests to provide the information on the minimum possible laser intensity given the starting point for the laser at coordinates $$$(s_i,t_i)$$$; your task is to come up with the resulting laser intensity.
The first line contains four integers $$$N,Q,A,B$$$ ($$$0 \le A,B \le 10^9,1 \le N,Q \le 100\,000$$$) — number of laser receivers, simulations, amplification power of vertical and horizontal glass panes.
Next, $$$N$$$ lines contain $$$x_i,y_i,c_i$$$ ($$$0 \le x_i,y_i \le 10^9,0 \le c_i \le 10^{18}$$$) — laser receiver coordinates in the Cartesian plane and laser amplification power.
Next, $$$Q$$$ lines contain $$$s_i,t_i$$$ ($$$0 \le s_i,t_i \le 10^9$$$) — laser emitter starting coordinates in the Cartesian plane in each simulation.
Print $$$Q$$$ lines, each line contains a single integer — the minimum possible laser intensity for the simulation.
5 3 1 21 1 04 2 02 3 35 4 04 5 23 34 11 6
3 2 7
The arrangement for minimum possible laser intensity for first and third simulation For the first simulation, the L-shaped reflector can be placed on coordinate (3,4); by activating the second receiver, the minimum final laser intensity is $$$1+2+0 = 3$$$.
For the second simulation, the L-shaped reflector is not used; by activating the second receiver, the minimum final laser intensity is $$$2+0 = 2$$$.
For the third simulation, the L-shaped reflector can be placed on coordinate (1,5); by activating the fifth receiver, the minimum final laser intensity is $$$2+1+1+1+2 = 7$$$.
The Marvelous Maximillian is a stage magician famous for his grand finale, The Perfect Permutation. He claims he can arrange $$$N$$$ cards, numbered $$$1$$$ to $$$N$$$, into any permutation $$$P$$$ requested by the audience.
As his apprentice, you know his secret: it's a precise $$$N$$$-step procedure. The trick starts with an empty pile. For each card $$$i$$$ from $$$1$$$ to $$$N$$$, in order:
Tonight, an audience member has demanded the final pile be in the specific order $$$P$$$, where $$$P_1$$$ is the top card and $$$P_N$$$ is the bottom.
Maximillian is on stage and looking at you. You must provide the correct sequence of cut numbers, $$$x_1, x_2, \ldots, x_N$$$, to produce the permutation $$$P$$$ and save the show.
The first line contains a single integer $$$N$$$ ($$$1 \le N \le 2 \cdot 1o^5$$$) — the number of cards.
The second line contains $$$N$$$ integers $$$P_1, P_2, \ldots, P_N$$$($$$1 \le P_i \le N$$$) — the permutation demanded by the audience.
Print one line containing $$$N$$$ integers — the sequence of cut numbers, $$$x_1, x_2, \ldots, x_N$$$.
51 2 3 4 5
1 1 1 1 1
44 1 3 2
1 2 2 4
For the first example, every cut is just taking the top card and putting it in the bottom.
For the second example, the pile after each cut is as follows.
Alice and Bob are standing somewhere in a vaccination queue of $$$N$$$ people (including themselves). With everyone wearing facemasks and keeping their distance, it's almost impossible to recognize anyone else.
Alice counts $$$A$$$ people standing in front of her, while Bob counts $$$B$$$ people standing behind him.
Even if they can't see each other, they still want to know how far apart they are. Can you help them find out how many people are standing between Alice and Bob (excluding both of them)?
One line contains three integers $$$N$$$, $$$A$$$, and $$$B$$$ $$$(2 \le N \le 1000, 0 \le A,B \le N-1; A+B \neq N-1)$$$ — the number of people in the queue, the number of people in front of Alice, and the number of people behind Bob, respectively.
Output a single integer — the number of people standing between Alice and Bob.
10 2 3
3
7 4 5
2
998 244 353
399
In the first example, the line, from front to back, can be described as ooAoooBooo where A is where Alice is and B is where Bob is.
In the second example, the line, from front to back, can be described as oBooAoo where A is where Alice is and B is where Bob is.