Codeforces Round 816 (Div. 2)
A. Crossmarket
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Stanley and Megan decided to shop in the "Crossmarket" grocery store, which can be represented as a matrix with $$$n$$$ rows and $$$m$$$ columns.

Stanley and Megan can move to an adjacent cell using $$$1$$$ unit of power. Two cells are considered adjacent if they share an edge. To speed up the shopping process, Megan brought her portals with her, and she leaves one in each cell she visits (if there is no portal yet). If a person (Stanley or Megan) is in a cell with a portal, that person can use $$$1$$$ unit of power to teleport to any other cell with a portal, including Megan's starting cell.

They decided to split up: Stanley will go from the upper-left cell (cell with coordinates $$$(1, 1)$$$) to the lower-right cell (cell with coordinates $$$(n, m)$$$), whilst Megan needs to get from the lower-left cell (cell with coordinates $$$(n, 1)$$$) to the upper-right cell (cell with coordinates $$$(1, m)$$$).

What is the minimum total energy needed for them both to do that?

Note that they can choose the time they move. Time does not affect energy.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows.

The only line in the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$).

Output

For each test case print a single integer on a new line – the answer.

Example
Input
7
7 5
5 7
1 1
100000 100000
57 228
1 5
5 1
Output
15
15
0
299998
340
5
5
Note

In the first test case they can stick to the following plan:

  1. Megan (red circle) moves to the cell $$$(7, 3)$$$. Then she goes to the cell $$$(1, 3)$$$, and Stanley (blue circle) does the same.
  2. Stanley uses the portal in that cell (cells with portals are grey) to get to the cell $$$(7, 3)$$$. Then he moves to his destination — cell $$$(7, 5)$$$.
  3. Megan also finishes her route and goes to the cell $$$(1, 5)$$$.

The total energy spent is $$$(2 + 6) + (2 + 1 + 2) + (2)= 15$$$, which is our final answer.

B. Beautiful Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Stanley defines the beauty of an array $$$a$$$ of length $$$n$$$, which contains non-negative integers, as follows: $$$$$$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$$$$$ which means that we divide each element by $$$k$$$, round it down, and sum up the resulting values.

Stanley told Sam the integer $$$k$$$ and asked him to find an array $$$a$$$ of $$$n$$$ non-negative integers, such that the beauty is equal to $$$b$$$ and the sum of elements is equal to $$$s$$$. Help Sam — find any of the arrays satisfying the conditions above.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows.

The first line of each test case contains integers $$$n$$$, $$$k$$$, $$$b$$$, $$$s$$$ ($$$1 \leq n \leq 10^{5}$$$, $$$1 \leq k \leq 10^{9}$$$, $$$0 \leq b \leq 10^{9}$$$, $$$0 \leq s \leq 10^{18}$$$).

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

Output

For each test case print $$$-1$$$ if such array $$$a$$$ does not exist. Otherwise print $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_{i} \leq 10^{18}$$$) — the answer.

Example
Input
8
1 6 3 100
3 6 3 12
3 6 3 19
5 4 7 38
5 4 7 80
99978 1000000000 100000000 1000000000000000000
1 1 0 0
4 1000000000 1000000000 1000000000000000000
Output
-1
-1
0 0 19
0 3 3 3 29
-1
-1
0
0 0 0 1000000000000000000
Note

In the first, the second, the fifth and the sixth test cases of the example it is possible to show that such array does not exist.

In the third testcase of the example $$$a = [0, 0, 19]$$$. The sum of elements in it is equal to 19, the beauty of it is equal to $$$\left ( \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{19}{6} \right \rfloor \right ) = (0 + 0 + 3) = 3$$$.

In the fourth testcase of the example $$$a = [0, 3, 3, 3, 29]$$$. The sum of elements in it is equal to $$$38$$$, the beauty of it is equal to $$$(0 + 0 + 0 + 0 + 7) = 7$$$.

C. Monoblock
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.

The awesomeness of an array is the minimum number of blocks of consecutive identical numbers in which the array could be split. For example, the awesomeness of an array

  • $$$[1, 1, 1]$$$ is $$$1$$$;
  • $$$[5, 7]$$$ is $$$2$$$, as it could be split into blocks $$$[5]$$$ and $$$[7]$$$;
  • $$$[1, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9]$$$ is 3, as it could be split into blocks $$$[1]$$$, $$$[7, 7, 7, 7, 7, 7, 7]$$$, and $$$[9, 9, 9, 9, 9, 9, 9, 9, 9]$$$.

You are given an array $$$a$$$ of length $$$n$$$. There are $$$m$$$ queries of two integers $$$i$$$, $$$x$$$. A query $$$i$$$, $$$x$$$ means that from now on the $$$i$$$-th element of the array $$$a$$$ is equal to $$$x$$$.

After each query print the sum of awesomeness values among all subsegments of array $$$a$$$. In other words, after each query you need to calculate $$$$$$\sum\limits_{l = 1}^n \sum\limits_{r = l}^n g(l, r),$$$$$$ where $$$g(l, r)$$$ is the awesomeness of the array $$$b = [a_l, a_{l + 1}, \ldots, a_r]$$$.

Input

In the first line you are given with two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$).

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

In the next $$$m$$$ lines you are given the descriptions of queries. Each line contains two integers $$$i$$$ and $$$x$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq x \leq 10^9$$$).

Output

Print the answer to each query on a new line.

Example
Input
5 5
1 2 3 4 5
3 2
4 2
3 1
2 1
2 2
Output
29
23
35
25
35
Note

After the first query $$$a$$$ is equal to $$$[1, 2, 2, 4, 5]$$$, and the answer is $$$29$$$ because we can split each of the subsegments the following way:

  1. $$$[1; 1]$$$: $$$[1]$$$, 1 block;
  2. $$$[1; 2]$$$: $$$[1] + [2]$$$, 2 blocks;
  3. $$$[1; 3]$$$: $$$[1] + [2, 2]$$$, 2 blocks;
  4. $$$[1; 4]$$$: $$$[1] + [2, 2] + [4]$$$, 3 blocks;
  5. $$$[1; 5]$$$: $$$[1] + [2, 2] + [4] + [5]$$$, 4 blocks;
  6. $$$[2; 2]$$$: $$$[2]$$$, 1 block;
  7. $$$[2; 3]$$$: $$$[2, 2]$$$, 1 block;
  8. $$$[2; 4]$$$: $$$[2, 2] + [4]$$$, 2 blocks;
  9. $$$[2; 5]$$$: $$$[2, 2] + [4] + [5]$$$, 3 blocks;
  10. $$$[3; 3]$$$: $$$[2]$$$, 1 block;
  11. $$$[3; 4]$$$: $$$[2] + [4]$$$, 2 blocks;
  12. $$$[3; 5]$$$: $$$[2] + [4] + [5]$$$, 3 blocks;
  13. $$$[4; 4]$$$: $$$[4]$$$, 1 block;
  14. $$$[4; 5]$$$: $$$[4] + [5]$$$, 2 blocks;
  15. $$$[5; 5]$$$: $$$[5]$$$, 1 block;
which is $$$1 + 2 + 2 + 3 + 4 + 1 + 1 + 2 + 3 + 1 + 2 + 3 + 1 + 2 + 1 = 29$$$ in total.

D. 2+ doors
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the bitwise OR operation.

Find the lexicographically smallest array $$$a$$$ that satisfies all the statements.

An array $$$a$$$ is lexicographically smaller than an array $$$b$$$ of the same length if and only if the following holds:

  • in the first position where $$$a$$$ and $$$b$$$ differ, the array $$$a$$$ has a smaller element than the corresponding element in $$$b$$$.
Input

In the first line you are given with two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le q \le 2 \cdot 10^5$$$).

In the next $$$q$$$ lines you are given with three integers $$$i$$$, $$$j$$$, and $$$x$$$ ($$$1 \le i, j \le n$$$, $$$0 \le x \lt 2^{30}$$$) — the statements.

It is guaranteed that all $$$q$$$ statements hold for at least one array.

Output

On a single line print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \lt 2^{30}$$$) — array $$$a$$$.

Examples
Input
4 3
1 2 3
1 3 2
4 1 2
Output
0 3 2 2 
Input
1 0
Output
0 
Input
2 1
1 1 1073741823
Output
1073741823 0 
Note

In the first sample, these are all the arrays satisfying the statements:

  • $$$[0, 3, 2, 2]$$$,
  • $$$[2, 1, 0, 0]$$$,
  • $$$[2, 1, 0, 2]$$$,
  • $$$[2, 1, 2, 0]$$$,
  • $$$[2, 1, 2, 2]$$$,
  • $$$[2, 3, 0, 0]$$$,
  • $$$[2, 3, 0, 2]$$$,
  • $$$[2, 3, 2, 0]$$$,
  • $$$[2, 3, 2, 2]$$$.

E. Long Way Home
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Stanley lives in a country that consists of $$$n$$$ cities (he lives in city $$$1$$$). There are bidirectional roads between some of the cities, and you know how long it takes to ride through each of them. Additionally, there is a flight between each pair of cities, the flight between cities $$$u$$$ and $$$v$$$ takes $$$(u - v)^2$$$ time.

Stanley is quite afraid of flying because of watching "Sully: Miracle on the Hudson" recently, so he can take at most $$$k$$$ flights. Stanley wants to know the minimum time of a journey to each of the $$$n$$$ cities from the city $$$1$$$.

Input

In the first line of input there are three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \leq n \leq 10^{5}$$$, $$$1 \leq m \leq 10^{5}$$$, $$$1 \leq k \leq 20$$$) — the number of cities, the number of roads, and the maximal number of flights Stanley can take.

The following $$$m$$$ lines describe the roads. Each contains three integers $$$u$$$, $$$v$$$, $$$w$$$ ($$$1 \leq u, v \leq n$$$, $$$u \neq v$$$, $$$1 \leq w \leq 10^{9}$$$) — the cities the road connects and the time it takes to ride through. Note that some pairs of cities may be connected by more than one road.

Output

Print $$$n$$$ integers, $$$i$$$-th of which is equal to the minimum time of traveling to city $$$i$$$.

Examples
Input
3 1 2
1 3 1
Output
0 1 1 
Input
4 3 1
1 2 3
2 4 5
3 4 7
Output
0 1 4 6 
Input
2 1 1
2 1 893746473
Output
0 1 
Input
5 5 2
2 1 33
1 5 93
5 3 48
2 3 21
4 2 1
Output
0 1 2 2 3 
Note

In the first sample, it takes no time to get to city 1; to get to city 2 it is possible to use a flight between 1 and 2, which will take 1 unit of time; to city 3 you can get via a road from city 1, which will take 1 unit of time.

In the second sample, it also takes no time to get to city 1. To get to city 2 Stanley should use a flight between 1 and 2, which will take 1 unit of time. To get to city 3 Stanley can ride between cities 1 and 2, which will take 3 units of time, and then use a flight between 2 and 3. To get to city 4 Stanley should use a flight between 1 and 2, then take a ride from 2 to 4, which will take 5 units of time.

F. Crop Squares
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

Farmer Stanley grows corn on a rectangular field of size $$$ n \times m $$$ meters with corners in points $$$(0, 0)$$$, $$$(0, m)$$$, $$$(n, 0)$$$, $$$(n, m)$$$. This year the harvest was plentiful and corn covered the whole field.

The night before harvest aliens arrived and poisoned the corn in a single $$$1 \times 1$$$ square with sides parallel to field borders. The corn inside the square must not be eaten, but you cannot distinguish it from ordinary corn by sight. Stanley can only collect a sample of corn from an arbitrary polygon and bring it to the laboratory, where it will be analyzed and Stanley will be told the amount of corn in the sample that was poisoned. Since the harvest will soon deteriorate, such a study can be carried out no more than $$$5$$$ times.

More formally, it is allowed to make no more than $$$5$$$ queries, each of them calculates the area of intersection of a chosen polygon with a square of poisoned corn. It is necessary to find out the coordinates of the lower-left corner of the drawn square (the vertex of the square with the smallest $$$x$$$ and $$$y$$$ coordinates).

Input

First line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — field sizes.

Interaction

In order to query the area of intersection of a polygon with $$$k$$$ ($$$3 \le k \le 1000$$$) vertices at points with coordinates $$$(x_1, y_1),\; \dots ,\;(x_k, y_k)$$$ with a square of poisoned corn print $$$k+1$$$ lines. In the first of these lines print "? k". In the $$$i$$$-th of the next $$$k$$$ lines print two real numbers $$$x_i$$$ and $$$y_i$$$ ($$$|x_i|, |y_i| \le 10^4$$$) with at most $$$15$$$ digits after decimal place.

The polygon must have strictly positive area and contain no self-intersections.

In response to this query you will receive a real number $$$s$$$ ($$$0 \le s \le 1$$$) with $$$15$$$ digits after decimal place — the area of intersection of the square with the given polygon. If the polygon is invalid, there is no guarantee on the valid response.

When you have identified the drawn square, print on a separate line "! x y", where $$$x$$$ and $$$y$$$ are real numbers with at most $$$15$$$ digits after decimal place representing the coordinates of its lower-left corner ($$$0 \le x \le n - 1$$$, $$$0 \le y \le m - 1$$$), and then you have to terminate your program.

Your answer will be considered correct if its absolute or relative error on both coordinates does not exceed $$$10^{-6}$$$. Formally let your answer be $$$a$$$, jury answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a-b|}{max(1,|b|)} \le 10^{-6}$$$.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

Hacks

To make a hack, use the following test format.

The first line of the input should contain two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 100$$$) — field sizes.

The second line should contain two real numbers $$$x$$$ ($$$0 \le x \le n - 1$$$) and $$$y$$$ ($$$0 \le y \le m - 1$$$) — coordinates of the lower-left corner of the square of poisoned corn.

Example
Input
3 3





0.5





0.5
Output
? 4
0 0
2 0
2 3
0 3

? 4
0 0
0 1
3 1
3 0

! 1.5 0.5
Note

In the first test from the statement, the aliens poisoned a square of corn with vertices at points with coordinates $$$(1.5, 0.5)$$$, $$$(1.5, 1.5)$$$, $$$(2.5, 1.5)$$$, $$$(2.5, 0.5)$$$. In the picture, it is red, the polygon selected in the query is blue, and their intersection is green.

Picture for the first query:

Picture for the second query: