On a dark and stormy night, Dr. Zomboss dispatched a vanguard of $$$n$$$ Dancing Zombies to breach Dave's defenses. When the upbeat music begins, the Dancing Zombies will appear one by one on the number line in a predetermined rhythm and start spreading out in all directions.
The specific rules are as follows:
The goal of Dr. Zomboss is to cover the entire battlefield with Dancing Zombies. What is the minimum number of seconds required to ensure that every integer coordinate in the interval $$$[0,k]$$$ on the number line contains at least one Dancing Zombie?
The first line contains two integers $$$n,k$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le k \le 10^{12}$$$), representing the total number of Dancing Zombies and the right endpoint of the area to be covered, respectively.
The next $$$n$$$ lines each contain two integers $$$a_i,b_i$$$ ($$$0 \le a_i,b_i \le k$$$), representing the time and initial position of the $$$i$$$th Dancing Zombie, respectively.
Output a single integer on a single line, representing the time required for Dancing Zombies to cover all integer coordinates in the interval $$$[0,k]$$$ on the number line.
3 50 00 51 2
2
2 1020 1026 66
72
For the first example, at the end of each second, the number of Dancing Zombies in the interval $$$[0,5]$$$ on the number line is as follows:
At second $$$2$$$, there is at least one Dancing Zombie at every integer coordinate in the interval $$$[0,5]$$$ on the number line.
Everyone has their own galaxy of stars that they long for but cannot reach.
In a dream, Xinghe has a non-negative integer $$$x$$$. He needs to find three non-negative integers $$$a, b, c$$$ such that $$$a \times b + c = x$$$. Let the maximum among these three numbers be $$$M = \max(a, b, c)$$$, and the minimum be $$$m = \min(a, b, c)$$$. His goal is to make the range $$$M - m$$$ as small as possible. Please help him determine the minimum possible value of $$$M - m$$$ among all triples $$$(a, b, c)$$$ satisfying the condition.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^5$$$), denoting the number of test cases.
For each test case, there is one line containing an integer $$$x$$$ ($$$0 \le x \le 10^{9}$$$), as described in the statement.
For each test case, output one integer on a separate line, representing the minimum value of $$$M - m$$$.
41121000729320
1085
Given a binary string $$$S = S_1 S_2 \dots S_n$$$ of length $$$n$$$, you need to insert a bitwise operator between every two adjacent digits $$$S_i$$$ and $$$S_{i+1}$$$ (there are $$$n-1$$$ such positions), so that the final value of the resulting expression is $$$0$$$.
There are three operators to choose from, with the following rules:
Note that in this problem, the precedence of bitwise operators is the same as in C, according to the following rules:
You need to construct a valid sequence of operators such that the final value of the whole expression is $$$0$$$. If there are multiple valid solutions, output any of them. It can be proved that for every valid input, at least one valid construction always exists.
The first line contains a positive integer $$$n$$$ ($$$2 \le n \le 10^5$$$), which denotes the length of the string.
The second line contains a string $$$S$$$ of length $$$n$$$ consisting only of 0 and 1.
Output one line containing a string of length $$$n-1$$$, representing the operators inserted in order. If there are multiple valid solutions, output any of them.
3000
&&
In the sample, the original string is 000. Two bitwise AND operators can be inserted in the middle to make the expression 0&0&0, whose result is 0. Therefore, output &&.
Given $$$n$$$ points on a two-dimensional plane, each point is labeled with a bracket, which may be either a left bracket ( or a right bracket ).
We say that a string $$$S$$$ is a valid bracket sequence if and only if it can be generated by the following recursive rules:
For example, (), (()), and ()() are valid bracket sequences, while )(, ((), and ())( are not valid bracket sequences.
Now you need to choose some distinct points from the given points as vertices to form a convex polygon.
In this problem, a polygon formed by $$$m$$$ points $$$p_{a_1},p_{a_2},\dots,p_{a_m}$$$ is called a convex polygon if and only if the following conditions are satisfied:
In other words, the selected points must appear exactly in the cyclic order of their own convex hull, and all interior angles must be strictly less than $$$180^\circ$$$; that is, the convex polygon has no three collinear points.
For a convex polygon, choose any vertex on its boundary as the starting point, and traverse all vertices along the polygon boundary in either clockwise or counterclockwise direction, stopping just before returning to the starting point. This yields a bracket sequence of length $$$m$$$: if the current vertex is labeled with a left bracket, write (; if it is labeled with a right bracket, write ).
Your task is to find a convex polygon containing at least one left bracket such that, for any vertex on the polygon labeled with a left bracket, the bracket sequence obtained by starting from that vertex and traversing the polygon boundary in either direction is a valid bracket sequence.
If such a convex polygon exists, output any one of them; otherwise, report no solution.
The first line contains an integer $$$T$$$ ($$$1\le T\le 400$$$), the number of test cases.
For each test case, the first line contains an integer $$$n$$$ ($$$1 \le n \le 2000$$$), the number of points.
The next $$$n$$$ lines each contain three integers $$$x_i,y_i,t_i$$$ ($$$0 \le x_i,y_i \le 10^9, t_i \in \{0,1\}$$$), representing the coordinates and bracket type of the $$$i$$$-th point. Here, $$$t_i = 0$$$ denotes a left bracket, and $$$t_i = 1$$$ denotes a right bracket.
It is guaranteed that, within each test case, all points are distinct and no three points are collinear.
It is also guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.
For each test case, if there is no solution, output a single integer $$$-1$$$ on one line.
Otherwise, output the number of vertices $$$m$$$ of the selected convex polygon on the first line.
On the second line, output $$$m$$$ pairwise distinct integers $$$a_1,a_2,\ldots,a_m$$$, representing the indices of the selected points.
These points must be output in the order along the boundary of the convex polygon, either clockwise or counterclockwise.
541 1 02 4 13 9 04 16 151 1 02 4 03 9 04 16 15 25 1647 58 030 23 027 34 135 7 110 30 11 25 1810 5 010 16 01 5 024 9 06 2 06 12 07 18 13 13 110 0 0
41 2 3 4-141 3 2 4-1-1
When a geometric problem is extended to three dimensions or even higher dimensions, its difficulty can increase significantly. To address complex $$$n$$$-dimensional geometric structures, researchers have proposed a model in which the $$$2^n$$$ key positions in space are abstracted as vertices of a graph, and specific geometric constraints between these positions are abstracted as edges in the graph.
You now have a model that has been abstracted into a graph, in which complex geometric features have been transformed into a simple undirected graph containing $$$2^n$$$ vertices with no duplicate edges or self-loops. However, for certain reasons, you cannot directly observe the edges in the graph. You want to know the total number of edges, $$$m$$$.
You may use a "subset detection detector" which works as follows:
Due to the high cost, the detector can be used at most $$$2^{n+1}$$$ times. Given the limited number of queries, find the total number of edges $$$m$$$ in the graph.
First, read an integer $$$n$$$ from standard input ($$$1 \le n \le 10$$$). This means the graph contains $$$2^n$$$ vertices, numbered from $$$1$$$ to $$$2^n$$$.
To make a query, output ? s to standard output, where $$$s$$$ is a binary string of length $$$2^n$$$. The $$$i$$$-th character should be:
You must ensure that the number of 1s in the string is exactly $$$2^{n-1}$$$. If you make an invalid query or exceed the query limit, the interactor will terminate your program.
After each query, you need to read an integer $$$d$$$ from standard input, which denotes the number of edges that have at least one endpoint in the subset $$$S$$$.
To output the answer, output ! m to standard output, where $$$m$$$ is the total number of edges. After outputting the answer, you must terminate the program immediately.
The interactor is non-adaptive. This means that the graph is fixed before the interaction begins and does not change according to your queries.
Note: After each output, you must print a newline and flush the standard output buffer. Use the following methods to flush:
2 1 0
? 1010 ? 0101 ! 1
Little L has a non-negative integer array $$$a = [a_1, a_2, \dots, a_n]$$$ of length $$$n$$$. The elements in the array may repeat, and each element can be any non-negative integer (that is, $$$a_i \ge 0$$$, with no upper bound). Little L chooses an unknown positive integer $$$m$$$, and performs a modulo operation on every element of array $$$a$$$, obtaining a new array $$$b$$$, where $$$b_i = a_i \bmod m$$$.
Now Little L tells you the array $$$b$$$, but both the original array $$$a$$$ and the modulus $$$m$$$ are unknown. He wants to know: among all possible original arrays $$$a$$$ and modulus $$$m$$$, how many different values can its $$$\text{mex}$$$ take?
The definition of $$$\text{mex}$$$: the smallest non-negative integer that does not appear in the array. For example, $$$\text{mex}\{0, 1, 3\} = 2$$$, and $$$\text{mex}\{1, 2, 3\} = 0$$$.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the length of the array.
The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i \le 10^9$$$), representing the array $$$b$$$ given by Little L.
Output an integer representing the number of possible values of $$$\text{mex}$$$ of the original array $$$a$$$.
60 1 2 3 1 2
5
For the example, all possible $$$\text{mex}$$$ values are $$$\{0,1,2,3,4\}$$$. For example, when $$$\text{mex}=3$$$, one possible construction is $$$m=5$$$, $$$a=\{0,1,2,8,6,7\}$$$.
A football team consists of $$$n$$$ players (numbered $$$1$$$ through $$$n$$$) and a goalkeeper, and they are practicing passing.
The practice procedure is as follows:
Now the goalkeeper wants to know the expected total number of passes made by the players when he stops the ball.
The first line contains a positive integer $$$n$$$ ($$$1\le n \le 16$$$), denoting the number of players.
The next $$$n$$$ lines each contain $$$n$$$ integers $$$a_{i,j}$$$ ($$$0\le a_{i,j} \lt 998244353$$$). Here, after player $$$i$$$ gets the ball, the probability that they pass it to player $$$j$$$ is $$$p_{i,j} = \frac{a_{i,j}}{\sum_{k=1}^n a_{i,k}}$$$.It is guaranteed that for every $$$1\le i\le n$$$, we have $$$\left(\sum_{k=1}^n a_{i,k}\right) \not\equiv 0 \pmod{998244353}$$$.
If the expectation converges, output the answer modulo $$$998244353$$$; otherwise, output infinity.
It can be proven that if the expectation converges, then it can always be written as a rational number $$$\frac{p}{q}$$$, where $$$p,q$$$ are integers, $$$p\ge 0$$$, and $$$q\ge 1$$$. You should output the value of $$$p\cdot q^{-1}\bmod 998244353$$$, where $$$q^{-1}$$$ denotes the modular inverse of $$$q$$$ modulo $$$998244353$$$, which satisfies $$$q \cdot q^{-1} \equiv 1 \pmod {998244353}$$$.
51 0 0 0 02 1 0 0 03 0 1 0 04 0 0 1 05 0 0 0 1
infinity
50 1 0 0 00 0 1 0 00 0 0 1 00 0 0 0 11 0 0 0 0
10
65 6 499122175 10 10 9982443527 998244351 7 4 499122176 34 10 2 9 8 96 6 6 3 10 10998244351 3 1 499122175 10 93 7 6 499122176 499122176 3
53368493
18
2
Sail is on Treasure Island. He foresees that $$$n$$$ events will occur on the island, and he will leave after all events have finished. Specifically, there are the following three types of events:
He wants to know whether he can leave the island safely, and if so, what is the maximum amount of money he can have left when leaving.
The first line contains a positive integer $$$T$$$ ($$$1 \le T \le 10^4$$$), indicating the number of test cases.
For each test case, the first line contains two positive integers $$$n$$$ ($$$1 \le n \le 2 \times 10^5$$$) and $$$k$$$ ($$$1 \le k \le 10^6$$$), where $$$n$$$ is the total number of events, and $$$k$$$ is the amount of money obtained from exchanging coins or the damage value of a bullet.
The next $$$n$$$ lines each contain two positive integers $$$o$$$ ($$$o \in \{1, 2, 3\}$$$) and $$$x$$$ ($$$1 \le x \le 10^6$$$), representing an event.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, if Sail cannot leave safely, output $$$-1$$$; otherwise, output the maximum amount of money that can remain.
54 31 23 52 33 34 31 22 23 53 14 31 22 23 53 34 31 23 52 23 34 31 21 33 43 9
010-10
For the second test case, Sail does the following in order:
In the end, Sail leaves with $$$1$$$ yuan.
For the fourth test case, Sail does the following in order:
No matter how he performs the exchanges, Sail cannot leave safely, so you should output $$$-1$$$.
Little H is a clever pig who can use artificial intelligence. Today, he is participating in the Little Pig IQ Test Contest, but he got stuck on the last problem:
A string $$$a$$$ is a subsequence of a string $$$b$$$ if and only if $$$a$$$ can be obtained from $$$b$$$ by deleting some characters (or none) without changing the relative order of the remaining characters.
Little H does not know how to solve this problem. As Little H's agent, please help him.
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 2 \times 10^4$$$), representing the number of test cases.
For each test case, two strings $$$s$$$ and $$$t$$$ are given on two separate lines ($$$1 \leq |s|,|t| \leq 10^5$$$). It is guaranteed that all strings consist only of lowercase letters.
It is guaranteed that over all test cases, the sum of $$$|s|+|t|$$$ does not exceed $$$2 \times 10^5$$$. $$$|s|$$$ and $$$|t|$$$ denote the lengths of strings $$$s$$$ and $$$t$$$, respectively.
For each test case, output one line containing a string representing the answer you found.
If the two strings do not have a common subsequence of length $$$2$$$, output one line containing HENG!.
3azzzazazazazzzazbzbzyouak
aazzHENG!
Little S really likes playing board games, especially Splendor. Now he has simplified and modified the rules.
The game includes the following components:
At the beginning of the game, the top $$$4$$$ cards (cards $$$1$$$ to $$$4$$$) of the deck are revealed on the table to serve as the initial exchangeable cards. The remaining cards in the deck are now cards $$$5$$$ through $$$n$$$.
In each turn, you may perform exactly one of the following three operations:
Whenever you successfully exchange an exchangeable card on the table:
Your goal is to empty the deck. Note that there may still be some exchangeable cards left on the table at this point; this situation is also considered a successful completion of the goal. Please calculate the minimum number of turns required to achieve this goal.
The first line contains an integer $$$n$$$ ($$$4\le n\le 100$$$).
For the next $$$n$$$ lines, the $$$i$$$-th line contains $$$6$$$ integers, respectively $$$c_i$$$, $$$p_{i,1}$$$, $$$p_{i,2}$$$, $$$p_{i,3}$$$, $$$p_{i,4}$$$, $$$p_{i,5}$$$ ($$$1 \le c_i \le 5$$$, $$$0 \le p_{i,j} \le 10^9$$$), indicating the color of the $$$i$$$-th card and the number of chips required.
Output an integer representing the minimum number of turns.
51 4 1 1 7 11 2 2 8 4 81 2 3 6 7 21 6 5 7 3 11 9 9 9 9 9
7
72 15 34 0 15 244 11 20 0 18 01 4 0 2 48 203 17 0 8 43 701 0 58 7 1 521 64 0 81 40 02 4 0 0 0 10
86
For the first example: For the first four cards, it takes $$$6$$$, $$$8$$$, $$$7$$$, and $$$8$$$ operations, respectively, to accumulate the required number of chips through chip-taking operations.
The optimal strategy is: First, spend $$$6$$$ moves to collect chips to meet the requirement of the first card, then use the $$$7$$$-th move to "exchange cards". After the exchange is complete, the $$$5$$$-th card (the last one) in the deck is placed on the table, at which point the deck is empty. This takes a total of $$$7$$$ moves.
The specific steps are as follows:
Alice is a quantitative trader. She is backtesting a high-frequency trading strategy now. Given a stock's price sequence at $$$n$$$ time points, denoted as $$$v_1, v_2, \ldots, v_n$$$.
The trading bot Alice has set up is controlled by two parameters: a buy threshold $$$a$$$ and a sell threshold $$$b$$$ ($$$a \lt b$$$), and strictly follows the following rules:
Given a fixed buy threshold $$$a$$$, there are $$$m$$$ independent queries, each specifying a sell threshold $$$b$$$. For each query, please help Alice calculate the total profit under this strategy (total proceeds from sales minus total costs from purchases).
The first line contains a positive integer $$$T$$$ ($$$1 \le T \le 10^4$$$), the number of test cases.
For each test case, the first line contains two positive integers $$$n, a$$$ ($$$1 \le n \le 2 \times 10^5$$$, $$$1 \le a \lt 10^9$$$), representing the number of time points and the buy threshold.
The second line contains $$$n$$$ integers $$$v_1, v_2, \ldots, v_n$$$ ($$$1 \le v_i \le 10^9$$$), giving the historical stock prices at each time point in chronological order.
The third line contains an integer $$$m$$$ ($$$1 \le m \le 2 \times 10^5$$$), representing the number of queries.
The next line contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_m$$$ ($$$a \lt b_i \le 10^9$$$), representing the sell threshold for each query.
It is guaranteed that over all test cases, the sum of $$$n$$$ and the sum of $$$m$$$ do not exceed $$$2 \times 10^5$$$.
For each test case, output one line containing $$$m$$$ integers separated by spaces, representing the final profit of the trading strategy for each query.
25 105 8 15 12 1311 13 166 105 5 15 12 20 11311 13 16
14 3 -1117 25 21
For the first query on the first test case ($$$a=10, b=11$$$), the trading process is as follows:
Insight and Maya are playing a game. Initially, they have an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of length $$$n$$$ containing only positive integers. Insight moves first, and the two players take turns. In each round, the current player must perform the following steps:
When it is a player's turn, if all elements in the array are $$$0$$$ (in which case no positive number $$$a_i$$$ can be selected), that player loses the game, and the other player wins. Assuming both players adopt optimal strategies to ensure their own victory, determine who will ultimately win the game.
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 10^4$$$), the number of test cases.
For each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 5 \times 10^5$$$), representing the length of the array.
The next line contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$), representing the initial array.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^6$$$.
For each test case, output one line: if Maya has a strategy that allows her to win, output Maya; otherwise, output Insight.
332 1 342 1 3 142 1 1 4
InsightInsightMaya