Summer-training-01-Intermediate
A. Assembly via Minimums
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Sasha has an array $$$a$$$ of $$$n$$$ integers. He got bored and for all $$$i$$$, $$$j$$$ ($$$i \lt j$$$), he wrote down the minimum value of $$$a_i$$$ and $$$a_j$$$. He obtained a new array $$$b$$$ of size $$$\frac{n\cdot (n-1)}{2}$$$.

For example, if $$$a=$$$ [$$$2,3,5,1$$$], he would write [$$$\min(2, 3), \min(2, 5), \min(2, 1), \min(3, 5), \min(3, 1), min(5, 1)$$$] $$$=$$$ [$$$2, 2, 1, 3, 1, 1$$$].

Then, he randomly shuffled all the elements of the array $$$b$$$.

Unfortunately, he forgot the array $$$a$$$, and your task is to restore any possible array $$$a$$$ from which the array $$$b$$$ could have been obtained.

The elements of array $$$a$$$ should be in the range $$$[-10^9,10^9]$$$.

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$2\le n\le 10^3$$$) — the length of array $$$a$$$.

The second line of each test case contains $$$\frac{n\cdot (n-1)}{2}$$$ integers $$$b_1,b_2,\dots,b_{\frac{n\cdot (n-1)}{2}}$$$ ($$$−10^9\le b_i\le 10^9$$$) — the elements of array $$$b$$$.

It is guaranteed that the sum of $$$n$$$ over all tests does not exceed $$$10^3$$$ and for each array $$$b$$$ in the test, there exists an original array.

Output

For each test case, output any possible array $$$a$$$ of length $$$n$$$.

Example
Input
5
3
1 3 1
2
10
4
7 5 3 5 3 3
5
2 2 2 2 2 2 2 2 2 2
5
3 0 0 -2 0 -2 0 0 -2 -2
Output
1 3 3
10 10
7 5 3 12
2 2 2 2 2
0 -2 0 3 5
Note

In the first sample, Sasha chose the array $$$[1,3,3]$$$, then the array $$$b$$$ will look like $$$[\min(a_1,a_2)=1, \min(a_1,a_3)=1, \min(a_2,a_3)=3]$$$, after shuffling its elements, the array can look like $$$[1,3,1]$$$.

In the second sample, there is only one pair, so the array $$$[10,10]$$$ is suitable. Another suitable array could be $$$[15,10]$$$.

B. Wara B3d Wara B3d
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your task is to determine whether it is possible to find exactly $$$m$$$ consecutive positive integers such that their total sum is exactly equal to $$$n$$$.

A sequence of numbers is considered strictly consecutive positive integers if it consists of integers greater than zero that follow each other continuously, with each subsequent number being exactly $$$1$$$ greater than the previous one. For example, $$$4, 5, 6$$$ are three consecutive positive integers, while $$$2, 4, 6$$$ (has gaps) and $$$-1, 0, 1$$$ (contains non-positive numbers) are not

Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.Each of the next $$$t$$$ lines contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^{9},1 \le m \le 10^{9}$$$) — the target sum and the required number of consecutive positive integers, respectively.

Output

For each test case, output YES if it is possible to form the sum $$$n$$$ using exactly $$$m$$$ consecutive positive integers. Otherwise, output NO.You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answer).

Example
Input
1
18 3
Output
YES
Note

for the given testcase the three consecutive integers are: 5,6,7

C. Mere Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array $$$a_1, a_2, \dots, a_n$$$ where all $$$a_i$$$ are integers and greater than $$$0$$$.

In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$). If $$$gcd(a_i, a_j)$$$ is equal to the minimum element of the whole array $$$a$$$, you can swap $$$a_i$$$ and $$$a_j$$$. $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.

Now you'd like to make $$$a$$$ non-decreasing using the operation any number of times (possibly zero). Determine if you can do this.

An array $$$a$$$ is non-decreasing if and only if $$$a_1 \le a_2 \le \ldots \le a_n$$$.

Input

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

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

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

It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

Output

For each test case, output "YES" if it is possible to make the array $$$a$$$ non-decreasing using the described operation, or "NO" if it is impossible to do so.

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

In the first and third sample, the array is already non-decreasing.

In the second sample, we can swap $$$a_1$$$ and $$$a_3$$$ first, and swap $$$a_1$$$ and $$$a_5$$$ second to make the array non-decreasing.

In the forth sample, we cannot the array non-decreasing using the operation.

D. Count The Raviolis { }
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Aziz is making raviolis today! He has rolled out a large sheet of dough that can be represented as an $$$n \times m$$$ grid of unit squares.

A ravioli is defined as any rectangular section of the dough with integer side lengths whose sides are parallel to the edges of the main grid.

Aziz's dough is magical: every time he chooses a valid rectangular area to cut, he simply notes its dimensions and position, and the dough remains intact for his next calculation.

Help Aziz find the total number of distinct ravioli (sub-rectangles) he can identify within the $$$n \times m$$$ grid.

Input

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

Each test case contains two integers $$$n,m$$$ $$$(1 \le n,m \le 10^{5})$$$– the size of the grid

Output

For each test case:

Output an integer answer modulo $$$10^9+7$$$.

Example
Input
5
1 1
2 2
2 3
3 3
50 34
Output
1
9
18
36
758625
Note

$$$n \times m$$$ ravioli roll

an image showcasing the number of cuts of the $$$2 \times 2 $$$ roll

The ways to cut the $$$2 \times 2$$$ roll:

  • four $$$ 1 \times 1$$$ raviolis
  • two $$$ 2 \times 1$$$ raviolis
  • two $$$ 1 \times 2$$$ raviolis
  • one $$$ 4 \times 4$$$ raviolis

E. Majd Aldeen's Gemstones
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Majd Aldeen, a gemologist inspecting a chain of $$$n$$$ rocks in the Hashemite desert, observes that each rock holds a gemstone labeled with a positive integer. His favorite gemstone has label $$$K$$$. He considers a contiguous subsegment of rocks interesting if it contains at least one gemstone labeled $$$K$$$.Help Majd Aldeen count the number of interesting contiguous subsegments.

Formally, given an array $$$a$$$ of $$$n$$$ positive integers, count the number of pairs $$$(L, R)$$$ such that $$$1 \le L \le R \le n$$$ and $$$a_j = K$$$ for at least one index $$$j$$$ satisfying $$$L \le j \le R$$$.

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 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 $$$K$$$ ($$$1 \leq n \leq 2\times10^5$$$ , $$$1 \leq K \leq 10^9$$$) — the length of the array and the target value.

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

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

Output

For each test case, output a single integer — the number of contiguous subsegments that contain $$$K$$$ at least once.

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

In the first test case, the array is $$$[1, 2, 3, 2]$$$ and $$$K = 2$$$. The $$$8$$$ interesting subsegments are: $$$[1, 2]$$$, $$$[2]$$$ , $$$[2, 3]$$$, $$$[1, 2, 3]$$$, $$$[2]$$$ , $$$[3, 2]$$$, $$$[2, 3, 2]$$$, and $$$[1, 2, 3, 2]$$$.

In the second test case, the array is $$$[1, 2, 3]$$$ and $$$K = 5$$$. No element equals $$$5$$$, so the answer is $$$0$$$.