problems
stringlengths 691
4.89k
|
|---|
Yelisey has an array a of n integers.
If a has length strictly greater than 1, then Yelisei can apply an operation called minimum extraction to it:
1. First, Yelisei finds the minimal number m in the array. If there are several identical minima, Yelisey can choose any of them.
2. Then the selected minimal element is removed from the array. After that, m is subtracted from each remaining element.
Thus, after each operation, the length of the array is reduced by 1.
For example, if a = [1, 6, -4, -2, -4], then the minimum element in it is a_3 = -4, which means that after this operation the array will be equal to a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0].
Since Yelisey likes big numbers, he wants the numbers in the array a to be as big as possible.
Formally speaking, he wants to make the minimum of the numbers in array a to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length 1.
Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases.
The next 2t lines contain descriptions of the test cases.
In the description of each test case, the first line contains an integer n (1 β€ n β€ 2 β
10^5) β the original length of the array a. The second line of the description lists n space-separated integers a_i (-10^9 β€ a_i β€ 10^9) β elements of the array a.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
Print t lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer β the maximal possible minimum in a, which can be obtained by several applications of the described operation to it.
Example
Input
8
1
10
2
0 0
3
-1 2 0
4
2 10 1 7
2
2 3
5
3 2 -4 -2 0
2
-1 1
1
-2
Output
10
0
2
5
2
2
2
-2
Note
In the first example test case, the original length of the array n = 1. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is a_1 = 10.
In the second set of input data, the array will always consist only of zeros.
In the third set, the array will be changing as follows: [\color{blue}{-1}, 2, 0] β [3, \color{blue}{1}] β [\color{blue}{2}]. The minimum elements are highlighted with \color{blue}{blue}. The maximal one is 2.
In the fourth set, the array will be modified as [2, 10, \color{blue}{1}, 7] β [\color{blue}{1}, 9, 6] β [8, \color{blue}{5}] β [\color{blue}{3}]. Similarly, the maximum of the minimum elements is 5.
|
You are given an array of integers a of length n. The elements of the array can be either different or the same.
Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step:
* either you can select any blue element and decrease its value by 1;
* or you can select any red element and increase its value by 1.
Situations in which there are no elements of some color at all are also possible. For example, if the whole array is colored blue or red, one of the operations becomes unavailable.
Determine whether it is possible to make 0 or more steps such that the resulting array is a permutation of numbers from 1 to n?
In other words, check whether there exists a sequence of steps (possibly empty) such that after applying it, the array a contains in some order all numbers from 1 to n (inclusive), each exactly once.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of input data sets in the test.
The description of each set of input data consists of three lines. The first line contains an integer n (1 β€ n β€ 2 β
10^5) β the length of the original array a. The second line contains n integers a_1, a_2, ..., a_n (-10^9 β€ a_i β€ 10^9) β the array elements themselves.
The third line has length n and consists exclusively of the letters 'B' and/or 'R': ith character is 'B' if a_i is colored blue, and is 'R' if colored red.
It is guaranteed that the sum of n over all input sets does not exceed 2 β
10^5.
Output
Print t lines, each of which contains the answer to the corresponding test case of the input. Print YES as an answer if the corresponding array can be transformed into a permutation, and NO otherwise.
You can print the answer in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a positive answer).
Example
Input
8
4
1 2 5 2
BRBR
2
1 1
BB
5
3 1 4 2 5
RBRRB
5
3 1 3 1 3
RBRRB
5
5 1 5 1 5
RBRRB
4
2 2 2 2
BRBR
2
1 -2
BR
4
-2 -1 4 0
RRRR
Output
YES
NO
YES
YES
NO
YES
YES
YES
Note
In the first test case of the example, the following sequence of moves can be performed:
* choose i=3, element a_3=5 is blue, so we decrease it, we get a=[1,2,4,2];
* choose i=2, element a_2=2 is red, so we increase it, we get a=[1,3,4,2];
* choose i=3, element a_3=4 is blue, so we decrease it, we get a=[1,3,3,2];
* choose i=2, element a_2=2 is red, so we increase it, we get a=[1,4,3,2].
We got that a is a permutation. Hence the answer is YES.
|
The robot is located on a checkered rectangular board of size n Γ m (n rows, m columns). The rows in the board are numbered from 1 to n from top to bottom, and the columns β from 1 to m from left to right.
The robot is able to move from the current cell to one of the four cells adjacent by side.
The sequence of commands s executed by the robot is given. Each command is denoted by one of the symbols 'L', 'R', 'D' or 'U', and triggers the movement to left, right, down or up, respectively.
The robot can start its movement in any cell. The robot executes the commands starting from the first one, strictly in the order in which they are listed in s. If the robot moves beyond the edge of the board, it falls and breaks. A command that causes the robot to break is not considered successfully executed.
The robot's task is to execute as many commands as possible without falling off the board. For example, on board 3 Γ 3, if the robot starts a sequence of actions s="RRDLUU" ("right", "right", "down", "left", "up", "up") from the central cell, the robot will perform one command, then the next command will force him to cross the edge. If the robot starts moving from the cell (2, 1) (second row, first column) then all commands will be executed successfully and the robot will stop at the cell (1, 2) (first row, second column).
<image> The robot starts from cell (2, 1) (second row, first column). It moves right, right, down, left, up, and up. In this case it ends in the cell (1, 2) (first row, second column).
Determine the cell from which the robot should start its movement in order to execute as many commands as possible.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases.
The next 2t lines contain descriptions of the test cases.
In the description of each test case, the first line contains two integers n and m (1 β€ n, m β€ 10^6) β the height and width of the field that the robot is located on. The second line of the description is a string s consisting solely of characters 'L', 'R', 'D' and 'U' β the sequence of commands the robot executes. The string has a length from 1 to 10^6 commands.
It is guaranteed that the total length of s over all test cases does not exceed 10^6.
Output
Print t lines, each of which contains the answer to the corresponding test case. The answer to the test case are two integers r (1 β€ r β€ n) and c (1 β€ c β€ m), separated by a space β the coordinates of the cell (row number and column number) from which the robot should start moving to perform as many commands as possible.
If there are several such cells, you may output any of them.
Example
Input
4
1 1
L
1 2
L
3 3
RRDLUU
4 3
LUURRDDLLLUU
Output
1 1
1 2
2 1
3 2
|
The robot is located on a checkered rectangular board of size n Γ m (n rows, m columns). The rows in the board are numbered from 1 to n from top to bottom, and the columns β from 1 to m from left to right.
The robot is able to move from the current cell to one of the four cells adjacent by side.
Each cell has one of the symbols 'L', 'R', 'D' or 'U' written on it, indicating the direction in which the robot will move when it gets in that cell β left, right, down or up, respectively.
The robot can start its movement in any cell. He then moves to the adjacent square in the direction indicated on the current square in one move.
* If the robot moves beyond the edge of the board, it falls and breaks.
* If the robot appears in the cell it already visited before, it breaks (it stops and doesn't move anymore).
Robot can choose any cell as the starting cell. Its goal is to make the maximum number of steps before it breaks or stops.
Determine from which square the robot should start its movement in order to execute as many commands as possible. A command is considered successfully completed if the robot has moved from the square on which that command was written (it does not matter whether to another square or beyond the edge of the board).
Input
The first line contains an integer t (1 β€ t β€ 10000) β the number of test cases in the test.
Each test case's description is preceded by a blank line. Next is a line that contains integers n and m (1 β€ n β€ 2000; 1 β€ m β€ 2000) β the height and width of the board. This line followed by n lines, the i-th of which describes the i-th line of the board. Each of them is exactly m letters long and consists of symbols 'L', 'R', 'D' and 'U'.
It is guaranteed that the sum of sizes of all boards in the input does not exceed 4β
10^6.
Output
For each test case, output three integers r, c and d (1 β€ r β€ n; 1 β€ c β€ m; d β₯ 0), which denote that the robot should start moving from cell (r, c) to make the maximum number of moves d. If there are several answers, output any of them.
Example
Input
7
1 1
R
1 3
RRL
2 2
DL
RU
2 2
UD
RU
3 2
DL
UL
RU
4 4
RRRD
RUUD
URUD
ULLR
4 4
DDLU
RDDU
UUUU
RDLD
Output
1 1 1
1 1 3
1 1 4
2 1 3
3 1 5
4 3 12
1 1 4
|
A known chef has prepared n dishes: the i-th dish consists of a_i grams of fish and b_i grams of meat.
The banquet organizers estimate the balance of n dishes as follows. The balance is equal to the absolute value of the difference between the total mass of fish and the total mass of meat.
Technically, the balance equals to \left|β_{i=1}^n a_i - β_{i=1}^n b_i\right|. The smaller the balance, the better.
In order to improve the balance, a taster was invited. He will eat exactly m grams of food from each dish. For each dish, the taster determines separately how much fish and how much meat he will eat. The only condition is that he should eat exactly m grams of each dish in total.
Determine how much of what type of food the taster should eat from each dish so that the value of the balance is as minimal as possible. If there are several correct answers, you may choose any of them.
Input
The first line of input data contains an integer t (1 β€ t β€ 10^4) β the number of the test cases.
Each test case's description is preceded by a blank line. Next comes a line that contains integers n and m (1 β€ n β€ 2 β
10^5; 0 β€ m β€ 10^6). The next n lines describe dishes, the i-th of them contains a pair of integers a_i and b_i (0 β€ a_i, b_i β€ 10^6) β the masses of fish and meat in the i-th dish.
It is guaranteed that it is possible to eat m grams of food from each dish. In other words, m β€ a_i+b_i for all i from 1 to n inclusive.
The sum of all n values over all test cases in the test does not exceed 2 β
10^5.
Output
For each test case, print on the first line the minimal balance value that can be achieved by eating exactly m grams of food from each dish.
Then print n lines that describe a way to do this: the i-th line should contain two integers x_i and y_i (0 β€ x_i β€ a_i; 0 β€ y_i β€ b_i; x_i+y_i=m), where x_i is how many grams of fish taster should eat from the i-th meal and y_i is how many grams of meat.
If there are several ways to achieve a minimal balance, find any of them.
Example
Input
8
1 5
3 4
1 6
3 4
2 2
1 3
4 2
2 4
1 3
1 7
3 6
1 7
1 8
1 9
3 6
1 8
1 9
30 10
3 4
3 1
3 2
4 1
5 4
0 7
6 4
0 8
4 1
5 3
Output
0
2 3
1
3 3
0
1 1
1 1
2
1 3
0 4
3
0 6
0 6
0 6
7
1 5
1 5
6 0
0
3 1
3 1
3 1
0
0 4
2 2
0 4
3 1
1 3
|
The chef has cooked n dishes yet again: the i-th dish consists of a_i grams of fish and b_i grams of meat.
Banquet organizers consider two dishes i and j equal if a_i=a_j and b_i=b_j at the same time.
The banquet organizers estimate the variety of n dishes as follows. The variety of a set of dishes is equal to the number of different dishes in it. The less variety is, the better.
In order to reduce the variety, a taster was invited. He will eat exactly m_i grams of food from each dish. For each dish, the taster determines separately how much fish and how much meat he will eat. The only condition is that he will eat exactly m_i grams of the i-th dish in total.
Determine how much of what type of food the taster should eat from each dish so that the value of variety is the minimum possible. If there are several correct answers, you may output any of them.
Input
The first line of input data contains an integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case's description is preceded by a blank line. Next comes a line that contains an integer n (1 β€ n β€ 2 β
10^5) β the number of dishes. Then follows n lines, i-th of which contains three integers a_i, b_i and m_i (0 β€ a_i, b_i β€ 10^6; 0 β€ m_i β€ a_i+b_i) β the mass of fish in i-th dish, the mass of meat in i-th dish and how many grams in total the taster should eat in i-th dish.
The sum of all n values for all input data sets in the test does not exceed 2 β
10^5.
Output
For each test case, print on the first line the minimum value of variety that can be achieved by eating exactly m_i grams of food (for all i from 1 to n) from a dish i.
Then print n lines that describe a way to do this: the i-th line should contain two integers x_i and y_i (0 β€ x_i β€ a_i; 0 β€ y_i β€ b_i; x_i+y_i=m_i), where x_i is how many grams of fish the taster should eat from i-th dish, and y_i is how many grams of meat.
If there are several ways to achieve a minimum balance, print any of them.
Example
Input
5
3
10 10 2
9 9 0
10 9 1
2
3 4 1
5 1 2
3
7 2 5
6 5 4
5 5 6
1
13 42 50
5
5 7 12
3 1 4
7 3 7
0 0 0
4 1 5
Output
1
1 1
0 0
1 0
2
0 1
1 1
2
3 2
0 4
1 5
1
8 42
2
5 7
3 1
4 3
0 0
4 1
|
Given n, find any array a_1, a_2, β¦, a_n of integers such that all of the following conditions hold:
* 1 β€ a_i β€ 10^9 for every i from 1 to n.
* a_1 < a_2 < β¦ <a_n
* For every i from 2 to n, a_i isn't divisible by a_{i-1}
It can be shown that such an array always exists under the constraints of the problem.
Input
The first line contains the number of test cases t (1 β€ t β€ 100). Description of the test cases follows.
The only line of each test case contains a single integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 10^4.
Output
For each test case print n integers a_1, a_2, β¦, a_n β the array you found. If there are multiple arrays satisfying all the conditions, print any of them.
Example
Input
3
1
2
7
Output
1
2 3
111 1111 11111 111111 1111111 11111111 111111111
Note
In the first test case, array [1] satisfies all the conditions.
In the second test case, array [2, 3] satisfies all the conditions, as 2<3 and 3 is not divisible by 2.
In the third test case, array [111, 1111, 11111, 111111, 1111111, 11111111, 111111111] satisfies all the conditions, as it's increasing and a_i isn't divisible by a_{i-1} for any i from 2 to 7.
|
You are given three integers n, a, b. Determine if there exists a permutation p_1, p_2, β¦, p_n of integers from 1 to n, such that:
* There are exactly a integers i with 2 β€ i β€ n-1 such that p_{i-1} < p_i > p_{i+1} (in other words, there are exactly a local maximums).
* There are exactly b integers i with 2 β€ i β€ n-1 such that p_{i-1} > p_i < p_{i+1} (in other words, there are exactly b local minimums).
If such permutations exist, find any such permutation.
Input
The first line of the input contains a single integer t (1 β€ t β€ 10^4) β the number of test cases. The description of test cases follows.
The only line of each test case contains three integers n, a and b (2 β€ n β€ 10^5, 0 β€ a,b β€ n).
The sum of n over all test cases doesn't exceed 10^5.
Output
For each test case, if there is no permutation with the requested properties, output -1.
Otherwise, print the permutation that you are found. If there are several such permutations, you may print any of them.
Example
Input
3
4 1 1
6 1 2
6 4 0
Output
1 3 2 4
4 2 3 1 5 6
-1
Note
In the first test case, one example of such permutations is [1, 3, 2, 4]. In it p_1 < p_2 > p_3, and 2 is the only such index, and p_2> p_3 < p_4, and 3 the only such index.
One can show that there is no such permutation for the third test case.
|
n players are playing a game.
There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map.
You are the game master and want to organize a tournament. There will be a total of n-1 battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament.
In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
Input
The first line contains a single integer t (1 β€ t β€ 100) β the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 10^5) β the number of players.
The second line of each test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9, a_i β a_j for i β j), where a_i is the strength of the i-th player on the first map.
The third line of each test case contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^9, b_i β b_j for i β j), where b_i is the strength of the i-th player on the second map.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print a string of length n. i-th character should be "1" if the i-th player can win the tournament, or "0" otherwise.
Example
Input
3
4
1 2 3 4
1 2 3 4
4
11 12 20 21
44 22 11 30
1
1000000000
1000000000
Output
0001
1111
1
Note
In the first test case, the 4-th player will beat any other player on any game, so he will definitely win the tournament.
In the second test case, everyone can be a winner.
In the third test case, there is only one player. Clearly, he will win the tournament.
|
You are given n dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet.
The coloring is said to be valid if and only if it is possible to rearrange the dominoes in some order such that for each 1 β€ i β€ n the color of the right cell of the i-th domino is different from the color of the left cell of the ((i mod n)+1)-st domino.
Note that you can't rotate the dominoes, so the left cell always remains the left cell, and the right cell always remains the right cell.
Count the number of valid ways to color the yet uncolored cells of dominoes. Two ways are considered different if there is a cell that is colored white in one way and black in the other. In particular, colorings BW WB and WB BW different (and both invalid).
As this number can be very big, output it modulo 998 244 353.
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the number of dominoes.
The next n lines describe dominoes. Each line contains two characters which represent the left and the right cell. Character B means that the corresponding cell is black, character W means that the corresponding cell is white, and ? means that the cell is yet to be colored.
Output
Print a single integer β the answer to the problem.
Examples
Input
1
?W
Output
1
Input
2
??
W?
Output
2
Input
4
BB
??
W?
??
Output
10
Note
In the first test case, there is only one domino, and we need the color of its right cell to be different from the color of its left cell. There is only one way to achieve this.
In the second test case, there are only 2 such colorings:
BB WW and WB WB.
|
On an endless checkered sheet of paper, n cells are chosen and colored in three colors, where n is divisible by 3. It turns out that there are exactly n/3 marked cells of each of three colors!
Find the largest such k that it's possible to choose k/3 cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold:
* No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be 0.
* The i-th rectangle contains all the chosen cells of the i-th color and no chosen cells of other colors, for i = 1, 2, 3.
Input
The first line of the input contains a single integer n β the number of the marked cells (3 β€ n β€ 10^5, n is divisible by 3).
The i-th of the following n lines contains three integers x_i, y_i, c_i (|x_i|,|y_i| β€ 10^9; 1 β€ c_i β€ 3), where (x_i, y_i) are the coordinates of the i-th marked cell and c_i is its color.
It's guaranteed that all cells (x_i, y_i) in the input are distinct, and that there are exactly n/3 cells of each color.
Output
Output a single integer k β the largest number of cells you can leave.
Examples
Input
9
2 3 1
4 1 2
2 1 3
3 4 1
5 3 2
4 4 3
2 4 1
5 2 2
3 5 3
Output
6
Input
3
1 1 1
2 2 2
3 3 3
Output
3
Note
In the first sample, it's possible to leave 6 cells with indexes 1, 5, 6, 7, 8, 9.
In the second sample, it's possible to leave 3 cells with indexes 1, 2, 3.
|
For an array c of nonnegative integers, MEX(c) denotes the smallest nonnegative integer that doesn't appear in it. For example, MEX([0, 1, 3]) = 2, MEX([42]) = 0.
You are given integers n, k, and an array [b_1, b_2, β¦, b_n].
Find the number of arrays [a_1, a_2, β¦, a_n], for which the following conditions hold:
* 0 β€ a_i β€ n for each i for each i from 1 to n.
* |MEX([a_1, a_2, β¦, a_i]) - b_i| β€ k for each i from 1 to n.
As this number can be very big, output it modulo 998 244 353.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 2000, 0 β€ k β€ 50).
The second line of the input contains n integers b_1, b_2, β¦, b_n (-k β€ b_i β€ n+k) β elements of the array b.
Output
Output a single integer β the number of arrays which satisfy the conditions from the statement, modulo 998 244 353.
Examples
Input
4 0
0 0 0 0
Output
256
Input
4 1
0 0 0 0
Output
431
Input
4 1
0 0 1 1
Output
509
Input
5 2
0 0 2 2 0
Output
6546
Input
3 2
-2 0 4
Output
11
|
You are given m strings and a tree on n nodes. Each edge has some letter written on it.
You have to answer q queries. Each query is described by 4 integers u, v, l and r. The answer to the query is the total number of occurrences of str(u,v) in strings with indices from l to r. str(u,v) is defined as the string that is made by concatenating letters written on the edges on the shortest path from u to v (in order that they are traversed).
Input
The first line of the input contains three integers n, m and q (2 β€ n β€ 10^5, 1 β€ m,q β€ 10^5).
The i-th of the following n-1 lines contains two integers u_i, v_i and a lowercase Latin letter c_i (1 β€ u_i, v_i β€ n, u_i β v_i), denoting the edge between nodes u_i, v_i with a character c_i on it.
It's guaranteed that these edges form a tree.
The following m lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed 10^5.
Then q lines follow, each containing four integers u, v, l and r (1 β€ u,v β€ n, u β v, 1 β€ l β€ r β€ m), denoting the queries.
Output
For each query print a single integer β the answer to the query.
Examples
Input
2 5 3
1 2 a
aab
abab
aaa
b
a
2 1 1 5
1 2 1 3
2 1 3 5
Output
8
7
4
Input
9 5 6
1 2 a
2 7 c
1 3 b
3 4 b
4 6 b
3 5 a
5 8 b
5 9 c
ababa
cabbb
bac
bbbac
abacaba
2 7 1 4
2 5 1 5
6 3 4 4
6 9 4 5
5 7 3 5
5 3 1 5
Output
3
4
2
1
1
10
|
Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer x with p zeros appended to its end.
Now Monocarp asks you to compare these two numbers. Can you help him?
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of testcases.
The first line of each testcase contains two integers x_1 and p_1 (1 β€ x_1 β€ 10^6; 0 β€ p_1 β€ 10^6) β the description of the first number.
The second line of each testcase contains two integers x_2 and p_2 (1 β€ x_2 β€ 10^6; 0 β€ p_2 β€ 10^6) β the description of the second number.
Output
For each testcase print the result of the comparison of the given two numbers. If the first number is smaller than the second one, print '<'. If the first number is greater than the second one, print '>'. If they are equal, print '='.
Example
Input
5
2 1
19 0
10 2
100 1
1999 0
2 3
1 0
1 0
99 0
1 2
Output
>
=
<
=
<
Note
The comparisons in the example are: 20 > 19, 1000 = 1000, 1999 < 2000, 1 = 1, 99 < 100.
|
You are given a sequence a_1, a_2, ..., a_n consisting of n pairwise distinct positive integers.
Find \leftβ \frac n 2 \rightβ different pairs of integers x and y such that:
* x β y;
* x and y appear in a;
* x~mod~y doesn't appear in a.
Note that some x or y can belong to multiple pairs.
β x β denotes the floor function β the largest integer less than or equal to x. x~mod~y denotes the remainder from dividing x by y.
If there are multiple solutions, print any of them. It can be shown that at least one solution always exists.
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of testcases.
The first line of each testcase contains a single integer n (2 β€ n β€ 2 β
10^5) β the length of the sequence.
The second line of each testcase contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^6).
All numbers in the sequence are pairwise distinct. The sum of n over all testcases doesn't exceed 2 β
10^5.
Output
The answer for each testcase should contain \leftβ \frac n 2 \rightβ different pairs of integers x and y such that x β y, x and y appear in a and x~mod~y doesn't appear in a. Print the pairs one after another.
You can print the pairs in any order. However, the order of numbers in the pair should be exactly such that the first number is x and the second number is y. All pairs should be pairwise distinct.
If there are multiple solutions, print any of them.
Example
Input
4
2
1 4
4
2 8 3 4
5
3 8 5 9 7
6
2 7 5 3 4 8
Output
4 1
8 2
8 4
9 5
7 5
8 7
4 3
5 2
Note
In the first testcase there are only two pairs: (1, 4) and (4, 1). \leftβ \frac 2 2 \rightβ=1, so we have to find one pair. 1~mod~4=1, and 1 appears in a, so that pair is invalid. Thus, the only possible answer is a pair (4, 1).
In the second testcase, we chose pairs 8~mod~2=0 and 8~mod~4=0. 0 doesn't appear in a, so that answer is valid. There are multiple possible answers for that testcase.
In the third testcase, the chosen pairs are 9~mod~5=4 and 7~mod~5=2. Neither 4, nor 2, appears in a, so that answer is valid.
|
Monocarp is playing yet another computer game. In this game, his character has to kill a dragon. The battle with the dragon lasts 100^{500} seconds, during which Monocarp attacks the dragon with a poisoned dagger. The i-th attack is performed at the beginning of the a_i-th second from the battle start. The dagger itself does not deal damage, but it applies a poison effect on the dragon, which deals 1 damage during each of the next k seconds (starting with the same second when the dragon was stabbed by the dagger). However, if the dragon has already been poisoned, then the dagger updates the poison effect (i.e. cancels the current poison effect and applies a new one).
For example, suppose k = 4, and Monocarp stabs the dragon during the seconds 2, 4 and 10. Then the poison effect is applied at the start of the 2-nd second and deals 1 damage during the 2-nd and 3-rd seconds; then, at the beginning of the 4-th second, the poison effect is reapplied, so it deals exactly 1 damage during the seconds 4, 5, 6 and 7; then, during the 10-th second, the poison effect is applied again, and it deals 1 damage during the seconds 10, 11, 12 and 13. In total, the dragon receives 10 damage.
Monocarp knows that the dragon has h hit points, and if he deals at least h damage to the dragon during the battle β he slays the dragon. Monocarp has not decided on the strength of the poison he will use during the battle, so he wants to find the minimum possible value of k (the number of seconds the poison effect lasts) that is enough to deal at least h damage to the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of the test case contains two integers n and h (1 β€ n β€ 100; 1 β€ h β€ 10^{18}) β the number of Monocarp's attacks and the amount of damage that needs to be dealt.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9; a_i < a_{i + 1}), where a_i is the second when the i-th attack is performed.
Output
For each test case, print a single integer β the minimum value of the parameter k, such that Monocarp will cause at least h damage to the dragon.
Example
Input
4
2 5
1 5
3 10
2 4 10
5 3
1 2 4 5 7
4 1000
3 25 64 1337
Output
3
4
1
470
Note
In the first example, for k=3, damage is dealt in seconds [1, 2, 3, 5, 6, 7].
In the second example, for k=4, damage is dealt in seconds [2, 3, 4, 5, 6, 7, 10, 11, 12, 13].
In the third example, for k=1, damage is dealt in seconds [1, 2, 4, 5, 7].
|
Let's call a sequence of integers x_1, x_2, ..., x_k MEX-correct if for all i (1 β€ i β€ k) |x_i - \operatorname{MEX}(x_1, x_2, ..., x_i)| β€ 1 holds. Where \operatorname{MEX}(x_1, ..., x_k) is the minimum non-negative integer that doesn't belong to the set x_1, ..., x_k. For example, \operatorname{MEX}(1, 0, 1, 3) = 2 and \operatorname{MEX}(2, 1, 5) = 0.
You are given an array a consisting of n non-negative integers. Calculate the number of non-empty MEX-correct subsequences of a given array. The number of subsequences can be very large, so print it modulo 998244353.
Note: a subsequence of an array a is a sequence [a_{i_1}, a_{i_2}, ..., a_{i_m}] meeting the constraints 1 β€ i_1 < i_2 < ... < i_m β€ n. If two different ways to choose the sequence of indices [i_1, i_2, ..., i_m] yield the same subsequence, the resulting subsequence should be counted twice (i. e. two subsequences are different if their sequences of indices [i_1, i_2, ..., i_m] are not the same).
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 5 β
10^5).
The second line contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ n).
The sum of n over all test cases doesn't exceed 5 β
10^5.
Output
For each test case, print a single integer β the number of non-empty MEX-correct subsequences of a given array, taken modulo 998244353.
Example
Input
4
3
0 2 1
2
1 0
5
0 0 0 0 0
4
0 1 2 3
Output
4
2
31
7
Note
In the first example, the valid subsequences are [0], [1], [0,1] and [0,2].
In the second example, the valid subsequences are [0] and [1].
In the third example, any non-empty subsequence is valid.
|
There is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked.
A crazy robot has escaped from this lab. It is currently in some free cell of the grid. You can send one of the following commands to the robot: "move right", "move down", "move left" or "move up". Each command means moving to a neighbouring cell in the corresponding direction.
However, as the robot is crazy, it will do anything except following the command. Upon receiving a command, it will choose a direction such that it differs from the one in command and the cell in that direction is not blocked. If there is such a direction, then it will move to a neighbouring cell in that direction. Otherwise, it will do nothing.
We want to get the robot to the lab to get it fixed. For each free cell, determine if the robot can be forced to reach the lab starting in this cell. That is, after each step of the robot a command can be sent to a robot such that no matter what different directions the robot chooses, it will end up in a lab.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
The first line of each testcase contains two integers n and m (1 β€ n, m β€ 10^6; n β
m β€ 10^6) β the number of rows and the number of columns in the grid.
The i-th of the next n lines provides a description of the i-th row of the grid. It consists of m elements of one of three types:
* '.' β the cell is free;
* '#' β the cell is blocked;
* 'L' β the cell contains a lab.
The grid contains exactly one lab. The sum of n β
m over all testcases doesn't exceed 10^6.
Output
For each testcase find the free cells that the robot can be forced to reach the lab from. Given the grid, replace the free cells (marked with a dot) with a plus sign ('+') for the cells that the robot can be forced to reach the lab from. Print the resulting grid.
Example
Input
4
3 3
...
.L.
...
4 5
#....
..##L
...#.
.....
1 1
L
1 9
....L..#.
Output
...
.L.
...
#++++
..##L
...#+
...++
L
++++L++#.
Note
In the first testcase there is no free cell that the robot can be forced to reach the lab from. Consider a corner cell. Given any direction, it will move to a neighbouring border grid that's not a corner. Now consider a non-corner free cell. No matter what direction you send to the robot, it can choose a different direction such that it ends up in a corner.
In the last testcase, you can keep sending the command that is opposite to the direction to the lab and the robot will have no choice other than move towards the lab.
|
You are given a rooted tree consisting of n vertices numbered from 1 to n. The root of the tree is the vertex 1.
You have to color all vertices of the tree into n colors (also numbered from 1 to n) so that there is exactly one vertex for each color. Let c_i be the color of vertex i, and p_i be the parent of vertex i in the rooted tree. The coloring is considered beautiful if there is no vertex k (k > 1) such that c_k = c_{p_k} - 1, i. e. no vertex such that its color is less than the color of its parent by exactly 1.
Calculate the number of beautiful colorings, and print it modulo 998244353.
Input
The first line contains one integer n (2 β€ n β€ 250000) β the number of vertices in the tree.
Then n-1 lines follow, the i-th line contains two integers x_i and y_i (1 β€ x_i, y_i β€ n; x_i β y_i) denoting an edge between the vertex x_i and the vertex y_i. These edges form a tree.
Output
Print one integer β the number of beautiful colorings, taken modulo 998244353.
Examples
Input
5
1 2
3 2
4 2
2 5
Output
42
Input
5
1 2
2 3
3 4
4 5
Output
53
Input
20
20 19
20 4
12 4
5 8
1 2
20 7
3 10
7 18
11 8
9 10
17 10
1 15
11 16
14 11
18 10
10 1
14 2
13 17
20 6
Output
955085064
|
There are n block towers in a row, where tower i has a height of a_i. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation:
* Choose two indices i and j (1 β€ i, j β€ n; i β j), and move a block from tower i to tower j. This essentially decreases a_i by 1 and increases a_j by 1.
You think the ugliness of the buildings is the height difference between the tallest and shortest buildings. Formally, the ugliness is defined as max(a)-min(a).
What's the minimum possible ugliness you can achieve, after any number of days?
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of buildings.
The second line of each test case contains n space separated integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7) β the heights of the buildings.
Output
For each test case, output a single integer β the minimum possible ugliness of the buildings.
Example
Input
3
3
10 10 10
4
3 2 1 2
5
1 2 3 1 5
Output
0
0
1
Note
In the first test case, the ugliness is already 0.
In the second test case, you should do one operation, with i = 1 and j = 3. The new heights will now be [2, 2, 2, 2], with an ugliness of 0.
In the third test case, you may do three operations:
1. with i = 3 and j = 1. The new array will now be [2, 2, 2, 1, 5],
2. with i = 5 and j = 4. The new array will now be [2, 2, 2, 2, 4],
3. with i = 5 and j = 3. The new array will now be [2, 2, 3, 2, 3].
The resulting ugliness is 1. It can be proven that this is the minimum possible ugliness for this test.
|
You are given an array consisting of all integers from [l, r] inclusive. For example, if l = 2 and r = 5, the array would be [2, 3, 4, 5]. What's the minimum number of elements you can delete to make the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the array non-zero?
A bitwise AND is a binary operation that takes two equal-length binary representations and performs the AND operation on each pair of the corresponding bits.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t cases follow.
The first line of each test case contains two integers l and r (1 β€ l β€ r β€ 2 β
10^5) β the description of the array.
Output
For each test case, output a single integer β the answer to the problem.
Example
Input
5
1 2
2 8
4 5
1 5
100000 200000
Output
1
3
0
2
31072
Note
In the first test case, the array is [1, 2]. Currently, the bitwise AND is 0, as 1\ \& \ 2 = 0. However, after deleting 1 (or 2), the array becomes [2] (or [1]), and the bitwise AND becomes 2 (or 1). This can be proven to be the optimal, so the answer is 1.
In the second test case, the array is [2, 3, 4, 5, 6, 7, 8]. Currently, the bitwise AND is 0. However, after deleting 4, 5, and 8, the array becomes [2, 3, 6, 7], and the bitwise AND becomes 2. This can be proven to be the optimal, so the answer is 3. Note that there may be other ways to delete 3 elements.
|
There are n candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string s, where the i-th candle is lit if and only if s_i=1.
<image>
Initially, the candle lights are described by a string a. In an operation, you select a candle that is currently lit. By doing so, the candle you selected will remain lit, and every other candle will change (if it was lit, it will become unlit and if it was unlit, it will become lit).
You would like to make the candles look the same as string b. Your task is to determine if it is possible, and if it is, find the minimum number of operations required.
Input
The first line contains an integer t (1β€ tβ€ 10^4) β the number of test cases. Then t cases follow.
The first line of each test case contains a single integer n (1β€ nβ€ 10^5) β the number of candles.
The second line contains a string a of length n consisting of symbols 0 and 1 β the initial pattern of lights.
The third line contains a string b of length n consisting of symbols 0 and 1 β the desired pattern of lights.
It is guaranteed that the sum of n does not exceed 10^5.
Output
For each test case, output the minimum number of operations required to transform a to b, or -1 if it's impossible.
Example
Input
5
5
11010
11010
2
01
11
3
000
101
9
100010111
101101100
9
001011011
011010101
Output
0
1
-1
3
4
Note
In the first test case, the two strings are already equal, so we don't have to perform any operations.
In the second test case, we can perform a single operation selecting the second candle to transform 01 into 11.
In the third test case, it's impossible to perform any operations because there are no lit candles to select.
In the fourth test case, we can perform the following operations to transform a into b:
1. Select the 7-th candle: 100010{\color{red}1}11β 011101{\color{red} 1}00.
2. Select the 2-nd candle: 0{\color{red} 1}1101100β 1{\color{red} 1}0010011.
3. Select the 1-st candle: {\color{red}1}10010011β {\color{red}1}01101100.
In the fifth test case, we can perform the following operations to transform a into b:
1. Select the 6-th candle: 00101{\color{red}1}011β 11010{\color{red}1}100
2. Select the 2-nd candle: 1{\color{red}1}0101100β 0{\color{red}1}1010011
3. Select the 8-th candle: 0110100{\color{red}1}1β 1001011{\color{red}1}0
4. Select the 7-th candle: 100101{\color{red}1}10β 011010{\color{red}1}01
|
'Twas the night before Christmas, and Santa's frantically setting up his new Christmas tree! There are n nodes in the tree, connected by n-1 edges. On each edge of the tree, there's a set of Christmas lights, which can be represented by an integer in binary representation.
<image>
He has m elves come over and admire his tree. Each elf is assigned two nodes, a and b, and that elf looks at all lights on the simple path between the two nodes. After this, the elf's favorite number becomes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of the values of the lights on the edges in that path.
However, the North Pole has been recovering from a nasty bout of flu. Because of this, Santa forgot some of the configurations of lights he had put on the tree, and he has already left the North Pole! Fortunately, the elves came to the rescue, and each one told Santa what pair of nodes he was assigned (a_i, b_i), as well as the parity of the number of set bits in his favorite number. In other words, he remembers whether the number of 1's when his favorite number is written in binary is odd or even.
Help Santa determine if it's possible that the memories are consistent, and if it is, remember what his tree looked like, and maybe you'll go down in history!
Input
The first line contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t cases follow.
The first line of each test case contains two integers, n and m (2 β€ n β€ 2 β
10^5; 1 β€ m β€ 2 β
10^5) β the size of tree and the number of elves respectively.
The next n-1 lines of each test case each contains three integers, x, y, and v (1 β€ x, y β€ n; -1 β€ v < 2^{30}) β meaning that there's an edge between nodes x and y. If
* v = -1: Santa doesn't remember what the set of lights were on for this edge.
* v β₯ 0: The set of lights on the edge is v.
The next m lines of each test case each contains three integers, a, b, and p (1 β€ a, b β€ n; a β b; 0 β€ p β€ 1) β the nodes that the elf was assigned to, and the parity of the number of set bits in the elf's favorite number.
It is guaranteed that the sum of all n and the sum of all m don't exceed 2 β
10^5 each.
It is guaranteed that the given edges form a tree.
Output
For each test case, first print either YES or NO (in any case), whether there's a tree consistent with Santa's memory or not.
If the answer is YES, print n-1 lines each containing three integers: x, y, and v (1 β€ x, y β€ n; 0 β€ v < 2^{30}) β the edge and the integer on that edge. The set of edges must be the same as in the input, and if the value of some edge was specified earlier, it can not change. You can print the edges in any order.
If there are multiple answers, print any.
Example
Input
4
6 5
1 2 -1
1 3 1
4 2 7
6 3 0
2 5 -1
2 3 1
2 5 0
5 6 1
6 1 1
4 5 1
5 3
1 2 -1
1 3 -1
1 4 1
4 5 -1
2 4 0
3 4 1
2 3 1
3 3
1 2 -1
1 3 -1
1 2 0
1 3 1
2 3 0
2 1
1 2 1
1 2 0
Output
YES
1 2 0
1 3 1
2 4 7
3 6 0
2 5 0
YES
1 2 1
1 3 0
1 4 1
4 5 1
NO
NO
Note
The first test case is the image in the statement.
One possible answer is assigning the value of the edge (1, 2) to 5, and the value of the edge (2, 5) to 3. This is correct because:
* The first elf goes from node 2 to node 3. This elf's favorite number is 4, so he remembers the value 1 (as 4 has an odd number of 1 bits in its binary representation).
* The second elf goes from node 2 to node 5. This elf's favorite number is 3, so he remembers the value 0 (as 3 has an even number of 1 bits in its binary representation).
* The third elf goes from node 5 to node 6. This elf's favorite number is 7, so he remembers the value 1 (as 7 has an odd number of 1 bits in its binary representation).
* The fourth elf goes from node 6 to node 1. This elf's favorite number is 1, so he remembers the value 1 (as 1 has an odd number of 1 bits in its binary representation).
* The fifth elf goes from node 4 to node 5. This elf's favorite number is 4, so he remembers the number 1 (as 4 has an odd number of 1 bits in its binary representation).
Note that there are other possible answers.
|
Two players, Red and Blue, are at it again, and this time they're playing with crayons! The mischievous duo is now vandalizing a rooted tree, by coloring the nodes while playing their favorite game.
The game works as follows: there is a tree of size n, rooted at node 1, where each node is initially white. Red and Blue get one turn each. Red goes first.
In Red's turn, he can do the following operation any number of times:
* Pick any subtree of the rooted tree, and color every node in the subtree red.
However, to make the game fair, Red is only allowed to color k nodes of the tree. In other words, after Red's turn, at most k of the nodes can be colored red.
Then, it's Blue's turn. Blue can do the following operation any number of times:
* Pick any subtree of the rooted tree, and color every node in the subtree blue. However, he's not allowed to choose a subtree that contains a node already colored red, as that would make the node purple and no one likes purple crayon.
Note: there's no restriction on the number of nodes Blue can color, as long as he doesn't color a node that Red has already colored.
After the two turns, the score of the game is determined as follows: let w be the number of white nodes, r be the number of red nodes, and b be the number of blue nodes. The score of the game is w β
(r - b).
Red wants to maximize this score, and Blue wants to minimize it. If both players play optimally, what will the final score of the game be?
Input
The first line contains two integers n and k (2 β€ n β€ 2 β
10^5; 1 β€ k β€ n) β the number of vertices in the tree and the maximum number of red nodes.
Next n - 1 lines contains description of edges. The i-th line contains two space separated integers u_i and v_i (1 β€ u_i, v_i β€ n; u_i β v_i) β the i-th edge of the tree.
It's guaranteed that given edges form a tree.
Output
Print one integer β the resulting score if both Red and Blue play optimally.
Examples
Input
4 2
1 2
1 3
1 4
Output
1
Input
5 2
1 2
2 3
3 4
4 5
Output
6
Input
7 2
1 2
1 3
4 2
3 5
6 3
6 7
Output
4
Input
4 1
1 2
1 3
1 4
Output
-1
Note
In the first test case, the optimal strategy is as follows:
* Red chooses to color the subtrees of nodes 2 and 3.
* Blue chooses to color the subtree of node 4.
At the end of this process, nodes 2 and 3 are red, node 4 is blue, and node 1 is white. The score of the game is 1 β
(2 - 1) = 1.
In the second test case, the optimal strategy is as follows:
* Red chooses to color the subtree of node 4. This colors both nodes 4 and 5.
* Blue does not have any options, so nothing is colored blue.
At the end of this process, nodes 4 and 5 are red, and nodes 1, 2 and 3 are white. The score of the game is 3 β
(2 - 0) = 6.
For the third test case:
<image>
The score of the game is 4 β
(2 - 1) = 4.
|
After getting bored by playing with crayons, you decided to switch to Legos! Today, you're working with a long strip, with height 1 and length n, some positions of which are occupied by 1 by 1 Lego pieces.
In one second, you can either remove two adjacent Lego pieces from the strip (if both are present), or add two Lego pieces to adjacent positions (if both are absent). You can only add or remove Lego's at two adjacent positions at the same time, as otherwise your chubby fingers run into precision issues.
You want to know exactly how much time you'll spend playing with Legos. You value efficiency, so given some starting state and some ending state, you'll always spend the least number of seconds to transform the starting state into the ending state. If it's impossible to transform the starting state into the ending state, you just skip it (so you spend 0 seconds).
The issue is that, for some positions, you don't remember whether there were Legos there or not (in either the starting state, the ending state, or both). Over all pairs of (starting state, ending state) that are consistent with your memory, find the total amount of time it will take to transform the starting state to the ending state. Print this value modulo 1 000 000 007 (10^9 + 7).
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 2000) β the size of the Lego strip.
The second line of each test case contains a string s of length n, consisting of the characters 0, 1, and ? β your memory of the starting state:
* 1 represents a position that definitely has a Lego piece,
* 0 represents a position that definitely does not have a Lego piece,
* and ? represents a position that you don't remember.
The third line of each test case contains a string t of length n, consisting of the characters 0, 1, and ? β your memory of the ending state. It follows a similar format to the starting state.
It's guaranteed that the sum of n over all test cases doesn't exceed 2000.
Output
For each test case, output a single integer β the answer to the problem modulo 1 000 000 007 (10^9 + 7).
Example
Input
6
2
00
11
3
???
???
3
??1
0?0
4
??0?
??11
5
?????
0??1?
10
?01??01?1?
??100?1???
Output
1
16
1
14
101
1674
Note
For the first test case, 00 is the only possible starting state, and 11 is the only possible ending state. It takes exactly one operation to change 00 to 11.
For the second test case, some of the possible starting and ending state pairs are:
* (000, 011) β takes 1 operation.
* (001, 100) β takes 2 operations.
* (010, 000) β takes 0 operations, as it's impossible to achieve the ending state.
|
You are given an array a consisting of n non-negative integers.
You have to replace each 0 in a with an integer from 1 to n (different elements equal to 0 can be replaced by different integers).
The value of the array you obtain is the number of integers k from 1 to n such that the following condition holds: there exist a pair of adjacent elements equal to k (i. e. there exists some i β [1, n - 1] such that a_i = a_{i + 1} = k). If there are multiple such pairs for some integer k, this integer is counted in the value only once.
Your task is to obtain the array with the maximum possible value.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of elements in the array.
The second line contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ min(n, 600)) β the elements of the array.
Output
Print n integers not less than 1 and not greater than n β the array with the maximum possible value you can obtain.
If there are multiple answers, print any of them.
Examples
Input
4
1 1 0 2
Output
1 1 2 2
Input
5
0 0 0 0 0
Output
3 1 1 3 3
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Input
6
1 0 0 0 0 1
Output
1 2 3 3 1 1
Input
3
3 0 2
Output
3 2 2
Input
5
1 0 2 0 1
Output
1 2 2 1 1
Input
7
1 0 2 3 1 0 2
Output
1 2 2 3 1 1 2
|
There are n reindeer at the North Pole, all battling for the highest spot on the "Top Reindeer" leaderboard on the front page of CodeNorses (a popular competitive reindeer gaming website). Interestingly, the "Top Reindeer" title is just a measure of upvotes and has nothing to do with their skill level in the reindeer games, but they still give it the utmost importance.
Currently, the i-th reindeer has a score of a_i. You would like to influence the leaderboard with some operations. In an operation, you can choose a reindeer, and either increase or decrease his score by 1 unit. Negative scores are allowed.
You have m requirements for the resulting scores. Each requirement is given by an ordered pair (u, v), meaning that after all operations, the score of reindeer u must be less than or equal to the score of reindeer v.
Your task is to perform the minimum number of operations so that all requirements will be satisfied.
Input
The first line contains two integers n and m (2β€ nβ€ 1000; 1β€ mβ€ 1000) β the number of reindeer and requirements, respectively.
The second line contains n integers a_1,β¦, a_n (1β€ a_iβ€ 10^9), where a_i is the current score of reindeer i.
The next m lines describe the requirements.
The i-th of these lines contains two integers u_i and v_i (1β€ u_i, v_iβ€ n; u_iβ v_i) β the two reindeer of the i-th requirement.
Output
Print n integers b_1,β¦, b_n (-10^{15}β€ b_iβ€ 10^{15}), where b_i is the score of the i-th reindeer after all operations.
If there are multiple solutions achieving the minimum number of operations, you may output any.
We can prove that there is always an optimal solution such that |b_i|β€ 10^{15} for all i.
Examples
Input
7 6
3 1 4 9 2 5 6
1 2
2 3
3 4
4 5
5 6
6 7
Output
1 1 4 4 4 5 6
Input
4 6
6 5 8 2
3 1
4 1
3 2
1 2
2 3
3 1
Output
6 6 6 2
Input
10 18
214 204 195 182 180 176 176 172 169 167
1 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
10 2
6 1
6 2
6 3
6 4
6 5
6 7
6 8
6 9
6 10
Output
204 204 195 182 180 167 176 172 169 167
|
You are given strings S and T, consisting of lowercase English letters. It is guaranteed that T is a permutation of the string abc.
Find string S', the lexicographically smallest permutation of S such that T is not a subsequence of S'.
String a is a permutation of string b if the number of occurrences of each distinct character is the same in both strings.
A string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) elements.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The first line of each test case contains a string S (1 β€ |S| β€ 100), consisting of lowercase English letters.
The second line of each test case contains a string T that is a permutation of the string abc. (Hence, |T| = 3).
Note that there is no limit on the sum of |S| across all test cases.
Output
For each test case, output a single string S', the lexicographically smallest permutation of S such that T is not a subsequence of S'.
Example
Input
7
abacaba
abc
cccba
acb
dbsic
bac
abracadabra
abc
dddddddddddd
cba
bbc
abc
ac
abc
Output
aaaacbb
abccc
bcdis
aaaaacbbdrr
dddddddddddd
bbc
ac
Note
In the first test case, both aaaabbc and aaaabcb are lexicographically smaller than aaaacbb, but they contain abc as a subsequence.
In the second test case, abccc is the smallest permutation of cccba and does not contain acb as a subsequence.
In the third test case, bcdis is the smallest permutation of dbsic and does not contain bac as a subsequence.
|
Given a positive integer n. Find three distinct positive integers a, b, c such that a + b + c = n and \operatorname{gcd}(a, b) = c, where \operatorname{gcd}(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases. Description of the test cases follows.
The first and only line of each test case contains a single integer n (10 β€ n β€ 10^9).
Output
For each test case, output three distinct positive integers a, b, c satisfying the requirements. If there are multiple solutions, you can print any. We can show that an answer always exists.
Example
Input
6
18
63
73
91
438
122690412
Output
6 9 3
21 39 3
29 43 1
49 35 7
146 219 73
28622 122661788 2
Note
In the first test case, 6 + 9 + 3 = 18 and \operatorname{gcd}(6, 9) = 3.
In the second test case, 21 + 39 + 3 = 63 and \operatorname{gcd}(21, 39) = 3.
In the third test case, 29 + 43 + 1 = 73 and \operatorname{gcd}(29, 43) = 1.
|
Paprika loves permutations. She has an array a_1, a_2, ..., a_n. She wants to make the array a permutation of integers 1 to n.
In order to achieve this goal, she can perform operations on the array. In each operation she can choose two integers i (1 β€ i β€ n) and x (x > 0), then perform a_i := a_i mod x (that is, replace a_i by the remainder of a_i divided by x). In different operations, the chosen i and x can be different.
Determine the minimum number of operations needed to make the array a permutation of integers 1 to n. If it is impossible, output -1.
A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Input
Each test contains multiple test cases. The first line contains a single integer t (1 β€ t β€ 10^4) β the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer n (1 β€ n β€ 10^5).
The second line of each test case contains n integers a_1, a_2, ..., a_n. (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, output the minimum number of operations needed to make the array a permutation of integers 1 to n, or -1 if it is impossible.
Example
Input
4
2
1 7
3
1 5 4
4
12345678 87654321 20211218 23571113
9
1 2 3 4 18 19 5 6 7
Output
1
-1
4
2
Note
For the first test, the only possible sequence of operations which minimizes the number of operations is:
* Choose i=2, x=5. Perform a_2 := a_2 mod 5 = 2.
For the second test, it is impossible to obtain a permutation of integers from 1 to n.
|
This is an interactive problem. The only difference between the easy and hard version is the limit on number of questions.
There are n players labelled from 1 to n. It is guaranteed that n is a multiple of 3.
Among them, there are k impostors and n-k crewmates. The number of impostors, k, is not given to you. It is guaranteed that n/3 < k < 2n/3.
In each question, you can choose three distinct integers a, b, c (1 β€ a, b, c β€ n) and ask: "Among the players labelled a, b and c, are there more impostors or more crewmates?" You will be given the integer 0 if there are more impostors than crewmates, and 1 otherwise.
Find the number of impostors k and the indices of players that are impostors after asking at most n+6 questions.
The jury is adaptive, which means the indices of impostors may not be fixed beforehand and can depend on your questions. It is guaranteed that there is at least one set of impostors which fulfills the constraints and the answers to your questions at any time.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 100). Description of the test cases follows.
The first and only line of each test case contains a single integer n (6 β€ n < 10^4, n is a multiple of 3) β the number of players.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^4.
Interaction
For each test case, the interaction starts with reading n.
Then you are allowed to make at most n+6 questions in the following way:
"? a b c" (1 β€ a, b, c β€ n, a, b and c are pairwise distinct).
After each one, you should read an integer r, which is equal to 0 if there are more impostors than crewmates among players labelled a, b and c, and equal to 1 otherwise.
Answer -1 instead of 0 or 1 means that you made an invalid query. Exit immediately after receiving -1 and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
When you have found the indices of all impostors, print a single line "! " (without quotes), followed by the number of impostors k, followed by k integers representing the indices of the impostors. Please note that you must print all this information on the same line.
After printing the answer, your program must then continue to solve the remaining test cases, or exit if all test cases have been solved.
After printing the queries and answers do not forget to output end of line and flush the output buffer. Otherwise, you will get the Idleness limit exceeded verdict. To do flush use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* Read documentation for other languages.
Hacks
You cannot make hacks in this problem.
Example
Input
2
6
0
1
9
1
Output
? 1 2 3
? 3 4 5
! 3 4 1 2
? 7 1 9
! 4 2 3 6 8
Note
Explanation for example interaction (note that this example only exists to demonstrate the interaction procedure and does not provide any hint for the solution):
For the first test case:
Question "? 1 2 3" returns 0, so there are more impostors than crewmates among players 1, 2 and 3.
Question "? 3 4 5" returns 1, so there are more crewmates than impostors among players 3, 4 and 5.
Outputting "! 3 4 1 2" means that one has found all the impostors, by some miracle. There are k = 3 impostors. The players who are impostors are players 4, 1 and 2.
For the second test case:
Question "? 7 1 9" returns 1, so there are more crewmates than impostors among players 7, 1 and 9.
Outputting "! 4 2 3 6 8" means that one has found all the impostors, by some miracle. There are k = 4 impostors. The players who are impostors are players 2, 3, 6 and 8.
|
Christmas is coming, Icy has just received a box of chocolates from her grandparents! The box contains n chocolates. The i-th chocolate has a non-negative integer type a_i.
Icy believes that good things come in pairs. Unfortunately, all types of chocolates are distinct (all a_i are distinct). Icy wants to make at least one pair of chocolates the same type.
As a result, she asks her grandparents to perform some chocolate exchanges. Before performing any chocolate exchanges, Icy chooses two chocolates with indices x and y (1 β€ x, y β€ n, x β y).
In a chocolate exchange, Icy's grandparents choose a non-negative integer k, such that 2^k β₯ a_x, and change the type of the chocolate x from a_x to 2^k - a_x (that is, perform a_x := 2^k - a_x).
The chocolate exchanges will be stopped only when a_x = a_y. Note that other pairs of equal chocolate types do not stop the procedure.
Icy's grandparents are smart, so they would choose the sequence of chocolate exchanges that minimizes the number of exchanges needed. Since Icy likes causing trouble, she wants to maximize the minimum number of exchanges needed by choosing x and y appropriately. She wonders what is the optimal pair (x, y) such that the minimum number of exchanges needed is maximized across all possible choices of (x, y).
Since Icy is not good at math, she hopes that you can help her solve the problem.
Input
The first line of the input contains a single integer n (2 β€ n β€ 2 β
10^5) β the number of chocolates.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ 10^9).
It is guaranteed that all a_i are distinct.
Output
Output three integers x, y, and m.
x and y are indices of the optimal chocolates to perform exchanges on. Your output must satisfy 1 β€ x, y β€ n, x β y.
m is the number of exchanges needed to obtain a_x = a_y. We can show that m β€ 10^9 for any pair of chocolates.
If there are multiple solutions, output any.
Examples
Input
5
5 6 7 8 9
Output
2 5 5
Input
2
4 8
Output
1 2 2
Note
In the first test case, the minimum number of exchanges needed to exchange a chocolate of type 6 to a chocolate of type 9 is 5. The sequence of exchanges is as follows: 6 β 2 β 0 β 1 β 7 β 9.
In the second test case, the minimum number of exchanges needed to exchange a chocolate of type 4 to a chocolate of type 8 is 2. The sequence of exchanges is as follows: 4 β 0 β 8.
|
Polycarp had an array a of 3 positive integers. He wrote out the sums of all non-empty subsequences of this array, sorted them in non-decreasing order, and got an array b of 7 integers.
For example, if a = \{1, 4, 3\}, then Polycarp wrote out 1, 4, 3, 1 + 4 = 5, 1 + 3 = 4, 4 + 3 = 7, 1 + 4 + 3 = 8. After sorting, he got an array b = \{1, 3, 4, 4, 5, 7, 8\}.
Unfortunately, Polycarp lost the array a. He only has the array b left. Help him to restore the array a.
Input
The first line contains one integer t (1 β€ t β€ 5000) β the number of test cases.
Each test case consists of one line which contains 7 integers b_1, b_2, ..., b_7 (1 β€ b_i β€ 10^9; b_i β€ b_{i+1}).
Additional constraint on the input: there exists at least one array a which yields this array b as described in the statement.
Output
For each test case, print 3 integers β a_1, a_2 and a_3. If there can be several answers, print any of them.
Example
Input
5
1 3 4 4 5 7 8
1 2 3 4 5 6 7
300000000 300000000 300000000 600000000 600000000 600000000 900000000
1 1 2 999999998 999999999 999999999 1000000000
1 2 2 3 3 4 5
Output
1 4 3
4 1 2
300000000 300000000 300000000
999999998 1 1
1 2 2
Note
The subsequence of the array a is a sequence that can be obtained from a by removing zero or more of its elements.
Two subsequences are considered different if index sets of elements included in them are different. That is, the values of the elements don't matter in the comparison of subsequences. In particular, any array of length 3 has exactly 7 different non-empty subsequences.
|
Polycarp has come up with a new game to play with you. He calls it "A missing bigram".
A bigram of a word is a sequence of two adjacent letters in it.
For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".
The game goes as follows. First, Polycarp comes up with a word, consisting only of lowercase letters 'a' and 'b'. Then, he writes down all its bigrams on a whiteboard in the same order as they appear in the word. After that, he wipes one of them off the whiteboard.
Finally, Polycarp invites you to guess what the word that he has come up with was.
Your goal is to find any word such that it's possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.
The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.
Input
The first line contains a single integer t (1 β€ t β€ 2000) β the number of testcases.
The first line of each testcase contains a single integer n (3 β€ n β€ 100) β the length of the word Polycarp has come up with.
The second line of each testcase contains n-2 bigrams of that word, separated by a single space. Each bigram consists of two letters, each of them is either 'a' or 'b'.
Additional constraint on the input: there exists at least one string such that it is possible to write down all its bigrams, except one, so that the resulting sequence is the same as the sequence in the input. In other words, the answer exists.
Output
For each testcase print a word, consisting of n letters, each of them should be either 'a' or 'b'. It should be possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.
The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.
Example
Input
4
7
ab bb ba aa ba
7
ab ba aa ab ba
3
aa
5
bb ab bb
Output
abbaaba
abaabaa
baa
bbabb
Note
The first two testcases from the example are produced from the word "abbaaba". As listed in the statement, it contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".
In the first testcase, the 5-th bigram is removed.
In the second testcase, the 2-nd bigram is removed. However, that sequence could also have been produced from the word "abaabaa". It contains bigrams "ab", "ba", "aa", "ab", "ba" and "aa". The missing bigram is the 6-th one.
In the third testcase, all of "baa", "aab" and "aaa" are valid answers.
|
You are given an array a consisting of n positive integers. You have to choose a positive integer d and paint all elements into two colors. All elements which are divisible by d will be painted red, and all other elements will be painted blue.
The coloring is called beautiful if there are no pairs of adjacent elements with the same color in the array. Your task is to find any value of d which yields a beautiful coloring, or report that it is impossible.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
The first line of each testcase contains one integer n (2 β€ n β€ 100) β the number of elements of the array.
The second line of each testcase contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{18}).
Output
For each testcase print a single integer. If there is no such value of d that yields a beautiful coloring, print 0. Otherwise, print any suitable value of d (1 β€ d β€ 10^{18}).
Example
Input
5
5
1 2 3 4 5
3
10 5 15
3
100 10 200
10
9 8 2 6 6 2 8 6 5 4
2
1 3
Output
2
0
100
0
3
|
You are given an array a of n integers, and another integer k such that 2k β€ n.
You have to perform exactly k operations with this array. In one operation, you have to choose two elements of the array (let them be a_i and a_j; they can be equal or different, but their positions in the array must not be the same), remove them from the array, and add β (a_i)/(a_j) β to your score, where β x/y β is the maximum integer not exceeding x/y.
Initially, your score is 0. After you perform exactly k operations, you add all the remaining elements of the array to the score.
Calculate the minimum possible score you can get.
Input
The first line of the input contains one integer t (1 β€ t β€ 500) β the number of test cases.
Each test case consists of two lines. The first line contains two integers n and k (1 β€ n β€ 100; 0 β€ k β€ β n/2 β).
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2 β
10^5).
Output
Print one integer β the minimum possible score you can get.
Example
Input
5
7 3
1 1 1 2 1 3 1
5 1
5 5 5 5 5
4 2
1 3 3 7
2 0
4 2
9 2
1 10 10 1 10 2 7 10 3
Output
2
16
0
6
16
Note
Let's consider the example test.
In the first test case, one way to obtain a score of 2 is the following one:
1. choose a_7 = 1 and a_4 = 2 for the operation; the score becomes 0 + β 1/2 β = 0, the array becomes [1, 1, 1, 1, 3];
2. choose a_1 = 1 and a_5 = 3 for the operation; the score becomes 0 + β 1/3 β = 0, the array becomes [1, 1, 1];
3. choose a_1 = 1 and a_2 = 1 for the operation; the score becomes 0 + β 1/1 β = 1, the array becomes [1];
4. add the remaining element 1 to the score, so the resulting score is 2.
In the second test case, no matter which operations you choose, the resulting score is 16.
In the third test case, one way to obtain a score of 0 is the following one:
1. choose a_1 = 1 and a_2 = 3 for the operation; the score becomes 0 + β 1/3 β = 0, the array becomes [3, 7];
2. choose a_1 = 3 and a_2 = 7 for the operation; the score becomes 0 + β 3/7 β = 0, the array becomes empty;
3. the array is empty, so the score doesn't change anymore.
In the fourth test case, no operations can be performed, so the score is the sum of the elements of the array: 4 + 2 = 6.
|
n towns are arranged in a circle sequentially. The towns are numbered from 1 to n in clockwise order. In the i-th town, there lives a singer with a repertoire of a_i minutes for each i β [1, n].
Each singer visited all n towns in clockwise order, starting with the town he lives in, and gave exactly one concert in each town. In addition, in each town, the i-th singer got inspired and came up with a song that lasts a_i minutes. The song was added to his repertoire so that he could perform it in the rest of the cities.
Hence, for the i-th singer, the concert in the i-th town will last a_i minutes, in the (i + 1)-th town the concert will last 2 β
a_i minutes, ..., in the ((i + k) mod n + 1)-th town the duration of the concert will be (k + 2) β
a_i, ..., in the town ((i + n - 2) mod n + 1) β n β
a_i minutes.
You are given an array of b integer numbers, where b_i is the total duration of concerts in the i-th town. Reconstruct any correct sequence of positive integers a or say that it is impossible.
Input
The first line contains one integer t (1 β€ t β€ 10^3) β the number of test cases. Then the test cases follow.
Each test case consists of two lines. The first line contains a single integer n (1 β€ n β€ 4 β
10^4) β the number of cities. The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 10^{9}) β the total duration of concerts in i-th city.
The sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the answer as follows:
If there is no suitable sequence a, print NO. Otherwise, on the first line print YES, on the next line print the sequence a_1, a_2, ..., a_n of n integers, where a_i (1 β€ a_i β€ 10^{9}) is the initial duration of repertoire of the i-th singer. If there are multiple answers, print any of them.
Example
Input
4
3
12 16 14
1
1
3
1 2 3
6
81 75 75 93 93 87
Output
YES
3 1 3
YES
1
NO
YES
5 5 4 1 4 5
Note
Let's consider the 1-st test case of the example:
1. the 1-st singer in the 1-st city will give a concert for 3 minutes, in the 2-nd β for 6 minutes, in the 3-rd β for 9 minutes;
2. the 2-nd singer in the 1-st city will give a concert for 3 minutes, in the 2-nd β for 1 minute, in the 3-rd - for 2 minutes;
3. the 3-rd singer in the 1-st city will give a concert for 6 minutes, in the 2-nd β for 9 minutes, in the 3-rd β for 3 minutes.
|
You are given two positive integers x and y. You can perform the following operation with x: write it in its binary form without leading zeros, add 0 or 1 to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of x.
For example:
* 34 can be turned into 81 via one operation: the binary form of 34 is 100010, if you add 1, reverse it and remove leading zeros, you will get 1010001, which is the binary form of 81.
* 34 can be turned into 17 via one operation: the binary form of 34 is 100010, if you add 0, reverse it and remove leading zeros, you will get 10001, which is the binary form of 17.
* 81 can be turned into 69 via one operation: the binary form of 81 is 1010001, if you add 0, reverse it and remove leading zeros, you will get 1000101, which is the binary form of 69.
* 34 can be turned into 69 via two operations: first you turn 34 into 81 and then 81 into 69.
Your task is to find out whether x can be turned into y after a certain number of operations (possibly zero).
Input
The only line of the input contains two integers x and y (1 β€ x, y β€ 10^{18}).
Output
Print YES if you can make x equal to y and NO if you can't.
Examples
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
Note
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
Monocarp plays a computer game (yet again!). This game has a unique trading mechanics.
To trade with a character, Monocarp has to choose one of the items he possesses and trade it for some item the other character possesses. Each item has an integer price. If Monocarp's chosen item has price x, then he can trade it for any item (exactly one item) with price not greater than x+k.
Monocarp initially has n items, the price of the i-th item he has is a_i. The character Monocarp is trading with has m items, the price of the i-th item they have is b_i. Monocarp can trade with this character as many times as he wants (possibly even zero times), each time exchanging one of his items with one of the other character's items according to the aforementioned constraints. Note that if Monocarp gets some item during an exchange, he can trade it for another item (since now the item belongs to him), and vice versa: if Monocarp trades one of his items for another item, he can get his item back by trading something for it.
You have to answer q queries. Each query consists of one integer, which is the value of k, and asks you to calculate the maximum possible total cost of items Monocarp can have after some sequence of trades, assuming that he can trade an item of cost x for an item of cost not greater than x+k during each trade. Note that the queries are independent: the trades do not actually occur, Monocarp only wants to calculate the maximum total cost he can get.
Input
The first line contains three integers n, m and q (1 β€ n, m, q β€ 2 β
10^5).
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the prices of the items Monocarp has.
The third line contains m integers b_1, b_2, ..., b_m (1 β€ b_i β€ 10^9) β the prices of the items the other character has.
The fourth line contains q integers, where the i-th integer is the value of k for the i-th query (0 β€ k β€ 10^9).
Output
For each query, print one integer β the maximum possible total cost of items Monocarp can have after some sequence of trades, given the value of k from the query.
Example
Input
3 4 5
10 30 15
12 31 14 18
0 1 2 3 4
Output
55
56
60
64
64
|
A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square.
For a given string s determine if it is square.
Input
The first line of input data contains an integer t (1 β€ t β€ 100) βthe number of test cases.
This is followed by t lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between 1 and 100 inclusive.
Output
For each test case, output on a separate line:
* YES if the string in the corresponding test case is square,
* NO otherwise.
You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
Example
Input
10
a
aa
aaa
aaaa
abab
abcabc
abacaba
xxyy
xyyx
xyxy
Output
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
|
Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: 1, 4, 8, 9, ....
For a given number n, count the number of integers from 1 to n that Polycarp likes. In other words, find the number of such x that x is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).
Input
The first line contains an integer t (1 β€ t β€ 20) β the number of test cases.
Then t lines contain the test cases, one per line. Each of the lines contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer you are looking for β the number of integers from 1 to n that Polycarp likes.
Example
Input
6
10
1
25
1000000000
999999999
500000000
Output
4
1
6
32591
32590
23125
|
Tanya is learning how to add numbers, but so far she is not doing it correctly. She is adding two numbers a and b using the following algorithm:
1. If one of the numbers is shorter than the other, Tanya adds leading zeros so that the numbers are the same length.
2. The numbers are processed from right to left (that is, from the least significant digits to the most significant).
3. In the first step, she adds the last digit of a to the last digit of b and writes their sum in the answer.
4. At each next step, she performs the same operation on each pair of digits in the same place and writes the result to the left side of the answer.
For example, the numbers a = 17236 and b = 3465 Tanya adds up as follows:
$$$ \large{ \begin{array}{r} + \begin{array}{r} 17236\\\ 03465\\\ \end{array} \\\ \hline \begin{array}{r} 1106911 \end{array} \end{array}} $$$
* calculates the sum of 6 + 5 = 11 and writes 11 in the answer.
* calculates the sum of 3 + 6 = 9 and writes the result to the left side of the answer to get 911.
* calculates the sum of 2 + 4 = 6 and writes the result to the left side of the answer to get 6911.
* calculates the sum of 7 + 3 = 10, and writes the result to the left side of the answer to get 106911.
* calculates the sum of 1 + 0 = 1 and writes the result to the left side of the answer and get 1106911.
As a result, she gets 1106911.
You are given two positive integers a and s. Find the number b such that by adding a and b as described above, Tanya will get s. Or determine that no suitable b exists.
Input
The first line of input data contains an integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of a single line containing two positive integers a and s (1 β€ a < s β€ 10^{18}) separated by a space.
Output
For each test case print the answer on a separate line.
If the solution exists, print a single positive integer b. The answer must be written without leading zeros. If multiple answers exist, print any of them.
If no suitable number b exists, output -1.
Example
Input
6
17236 1106911
1 5
108 112
12345 1023412
1 11
1 20
Output
3465
4
-1
90007
10
-1
Note
The first test case is explained in the main part of the statement.
In the third test case, we cannot choose b that satisfies the problem statement.
|
Vlad has n friends, for each of whom he wants to buy one gift for the New Year.
There are m shops in the city, in each of which he can buy a gift for any of his friends. If the j-th friend (1 β€ j β€ n) receives a gift bought in the shop with the number i (1 β€ i β€ m), then the friend receives p_{ij} units of joy. The rectangular table p_{ij} is given in the input.
Vlad has time to visit at most n-1 shops (where n is the number of friends). He chooses which shops he will visit and for which friends he will buy gifts in each of them.
Let the j-th friend receive a_j units of joy from Vlad's gift. Let's find the value Ξ±=min\\{a_1, a_2, ..., a_n\}. Vlad's goal is to buy gifts so that the value of Ξ± is as large as possible. In other words, Vlad wants to maximize the minimum of the joys of his friends.
For example, let m = 2, n = 2. Let the joy from the gifts that we can buy in the first shop: p_{11} = 1, p_{12}=2, in the second shop: p_{21} = 3, p_{22}=4.
Then it is enough for Vlad to go only to the second shop and buy a gift for the first friend, bringing joy 3, and for the second β bringing joy 4. In this case, the value Ξ± will be equal to min\{3, 4\} = 3
Help Vlad choose gifts for his friends so that the value of Ξ± is as high as possible. Please note that each friend must receive one gift. Vlad can visit at most n-1 shops (where n is the number of friends). In the shop, he can buy any number of gifts.
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input.
An empty line is written before each test case. Then there is a line containing integers m and n (2 β€ n, 2 β€ n β
m β€ 10^5) separated by a space β the number of shops and the number of friends, where n β
m is the product of n and m.
Then m lines follow, each containing n numbers. The number in the i-th row of the j-th column p_{ij} (1 β€ p_{ij} β€ 10^9) is the joy of the product intended for friend number j in shop number i.
It is guaranteed that the sum of the values n β
m over all test cases in the test does not exceed 10^5.
Output
Print t lines, each line must contain the answer to the corresponding test case β the maximum possible value of Ξ±, where Ξ± is the minimum of the joys from a gift for all of Vlad's friends.
Example
Input
5
2 2
1 2
3 4
4 3
1 3 1
3 1 1
1 2 2
1 1 3
2 3
5 3 4
2 5 1
4 2
7 9
8 1
9 6
10 8
2 4
6 5 2 1
7 9 7 2
Output
3
2
4
8
2
|
Dmitry has an array of n non-negative integers a_1, a_2, ..., a_n.
In one operation, Dmitry can choose any index j (1 β€ j β€ n) and increase the value of the element a_j by 1. He can choose the same index j multiple times.
For each i from 0 to n, determine whether Dmitry can make the MEX of the array equal to exactly i. If it is possible, then determine the minimum number of operations to do it.
The MEX of the array is equal to the minimum non-negative integer that is not in the array. For example, the MEX of the array [3, 1, 0] is equal to 2, and the array [3, 3, 1, 4] is equal to 0.
Input
The first line of input data contains a single integer t (1 β€ t β€ 10^4) β the number of test cases in the input.
The descriptions of the test cases follow.
The first line of the description of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the length of the array a.
The second line of the description of each test case contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ n) β elements of the array a.
It is guaranteed that the sum of the values n over all test cases in the test does not exceed 2β
10^5.
Output
For each test case, output n + 1 integer β i-th number is equal to the minimum number of operations for which you can make the array MEX equal to i (0 β€ i β€ n), or -1 if this cannot be done.
Example
Input
5
3
0 1 3
7
0 1 2 3 4 3 2
4
3 0 0 0
7
4 6 2 3 5 0 5
5
4 0 1 0 4
Output
1 1 0 -1
1 1 2 2 1 0 2 6
3 0 1 4 3
1 0 -1 -1 -1 -1 -1 -1
2 1 0 2 -1 -1
Note
In the first set of example inputs, n=3:
* to get MEX=0, it is enough to perform one increment: a_1++;
* to get MEX=1, it is enough to perform one increment: a_2++;
* MEX=2 for a given array, so there is no need to perform increments;
* it is impossible to get MEX=3 by performing increments.
|
The Hat is a game of speedy explanation/guessing words (similar to Alias). It's fun. Try it! In this problem, we are talking about a variant of the game when the players are sitting at the table and everyone plays individually (i.e. not teams, but individual gamers play).
n people gathered in a room with m tables (n β₯ 2m). They want to play the Hat k times. Thus, k games will be played at each table. Each player will play in k games.
To do this, they are distributed among the tables for each game. During each game, one player plays at exactly one table. A player can play at different tables.
Players want to have the most "fair" schedule of games. For this reason, they are looking for a schedule (table distribution for each game) such that:
* At any table in each game there are either βn/mβ people or βn/mβ people (that is, either n/m rounded down, or n/m rounded up). Different numbers of people can play different games at the same table.
* Let's calculate for each player the value b_i β the number of times the i-th player played at a table with βn/mβ persons (n/m rounded up). Any two values of b_imust differ by no more than 1. In other words, for any two players i and j, it must be true |b_i - b_j| β€ 1.
For example, if n=5, m=2 and k=2, then at the request of the first item either two players or three players should play at each table. Consider the following schedules:
* First game: 1, 2, 3 are played at the first table, and 4, 5 at the second one. The second game: at the first table they play 5, 1, and at the second β 2, 3, 4. This schedule is not "fair" since b_2=2 (the second player played twice at a big table) and b_5=0 (the fifth player did not play at a big table).
* First game: 1, 2, 3 are played at the first table, and 4, 5 at the second one. The second game: at the first table they play 4, 5, 2, and at the second one β 1, 3. This schedule is "fair": b=[1,2,1,1,1] (any two values of b_i differ by no more than 1).
Find any "fair" game schedule for n people if they play on the m tables of k games.
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the test.
Each test case consists of one line that contains three integers n, m and k (2 β€ n β€ 2β
10^5, 1 β€ m β€ βn/2β, 1 β€ k β€ 10^5) β the number of people, tables and games, respectively.
It is guaranteed that the sum of nk (n multiplied by k) over all test cases does not exceed 2β
10^5.
Output
For each test case print a required schedule β a sequence of k blocks of m lines. Each block corresponds to one game, a line in a block corresponds to one table. In each line print the number of players at the table and the indices of the players (numbers from 1 to n) who should play at this table.
If there are several required schedules, then output any of them. We can show that a valid solution always exists.
You can output additional blank lines to separate responses to different sets of inputs.
Example
Input
3
5 2 2
8 3 1
2 1 3
Output
3 1 2 3
2 4 5
3 4 5 2
2 1 3
2 6 2
3 3 5 1
3 4 7 8
2 2 1
2 2 1
2 2 1
|
Polycarp is very fond of playing the game Minesweeper. Recently he found a similar game and there are such rules.
There are mines on the field, for each the coordinates of its location are known (x_i, y_i). Each mine has a lifetime in seconds, after which it will explode. After the explosion, the mine also detonates all mines vertically and horizontally at a distance of k (two perpendicular lines). As a result, we get an explosion on the field in the form of a "plus" symbol ('+'). Thus, one explosion can cause new explosions, and so on.
Also, Polycarp can detonate anyone mine every second, starting from zero seconds. After that, a chain reaction of explosions also takes place. Mines explode instantly and also instantly detonate other mines according to the rules described above.
Polycarp wants to set a new record and asks you to help him calculate in what minimum number of seconds all mines can be detonated.
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the test.
An empty line is written in front of each test suite.
Next comes a line that contains integers n and k (1 β€ n β€ 2 β
10^5, 0 β€ k β€ 10^9) β the number of mines and the distance that hit by mines during the explosion, respectively.
Then n lines follow, the i-th of which describes the x and y coordinates of the i-th mine and the time until its explosion (-10^9 β€ x, y β€ 10^9, 0 β€ timer β€ 10^9). It is guaranteed that all mines have different coordinates.
It is guaranteed that the sum of the values n over all test cases in the test does not exceed 2 β
10^5.
Output
Print t lines, each of the lines must contain the answer to the corresponding set of input data β the minimum number of seconds it takes to explode all the mines.
Example
Input
3
5 0
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
5 2
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
6 1
1 -1 3
0 -1 9
0 1 7
-1 0 1
-1 1 9
-1 -1 7
Output
2
1
0
Note
<image> Picture from examples
First example:
* 0 second: we explode a mine at the cell (2, 2), it does not detonate any other mine since k=0.
* 1 second: we explode the mine at the cell (0, 1), and the mine at the cell (0, 0) explodes itself.
* 2 second: we explode the mine at the cell (1, 1), and the mine at the cell (1, 0) explodes itself.
Second example:
* 0 second: we explode a mine at the cell (2, 2) we get:
<image>
* 1 second: the mine at coordinate (0, 0) explodes and since k=2 the explosion detonates mines at the cells (0, 1) and (1, 0), and their explosions detonate the mine at the cell (1, 1) and there are no mines left on the field.
|
You are given a permutation p of n elements. A permutation of n elements is an array of length n containing each integer from 1 to n exactly once. For example, [1, 2, 3] and [4, 3, 5, 1, 2] are permutations, but [1, 2, 4] and [4, 3, 2, 1, 2] are not permutations. You should perform q queries.
There are two types of queries:
* 1 x y β swap p_x and p_y.
* 2 i k β print the number that i will become if we assign i = p_i k times.
Input
The first line contains two integers n and q (1 β€ n, q β€ 10^5).
The second line contains n integers p_1, p_2, ..., p_n.
Each of the next q lines contains three integers. The first integer is t (1 β€ t β€ 2) β type of query. If t = 1, then the next two integers are x and y (1 β€ x, y β€ n; x β y) β first-type query. If t = 2, then the next two integers are i and k (1 β€ i, k β€ n) β second-type query.
It is guaranteed that there is at least one second-type query.
Output
For every second-type query, print one integer in a new line β answer to this query.
Examples
Input
5 4
5 3 4 2 1
2 3 1
2 1 2
1 1 3
2 1 2
Output
4
1
2
Input
5 9
2 3 5 1 4
2 3 5
2 5 5
2 5 1
2 5 3
2 5 4
1 5 4
2 5 3
2 2 5
2 5 1
Output
3
5
4
2
3
3
3
1
Note
In the first example p = \{5, 3, 4, 2, 1\}.
The first query is to print p_3. The answer is 4.
The second query is to print p_{p_1}. The answer is 1.
The third query is to swap p_1 and p_3. Now p = \{4, 3, 5, 2, 1\}.
The fourth query is to print p_{p_1}. The answer is 2.
|
You had n positive integers a_1, a_2, ..., a_n arranged in a circle. For each pair of neighboring numbers (a_1 and a_2, a_2 and a_3, ..., a_{n - 1} and a_n, and a_n and a_1), you wrote down: are the numbers in the pair equal or not.
Unfortunately, you've lost a piece of paper with the array a. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array a which is consistent with information you have about equality or non-equality of corresponding pairs?
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases. Next t cases follow.
The first and only line of each test case contains a non-empty string s consisting of characters E and/or N. The length of s is equal to the size of array n and 2 β€ n β€ 50. For each i from 1 to n:
* if s_i = E then a_i is equal to a_{i + 1} (a_n = a_1 for i = n);
* if s_i = N then a_i is not equal to a_{i + 1} (a_n β a_1 for i = n).
Output
For each test case, print YES if it's possible to choose array a that are consistent with information from s you know. Otherwise, print NO.
It can be proved, that if there exists some array a, then there exists an array a of positive integers with values less or equal to 10^9.
Example
Input
4
EEE
EN
ENNEENE
NENN
Output
YES
NO
YES
YES
Note
In the first test case, you can choose, for example, a_1 = a_2 = a_3 = 5.
In the second test case, there is no array a, since, according to s_1, a_1 is equal to a_2, but, according to s_2, a_2 is not equal to a_1.
In the third test case, you can, for example, choose array a = [20, 20, 4, 50, 50, 50, 20].
In the fourth test case, you can, for example, choose a = [1, 3, 3, 7].
|
A rectangle with its opposite corners in (0, 0) and (w, h) and sides parallel to the axes is drawn on a plane.
You are given a list of lattice points such that each point lies on a side of a rectangle but not in its corner. Also, there are at least two points on every side of a rectangle.
Your task is to choose three points in such a way that:
* exactly two of them belong to the same side of a rectangle;
* the area of a triangle formed by them is maximum possible.
Print the doubled area of this triangle. It can be shown that the doubled area of any triangle formed by lattice points is always an integer.
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of testcases.
The first line of each testcase contains two integers w and h (3 β€ w, h β€ 10^6) β the coordinates of the corner of a rectangle.
The next two lines contain the description of the points on two horizontal sides. First, an integer k (2 β€ k β€ 2 β
10^5) β the number of points. Then, k integers x_1 < x_2 < ... < x_k (0 < x_i < w) β the x coordinates of the points in the ascending order. The y coordinate for the first line is 0 and for the second line is h.
The next two lines contain the description of the points on two vertical sides. First, an integer k (2 β€ k β€ 2 β
10^5) β the number of points. Then, k integers y_1 < y_2 < ... < y_k (0 < y_i < h) β the y coordinates of the points in the ascending order. The x coordinate for the first line is 0 and for the second line is w.
The total number of points on all sides in all testcases doesn't exceed 2 β
10^5.
Output
For each testcase print a single integer β the doubled maximum area of a triangle formed by such three points that exactly two of them belong to the same side.
Example
Input
3
5 8
2 1 2
3 2 3 4
3 1 4 6
2 4 5
10 7
2 3 9
2 1 7
3 1 3 4
3 4 5 6
11 5
3 1 6 8
3 3 6 8
3 1 3 4
2 2 4
Output
25
42
35
Note
The points in the first testcase of the example:
* (1, 0), (2, 0);
* (2, 8), (3, 8), (4, 8);
* (0, 1), (0, 4), (0, 6);
* (5, 4), (5, 5).
The largest triangle is formed by points (0, 1), (0, 6) and (5, 4) β its area is 25/2. Thus, the doubled area is 25. Two points that are on the same side are: (0, 1) and (0, 6).
|
You are given an integer k and a string s that consists only of characters 'a' (a lowercase Latin letter) and '*' (an asterisk).
Each asterisk should be replaced with several (from 0 to k inclusive) lowercase Latin letters 'b'. Different asterisk can be replaced with different counts of letter 'b'.
The result of the replacement is called a BA-string.
Two strings a and b are different if they either have different lengths or there exists such a position i that a_i β b_i.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Now consider all different BA-strings and find the x-th lexicographically smallest of them.
Input
The first line contains a single integer t (1 β€ t β€ 2000) β the number of testcases.
The first line of each testcase contains three integers n, k and x (1 β€ n β€ 2000; 0 β€ k β€ 2000; 1 β€ x β€ 10^{18}). n is the length of string s.
The second line of each testcase is a string s. It consists of n characters, each of them is either 'a' (a lowercase Latin letter) or '*' (an asterisk).
The sum of n over all testcases doesn't exceed 2000. For each testcase x doesn't exceed the total number of different BA-strings. String s contains at least one character 'a'.
Output
For each testcase, print a single string, consisting only of characters 'b' and 'a' (lowercase Latin letters) β the x-th lexicographically smallest BA-string.
Example
Input
3
2 4 3
a*
4 1 3
a**a
6 3 20
**a***
Output
abb
abba
babbbbbbbbb
Note
In the first testcase of the example, BA-strings ordered lexicographically are:
1. a
2. ab
3. abb
4. abbb
5. abbbb
In the second testcase of the example, BA-strings ordered lexicographically are:
1. aa
2. aba
3. abba
Note that string "aba" is only counted once, even though there are two ways to replace asterisks with characters 'b' to get it.
|
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of n different flavors. A bag of the i-th flavor costs a_i burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
1. you have only coins of 1, 2 and 3 burles;
2. since it's morning, the store will ask you to pay in exact change, i. e. if you choose the i-th flavor, you'll have to pay exactly a_i burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains the single integer n (1 β€ n β€ 100) β the number of flavors in the store.
The second line of each test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the cost of one bag of each flavor.
Output
For each test case, print one integer β the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
Example
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
Note
In the first test case, you should, for example, take with you 445 coins of value 3 and 1 coin of value 2. So, 1337 = 445 β
3 + 1 β
2.
In the second test case, you should, for example, take 2 coins of value 3 and 2 coins of value 2. So you can pay either exactly 8 = 2 β
3 + 1 β
2 or 10 = 2 β
3 + 2 β
2.
In the third test case, it's enough to take 1 coin of value 3 and 2 coins of value 1.
|
You have an array of integers (initially empty).
You have to perform q queries. Each query is of one of two types:
* "1 x" β add the element x to the end of the array;
* "2 x y" β replace all occurrences of x in the array with y.
Find the resulting array after performing all the queries.
Input
The first line contains a single integer q (1 β€ q β€ 5 β
10^5) β the number of queries.
Next q lines contain queries (one per line). Each query is of one of two types:
* "1 x" (1 β€ x β€ 5 β
10^5);
* "2 x y" (1 β€ x, y β€ 5 β
10^5).
It's guaranteed that there is at least one query of the first type.
Output
In a single line, print k integers β the resulting array after performing all the queries, where k is the number of queries of the first type.
Examples
Input
7
1 3
1 1
2 1 2
1 2
1 1
1 2
2 1 3
Output
3 2 2 3 2
Input
4
1 1
1 2
1 1
2 2 2
Output
1 2 1
Input
8
2 1 4
1 1
1 4
1 2
2 2 4
2 4 3
1 2
2 2 7
Output
1 3 3 7
Note
In the first example, the array changes as follows:
[] β [3] β [3, 1] β [3, 2] β [3, 2, 2] β [3, 2, 2, 1] β [3, 2, 2, 1, 2] β [3, 2, 2, 3, 2].
In the second example, the array changes as follows:
[] β [1] β [1, 2] β [1, 2, 1] β [1, 2, 1].
In the third example, the array changes as follows:
[] β [] β [1] β [1, 4] β [1, 4, 2] β [1, 4, 4] β [1, 3, 3] β [1, 3, 3, 2] β [1, 3, 3, 7].
|
You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).
Let's call an array a bipartite if the following undirected graph is bipartite:
* the graph consists of n vertices;
* two vertices i and j are connected by an edge if i < j and a_i > a_j.
Your task is to find a bipartite array of integers a of size n, such that a_i = p_i or a_i = -p_i, or report that no such array exists. If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 10^6) β the size of the permutation.
The second line contains n integers p_1, p_2, ..., p_n.
The sum of n over all test cases doesn't exceed 10^6.
Output
For each test case, print the answer in the following format. If such an array a does not exist, print "NO" in a single line. Otherwise, print "YES" in the first line and n integers β array a in the second line.
Example
Input
4
3
1 2 3
6
1 3 2 6 5 4
4
4 1 3 2
8
3 2 1 6 7 8 5 4
Output
YES
1 2 3
NO
YES
-4 -1 -3 -2
YES
-3 -2 1 6 7 -8 -5 -4
|
For a sequence of strings [t_1, t_2, ..., t_m], let's define the function f([t_1, t_2, ..., t_m]) as the number of different strings (including the empty string) that are subsequences of at least one string t_i. f([]) = 0 (i. e. the number of such strings for an empty sequence is 0).
You are given a sequence of strings [s_1, s_2, ..., s_n]. Every string in this sequence consists of lowercase Latin letters and is sorted (i. e., each string begins with several (maybe zero) characters a, then several (maybe zero) characters b, ..., ends with several (maybe zero) characters z).
For each of 2^n subsequences of [s_1, s_2, ..., s_n], calculate the value of the function f modulo 998244353.
Input
The first line contains one integer n (1 β€ n β€ 23) β the number of strings.
Then n lines follow. The i-th line contains the string s_i (1 β€ |s_i| β€ 2 β
10^4), consisting of lowercase Latin letters. Each string s_i is sorted.
Output
Since printing up to 2^{23} integers would be really slow, you should do the following:
For each of the 2^n subsequences (which we denote as [s_{i_1}, s_{i_2}, ..., s_{i_k}]), calculate f([s_{i_1}, s_{i_2}, ..., s_{i_k}]), take it modulo 998244353, then multiply it by k β
(i_1 + i_2 + ... + i_k). Print the XOR of all 2^n integers you get.
The indices i_1, i_2, ..., i_k in the description of each subsequences are 1-indexed (i. e. are from 1 to n).
Examples
Input
3
a
b
c
Output
92
Input
2
aa
a
Output
21
Input
2
a
a
Output
10
Input
2
abcd
aabb
Output
124
Input
3
ddd
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaabbbbbbbbbbbcccccccccccciiiiiiiiiiiiiiiiiiiiiiooooooooooqqqqqqqqqqqqqqqqqqvvvvvzzzzzzzzzzzz
Output
15706243380
|
There are three sticks with integer lengths l_1, l_2 and l_3.
You are asked to break exactly one of them into two pieces in such a way that:
* both pieces have positive (strictly greater than 0) integer length;
* the total length of the pieces is equal to the original length of the stick;
* it's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides.
A square is also considered a rectangle.
Determine if it's possible to do that.
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of testcases.
The only line of each testcase contains three integers l_1, l_2, l_3 (1 β€ l_i β€ 10^8) β the lengths of the sticks.
Output
For each testcase, print "YES" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "NO".
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as a positive answer).
Example
Input
4
6 1 5
2 5 2
2 4 2
5 5 4
Output
YES
NO
YES
YES
Note
In the first testcase, the first stick can be broken into parts of length 1 and 5. We can construct a rectangle with opposite sides of length 1 and 5.
In the second testcase, breaking the stick of length 2 can only result in sticks of lengths 1, 1, 2, 5, which can't be made into a rectangle. Breaking the stick of length 5 can produce results 2, 3 or 1, 4 but neither of them can't be put into a rectangle.
In the third testcase, the second stick can be broken into parts of length 2 and 2. The resulting rectangle has opposite sides 2 and 2 (which is a square).
In the fourth testcase, the third stick can be broken into parts of length 2 and 2. The resulting rectangle has opposite sides 2 and 5.
|
Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.
So imagine Monocarp got recommended n songs, numbered from 1 to n. The i-th song had its predicted rating equal to p_i, where 1 β€ p_i β€ n and every integer from 1 to n appears exactly once. In other words, p is a permutation.
After listening to each of them, Monocarp pressed either a like or a dislike button. Let his vote sequence be represented with a string s, such that s_i=0 means that he disliked the i-th song, and s_i=1 means that he liked it.
Now the service has to re-evaluate the song ratings in such a way that:
* the new ratings q_1, q_2, ..., q_n still form a permutation (1 β€ q_i β€ n; each integer from 1 to n appears exactly once);
* every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all i, j such that s_i=1 and s_j=0, q_i>q_j should hold).
Among all valid permutations q find the one that has the smallest value of β_{i=1}^n |p_i-q_i|, where |x| is an absolute value of x.
Print the permutation q_1, q_2, ..., q_n. If there are multiple answers, you can print any of them.
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of testcases.
The first line of each testcase contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of songs.
The second line of each testcase contains n integers p_1, p_2, ..., p_n (1 β€ p_i β€ n) β the permutation of the predicted ratings.
The third line contains a single string s, consisting of n characters. Each character is either a 0 or a 1. 0 means that Monocarp disliked the song, and 1 means that he liked it.
The sum of n over all testcases doesn't exceed 2 β
10^5.
Output
For each testcase, print a permutation q β the re-evaluated ratings of the songs. If there are multiple answers such that β_{i=1}^n |p_i-q_i| is minimum possible, you can print any of them.
Example
Input
3
2
1 2
10
3
3 1 2
111
8
2 3 1 8 5 4 7 6
01110001
Output
2 1
3 1 2
1 6 5 8 3 2 4 7
Note
In the first testcase, there exists only one permutation q such that each liked song is rating higher than each disliked song: song 1 gets rating 2 and song 2 gets rating 1. β_{i=1}^n |p_i-q_i|=|1-2|+|2-1|=2.
In the second testcase, Monocarp liked all songs, so all permutations could work. The permutation with the minimum sum of absolute differences is the permutation equal to p. Its cost is 0.
|
You are given an integer array a_1, a_2, ..., a_n and integer k.
In one step you can
* either choose some index i and decrease a_i by one (make a_i = a_i - 1);
* or choose two indices i and j and set a_i equal to a_j (make a_i = a_j).
What is the minimum number of steps you need to make the sum of array β_{i=1}^{n}{a_i} β€ k? (You are allowed to make values of array negative).
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
The first line of each test case contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 10^{15}) β the size of array a and upper bound on its sum.
The second line of each test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
It's guaranteed that the sum of n over all test cases doesn't exceed 2 β
10^5.
Output
For each test case, print one integer β the minimum number of steps to make β_{i=1}^{n}{a_i} β€ k.
Example
Input
4
1 10
20
2 69
6 9
7 8
1 2 1 3 1 2 1
10 1
1 2 3 1 2 6 1 6 8 10
Output
10
0
2
7
Note
In the first test case, you should decrease a_1 10 times to get the sum lower or equal to k = 10.
In the second test case, the sum of array a is already less or equal to 69, so you don't need to change it.
In the third test case, you can, for example:
1. set a_4 = a_3 = 1;
2. decrease a_4 by one, and get a_4 = 0.
As a result, you'll get array [1, 2, 1, 0, 1, 2, 1] with sum less or equal to 8 in 1 + 1 = 2 steps.
In the fourth test case, you can, for example:
1. choose a_7 and decrease in by one 3 times; you'll get a_7 = -2;
2. choose 4 elements a_6, a_8, a_9 and a_{10} and them equal to a_7 = -2.
As a result, you'll get array [1, 2, 3, 1, 2, -2, -2, -2, -2, -2] with sum less or equal to 1 in 3 + 4 = 7 steps.
|
You are given a binary string (i. e. a string consisting of characters 0 and/or 1) s of length n. You can perform the following operation with the string s at most once: choose a substring (a contiguous subsequence) of s having exactly k characters 1 in it, and shuffle it (reorder the characters in the substring as you wish).
Calculate the number of different strings which can be obtained from s by performing this operation at most once.
Input
The first line contains two integers n and k (2 β€ n β€ 5000; 0 β€ k β€ n).
The second line contains the string s of length n, consisting of characters 0 and/or 1.
Output
Print one integer β the number of different strings which can be obtained from s by performing the described operation at most once. Since the answer can be large, output it modulo 998244353.
Examples
Input
7 2
1100110
Output
16
Input
5 0
10010
Output
1
Input
8 1
10001000
Output
10
Input
10 8
0010011000
Output
1
Note
Some strings you can obtain in the first example:
* to obtain 0110110, you can take the substring from the 1-st character to the 4-th character, which is 1100, and reorder its characters to get 0110;
* to obtain 1111000, you can take the substring from the 3-rd character to the 7-th character, which is 00110, and reorder its characters to get 11000;
* to obtain 1100101, you can take the substring from the 5-th character to the 7-th character, which is 110, and reorder its characters to get 101.
In the second example, k = 0 so you can only choose the substrings consisting only of 0 characters. Reordering them doesn't change the string at all, so the only string you can obtain is 10010.
|
Petya is a math teacher. n of his students has written a test consisting of m questions. For each student, it is known which questions he has answered correctly and which he has not.
If the student answers the j-th question correctly, he gets p_j points (otherwise, he gets 0 points). Moreover, the points for the questions are distributed in such a way that the array p is a permutation of numbers from 1 to m.
For the i-th student, Petya knows that he expects to get x_i points for the test. Petya wonders how unexpected the results could be. Petya believes that the surprise value of the results for students is equal to β_{i=1}^{n} |x_i - r_i|, where r_i is the number of points that the i-th student has got for the test.
Your task is to help Petya find such a permutation p for which the surprise value of the results is maximum possible. If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
The first line of each test case contains two integers n and m (1 β€ n β€ 10; 1 β€ m β€ 10^4) β the number of students and the number of questions, respectively.
The second line contains n integers x_1, x_2, ..., x_n (0 β€ x_i β€ (m(m+1))/(2)), where x_i is the number of points that the i-th student expects to get.
This is followed by n lines, the i-th line contains the string s_i (|s_i| = m; s_{i, j} β \{0, 1\}), where s_{i, j} is 1 if the i-th student has answered the j-th question correctly, and 0 otherwise.
The sum of m for all test cases does not exceed 10^4.
Output
For each test case, print m integers β a permutation p for which the surprise value of the results is maximum possible. If there are multiple answers, print any of them.
Example
Input
3
4 3
5 1 2 2
110
100
101
100
4 4
6 2 0 10
1001
0010
0110
0101
3 6
20 3 15
010110
000101
111111
Output
3 1 2
2 3 4 1
3 1 4 5 2 6
|
Let's call a set of positive integers a_1, a_2, ..., a_k quadratic if the product of the factorials of its elements is a square of an integer, i. e. β_{i=1}^{k} a_i! = m^2, for some integer m.
You are given a positive integer n.
Your task is to find a quadratic subset of a set 1, 2, ..., n of maximum size. If there are multiple answers, print any of them.
Input
A single line contains a single integer n (1 β€ n β€ 10^6).
Output
In the first line, print a single integer β the size of the maximum subset. In the second line, print the subset itself in an arbitrary order.
Examples
Input
1
Output
1
1
Input
4
Output
3
1 3 4
Input
7
Output
4
1 4 5 6
Input
9
Output
7
1 2 4 5 6 7 9
|
A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are numbered from 1 to n from top to bottom, and columns of the floor are numbered from 1 to m from left to right. The cell on the intersection of the r-th row and the c-th column is denoted as (r,c). The initial position of the robot is (r_b, c_b).
In one second, the robot moves by dr rows and dc columns, that is, after one second, the robot moves from the cell (r, c) to (r + dr, c + dc). Initially dr = 1, dc = 1. If there is a vertical wall (the left or the right walls) in the movement direction, dc is reflected before the movement, so the new value of dc is -dc. And if there is a horizontal wall (the upper or lower walls), dr is reflected before the movement, so the new value of dr is -dr.
Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at (r_d, c_d). The job of the robot is to clean that dirty cell.
<image> Illustration for the first example. The blue arc is the robot. The red star is the target dirty cell. Each second the robot cleans a row and a column, denoted by yellow stripes.
Given the floor size n and m, the robot's initial position (r_b, c_b) and the dirty cell's position (r_d, c_d), find the time for the robot to do its job.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 10^4). Description of the test cases follows.
A test case consists of only one line, containing six integers n, m, r_b, c_b, r_d, and c_d (1 β€ n, m β€ 100, 1 β€ r_b, r_d β€ n, 1 β€ c_b, c_d β€ m) β the sizes of the room, the initial position of the robot and the position of the dirt cell.
Output
For each test case, print an integer β the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.
Example
Input
5
10 10 6 1 2 8
10 10 9 9 1 1
9 8 5 6 2 1
6 9 2 2 5 8
2 2 1 1 2 1
Output
7
10
9
3
0
Note
In the first example, the floor has the size of 10Γ 10. The initial position of the robot is (6, 1) and the position of the dirty cell is (2, 8). See the illustration of this example in the problem statement.
In the second example, the floor is the same, but the initial position of the robot is now (9, 9), and the position of the dirty cell is (1, 1). In this example, the robot went straight to the dirty cell and clean it.
<image>
In the third example, the floor has the size 9 Γ 8. The initial position of the robot is (5, 6), and the position of the dirty cell is (2, 1).
<image>
In the fourth example, the floor has the size 6 Γ 9. The initial position of the robot is (2, 2) and the position of the dirty cell is (5, 8).
<image>
In the last example, the robot was already standing in the same column as the dirty cell, so it can clean the cell right away.
<image>
|
Alice and Bob play the following game. Alice has a set S of disjoint ranges of integers, initially containing only one range [1, n]. In one turn, Alice picks a range [l, r] from the set S and asks Bob to pick a number in the range. Bob chooses a number d (l β€ d β€ r). Then Alice removes [l, r] from S and puts into the set S the range [l, d - 1] (if l β€ d - 1) and the range [d + 1, r] (if d + 1 β€ r). The game ends when the set S is empty. We can show that the number of turns in each game is exactly n.
After playing the game, Alice remembers all the ranges [l, r] she picked from the set S, but Bob does not remember any of the numbers that he picked. But Bob is smart, and he knows he can find out his numbers d from Alice's ranges, and so he asks you for help with your programming skill.
Given the list of ranges that Alice has picked ([l, r]), for each range, help Bob find the number d that Bob has picked.
We can show that there is always a unique way for Bob to choose his number for a list of valid ranges picked by Alice.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 1000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 1000).
Each of the next n lines contains two integers l and r (1 β€ l β€ r β€ n), denoting the range [l, r] that Alice picked at some point.
Note that the ranges are given in no particular order.
It is guaranteed that the sum of n over all test cases does not exceed 1000, and the ranges for each test case are from a valid game.
Output
For each test case print n lines. Each line should contain three integers l, r, and d, denoting that for Alice's range [l, r] Bob picked the number d.
You can print the lines in any order. We can show that the answer is unique.
It is not required to print a new line after each test case. The new lines in the output of the example are for readability only.
Example
Input
4
1
1 1
3
1 3
2 3
2 2
6
1 1
3 5
4 4
3 6
4 5
1 6
5
1 5
1 2
4 5
2 2
4 4
Output
1 1 1
1 3 1
2 2 2
2 3 3
1 1 1
3 5 3
4 4 4
3 6 6
4 5 5
1 6 2
1 5 3
1 2 1
4 5 5
2 2 2
4 4 4
Note
In the first test case, there is only 1 range [1, 1]. There was only one range [1, 1] for Alice to pick, and there was only one number 1 for Bob to pick.
In the second test case, n = 3. Initially, the set contains only one range [1, 3].
* Alice picked the range [1, 3]. Bob picked the number 1. Then Alice put the range [2, 3] back to the set, which after this turn is the only range in the set.
* Alice picked the range [2, 3]. Bob picked the number 3. Then Alice put the range [2, 2] back to the set.
* Alice picked the range [2, 2]. Bob picked the number 2. The game ended.
In the fourth test case, the game was played with n = 5. Initially, the set contains only one range [1, 5]. The game's turn is described in the following table.
Game turn| Alice's picked range| Bob's picked number| The range set after
---|---|---|---
Before the game start| | | \{ [1, 5] \}
1| [1, 5]| 3| \{ [1, 2], [4, 5] \}
2| [1, 2]| 1| \{ [2, 2], [4, 5] \}
3| [4, 5]| 5| \{ [2, 2], [4, 4] \}
4| [2, 2]| 2| \{ [4, 4] \}
5| [4, 4]| 4| \{ \} (empty set)
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
The statement of this problem shares a lot with problem A. The differences are that in this problem, the probability is introduced, and the constraint is different.
A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are numbered from 1 to n from top to bottom, and columns of the floor are numbered from 1 to m from left to right. The cell on the intersection of the r-th row and the c-th column is denoted as (r,c). The initial position of the robot is (r_b, c_b).
In one second, the robot moves by dr rows and dc columns, that is, after one second, the robot moves from the cell (r, c) to (r + dr, c + dc). Initially dr = 1, dc = 1. If there is a vertical wall (the left or the right walls) in the movement direction, dc is reflected before the movement, so the new value of dc is -dc. And if there is a horizontal wall (the upper or lower walls), dr is reflected before the movement, so the new value of dr is -dr.
Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at (r_d, c_d). The job of the robot is to clean that dirty cell.
After a lot of testings in problem A, the robot is now broken. It cleans the floor as described above, but at each second the cleaning operation is performed with probability \frac p {100} only, and not performed with probability 1 - \frac p {100}. The cleaning or not cleaning outcomes are independent each second.
Given the floor size n and m, the robot's initial position (r_b, c_b) and the dirty cell's position (r_d, c_d), find the expected time for the robot to do its job.
It can be shown that the answer can be expressed as an irreducible fraction \frac x y, where x and y are integers and y not β‘ 0 \pmod{10^9 + 7} . Output the integer equal to x β
y^{-1} mod (10^9 + 7). In other words, output such an integer a that 0 β€ a < 10^9 + 7 and a β
y β‘ x \pmod {10^9 + 7}.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 10). Description of the test cases follows.
A test case consists of only one line, containing n, m, r_b, c_b, r_d, c_d, and p (4 β€ n β
m β€ 10^5, n, m β₯ 2, 1 β€ r_b, r_d β€ n, 1 β€ c_b, c_d β€ m, 1 β€ p β€ 99) β the sizes of the room, the initial position of the robot, the position of the dirt cell and the probability of cleaning in percentage.
Output
For each test case, print a single integer β the expected time for the robot to clean the dirty cell, modulo 10^9 + 7.
Example
Input
6
2 2 1 1 2 1 25
3 3 1 2 2 2 25
10 10 1 1 10 10 75
10 10 10 10 1 1 75
5 5 1 3 2 2 10
97 98 3 5 41 43 50
Output
3
3
15
15
332103349
99224487
Note
In the first test case, the robot has the opportunity to clean the dirty cell every second. Using the [geometric distribution](https://en.wikipedia.org/wiki/Geometric_distribution), we can find out that with the success rate of 25\%, the expected number of tries to clear the dirty cell is \frac 1 {0.25} = 4. But because the first moment the robot has the opportunity to clean the cell is before the robot starts moving, the answer is 3.
<image> Illustration for the first example. The blue arc is the robot. The red star is the target dirt cell. The purple square is the initial position of the robot. Each second the robot has an opportunity to clean a row and a column, denoted by yellow stripes.
In the second test case, the board size and the position are different, but the robot still has the opportunity to clean the dirty cell every second, and it has the same probability of cleaning. Therefore the answer is the same as in the first example.
<image> Illustration for the second example.
The third and the fourth case are almost the same. The only difference is that the position of the dirty cell and the robot are swapped. But the movements in both cases are identical, hence the same result.
|
A binary tree of n nodes is given. Nodes of the tree are numbered from 1 to n and the root is the node 1. Each node can have no child, only one left child, only one right child, or both children. For convenience, let's denote l_u and r_u as the left and the right child of the node u respectively, l_u = 0 if u does not have the left child, and r_u = 0 if the node u does not have the right child.
Each node has a string label, initially is a single character c_u. Let's define the string representation of the binary tree as the concatenation of the labels of the nodes in the in-order. Formally, let f(u) be the string representation of the tree rooted at the node u. f(u) is defined as follows: $$$ f(u) = \begin{cases} <empty string>, & if u = 0; \\\ f(l_u) + c_u + f(r_u) & otherwise, \end{cases} where +$$$ denotes the string concatenation operation.
This way, the string representation of the tree is f(1).
For each node, we can duplicate its label at most once, that is, assign c_u with c_u + c_u, but only if u is the root of the tree, or if its parent also has its label duplicated.
You are given the tree and an integer k. What is the lexicographically smallest string representation of the tree, if we can duplicate labels of at most k nodes?
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5).
The second line contains a string c of n lower-case English letters, where c_i is the initial label of the node i for 1 β€ i β€ n. Note that the given string c is not the initial string representation of the tree.
The i-th of the next n lines contains two integers l_i and r_i (0 β€ l_i, r_i β€ n). If the node i does not have the left child, l_i = 0, and if the node i does not have the right child, r_i = 0.
It is guaranteed that the given input forms a binary tree, rooted at 1.
Output
Print a single line, containing the lexicographically smallest string representation of the tree if at most k nodes have their labels duplicated.
Examples
Input
4 3
abab
2 3
0 0
0 4
0 0
Output
baaaab
Input
8 2
kadracyn
2 5
3 4
0 0
0 0
6 8
0 7
0 0
0 0
Output
daarkkcyan
Input
8 3
kdaracyn
2 5
0 3
0 4
0 0
6 8
0 7
0 0
0 0
Output
darkcyan
Note
The images below present the tree for the examples. The number in each node is the node number, while the subscripted letter is its label. To the right is the string representation of the tree, with each letter having the same color as the corresponding node.
Here is the tree for the first example. Here we duplicated the labels of nodes 1 and 3. We should not duplicate the label of node 2 because it would give us the string "bbaaab", which is lexicographically greater than "baaaab".
<image>
In the second example, we can duplicate the labels of nodes 1 and 2. Note that only duplicating the label of the root will produce a worse result than the initial string.
<image>
In the third example, we should not duplicate any character at all. Even though we would want to duplicate the label of the node 3, by duplicating it we must also duplicate the label of the node 2, which produces a worse result.
<image>
There is no way to produce string "darkkcyan" from a tree with the initial string representation "darkcyan" :(.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.