HIAST Collegiate Programming Contest 2024
A. Levi Is Sad
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a faraway school early in the morning. The school manager asked the $$$n$$$ students to line up in a row at the top of the wall.

They lined up one after the other according to the time of their arrival. Each student has a length of $$$h_i$$$ centimeters.

Meanwhile, there was a student named Levi who was angry because he was the shortest among the students. When he was asked about the reason for his anger, it became clear that he did not want to be the shortest person between the person in front of him and the person behind him.

The manager decided to make everyone happy without changing their places, by removing stones below any student, or even by adding stones under any student. Each stone is only one centimeter long, so when a stone is added, the person becomes one centimeter taller, and vice versa when removed.

Adding a stone anywhere costs $$$x$$$ energy units, and removing a stone anywhere costs $$$y$$$ energy units.

You can consider the length of the wall to be infinite and you can remove any amount of stones you want.

You can consider that the first and last students are always happy.

You need to find the minimum cost to make all students happy.

Input

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

The first line of each test case contains three integers $$$n,x,y$$$ $$$(1 \le n \le 10^5, 0 \le x,y \le 10^9)$$$ — the number of students, the cost of adding a stone, and the cost of removing a stone, respectively.

The second line of each test case contains $$$n$$$ integers $$$h_1, h_2, \ldots, h_n$$$ $$$(0 \le h_i \le 5 \cdot 10^3)$$$ — the length of each student.

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

Output

For each test case, print a single integer — the minimum cost to make all students happy.

Example
Input
2
4 5 5
1 6 2 5
6 2 4
5 4 5 5 4 6
Output
15
4
Note

In the first test case, the student standing in place $$$3$$$ is sad because he is shorter than the one in front of him in place $$$4$$$ and the one behind him in place $$$2$$$, to make him happy we will remove $$$3$$$ stones from the person in front of him. Thus, the lengths become as follows $$$h=[1,6,2,2]$$$ and everyone becomes happy.

In the second test case, students $$$2$$$ and $$$5$$$ are sad, so to make them happy at the lowest cost, we will add a stone below each one of them, then the lengths become as follows $$$h=[5,5,5,5,5,6]$$$.

B. A Problem You Will Hate More Than Yourself
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Shaaban found the contestants eager to participate in the competition and solve educational problems, so he wanted to disappoint everyone and give them the following problem.

You are given a tree consisting of $$$n$$$ vertices, numbered from $$$1$$$ to $$$n$$$. You need to add the minimum number of vertices to the tree such that the following conditions are satisfied after all additions:

  • the graph must still be a tree;
  • the longest path in the tree must consist of an even number of vertices;
  • there must be exactly $$$k$$$ distinct such longest paths.

Two paths are considered different if there exists at least one vertex which belongs to exactly one of the two paths.

Print the minimum number of vertices you have to add, then print the edges you added.

Input

The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 \le n \le 2 \cdot 10^5, 1 \le k \le 10^6)$$$ — the number of vertices in the tree, and the desired length of the longest paths.

Each of the following $$$n - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ $$$(1 \le u, v \le n, u \neq v)$$$ — the description of the edges of the tree. It's guaranteed that the given edges form a valid tree.

Output

Print a single integer $$$m$$$, representing the minimum number of vertices you have to add.

For each of the next $$$m$$$ lines, print two integers $$$u$$$ and $$$v$$$ $$$(1 \le u, v \le n + m)$$$ — representing an edge you added to the tree.

Example
Input
3 3
1 2
2 3
Output
3
2 4
2 5
1 6
Note
The final graph, where the length of the longest path is even, and the number of such longest paths is exactly $$$3$$$. All longest paths are: $$$(4,1), (4,5), (4,6)$$$.

C. Bit And Segment
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array of integers $$$a$$$ of length $$$n$$$. Let's say that segment $$$[l,r]$$$ is $$$i$$$-$$$th \: good$$$ if:

  • $$$1 \leq l \leq i \leq r \leq n$$$;
  • $$$ a_{l}\, \& \, a_{l+1} \, \& \, ... \, a_{i} \, \& \, ... \, a_{r-1} \, \& \,a_{r}\, =\, a_{i}$$$.

For each $$$i$$$ from $$$1$$$ to $$$n$$$, count all segments which are $$$i$$$-$$$th \: good$$$.

Here $$$\&$$$ denotes the bitwise AND operation.

Input

Each test consists of 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 contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the length of the array $$$a$$$.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^6)$$$ — the elements of the array $$$a$$$.

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

Output

For each test case, output $$$n$$$ integers on a single line — the number of $$$i$$$-$$$th \: good$$$ segments for each $$$i$$$ $$$(1 \le i \le n)$$$.

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

For the first test case, $$$a=[3,7,6,2,10]$$$.

  • The $$$1$$$-$$$th \: good$$$ segments are : $$$[1,1], [1,2]$$$.
  • The $$$2$$$-$$$th \: good$$$ segments are : $$$[2,2]$$$.
  • The $$$3$$$-$$$th \: good$$$ segments are : $$$[2,3],[3,3]$$$.
  • The $$$4$$$-$$$th \: good$$$ segments are : $$$[1,4],[2,4],[3,4],[4,4],[1,5],[2,5],[3,5],[4,5]$$$.
  • The $$$5$$$-$$$th \: good$$$ segments are : $$$[5,5]$$$.

D. Coconuting
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mouf, a little penguin from Aleppo, dreamed of sunny beaches and coconuts. One day, his penguin companions created a challenge for him to unravel, with a ticket to their island awaiting as the reward.

Mouf was given an array of integers $$$a$$$ of length $$$n$$$. Mouf's companions consider a pair of indices $$$\langle i, j \rangle$$$ $$$(1 \le i \lt j \le n)$$$ $$$\it{coconut}$$$ if there exists positive integers $$$x$$$ and $$$y$$$ such that:

  • $$$a_i = \dfrac{x^2}{y}$$$;
  • $$$a_j = \dfrac{y^2}{x}$$$.

Help Mouf find the number of $$$\it{coconut}$$$ pairs in the array $$$a$$$ to win a trip to the magical island and enjoy sunny days and coconut feasts with his companions.

Input

Each test consists of 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 contains a single integer $$$n$$$ $$$(1 \le n \le 5 \cdot 10^4)$$$ — the length of the array $$$a$$$.

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 elements of the array $$$a$$$.

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

Output

For each test case, output a single integer — the number of $$$\it{coconut}$$$ pairs in the array $$$a$$$.

Example
Input
3
2
1 1
5
2 3 2 3 2
8
2 2 2 2 4 4 8 16
Output
1
4
11

E. Lazy Fouad
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Fouad has just moved to a new city that contains $$$n$$$ houses and $$$m$$$ schools. In this problem, the city is represented as an infinite $$$2D$$$ plane, with both the schools and the houses represented as lattice points$$$^\dagger$$$ on this plane. Being a lazy person, Fouad wants to choose exactly one house and exactly one school in such a way that minimizes the Manhattan distance$$$^\ddagger$$$ between them. Please help him calculate the minimum Manhattan distance between any of the $$$n$$$ houses and any of the $$$m$$$ schools.

$$$^\dagger$$$ A lattice point is a point $$$p = (x, y)$$$ with integer coordinates $$$x$$$ and $$$y$$$.

$$$^\ddagger$$$ The Manhattan distance between two points $$$p_1 = (x_1, y_1)$$$ and $$$p_2 = (x_2, y_2)$$$ is equal to: $$$$$$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|$$$$$$

Input

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^3)$$$ — 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 2 \cdot 10^5)$$$ — the number of houses and schools respectively.

The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ $$$(1 \le a_i, b_i \le 10^{18})$$$ — the coordinates of the $$$i$$$-th house.

Rhe $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$c_i$$$ and $$$d_i$$$ $$$(1 \le c_i, d_i \le 10^{18})$$$ — the coordinates of the $$$i$$$-th school.

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

Output

For each test case, print a single integer — the minimum Manhattan distance between any of the $$$n$$$ houses and any of the $$$m$$$ schools.

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

Explanation of the example:

The above figure illustrates the first test case in the example, where $$$H_i$$$ denotes the $$$i$$$-th house and $$$S_i$$$ denotes the $$$i$$$-th school.

There are $$$6$$$ possible pairs for Fouad to choose from:

  1. $$$d(H_1, S_1) = |4 - 2| + |4 - 2| = 4$$$.
  2. $$$d(H_1, S_2) = |4 - 1| + |4 - 5| = 4$$$.
  3. $$$d(H_2, S_1) = |1 - 2| + |1 - 2| = 2$$$.
  4. $$$d(H_2, S_2) = |1 - 1| + |1 - 5| = 4$$$.
  5. $$$d(H_3, S_1) = |3 - 2| + |4 - 2| = 3$$$.
  6. $$$d(H_3, S_2) = |3 - 1| + |4 - 5| = 3$$$.

Therefore, the answer is $$$\min(\{4, 4, 2, 4, 3, 3\}) = 2$$$.

F. Fire Kings
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After a long ACPC contest, Mouf could finally buy a new Yu-Gi-Oh structure deck "Fire Kings". He was amazed by how strong this deck is, and now he is ready to duel with Jack Atlas, The Crimson King.

However, during the duel, Mouf found a little problem. Calculating the damage he inflicted on Jack is very complicated as Fire Kings monsters are burning the field! Mouf has $$$n$$$ monsters on the field, and each of them has the following five parameters:

Level $$$l$$$, strength $$$s$$$, developing rate $$$x$$$, damage suppression $$$ds$$$, and $$$t$$$, the number of turns it will remain on the field before it will be destroyed.

Every monster will do the following until the end of the $$$t_{th}$$$ turn, respectively:

  • It attacks Jack, causing $$$l \cdot s$$$ damage to him. But the attack will not disappear; instead, it will last until the $$$t_{th}$$$ turn and continue burning Jack every turn by $$$\left (\frac{l \cdot s}{ds^{tt}} \right)$$$, where $$$tt$$$ is the number of turns that have passed since the attack time.

  • The level of the monster will increase by $$$x$$$.

It took Mouf a few minutes to calculate damage fast, and now he is challenging you -yes, you bot! For every monster given in the input, output the total damage it causes during all $$$t$$$ turns modulo $$$10^9+7$$$.

Input

The first line of the input contains one integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^4)$$$ — the number of monsters Mouf has on the field.

Then next $$$n$$$ lines follows, each of them contains five integers $$$l$$$, $$$s$$$, $$$x$$$, $$$ds$$$, $$$t$$$ $$$(1 \le l, s, x, ds, t \le 10^9)$$$.

Output

Print $$$n$$$ lines, the $$$i$$$-th line contains one integer, the total damage the $$$i$$$-th monster causes to Jack Atlas, modulo $$$10^9+7$$$.

Examples
Input
1
1 8 2 2 3
Output
90
Input
3
5 4 6 9 8
2 9 5 8 3
6 9 8 1 9
Output
149564498
656250204
11070
Note

In the first test case, Mouf has a monster with these parameters: $$$l=1, s=8, x=2, ds=2, t=3$$$. Then the following will happen:

  • First turn: the monster will cause $$$1 \cdot 8 = 8$$$ damage and $$$\frac{8}{2} = 4$$$ and $$$\frac{8}{4} = 2$$$ damage on the second and third turn, respectively. After that, its level will increase by 2 and become 3.
  • Second turn: the monster will cause $$$3 \cdot 8 = 24$$$ damage and $$$\frac{24}{2} = 12$$$ damage on the third turn. After that, its level will increase and become $$$5$$$.
  • Third turn: the monster will cause $$$5 \cdot 8 = 40$$$ damage. After that, its level will increase and become $$$7$$$.

During the end of the third turn, the monster will be destroyed, and the total damage it causes is $$$8 + 4 + 2 + 24 + 12 + 40 = 90$$$.

G. Subsubsequence
time limit per test
2.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

For an array $$$a$$$, let's define the function $$$f(a)$$$ as the sum of the bitwise XOR sum of each non-empty subsequence$$$^\dagger$$$ of it.

For example, if $$$a$$$ = $$$[5 , 2 , 4]$$$, then $$$f(a) = (5 \oplus 2 \oplus 4) + (5 \oplus 2) + (5 \oplus 4) + (2 \oplus 4) + 5 + 2 + 4$$$.

Let's define an array of arrays $$$A$$$, which contains all non-empty subsequences$$$^\dagger$$$ of the array $$$a$$$.

You are given an array of $$$a$$$ of length $$$n$$$. You have to process the following $$$q$$$ updates:

  • given and index $$$i$$$ and a value $$$x$$$, set $$$a_i := x$$$;
  • print the value of $$$\displaystyle\sum_{s \in A} f(s)$$$.

Since this value could be too large, find it modulo $$$10^9 + 7$$$.

Here $$$\oplus$$$ denotes the bitwise XOR operation.

$$$\dagger$$$ A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) elements. For example, $$$[3,1]$$$ is a subsequence of $$$[3,2,1]$$$ and $$$[4,3,1]$$$, but not a subsequence of $$$[1,3,3,7]$$$ and $$$[3,10,4]$$$.

Input

The first line contains one integer $$$n$$$ $$$(1 \le n \le 10^6)$$$ — the length of the array $$$a$$$.

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

The third line contains one integer $$$q$$$ $$$(1 \le q \le 10^6)$$$ — the number of update operations.

Each of the next $$$q$$$ lines contains two integers $$$i$$$ and $$$x$$$ $$$(1 \le i \le n, 1 \le x \le 10^9)$$$ — denoting the updated index and value.

Output

After each update, output a single integer — the sum $$$\displaystyle\sum_{s \in A} f(s)$$$, modulo $$$10^9 + 7$$$.

Example
Input
3
1 2 3
3
1 2
2 5
2 7
Output
35
72
74
Note

For the first update, $$$A = [[2],[2],[3],[2,2],[2,3],[2,3],[2,2,3]]$$$, then:

$$$f([2]) + f([2]) + f([3]) + f([2,2]) + f([2,3]) + f([2,3]) + f([2,2,3]) = 2 + 2 + 3 + 4 + 6 + 6 + 12 = 35$$$.

H. Game with wife
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Besher and his wife are playing a game on $$$n$$$ piles of stones, each one contains $$$a_i$$$ stones. On each player's turn, they can do one of these actions:

  • choose $$$1$$$ non-empty pile and take $$$1$$$ stone from it.
  • choose $$$3$$$ non-empty piles of same parity of numbers of stones and take $$$1$$$ stone from each of them.

The first player who is unable to make a move loses (all piles are empty).

Given that Besher goes first, who will win the game if both players play optimally?

Input

Each test consists of 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 contains a single integer $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^{5})$$$ — the number of piles in the game.

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 elements of the array $$$a$$$, describing the initial number of stones.

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

Output

For each test case, output "YES" if Besher wins, and output "NO" otherwise.

Example
Input
3
3
1 2 3
2
1 2
1
1
Output
NO
YES
YES

I. Fofo Loves Bitset
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Our lovely judge Fofo loves "bitset" very much, and when the judges were discussing the problems to be put in this contest, he sometimes heard the word "bitset" being mentioned.

As he loves "bitset" very much, he usually says his favorite word "7as" when the solution includes "bitset" as a substring$$$^\dagger$$$, and when he does not find "bitset", he gets sad and says "no 7as for you today".

Fofo wants to automate this procedure, so can you help him do that?

$$$\dagger$$$ A string $$$t$$$ is a substring of another string $$$s$$$ if you can obtain $$$t$$$ from $$$s$$$ by deleting (several, maybe $$$0$$$) characters from the beginning of $$$s$$$ and deleting (several, maybe $$$0$$$) characters from the end of $$$s$$$.

Input

Each test consists of 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 only line of each test case contains a single string of lowercase English letters $$$s$$$ ($$$1 \le |s| \le 26$$$) — the solution to the problem.

Output

For each test case, print a single line — "7as" if the string contains "bitset", and "no 7as for you today" otherwise (without quotation marks).

Example
Input
6
fofolovesbitset
obitsetobitseto
bitnoset
blueblisteringbarnacles
thearkoffz
bitset
Output
7as
7as
no 7as for you today
no 7as for you today
no 7as for you today
7as

J. Only Two
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In this problem, you are given $$$2$$$ points describing a square (i.e. the upper right and lower left corners) such that the sides of the square are parallel to either $$$x$$$-axis and $$$y$$$-axis.

You are also given $$$n$$$ segments such that each segment is strictly inside the square and parallel to one of the axes.

You need to find whether there exist two segments $$$i$$$ and $$$j$$$ ($$$i \neq j$$$) such that if both were extended to a line, they divide the square into multiple rectangles, where only two of them are equal$$$^\dagger$$$.

$$$^\dagger$$$ Two rectangles are considered equal if their sides are equal apart from the vertical or horizontal alignment.

Input

The first line contains five integers $$$n,x_s,y_s,x_e,y_e$$$ $$$(1 \le n \le 10^5, 1 \le x_s,y_s,x_e,y_e \le 10^9)$$$ — the number of segments, and the coordinates of the lower left and upper right corners of the square.

Each of the next $$$n$$$ lines contains four integers $$$x_1, y_1, x_2, y_2$$$ $$$(1 \le x_1, y_1, x_2, y_2 \le 10^9)$$$ — the coordinates of the endpoints of the segments.

It is guaranteed that all the segments are parallel to one of the coordinate axes, and strictly lie inside the square. Segments may touch, overlap, and even completely coincide.

Output

On a single line, print the two indices of segments you chose. If there are multiple answers, you may print any of them. Otherwise, if there is no answer, print "$$$-1$$$ $$$-1$$$" (without quotation marks).

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

K. Water Filling
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $$$n$$$ water tanks, each one liter in size. Water tanks are connected by pipes, where a pipe connects tank $$$v$$$ to parent tank $$$p_v$$$. Tank $$$1$$$ is the root.

Let's define the process of filling water tank $$$v$$$ with $$$x$$$ liters as follows:

  • water fills tank $$$v$$$ with one liter;
  • if there's more water left, then while there are unfilled child tanks, water flows in the direction of the smallest (i.e., by index) tank and repeats the same process;
  • if there's more water left, it goes up and starts filling the parent tank with the same process.

Here are some examples of the process described above:

filling tank 5 with 2 litersfilling tank 6 with 4 liters

Given $$$q$$$ queries of the form $$$(v, x, u)$$$, you should answer the following task:

If $$$x$$$ liters are added to tank $$$v$$$, will tank $$$u$$$ be filled as well?

Input

Each test consists of 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 contains two integers $$$n$$$ and $$$q$$$ $$$(2 \le n, q \le 10^5)$$$ — the number of water tanks and queries respectively.

The second line of each test case contains $$$n - 1$$$ integers $$$p_2, \ldots, p_n$$$ $$$(1 \le p_i \le n)$$$ — the parent of tank $$$i$$$, i.e., there is a pipe between $$$i$$$ and $$$p_i$$$ in the tree.

Each of the next $$$q$$$ lines contains three integers $$$v_i, x_i, u_i$$$ $$$(1 \le v_i, x_i, u_i \leq n)$$$ — indicating the $$$i$$$-th query.

It is guaranteed that the given set of pipes forms a tree.

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

Output

For each query, output "YES" if the tank will be filled, and output "NO" otherwise.

Example
Input
2
6 6
1 1 2 2 3
5 2 2
5 2 1
5 2 5
6 4 3
6 4 2
6 4 4
7 7
1 1 2 2 3 3
3 2 7
3 3 7
3 2 1
3 4 1
3 3 1
3 6 4
2 3 4
Output
YES
NO
YES
YES
YES
NO
NO
YES
NO
YES
NO
YES
YES

L. Geoland
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an integer $$$n \ge 3$$$, determine if there exists a non-self-intersecting$$$^\dagger$$$ polygon with $$$n$$$ distinct vertices of integer coordinates such that:

  • no three consecutive vertices of the polygon are collinear;
  • all $$$n$$$ sides are equal.

In case such a polygon exists, provide a construction.

$$$^\dagger$$$ A polygon with $$$n$$$ distinct vertices is non-self-intersecting if no two distinct sides intersect except in the vertices.

Input

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

The first and only line of each test case contains a single integer $$$n$$$ $$$(3 \le n \le 10^4)$$$ — the number of vertices.

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

Output

For each test case:

  • If there is no such polygon, output a single line containing $$$-1$$$.
  • Otherwise, output $$$n$$$ lines the $$$i$$$-th of which contains two integers $$$x_i$$$ and $$$y_i$$$ $$$(-10^9 \le x_i, y_i \le 10^9)$$$, representing that the $$$i$$$-th point of the polygon has coordinates $$$(x_i, y_i)$$$.

If there are multiple possible answers, you may print any of them.

Example
Input
2
3
4
Output
-1
0 0
1 0
1 1
0 1
Note
The polygon is non-self-intersecting but sides are not equal. There exist a pair of three consecutive vertices $$$[6, 1, 2]$$$ and $$$[2, 3, 4]$$$ which are collinear. The polygon is self-intersecting, as there exist two distinct sides $$$[3, 4]$$$ and $$$[5, 6]$$$ that intersect in a non-vertex point.

M. Minimize Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ where $$$|a_i| = 1$$$ for each index $$$i$$$ $$$(1 \le i \le n)$$$, and two integers $$$l$$$ and $$$r$$$ $$$(l \le r)$$$.

We have a real-valued function $$$f$$$ defined as follows:

$$$$$$f(x) = \sum_{i=1}^{n} |a_i \cdot x + b_i|.$$$$$$

Suppose we randomly pick a real value $$$m$$$ in the range $$$(l \le m \le r)$$$. What is the probability that $$$f(m)$$$ equals the minimum value of $$$f$$$ in the given range $$$[l, r]$$$. More formally,

$$$$$$f(m) = \displaystyle\min_{l \le x \le r} f(x).$$$$$$

Input

Each test consists of 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 contains three integers $$$n, l, r$$$ $$$(1 \le n \le 2 \cdot 10^5, -10^9 \le l \le r \le 10^9)$$$ — the length of the array $$$a$$$, and the endpoints of the given range.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(|a_i| = 1)$$$ — the elements of the array $$$a$$$.

The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ $$$(-10^9 \le b_i \le 10^9)$$$ — the elements of the array $$$b$$$.

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

Output

For each test case, output the probability that $$$f(m)$$$ equals the minimum value of $$$f$$$ in the given range $$$[l, r]$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$.

Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if and only if $$$\dfrac{|p - q|}{\max(1, |q|)} \le 10^{-9}$$$.

Example
Input
3
1 2 2
-1
3
1 2 4
-1
3
2 3 5
1 1
-2 -4
Output
1.0000000000
0.0000000000
0.5000000000
Note

For the first test case, there is only one possible value for $$$m$$$ which satisfies $$$f(m) = \displaystyle\min_{2 \le x \le 2} f(x) = 1$$$, and it is $$$2$$$. Thus, the probability of randomly picking $$$2$$$ in the range $$$[2, 2]$$$ is $$$1$$$.

For the second test case, there is only one possible value for $$$m$$$ which satisfies $$$f(m) = \displaystyle\min_{2 \le x \le 4} f(x) = 0$$$, and it is $$$3$$$. Thus, the probability of randomly picking $$$3$$$ in the range $$$[2, 4]$$$ is $$$0$$$.

For the third test case, there is a range of possible values for $$$m$$$ which satisfies $$$f(m) = \displaystyle\min_{3 \le x \le 5} f(x) = 2$$$, and it is $$$[3, 4]$$$. Thus, if we randomly pick a value in the range $$$[3, 5]$$$, the probability that it lies in the range $$$[3, 4]$$$ is $$$\dfrac{1}{2} = 0.5$$$.

N. Larger but smaller!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an integer $$$x$$$. Find the smallest integer $$$y$$$ that satisfy the following:

  • $$$y \gt x$$$
  • $$$string(y) \lt string(x)$$$

Here, $$$string(x)$$$ is the decimal representation of $$$x$$$ (without leading zeros) as a string.

Strings are compared lexicographically$$$^\dagger$$$. For example,

  • $$$string(1111) \lt string(123)$$$;
  • $$$string(123456789) \lt string(9)$$$;
  • $$$string(33) \lt string(333)$$$.

If such an integer $$$y$$$ does not exist, print $$$-1$$$.

$$$^\dagger$$$ A string $$$s$$$ is lexicographically larger than a string $$$t$$$ if and only if one of the following holds:

  • $$$t$$$ is a prefix of $$$s$$$, but $$$s \neq t$$$;
  • in the first position where $$$s$$$ and $$$t$$$ differ, the string $$$s$$$ has a larger character (digit) than the corresponding character (digit) in $$$t$$$.
Input

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

The first and only line of each test case contains a single integer $$$x$$$ $$$(1 \le x \le 10^{18})$$$.

Output

For each test case:

  • If there is no such integer $$$y$$$, output a single line containing $$$-1$$$.
  • Otherwise, output a single line containing $$$y$$$.
Example
Input
1
9
Output
10