Hello 2025
A. MEX Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day, the schoolboy Mark misbehaved, so the teacher Sasha called him to the whiteboard.

Sasha gave Mark a table with $$$n$$$ rows and $$$m$$$ columns. His task is to arrange the numbers $$$0, 1, \ldots, n \cdot m - 1$$$ in the table (each number must be used exactly once) in such a way as to maximize the sum of MEX$$$^{\text{∗}}$$$ across all rows and columns. More formally, he needs to maximize $$$$$$\sum\limits_{i = 1}^{n} \operatorname{mex}(\{a_{i,1}, a_{i,2}, \ldots, a_{i,m}\}) + \sum\limits_{j = 1}^{m} \operatorname{mex}(\{a_{1,j}, a_{2,j}, \ldots, a_{n,j}\}),$$$$$$ where $$$a_{i,j}$$$ is the number in the $$$i$$$-th row and $$$j$$$-th column.

Sasha is not interested in how Mark arranges the numbers, so he only asks him to state one number — the maximum sum of MEX across all rows and columns that can be achieved.

$$$^{\text{∗}}$$$The minimum excluded (MEX) of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.

For example:

  • $$$\operatorname{mex}([2,2,1])= 0$$$, since $$$0$$$ does not belong to the array.
  • $$$\operatorname{mex}([3,1,0,1]) = 2$$$, since $$$0$$$ and $$$1$$$ belong to the array, but $$$2$$$ does not.
  • $$$\operatorname{mex}([0,3,1,2]) = 4$$$, since $$$0$$$, $$$1$$$, $$$2$$$, and $$$3$$$ belong to the array, but $$$4$$$ does not.
Input

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$) — the number of rows and columns in the table, respectively.

Output

For each test case, output the maximum possible sum of $$$\operatorname{mex}$$$ across all rows and columns.

Example
Input
3
1 1
2 2
3 5
Output
2
3
6
Note

In the first test case, the only element is $$$0$$$, and the sum of the $$$\operatorname{mex}$$$ of the numbers in the first row and the $$$\operatorname{mex}$$$ of the numbers in the first column is $$$\operatorname{mex}(\{0\}) + \operatorname{mex}(\{0\}) = 1 + 1 = 2$$$.

In the second test case, the optimal table may look as follows:

$$$3$$$$$$0$$$
$$$2$$$$$$1$$$

Then $$$\sum\limits_{i = 1}^{n} \operatorname{mex}(\{a_{i,1}, a_{i,2}, \ldots, a_{i,m}\}) + \sum\limits_{j = 1}^{m} \operatorname{mex}(\{a_{1,j}, a_{2,j}, \ldots, a_{n,j}\}) = \operatorname{mex}(\{3, 0\}) + \operatorname{mex}(\{2, 1\})$$$ $$$+ \operatorname{mex}(\{3, 2\}) + \operatorname{mex}(\{0, 1\}) = 1 + 0 + 0 + 2 = 3$$$.

B. Gorilla and the Exam
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Due to a shortage of teachers in the senior class of the "T-generation", it was decided to have a huge male gorilla conduct exams for the students. However, it is not that simple; to prove his competence, he needs to solve the following problem.

For an array $$$b$$$, we define the function $$$f(b)$$$ as the smallest number of the following operations required to make the array $$$b$$$ empty:

  • take two integers $$$l$$$ and $$$r$$$, such that $$$l \le r$$$, and let $$$x$$$ be the $$$\min(b_l, b_{l+1}, \ldots, b_r)$$$; then
  • remove all such $$$b_i$$$ that $$$l \le i \le r$$$ and $$$b_i = x$$$ from the array, the deleted elements are removed, the indices are renumerated.

You are given an array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$. No more than $$$k$$$ times, you can choose any index $$$i$$$ ($$$1 \le i \le n$$$) and any integer $$$p$$$, and replace $$$a_i$$$ with $$$p$$$.

Help the gorilla to determine the smallest value of $$$f(a)$$$ that can be achieved after such replacements.

Input

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.

The first line of each set of input data contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le k \le n$$$) — the length of the array $$$a$$$ and the maximum number of changes, respectively.

The second line of each set of input data contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array $$$a$$$ itself.

It is guaranteed that the sum of the values of $$$n$$$ across all sets of input data does not exceed $$$10^5$$$.

Output

For each set of input data, output a single integer on a separate line — the smallest possible value of $$$f(a)$$$.

Example
Input
6
1 0
48843
3 1
2 3 2
5 3
1 2 3 4 5
7 0
4 7 1 3 2 4 1
11 4
3 2 1 4 4 3 4 2 1 3 3
5 5
1 2 3 4 5
Output
1
1
2
5
2
1
Note

In the first set of input data, $$$f([48\,843]) = 1$$$, since the array consists of a single number, and thus it can be removed in one operation.

In the second set of input data, you can change the second number to $$$2$$$, resulting in the array $$$[2, 2, 2]$$$, where $$$f([2, 2, 2]) = 1$$$, since you can take the entire array as a subarray, the minimum on it is $$$2$$$, so we will remove all the $$$2$$$s from the array, and the array will become empty.

C. Trip to the Olympiad
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In the upcoming year, there will be many team olympiads, so the teachers of "T-generation" need to assemble a team of three pupils to participate in them. Any three pupils will show a worthy result in any team olympiad. But winning the olympiad is only half the battle; first, you need to get there...

Each pupil has an independence level, expressed as an integer. In "T-generation", there is exactly one student with each independence levels from $$$l$$$ to $$$r$$$, inclusive. For a team of three pupils with independence levels $$$a$$$, $$$b$$$, and $$$c$$$, the value of their team independence is equal to $$$(a \oplus b) + (b \oplus c) + (a \oplus c)$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.

Your task is to choose any trio of students with the maximum possible team independence.

Input

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case set contains two integers $$$l$$$ and $$$r$$$ ($$$0 \le l, r \lt 2^{30}$$$, $$$r - l \gt 1$$$) — the minimum and maximum independence levels of the students.

Output

For each test case set, output three pairwise distinct integers $$$a, b$$$, and $$$c$$$, such that $$$l \le a, b, c \le r$$$ and the value of the expression $$$(a \oplus b) + (b \oplus c) + (a \oplus c)$$$ is maximized. If there are multiple triples with the maximum value, any of them can be output.

Example
Input
8
0 2
0 8
1 3
6 22
128 137
69 98
115 127
0 1073741823
Output
1 2 0
8 7 1
2 1 3
7 16 11
134 132 137
98 85 76
123 121 118
965321865 375544086 12551794
Note

In the first test case, the only suitable triplet of numbers ($$$a, b, c$$$) (up to permutation) is ($$$0, 1, 2$$$).

In the second test case, one of the suitable triplets is ($$$8, 7, 1$$$), where $$$(8 \oplus 7) + (7 \oplus 1) + (8 \oplus 1) = 15 + 6 + 9 = 30$$$. It can be shown that $$$30$$$ is the maximum possible value of $$$(a \oplus b) + (b \oplus c) + (a \oplus c)$$$ for $$$0 \le a, b, c \le 8$$$.

D. Gifts Order
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

"T-Generation" has decided to purchase gifts for various needs; thus, they have $$$n$$$ different sweaters numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th sweater has a size of $$$a_i$$$. Now they need to send some subsegment of sweaters to an olympiad. It is necessary that the sweaters fit as many people as possible, but without having to take too many of them.

They need to choose two indices $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) to maximize the convenience equal to $$$$$$\operatorname{max} (a_l, a_{l + 1}, \ldots, a_r) - \operatorname{min} (a_l, a_{l + 1}, \ldots, a_r) - (r - l),$$$$$$ that is, the range of sizes minus the number of sweaters.

Sometimes the sizes of the sweaters change; it is known that there have been $$$q$$$ changes, in each change, the size of the $$$p$$$-th sweater becomes $$$x$$$.

Help the "T-Generation" team and determine the maximum convenience among all possible pairs $$$(l, r)$$$ initially, as well as after each size change.

Input

Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of sweaters and the number of size changes.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sizes of the sweaters.

Each of the following $$$q$$$ lines of each test case contains two integers $$$p$$$ and $$$x$$$ ($$$1 \le p \le n$$$, $$$1 \le x \le 10^9$$$) — the next size change.

It is guaranteed that the sum of the values of $$$n$$$ and the sum of the values of $$$q$$$ across all test cases do not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, output the maximum value of convenience among all possible pairs $$$(l, r)$$$ before any actions, as well as after each size change.

Example
Input
3
2 2
1 10
1 10
2 2
5 3
1 2 3 4 5
3 7
1 4
5 2
8 5
7 4 2 4 8 2 1 4
5 4
1 10
3 2
8 11
7 7
Output
8
0
7
0
4
4
4
5
3
6
6
9
7
Note

Consider the first test case.

  • Before any changes, you can take all the sweaters; then the convenience is equal to $$$\operatorname{max} (a_1, a_2) - \operatorname{min} (a_1, a_2) - (2 - 1) = 10 - 1 - 1 = 8$$$.
  • After the first query, the sizes of both sweaters will be equal to $$$10$$$, you can only take the first sweater and the convenience is equal to $$$10 - 10 - 0 = 0$$$.
  • After the second query, the size of the first sweater will be $$$10$$$, and the second $$$2$$$, you can take all the sweaters and the convenience is equal to $$$\operatorname{max} (a_1, a_2) - \operatorname{min} (a_1, a_2) - (2 - 1) = 10 - 2 - 1 = 7$$$.

E1. Another Exercise on Graphs (Easy Version)
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This is the easy version of the problem. The difference between the versions is that in this version, there is an additional constraint on $$$m$$$. You can hack only if you solved all versions of this problem.

Recently, the instructors of "T-generation" needed to create a training contest. They were missing one problem, and there was not a single problem on graphs in the contest, so they came up with the following problem.

You are given a connected weighted undirected graph with $$$n$$$ vertices and $$$m$$$ edges, which does not contain self-loops or multiple edges.

There are $$$q$$$ queries of the form $$$(a, b, k)$$$: among all paths from vertex $$$a$$$ to vertex $$$b$$$, find the smallest $$$k$$$-th maximum weight of edges on the path$$$^{\dagger}$$$.

The instructors thought that the problem sounded very interesting, but there is one catch. They do not know how to solve it. Help them and solve the problem, as there are only a few hours left until the contest starts.

$$$^{\dagger}$$$ Let $$$w_1 \ge w_2 \ge \ldots \ge w_{h}$$$ be the weights of all edges in a path, in non-increasing order. The $$$k$$$-th maximum weight of the edges on this path is $$$w_{k}$$$.

Input

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows.

The first line of each set of test case contains three integers $$$n, m$$$ and $$$q$$$ ($$$2 \le n \le 400$$$, $$$n - 1 \le m \le \operatorname{min}(\mathbf{400}, \frac{n \cdot (n - 1)}{2})$$$, $$$1 \le q \le 3 \cdot 10^5$$$) — the number of vertices, the number of edges, and the number of questions, respectively.

Each of the following $$$m$$$ lines of each set of test case contains three integers $$$v, u$$$ and $$$w$$$ ($$$1 \le v, u \le n$$$, $$$1 \le w \le 10^9$$$) — the ends of the next edge of the graph and its weight, respectively. It is guaranteed that the graph does not contain self-loops and multiple edges.

Each of the following $$$q$$$ lines of each set of test case contains three integers $$$a, b$$$ and $$$k$$$ ($$$1 \le a, b \le n$$$, $$$k \ge 1$$$) — the next question. It is guaranteed that any path from vertex $$$a$$$ to vertex $$$b$$$ contains at least $$$k$$$ edges.

It is guaranteed that the sum of the values of $$$n$$$ across all sets of test cases does not exceed $$$400$$$.

It is guaranteed that the sum of the values of $$$m$$$ across all sets of test cases does not exceed $$$400$$$.

It is guaranteed that the sum of the values of $$$q$$$ across all sets of test cases does not exceed $$$3 \cdot 10^5$$$.

Output

For each test case, output the answers to all questions.

Example
Input
3
4 4 2
1 2 2
2 4 2
1 3 4
3 4 1
1 4 2
2 3 1
6 7 3
1 2 10
2 3 3
3 4 9
4 5 2
5 6 1
2 4 10
4 6 10
1 6 3
1 6 2
2 4 1
11 17 10
1 4 5
1 3 19
1 2 10
3 2 13
4 5 1
4 6 11
3 5 9
3 6 18
2 7 17
5 8 15
5 10 8
6 9 4
7 10 20
7 8 16
8 11 3
9 11 6
10 11 14
3 11 1
3 11 3
1 11 1
1 11 4
1 11 3
8 2 2
10 4 1
3 9 2
3 9 1
6 7 3
Output
1 2
2 9 9
11 3 11 1 3 10 8 4 11 4
Note

In the first set of test cases, one of the optimal paths in the first query is the path $$$1 \rightarrow 3 \rightarrow 4$$$; the $$$2$$$-nd maximum weight of the edges on this path is $$$1$$$. In the second query, one of the optimal paths is $$$2 \rightarrow 4 \rightarrow 3$$$; $$$1$$$-st maximum weight of the edges is $$$2$$$.

In the second set of input data, one of the optimal paths in the first query is the path $$$1 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 6$$$; the $$$3$$$-rd maximum weight of the edges on this path is $$$2$$$.

E2. Another Exercise on Graphs (hard version)
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This is the hard version of the problem. The difference between the versions is that in this version, there is no additional constraint on $$$m$$$. You can hack only if you solved all versions of this problem.

Recently, the instructors of "T-generation" needed to create a training contest. They were missing one problem, and there was not a single problem on graphs in the contest, so they came up with the following problem.

You are given a connected weighted undirected graph with $$$n$$$ vertices and $$$m$$$ edges, which does not contain self-loops or multiple edges.

There are $$$q$$$ queries of the form $$$(a, b, k)$$$: among all paths from vertex $$$a$$$ to vertex $$$b$$$, find the smallest $$$k$$$-th maximum weight of edges on the path$$$^{\dagger}$$$.

The instructors thought that the problem sounded very interesting, but there is one catch. They do not know how to solve it. Help them and solve the problem, as there are only a few hours left until the contest starts.

$$$^{\dagger}$$$ Let $$$w_1 \ge w_2 \ge \ldots \ge w_{h}$$$ be the weights of all edges in a path, in non-increasing order. The $$$k$$$-th maximum weight of the edges on this path is $$$w_{k}$$$.

Input

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows.

The first line of each set of test case contains three integers $$$n, m$$$ and $$$q$$$ ($$$2 \le n \le 400$$$, $$$n - 1 \le m \le \frac{n \cdot (n - 1)}{2}$$$, $$$1 \le q \le 3 \cdot 10^5$$$) — the number of vertices, the number of edges, and the number of questions, respectively.

Each of the following $$$m$$$ lines of each set of test case contains three integers $$$v, u$$$ and $$$w$$$ ($$$1 \le v, u \le n$$$, $$$1 \le w \le 10^9$$$) — the ends of the next edge of the graph and its weight, respectively. It is guaranteed that the graph does not contain self-loops and multiple edges.

Each of the following $$$q$$$ lines of each set of test case contains three integers $$$a, b$$$ and $$$k$$$ ($$$1 \le a, b \le n$$$, $$$k \ge 1$$$) — the next question. It is guaranteed that any path from vertex $$$a$$$ to vertex $$$b$$$ contains at least $$$k$$$ edges.

It is guaranteed that the sum of the values of $$$n$$$ across all sets of test cases does not exceed $$$400$$$.

It is guaranteed that the sum of the values of $$$q$$$ across all sets of test cases does not exceed $$$3 \cdot 10^5$$$.

Output

For each set of test case, output the answers to all questions.

Example
Input
3
4 4 2
1 2 2
2 4 2
1 3 4
3 4 1
1 4 2
2 3 1
6 7 3
1 2 10
2 3 3
3 4 9
4 5 2
5 6 1
2 4 10
4 6 10
1 6 3
1 6 2
2 4 1
11 17 10
1 4 5
1 3 19
1 2 10
3 2 13
4 5 1
4 6 11
3 5 9
3 6 18
2 7 17
5 8 15
5 10 8
6 9 4
7 10 20
7 8 16
8 11 3
9 11 6
10 11 14
3 11 1
3 11 3
1 11 1
1 11 4
1 11 3
8 2 2
10 4 1
3 9 2
3 9 1
6 7 3
Output
1 2
2 9 9
11 3 11 1 3 10 8 4 11 4
Note

In the first set of test cases, one of the optimal paths in the first query is the path $$$1 \rightarrow 3 \rightarrow 4$$$; the $$$2$$$-nd maximum weight of the edges on this path is $$$1$$$. In the second query, one of the optimal paths is $$$2 \rightarrow 4 \rightarrow 3$$$; $$$1$$$-st maximum weight of the edges is $$$2$$$.

In the second set of input data, one of the optimal paths in the first query is the path $$$1 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 6$$$; the $$$3$$$-rd maximum weight of the edges on this path is $$$2$$$.

F. Formation
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

One day, the teachers of "T-generation" decided to instill discipline in the pupils, so they lined them up and made them calculate in order. There are a total of $$$n$$$ pupils, the height of the $$$i$$$-th pupil in line is $$$a_i$$$.

The line is comfortable, if for each $$$i$$$ from $$$1$$$ to $$$n - 1$$$, the following condition holds: $$$a_i \cdot 2 \ge a_{i + 1}$$$. Initially, the line is comfortable.

The teachers do not like that the maximum height in the line is too small, so they want to feed the pupils pizza. You know that when a pupil eats one pizza, their height increases by $$$1$$$. One pizza can only be eaten by only one pupil, but each pupil can eat an unlimited number of pizzas. It is important that after all the pupils have eaten their pizzas, the line is comfortable.

The teachers have $$$q$$$ options for how many pizzas they will order. For each option $$$k_i$$$, answer the question: what is the maximum height $$$\max(a_1, a_2, \ldots, a_n)$$$ that can be achieved if the pupils eat at most $$$k_i$$$ pizzas.

Input

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.

The first line of each set of test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 5 \cdot 10^4$$$) — the number of pupils and the number of options for how many pizzas the teachers will order.

The second line of each set of test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the heights of the pupils.It is guaranteed that initially, the line is comfortable.

Each of the following $$$q$$$ lines of each set of input data contains one integer $$$k_i$$$ ($$$1 \le k_i \le 10^9$$$) — the next limit for how many pizzas the pupils can eat.

It is guaranteed that the sum of the values of $$$n$$$ across all sets of input data does not exceed $$$5 \cdot 10^4$$$.

It is guaranteed that the sum of the values of $$$q$$$ across all sets of input data does not exceed $$$5 \cdot 10^4$$$.

Output

For each test case, for each limit for how many pizzas the pupils can eat, output the maximum value $$$\max(a_1, a_2, \ldots, a_n)$$$ that can be achieved while ensuring that the line is comfortable.

Example
Input
3
2 1
10 20
10
6 7
3 1 2 4 5 6
1
2
4
8
16
32
64
10 4
1 2 4 8 16 32 64 128 256 512
10
100
1000
10000
Output
26
7 8 10 12 19 35 67
513 560 1011 10001
Note

In the first query of the first set of input data, you can first give $$$3$$$ pizzas to the first pupil, and then give $$$6$$$ pizzas to the second pupil, making the final array $$$[13, 26]$$$ (the line is comfortable since $$$13 \cdot 2 \ge 26$$$), and the maximum element in it is $$$26$$$.

G. Secret Message
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Every Saturday, Alexander B., a teacher of parallel X, writes a secret message to Alexander G., a teacher of parallel B, in the evening. Since Alexander G. is giving a lecture at that time and the message is very important, Alexander B. has to write this message on an interactive online board.

The interactive online board is a grid consisting of $$$n$$$ rows and $$$m$$$ columns, where each cell is $$$1 \times 1$$$ in size. Some cells of this board are already filled in, and it is impossible to write a message in them; such cells are marked with the symbol ".", while the remaining cells are called free and are marked with the symbol "#".

Let us introduce two characteristics of the online board:

  • $$$s$$$ is the number of free cells.
  • $$$p$$$ is the perimeter of the grid figure formed by the union of free cells.

Let $$$A$$$ be the set of free cells. Your goal is to find a set of cells $$$S \subseteq A$$$ that satisfies the following properties:

  • $$$|S| \le \frac{1}{5} \cdot (s+p)$$$.
  • Any cell from $$$A$$$ either lies in $$$S$$$ or shares a side with some cell from $$$S$$$.

We can show that at least one set $$$S$$$ satisfying these properties exists; you are required to find any suitable one.

Input

The first line contains the number $$$t$$$ ($$$1 \le t \le 80\,000$$$) — the number of test cases.

In the first line of each test case, the numbers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^6$$$) — the dimensions of the grid are given.

The following $$$n$$$ lines contain the description of the grid.

It is guaranteed that the sum of $$$n \cdot m$$$ across all test cases does not exceed $$$2 \cdot 10^6$$$.

Output

For each test case, output $$$n$$$ lines consisting of $$$m$$$ symbols, where each symbol encodes the state of the cell:

  • "#" — the cell is in $$$A$$$ but not in $$$S$$$;
  • "S" — the cell is in both $$$A$$$ and $$$S$$$;
  • "." — the cell is neither in $$$A$$$ nor in $$$S$$$.
Example
Input
3
3 3
.#.
###
.#.
2 6
######
######
3 7
###....
#.#.###
###....
Output
.#.
#S#
.#.
#S##S#
#S##S#
S#S....
#.#.S#S
S#S....
Note

In the first example, $$$s=5$$$ and $$$p=12$$$, thus the number of cells in $$$S$$$ must not exceed $$$\frac{1}{5} \cdot (5+12) = 3.4$$$, meaning $$$|S| \le 3$$$. Note that the presented set $$$S$$$ consists of $$$1$$$ cell and clearly satisfies all the constraints.

In the second example, $$$s=12$$$ and $$$p=16$$$, thus the number of cells in $$$S$$$ must not exceed $$$\frac{1}{5} \cdot (12+16)= 5.6$$$, meaning $$$|S| \le 5$$$. Note that the presented set $$$S$$$ consists of $$$4$$$ cells and clearly satisfies all the constraints.

In the third example, we will explain what perimeter is, as it may not be obvious. Any grid figure has a boundary, which can be represented as a union of segments that do not intersect at interior points. Thus, in the picture below, the thick black line denotes the boundary of the figure formed by the union of free cells. The total length of these segments is $$$p=24$$$.

At the same time, the value $$$s=11$$$ and the upper limit is $$$|S| \le 7$$$, the presented set has a size of $$$6$$$ and clearly satisfies all the constraints.

H. Coffee Break
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are very long classes in the T-Generation. In one day, you need to have time to analyze the training and thematic contests, give a lecture with new material, and, if possible, also hold a mini-seminar. Therefore, there is a break where students can go to drink coffee and chat with each other.

There are a total of $$$n+2$$$ coffee machines located in sequentially arranged rooms along a long corridor. The coffee machines are numbered from $$$0$$$ to $$$n+1$$$, and immediately after the break starts, there are $$$a_i$$$ students gathered around the $$$i$$$-th coffee machine.

The students are talking too loudly among themselves, and the teachers need to make a very important announcement. Therefore, they want to gather the maximum number of students around some single coffee machine. The teachers are too lazy to run around the corridors and gather the students, so they came up with a more sophisticated way to manipulate them:

  • At any moment, the teachers can choose room $$$i$$$ ($$$1 \le i \le n$$$) and turn off the lights there;
  • If there were $$$x$$$ students in that room, then after turning off the lights, $$$\lfloor \frac12 x \rfloor$$$ students will go to room $$$(i-1)$$$, and $$$\lfloor \frac12 x \rfloor$$$ other students will go to room $$$(i+1)$$$.
  • If $$$x$$$ was odd, then one student remains in the same room.
  • After that, the lights in room $$$i$$$ are turned back on.

The teachers have not yet decided where they will gather the students, so for each $$$i$$$ from $$$1$$$ to $$$n$$$, you should determine what is the maximum number of students that can be gathered around the $$$i$$$-th coffee machine.

The teachers can turn off the lights in any rooms at their discretion, in any order, possibly turning off the lights in the same room multiple times.

Note that the values of $$$a_0$$$ and $$$a_{n+1}$$$ do not affect the answer to the problem, so their values will not be given to you.

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases.

In the first line of each test case, there is an integer $$$n$$$ ($$$1 \le n \le 10^6$$$).

In the second line of each test case, there are integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of students around coffee machines numbered $$$1, 2, \ldots, n$$$.

It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$10^6$$$.

Output

For each test case, output $$$n$$$ integers $$$b_1, \ldots, b_n$$$, where $$$b_i$$$ is the maximum number of students that can be around coffee machines number $$$i$$$.

Example
Input
3
2
8 0
5
2 2 2 2 2
5
0 0 9 0 0
Output
8 4 
4 5 4 5 4 
4 6 9 6 4 
Note

Let's analyze the first test case:

  • To maximize the number of students at the $$$1$$$-st coffee machine, all that needs to be done is nothing.
  • To maximize the number of students at the $$$2$$$-nd coffee machine, it is sufficient to turn off the lights in the $$$1$$$-st room once.