1076_B. Divisor Subtraction

You are given an integer number n. The following algorithm is applied to it:

  1. if n = 0, then end algorithm;
  2. find the smallest prime divisor d of n;
  3. subtract d from n and go to step 1.

Determine the number of subtrations the algorithm will make.

Input

The only line contains a single integer n (2 ≤ n ≤ 10^{10}).

Output

Print a single integer — the number of subtractions the algorithm will make.

Examples

Input

5

Output

1

Input

4

Output

2

Note

In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.

In the second example 2 is the smallest prime divisor at both steps.

```python
from collections import deque as de
import math
class My_stack():
    def __init__(self):
        self.data = []
    def my_push(self, x):
        return (self.data.append(x))
    def my_pop(self):
        return (self.data.pop())
    def my_peak(self):
        return (self.data[-1])
    def my_contains(self, x):
        return (self.data.count(x))
    def my_show_all(self):
        return (self.data)
    def isEmpty(self):
      return len(self.data)==0

arrStack = My_stack()
# A optimized school method based
# Python3 program to check
# if a number is prime

def isPrime(n) :

	# Corner cases
	if (n <= 1) :
		return False
	if (n <= 3) :
		return True

	# This is checked so that we can skip
	# middle five numbers in below loop
	if (n % 2 == 0 or n % 3 == 0) :
		return False

	i = 5
	while(i * i <= n) :
		if (n % i == 0 or n % (i + 2) == 0) :
			return False
		i = i + 6

	return True

def get_prime_factors(number):
    # create an empty list and later I will
    # run a for loop with range() function using the append() method to add elements to the list.
    prime_factors = []

    # First get the number of two's that divide number
    # i.e the number of 2's that are in the factors
    while number % 2 == 0:
        prime_factors.append(2)
        number = number / 2

    # After the above while loop, when number has been
    # divided by all the 2's - so the number must be odd at this point
    # Otherwise it would be perfectly divisible by 2 another time
    # so now that its odd I can skip 2 ( i = i + 2) for each increment
    for i in range(3, int(math.sqrt(number)) + 1, 2):
        while number % i == 0:
            prime_factors.append(int(i))
            number = number / i

    # Here is the crucial part.
    # First quick refreshment on the two key mathematical conjectures of Prime factorization of any non-Prime number
    # Which is - 1. If n is not a prime number AT-LEAST one Prime factor would be less than sqrt(n)
    # And - 2. If n is not a prime number - There can be AT-MOST 1 prime factor of n greater than sqrt(n).
    # Like 7 is a prime-factor for 14 which is greater than sqrt(14)
    # But if the above loop DOES NOT go beyond square root of the initial n.
    # Then how does that greater than sqrt(n) prime-factor
    # will be captured in my prime factorization function.
    # ANS to that is - in my first for-loop I am dividing n with the prime number if that prime is a factor of n.
    # Meaning, after this first for-loop gets executed completely, the adjusted initial n should become
    # either 1 or greater than 1
    # And if n has NOT become 1 after the previous for-loop, that means that
    # The remaining n is that prime factor which is greater that the square root of initial n.
    # And that's why in the next part of my gorithm, I need to check whether n becomes 1 or not,
    #This code is taken ny rohan paul's github
    if number > 2:
        prime_factors.append(int(number))

    return prime_factors
n=int(input())
if isPrime(n):
    print(1)
else:
    if n%2:
        l=get_prime_factors(n)
        print(((n-l[0])//2)+1)
    else:
        print(n//2)
```


1097_B. Petr and a Combination Lock

Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero:

<image>

Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero.

This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again.

Input

The first line contains one integer n (1 ≤ n ≤ 15) — the number of rotations.

Each of the following n lines contains one integer a_i (1 ≤ a_i ≤ 180) — the angle of the i-th rotation in degrees.

Output

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.

You can print each letter in any case (upper or lower).

Examples

Input

3
10
20
30

Output

YES

Input

3
10
10
10

Output

NO

Input

3
120
120
120

Output

YES

Note

In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.

In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.

In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.

```python
n = int(input())
a = [0]
for _ in range(n):
    curr = int(input())
    mods = []
    for o in a:
        mods.extend([o + curr, o - curr])
    a = mods[:]
#print(a)
print("YES" if any(x%360 == 0 for x in a) else "NO")

```


1118_C. Palindromic Matrix

Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.

For example, the following matrices are palindromic:

<image>

The following matrices are not palindromic because they change after the order of rows is reversed:

<image>

The following matrices are not palindromic because they change after the order of columns is reversed:

<image>

You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".

Input

The first line contains one integer n (1 ≤ n ≤ 20).

The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.

Output

If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.

If it's impossible to construct any matrix, then print "NO".

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

Examples

Input

4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1

Output

YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1

Input

3
1 1 1 1 1 3 3 3 3

Output

YES
1 3 1
3 1 3
1 3 1

Input

4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1

Output

NO

Input

1
10

Output

YES
10

Note

Note that there exist multiple answers for the first two examples.

```python
import os
from io import BytesIO, StringIO
#input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import defaultdict

def input_as_list():
    return list(map(int, input().split()))

def array_of(f, *dim):
    return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f()

def main():
    n = int(input())
    a = input_as_list()

    out = array_of(int, n, n)

    def put(x, i, j):
        out[i][j] = x
        out[n-i-1][j] = x
        out[i][n-j-1] = x
        out[n-i-1][n-j-1] = x

    d = defaultdict(int)
    for x in a:
        d[x] += 1

    if n%2 == 0:
        for v in d.values():
            if v%4 != 0:
                print('NO')
                return
        ix = 0
        for k in d.keys():
            for _ in range(d[k]//4):
                i, j = divmod(ix, n//2)
                put(k, i, j)
                ix += 1
    else:
        ones = []
        twos = []
        fours = []

        for k, v in d.items():
            if v%2 != 0:
                if ones:
                    print('NO')
                    return
                else:
                    ones.append(k)
                    d[k] -= 1

        for k, v in d.items():
            if v%4 != 0:
                if len(twos) >= n:
                    print('NO')
                    return
                else:
                    twos.append(k)
                    d[k] -= 2

        for k, v in d.items():
            if v%4 != 0:
                print('NO')
                return
            else:
                for _ in range(v//4):
                    fours.append(k)

        if not ones:
            print('NO')
            return

        while len(twos) < n-1:
            k = fours.pop()
            twos.append(k)
            twos.append(k)

        ix = 0
        for k in fours:
            i, j = divmod(ix, n//2)
            put(k, i, j)
            ix += 1

        for i in range(n//2):
            k = twos.pop()
            put(k, i, n//2)

        for i in range(n//2):
            k = twos.pop()
            put(k, n//2, i)

        put(ones[0], n//2, n//2)

    out_str = ['YES\n']
    for i in range(n):
        for j in range(n):
            out_str.append(str(out[i][j]) + ' ')
        out_str.append('\n')
    print(''.join(out_str))

main()
```


1144_F. Graph Without Long Directed Paths

You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph.

You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).

Input

The first line contains two integer numbers n and m (2 ≤ n ≤ 2 ⋅ 10^5, n - 1 ≤ m ≤ 2 ⋅ 10^5) — the number of vertices and edges, respectively.

The following m lines contain edges: edge i is given as a pair of vertices u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i). There are no multiple edges in the given graph, i. e. for each pair (u_i, v_i) there are no other pairs (u_i, v_i) and (v_i, u_i) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).

Output

If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line.

Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length m. The i-th element of this string should be '0' if the i-th edge of the graph should be directed from u_i to v_i, and '1' otherwise. Edges are numbered in the order they are given in the input.

Example

Input

6 5
1 5
2 1
1 4
3 1
6 1

Output

YES
10100

Note

The picture corresponding to the first example: <image>

And one of possible answers: <image>

```python
# lista doble enlazada o(1) en operaciones en los bordes
from collections import deque

def solve():
    global n, m
    n, m = map(lambda x: int(x), input().split())
    global maxValue
    maxValue = n**2
    graph = [[] for _ in range(0, n)]
    edges = []
    for _ in range(0, m):
        u, v = map(lambda x: int(x)-1, input().split())
        graph[u].append(v)
        graph[v].append(u)
        edges.append(v)

    distance = bfs_2k(graph, 0)
    if distance is None:
        print("NO")
    else:
        print("YES")
        print("".join(str(distance[e] % 2) for e in edges))

def bfs_2k(graph, initVertex):
    dist = [maxValue]*n
    queue = deque()
    queue.append(initVertex)
    dist[initVertex] = 0
    while queue:
        u = queue.popleft()
        for v in graph[u]:
            if(dist[v] == maxValue):
                dist[v] = dist[u] + 1
                queue.append(v)
            elif (dist[u] - dist[v]) % 2 == 0:
                return None
    return dist

solve()

```


1165_E. Two Arrays and Sum of Functions

You are given two arrays a and b, both of length n.

Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i.

Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.

The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b.

Output

Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder.

Examples

Input

5
1 8 7 2 4
9 7 2 9 3

Output

646

Input

1
1000000
1000000

Output

757402647

Input

2
1 3
4 2

Output

20

```python
m=998244353
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted([a[i]*(i+1)*(n-i) for i in range(n)])
b.sort(reverse=True)
ans=0
for i in range(n):
    ans=(ans+(a[i]*b[i])%m)%m
print(ans)

```


1184_D1. Parallel Universes (Easy)

The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.

Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe.

The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m.

Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.

More specifically,

  * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.
  * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist.

Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.

Input

The first line contains four integers n, k, m and t (2 ≤ k ≤ n ≤ m ≤ 250, 1 ≤ t ≤ 1000).

Each of the following t lines is in one of the following formats:

  * "1 i" — meaning that a universe is inserted at the position i (1 ≤ i ≤ l + 1), where l denotes the current length of the multiverse.
  * "0 i" — meaning that the i-th link is broken (1 ≤ i ≤ l - 1), where l denotes the current length of the multiverse.

Output

Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor.

It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse.

Example

Input

5 2 10 4
0 1
1 1
0 4
1 2

Output

4 1
5 2
4 2
5 3

Note

The multiverse initially consisted of 5 universes, with the Doctor being in the second.

First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.

Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.

Then, the rightmost link was broken.

Finally, a universe was added between the first and the second universe.

```python
n,k,m,t=map(int,input().split())
for i in range(t):
    a,b=map(int,input().split())
    if a==1:
        if b<=k:
            k+=1
        n+=1
        print(n,k)
    else :
        if k>b:
            n=n-b
            k=k-b
        else :
            n=b
        print(n,k)

```


1203_A. Circle of Students

There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).

Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after the student 1 in clockwise order (there are no students between them), the student 3 comes right after the student 2 in clockwise order, and so on, and the student n comes right after the student n - 1 in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student i should be right after the student i - 1 in counterclockwise order (this condition should be met for every i from 2 to n).

For example, if the indices of students listed in clockwise order are [2, 3, 4, 5, 1], then they can start a clockwise round dance. If the students have indices [3, 2, 1, 4] in clockwise order, then they can start a counterclockwise round dance.

Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 200) — the number of queries. Then q queries follow.

The first line of the query contains one integer n (1 ≤ n ≤ 200) — the number of students.

The second line of the query contains a permutation of indices p_1, p_2, ..., p_n (1 ≤ p_i ≤ n), where p_i is the index of the i-th student (in clockwise order). It is guaranteed that all p_i are distinct integers from 1 to n (i. e. they form a permutation).

Output

For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".

Example

Input

5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4

Output

YES
YES
NO
YES
YES

```python
t=int(input())
while t:
	n=int(input())
	a=list(map(int,input().split()))
	b=[0]*n
	for i in range(n):
		b[a[i]-1]=i+1
	k=0
	flag=0
	# print(b)
	if n==1:
		print("YES")
	elif abs(b[0]-b[1])==1 or abs(b[0]-b[1])==n-1:
		if abs(b[0]-b[1])==1:
			k=b[0]-b[1]
		else:
			k=b[1]-b[2]
		for j in range(1,n):
			if j==n-1:
				if b[j]-b[0]==k or abs(b[j]-b[0])==n-1:
					print("YES")
			else:
				if b[j]-b[j+1]!=k and abs(b[j]-b[j+1])!=n-1:
					flag=1
					break
		if flag:
			print("NO")
	else:
		print("NO")
	t-=1
```


121_C. Lucky Permutation

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 109) — the number of elements in the permutation and the lexicographical number of the permutation.

Output

If the k-th permutation of numbers from 1 to n does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes i, that i and ai are both lucky numbers.

Examples

Input

7 4

Output

1

Input

4 7

Output

1

Note

A permutation is an ordered set of n elements, where each integer from 1 to n occurs exactly once. The element of permutation in position with index i is denoted as ai (1 ≤ i ≤ n). Permutation a is lexicographically smaller that permutation b if there is such a i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Let's make a list of all possible permutations of n elements and sort it in the order of lexicographical increasing. Then the lexicographically k-th permutation is the k-th element of this list of permutations.

In the first sample the permutation looks like that:

1 2 3 4 6 7 5

The only suitable position is 4.

In the second sample the permutation looks like that:

2 1 3 4

The only suitable position is 4.

```python
def lucky(x):
    s=str(x)
    return s.count('4')+s.count('7')==len(s)

def Gen_lucky(n):
    if(len(n)==1):
        if(n<"4"):
            return 0
        if(n<"7"):
            return 1
        return 2
    s=str(n)
    if(s[0]<'4'):
        return 0
    if(s[0]=='4'):
        return Gen_lucky(s[1:])
    if(s[0]<'7'):
        return 2**(len(s)-1)
    if(s[0]=='7'):
        return 2**(len(s)-1)+Gen_lucky(s[1:])
    else:
        return 2**len(s)

def Form(X,k):
    if(k==0):
        return X
    for i in range(len(X)):
        if(k>=F[len(X)-i-1]):
            h=k//F[len(X)-i-1]
            r=k%F[len(X)-i-1]
            G=list(X[i+1:])
            G.remove(X[i+h])
            G=[X[i]]+G
            return Form(X[:i]+[X[i+h]]+G,r)

p=1

F=[1]
i=1
while(p<=10**15):
    p*=i
    F.append(p)
    i+=1

n,k=map(int,input().split())

if(n<=14):
    if(k>F[n]):
        print(-1)
    else:
        L=Form(list(range(1,n+1)),k-1)
        x=0
        for i in range(n):
            if(lucky(i+1) and lucky(L[i])):
                x+=1
        print(x)
else:
    L=Form(list(range(n-14,n+1)),k-1)
    ss=str(n-15)
    x=0
    for i in range(1,len(ss)):
        x+=2**i
    x+=Gen_lucky(ss)
    for i in range(n-14,n+1):
        if(lucky(L[i-n+14]) and lucky(i)):
            x+=1
    print(x)

```


1244_G. Running in Pairs

Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition!

Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds.

The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track.

The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks).

You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds.

Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = ∑_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it.

Input

The first line contains two integers n and k (1 ≤ n ≤ 10^6, 1 ≤ k ≤ n^2) — the number of runners on each track and the maximum possible duration of the competition, respectively.

Output

If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1.

Otherwise, print three lines. The first line should contain one integer sum — the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, all p_i should be pairwise distinct) — the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≤ q_i ≤ n, all q_i should be pairwise distinct) — the numbers of runners on the second track in the order they participate in the competition. The value of sum = ∑_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them.

Examples

Input

5 20

Output

20
1 2 3 4 5
5 2 4 3 1

Input

3 9

Output

8
1 2 3
3 2 1

Input

10 54

Output

-1

Note

In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration.

In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3.

```python
n, t = [int(i) for i in input().split()]
import os

def tr(qq):
    return (qq*(qq+1))//2
if t < tr(n):
    print(-1)
    exit()
upp = 2 * (tr(n) - tr(n//2))
if n % 2 == 1:
    upp -= (n+1)//2

if t >= upp:
    # print(upp)
    # exit()
    os.write(1, (str(upp) + '\n').encode())
    ans = list(range(1, n+1))
    # print(*ans)
    # for i in range(n//2):
    #     ans[i] = n - i
    os.write(1, (' '.join([str(a) for a in ans]) + '\n').encode())
    ans.reverse()
    # // print(*ans)
    os.write(1, (' '.join([str(a) for a in ans]) + '\n').encode())
    exit()

for k in range(n//2, n+1):
    goal = t - tr(n) + tr(k) - n

    lo = tr(k-1)
    hi = lo + (k-1)*(n-k)

    # print(goal, lo, hi)

    if goal >= lo and goal <= hi:
        #p q
        ex = goal - lo
        p = ex // (k-1)
        q = ex % (k-1)
        ansl = list(range(1 + p, k + p))
        for i in range(q):
            ansl[k-2-i] += 1
        ansls = set(ansl)
        ansr = []
        for i in range(1, n):
            if i not in ansls:
                ansr.append(i)

        ans = ansl + [n] + ansr
        # print(t)
        os.write(1, (str(t) + '\n').encode())
        # print(*list(range(1,n+1)))
        os.write(1, (' '.join([str(a) for a in range(1,n+1)]) + '\n').encode())
        # // print(*ans)
        os.write(1, (' '.join([str(a) for a in ans]) + '\n').encode())
        exit()

1//0
```


1286_A. Garland

Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.

<image>

Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by 2). For example, the complexity of 1 4 2 3 5 is 2 and the complexity of 1 3 5 7 6 4 2 is 1.

No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of light bulbs on the garland.

The second line contains n integers p_1,\ p_2,\ …,\ p_n (0 ≤ p_i ≤ n) — the number on the i-th bulb, or 0 if it was removed.

Output

Output a single number — the minimum complexity of the garland.

Examples

Input

5
0 5 0 2 3

Output

2

Input

7
1 0 0 5 0 0 2

Output

1

Note

In the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only (5, 4) and (2, 3) are the pairs of adjacent bulbs that have different parity.

In the second case, one of the correct answers is 1 7 3 5 6 4 2.

```python
def ip():
    n=int(input())
    a=list(map(int,input().split()))
    rem=set([i for i in range(1,n+1)])-set(a)
    if n==1:
        return 0
    o=e=0
    for i in rem:
        if i%2==0:
            e+=1
        else:
            o+=1
    ct=0
    i=0
    while i<len(a) and a[i]==0:
        i+=1
    if i==len(a):
        return 1
    else:
        startodd=starteven=endodd=endeven=0
        es=[]
        os=[]
        if i!=0:
            if a[i]%2==0:
                starteven=i
            else:
                startodd=i
        start=i
        i=len(a)-1
        end=0
        while i>=0 and a[i]==0:
            i-=1
            end+=1
        if end!=0:
            if a[i]%2==0:
                endeven=end
            else:
                endodd=end
        end=i
        prev=start

        for i in range(start+1,end+1):
            if a[i]==0:
                continue
            if i-prev>1:
                if a[i]%2==0 and a[prev]%2==0:
                    es.append(i-prev-1)
                elif a[i]%2!=0 and a[prev]%2!=0:
                    os.append(i-prev-1)
                else:
                    ct+=1
            elif i-prev==1:
                if a[i]%2!=a[prev]%2:
                    ct+=1
            prev=i
        os.sort(reverse=True)
        es.sort(reverse=True)
        while os and os[-1]<=o:
            o-=os[-1]
            os.pop()
        if startodd!=0 and o>=startodd:
            o-=startodd

            startodd=0
        elif startodd!=0:
            os.append(startodd)
        if endodd!=0 and o>=endodd:
            o-=endeven
            endodd=0
        elif endodd!=0:
            os.append(endodd)
        ct+=max((len(os))*2,0)
        while es and es[-1]<=e:
            e-=es[-1]
            es.pop()

        if starteven!=0 and e>=starteven:
            e-=starteven
            starteven=0

        elif starteven!=0:
            es.append(starteven)
        if endeven!=0 and e>=endeven:
            e-=endeven
            endeven=0
        elif endeven!=0:
            es.append(endeven)
        ct+=max((len(es))*2,0)
        if startodd!=0 and startodd in os or startodd+o in os:
            ct-=1
        if starteven!=0 and starteven in es or starteven+e in es:
            ct-=1
        if endodd!=0 and endodd in os or endodd+o in os:
            ct-=1
        if endeven!=0 and endeven in es or endeven+e in es:
            ct-=1
        return ct
print(ip())

```


1305_B. Kuroni and Simple Strings

Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!

We say that a string formed by n characters '(' or ')' is simple if its length n is even and positive, its first n/2 characters are '(', and its last n/2 characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.

Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'.

Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.

Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?

A sequence of characters a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.

Input

The only line of input contains a string s (1 ≤ |s| ≤ 1000) formed by characters '(' and ')', where |s| is the length of s.

Output

In the first line, print an integer k — the minimum number of operations you have to apply. Then, print 2k lines describing the operations in the following format:

For each operation, print a line containing an integer m — the number of characters in the subsequence you will remove.

Then, print a line containing m integers 1 ≤ a_1 < a_2 < ... < a_m — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string.

If there are multiple valid sequences of operations with the smallest k, you may print any of them.

Examples

Input

(()((

Output

1
2
1 3

Input

)(

Output

0

Input

(()())

Output

1
4
1 2 5 6

Note

In the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices 2 and 3, which results in the same final string.

In the second sample, it is already impossible to perform any operations.

```python
s = input()

to_ans = [False for _ in range(len(s))]
def solve(s, left, right): #right inclusive
	if left >= right:
		return
	while left <= right and s[left] == ")":
		left += 1
	while right >= left and s[right] == "(":
		right -= 1
	if left >= right:
		return
	else:
		to_ans[left] = True
		to_ans[right] = True
		solve(s, left+1, right-1)

solve(s, 0, len(s)-1)

if sum(to_ans) == 0:
	print(0)
else:
	print(1)
	print(sum(to_ans))
	print(" ".join([str(item + 1) for item in range(len(s)) if to_ans[item]]))

```


1349_D. Slime and Biscuits

Slime and his n friends are at a party. Slime has designed a game for his friends to play.

At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random uniform player among n-1 players except himself. The game stops when one person will have all the biscuits.

As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.

For convenience, as the answer can be represented as a rational number p/q for coprime p and q, you need to find the value of (p ⋅ q^{-1})mod 998 244 353. You can prove that qmod 998 244 353 ≠ 0.

Input

The first line contains one integer n\ (2≤ n≤ 100 000): the number of people playing the game.

The second line contains n non-negative integers a_1,a_2,...,a_n\ (1≤ a_1+a_2+...+a_n≤ 300 000), where a_i represents the number of biscuits the i-th person own at the beginning.

Output

Print one integer: the expected value of the time that the game will last, modulo 998 244 353.

Examples

Input

2
1 1

Output

1

Input

2
1 2

Output

3

Input

5
0 0 0 0 35

Output

0

Input

5
8 4 2 0 1

Output

801604029

Note

For the first example, in the first second, the probability that player 1 will give the player 2 a biscuit is 1/2, and the probability that player 2 will give the player 1 a biscuit is 1/2. But anyway, the game will stop after exactly 1 second because only one player will occupy all biscuits after 1 second, so the answer is 1.

```python
import os
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
#  list(map(int, input().split()))
#####################################################################################

class CF(object):
    def __init__(self):
        self.mod = 998244353
        self.n = int(input())
        self.a = list(map(int, input().split()))
        self.tot = sum(self.a)
        self.dp = [[0,0] for _ in range(self.tot+1)]

    def inv(self, x):
        return pow(x, self.mod - 2, self.mod)

    def gao(self):
        self.dp[0] = [0,1]
        self.dp[1] = [(1-self.n+self.mod)%self.mod, 1]
        for k in range(1, self.tot):
            temp = self.inv(self.tot-k)
            self.dp[k+1][0] = -self.tot*(self.n - 1) - self.dp[k][0] * (2*k - self.tot- k*self.n) - self.dp[k-1][0] *k*(self.n-1)
            self.dp[k+1][0] *= temp
            self.dp[k+1][0] = (self.dp[k+1][0] %self.mod+self.mod)%self.mod
            self.dp[k+1][1] = -self.dp[k][1]*(2*k - self.tot- k*self.n) - self.dp[k-1][1]*k*(self.n-1)
            self.dp[k+1][1] *= temp
            self.dp[k+1][1] = (self.dp[k+1][1] %self.mod+self.mod)%self.mod

        alpha = -self.dp[self.tot][0]*self.inv(self.dp[self.tot][1])
        alpha = (alpha%self.mod + self.mod)%self.mod
        #print(alpha)
        ans=0
        for i in range(self.n):
            ans += self.dp[self.a[i]][0] + self.dp[self.a[i]][1] * alpha
            ans = (ans%self.mod+self.mod)%self.mod
        ans -= alpha * (self.n - 1)
        ans = (ans%self.mod+self.mod)%self.mod
        ans *= self.inv(self.n)
        ans = (ans%self.mod+self.mod)%self.mod
        print(ans)

    def main(self):
        self.gao()
        pass

if __name__ == "__main__":
    cf = CF()
    cf.main()
    pass

'''
dp[k+1] *(tot-k) = -tot*(n-1) - dp[k]*(2*k - tot- k*n ) - dp[k-1] *k*(n-1)

'''
```


136_B. Ternary Logic

Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it).

It turned out that the operation does exist (however, it is called tor) and it works like this. Suppose that we need to calculate the value of the expression a tor b. Both numbers a and b are written in the ternary notation one under the other one (b under a). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 tor 5010 = 01123 tor 12123 = 10213 = 3410.

Petya wrote numbers a and c on a piece of paper. Help him find such number b, that a tor b = c. If there are several such numbers, print the smallest one.

Input

The first line contains two integers a and c (0 ≤ a, c ≤ 109). Both numbers are written in decimal notation.

Output

Print the single integer b, such that a tor b = c. If there are several possible numbers b, print the smallest one. You should print the number in decimal notation.

Examples

Input

14 34

Output

50

Input

50 34

Output

14

Input

387420489 225159023

Output

1000000001

Input

5 5

Output

0

```python
def untor(a, c):
    res = ''
    while a or c:
        a, ma = divmod(a, 3)
        c, mc = divmod(c, 3)
        x = 0
        while (ma + x)%3 != mc:
            x += 1
        res = str(x) + res
    try:
        return int(res, 3)
    except Exception as e:
        return 0

a, c = map(int, input().split())
print(untor(a, c))

```


1392_B. Omkar and Infinity Clock

Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:

You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k operations with this array.

Define one operation as the following:

  1. Set d to be the maximum value of your array.
  2. For every i from 1 to n, replace a_{i} with d-a_{i}.

The goal is to predict the contents in the array after k operations. Please help Ray determine what the final sequence will look like!

Input

Each test contains multiple test cases. The first line contains the number of cases t (1 ≤ t ≤ 100). Description of the test cases follows.

The first line of each test case contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 10^{18}) – the length of your array and the number of operations to perform.

The second line of each test case contains n integers a_{1},a_{2},...,a_{n} (-10^9 ≤ a_{i} ≤ 10^9) – the initial contents of your array.

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

Output

For each case, print the final version of array a after k operations described above.

Example

Input

3
2 1
-199 192
5 19
5 -1 4 2 0
1 2
69

Output

391 0
0 6 1 3 5
0

Note

In the first test case the array changes as follows:

  * Initially, the array is [-199, 192]. d = 192.

  * After the operation, the array becomes [d-(-199), d-192] = [391, 0].

```python
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    ar=list(map(int,input().split()))
    m=max(ar)
    new=[]
    for i in range(n):
        new.append(m-ar[i])
    if k%2==0:
        mx=max(new)
        for j in range(n):
            new[j]=mx-new[j]

    print(*new)

```


1433_C. Dominant Piranha

There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.

Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.

Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:

  * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
  * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.

When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).

Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.

Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.

For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:

  * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
  * The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
  * The piranha eats the first piranha and a becomes [\underline{7}, 5].
  * The piranha eats the second piranha and a becomes [\underline{8}].

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.

The first line of the test case contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9), where a_i is the size of the i-th piranha.

It is guaranteed that the sum of n does not exceed 3 ⋅ 10^5 (∑ n ≤ 3 ⋅ 10^5).

Output

For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.

Example

Input

6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5

Output

3
-1
4
3
3
1

Note

The first test case of the example is described in the problem statement.

In the second test case of the example, there are no dominant piranhas in the aquarium.

In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium.

```python
for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	if len(set(l))==1:
		print(-1)
	else:
		m=max(l)
		for i in range(n):
			if i>0:
				if i<n-1:
					if l[i]==m and (l[i-1]<m or l[i+1]<m):
						print(i+1)
						break
				else:
					if l[i]==m and l[i-1]<m:
						print(i+1)
						break
			else:
				if l[i]==m and l[i+1]<m:
					print(i+1)
					break
```


1458_B. Glass Half Spilled

There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water.

You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, because of the glasses' awkward shape (and totally unrelated to your natural clumsiness), each time you try to transfer any amount of water, half of the amount is spilled on the floor.

Formally, suppose a glass i currently contains c_i units of water, and a glass j contains c_j units of water. Suppose you try to transfer x units from glass i to glass j (naturally, x can not exceed c_i). Then, x / 2 units is spilled on the floor. After the transfer is done, the glass i will contain c_i - x units, and the glass j will contain min(a_j, c_j + x / 2) units (excess water that doesn't fit in the glass is also spilled).

Each time you transfer water, you can arbitrarlly choose from which glass i to which glass j to pour, and also the amount x transferred can be any positive real number.

For each k = 1, …, n, determine the largest possible total amount of water that can be collected in arbitrarily chosen k glasses after transferring water between glasses zero or more times.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of glasses.

The following n lines describe the glasses. The i-th of these lines contains two integers a_i and b_i (0 ≤ b_i ≤ a_i ≤ 100, a_i > 0) — capacity, and water amount currently contained for the glass i, respectively.

Output

Print n real numbers — the largest amount of water that can be collected in 1, …, n glasses respectively. Your answer will be accepted if each number is within 10^{-9} absolute or relative tolerance of the precise answer.

Example

Input

3
6 5
6 5
10 2

Output

7.0000000000 11.0000000000 12.0000000000

Note

In the sample case, you can act as follows:

  * for k = 1, transfer water from the first two glasses to the third one, spilling (5 + 5) / 2 = 5 units and securing 2 + (5 + 5) / 2 = 7 units;
  * for k = 2, transfer water from the third glass to any of the first two, spilling 2 / 2 = 1 unit and securing 5 + 5 + 2 / 2 = 11 units;
  * for k = 3, do nothing. All 5 + 5 + 2 = 12 units are secured.

```python
n=int(input())
dp=[[-10**8]*(10002) for _ in range(n+1)]
dp[0][0]=0
total=0
for i in range(n):
    a,b=map(int,input().split())
    total+=b
    for k in range(n-1,-1,-1):
        for c in range(10001-a,-1,-1):
            dp[k+1][c+a]=max(dp[k+1][c+a],dp[k][c]+b)
ans = [0 for i in range(n+1)]
for j in range(1,n+1):
    maxi = 0
    for i in range(10002):
        con = dp[j][i]
        maxi = max(maxi,min(i, (con+total)/2))
    ans[j]=maxi
for i in range(1,n+1):
    print(ans[i],end=' ')
```


1481_B. New Colony

After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you).

<image>

You are given an array h_1, h_2, ..., h_n, where h_i is the height of the i-th mountain, and k — the number of boulders you have.

You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is h_i):

  * if h_i ≥ h_{i + 1}, the boulder will roll to the next mountain;
  * if h_i < h_{i + 1}, the boulder will stop rolling and increase the mountain height by 1 (h_i = h_i + 1);
  * if the boulder reaches the last mountain it will fall to the waste collection system and disappear.

You want to find the position of the k-th boulder or determine that it will fall into the waste collection system.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.

Each test case consists of two lines. The first line in each test case contains two integers n and k (1 ≤ n ≤ 100; 1 ≤ k ≤ 10^9) — the number of mountains and the number of boulders.

The second line contains n integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 100) — the height of the mountains.

It is guaranteed that the sum of n over all test cases does not exceed 100.

Output

For each test case, print -1 if the k-th boulder will fall into the collection system. Otherwise, print the position of the k-th boulder.

Example

Input

4
4 3
4 1 2 3
2 7
1 8
4 5
4 1 2 3
3 1
5 3 1

Output

2
1
-1
-1

Note

Let's simulate the first case:

  * The first boulder starts at i = 1; since h_1 ≥ h_2 it rolls to i = 2 and stops there because h_2 < h_3.
  * The new heights are [4,2,2,3].
  * The second boulder starts at i = 1; since h_1 ≥ h_2 the boulder rolls to i = 2; since h_2 ≥ h_3 the boulder rolls to i = 3 and stops there because h_3 < h_4.
  * The new heights are [4,2,3,3].
  * The third boulder starts at i = 1; since h_1 ≥ h_2 it rolls to i = 2 and stops there because h_2 < h_3.
  * The new heights are [4,3,3,3].

The positions where each boulder stopped are the following: [2,3,2].

In the second case, all 7 boulders will stop right at the first mountain rising its height from 1 to 8.

The third case is similar to the first one but now you'll throw 5 boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to [4, 3, 3, 3], that's why the other two boulders will fall into the collection system.

In the fourth case, the first and only boulders will fall straight into the collection system.

```python
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

def input(): return sys.stdin.readline().rstrip("\r\n")

# n = 0
# m = 0

# n = int(input())

# li = [int(i) for i in input().split()]

# s = sorted(li)

mo = 998244353

def exgcd(a, b):
    if not b:
        return 1, 0
    y, x = exgcd(b, a % b)
    y -= a//b * x
    return x, y

def getinv(a, m):
    x, y = exgcd(a, m)
    return -(-1) if x == 1 else x % m

def comb(n, b):
    res = 1
    b = min(b, n-b)
    for i in range(b):
        res = res*(n-i)*getinv(i+1, mo) % mo
        # res %= mo
    return res % mo

def quickpower(a, n):
    res = 1
    while n:
        if n & 1:
            res = res * a % mo
        n >>= 1
        a = a*a % mo
    return res

def dis(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])

def getpref(x):
    if x > 1:
        return (x)*(x-1) >> 1
    else:
        return 0

def orafli(upp):
    primes = []
    marked = [False for i in range(upp+3)]
    for i in range(2, upp):
        if not marked[i]:
            primes.append(i)
        for j in primes:
            if i*j >= upp:
                break
            marked[i*j] = True
            if i % j == 0:
                break
    return primes

t = int(input())

for ti in range(t):
    n, k = map(int, input().split())
    li = [int(i) for i in input().split()]
    # s = input()
    ans = 0
    for i in range(k):
        for j in range(n):
            if j==n-1:
                ans = -1
                break
            else:
                if li[j+1]>li[j]:
                    li[j]+=1
                    ans = j+1
                    break
        if ans == -1:
            break
    print(ans)

```


1508_C. Complete the MST

As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows.

You are given an undirected complete graph with n nodes, where some edges are pre-assigned with a positive weight while the rest aren't. You need to assign all unassigned edges with non-negative weights so that in the resulting fully-assigned complete graph the [XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) sum of all weights would be equal to 0.

Define the ugliness of a fully-assigned complete graph the weight of its [minimum spanning tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree), where the weight of a spanning tree equals the sum of weights of its edges. You need to assign the weights so that the ugliness of the resulting graph is as small as possible.

As a reminder, an undirected complete graph with n nodes contains all edges (u, v) with 1 ≤ u < v ≤ n; such a graph has (n(n-1))/(2) edges.

She is not sure how to solve this problem, so she asks you to solve it for her.

Input

The first line contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ min(2 ⋅ 10^5, (n(n-1))/(2) - 1)) — the number of nodes and the number of pre-assigned edges. The inputs are given so that there is at least one unassigned edge.

The i-th of the following m lines contains three integers u_i, v_i, and w_i (1 ≤ u_i, v_i ≤ n, u ≠ v, 1 ≤ w_i < 2^{30}), representing the edge from u_i to v_i has been pre-assigned with the weight w_i. No edge appears in the input more than once.

Output

Print on one line one integer — the minimum ugliness among all weight assignments with XOR sum equal to 0.

Examples

Input

4 4
2 1 14
1 4 14
3 2 15
4 3 8

Output

15

Input

6 6
3 6 4
2 4 1
4 5 7
3 4 10
3 5 1
5 2 15

Output

0

Input

5 6
2 3 11
5 3 7
1 4 10
2 4 14
4 3 8
2 5 6

Output

6

Note

The following image showcases the first test case. The black weights are pre-assigned from the statement, the red weights are assigned by us, and the minimum spanning tree is denoted by the blue edges.

<image>

```python
def divisors(M):
    d=[]
    i=1
    while M>=i**2:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    return d

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f

def eratosthenes(n):
    res=[0 for i in range(n+1)]
    prime=set([])
    for i in range(2,n+1):
        if not res[i]:
            prime.add(i)
            for j in range(1,n//i+1):
                res[i*j]=1
    return prime

def factorization(n):
    res=[]
    for p in prime:
        if n%p==0:
            while n%p==0:
                n//=p
            res.append(p)
    if n!=1:
        res.append(n)
    return res

def euler_phi(n):
    res = n
    for x in range(2,n+1):
        if x ** 2 > n:
            break
        if n%x==0:
            res = res//x * (x-1)
            while n%x==0:
                n //= x
    if n!=1:
        res = res//n * (n-1)
    return res

def ind(b,n):
    res=0
    while n%b==0:
        res+=1
        n//=b
    return res

def isPrimeMR(n):
    if n==1:
        return 0
    d = n - 1
    d = d // (d & -d)
    L = [2, 3, 5, 7, 11, 13, 17]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    from math import gcd
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

def divisors(n):
    res = [1]
    prime = primeFactor(n)
    for p in prime:
        newres = []
        for d in res:
            for j in range(prime[p]+1):
                newres.append(d*p**j)
        res = newres
    res.sort()
    return res

def xorfactorial(num):#排他的論理和の階乗
    if num==0:
        return 0
    elif num==1:
        return 1
    elif num==2:
        return 3
    elif num==3:
        return 0
    else:
        x=baseorder(num)
        return (2**x)*((num-2**x+1)%2)+function(num-2**x)

def xorconv(n,X,Y):
    if n==0:
        res=[(X[0]*Y[0])%mod]
        return res
    x=[digit[i]+X[i+2**(n-1)] for i in range(2**(n-1))]
    y=[Y[i]+Y[i+2**(n-1)] for i in range(2**(n-1))]
    z=[digit[i]-X[i+2**(n-1)] for i in range(2**(n-1))]
    w=[Y[i]-Y[i+2**(n-1)] for i in range(2**(n-1))]
    res1=xorconv(n-1,x,y)
    res2=xorconv(n-1,z,w)
    former=[(res1[i]+res2[i])*inv for i in range(2**(n-1))]
    latter=[(res1[i]-res2[i])*inv for i in range(2**(n-1))]
    former=list(map(lambda x:x%mod,former))
    latter=list(map(lambda x:x%mod,latter))
    return former+latter

def merge_sort(A,B):
    pos_A,pos_B = 0,0
    n,m = len(A),len(B)
    res = []
    while pos_A < n and pos_B < m:
        a,b = A[pos_A],B[pos_B]
        if a < b:
            res.append(a)
            pos_A += 1
        else:
            res.append(b)
            pos_B += 1
    res += A[pos_A:]
    res += B[pos_B:]
    return res

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        stack = [x]
        while self._parent[stack[-1]]!=stack[-1]:
            stack.append(self._parent[stack[-1]])
        for v in stack:
            self._parent[v] = stack[-1]
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

class WeightedUnionFind():
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.size = [1 for i in range(N)]
        self.val = [0 for i in range(N)]
        self.flag = True
        self.edge = [[] for i in range(N)]

    def dfs(self,v,pv):
        stack = [(v,pv)]
        new_parent = self.parent[pv]
        while stack:
            v,pv = stack.pop()
            self.parent[v] = new_parent
            for nv,w in self.edge[v]:
                if nv!=pv:
                    self.val[nv] = self.val[v] + w
                    stack.append((nv,v))

    def unite(self,x,y,w):
        if not self.flag:
            return
        if self.parent[x]==self.parent[y]:
            self.flag = (self.val[x] - self.val[y] == w)
            return

        if self.size[self.parent[x]]>self.size[self.parent[y]]:
            self.edge[x].append((y,-w))
            self.edge[y].append((x,w))
            self.size[x] += self.size[y]
            self.val[y] = self.val[x] - w
            self.dfs(y,x)
        else:
            self.edge[x].append((y,-w))
            self.edge[y].append((x,w))
            self.size[y] += self.size[x]
            self.val[x] = self.val[y] + w
            self.dfs(x,y)

class Dijkstra():
    class Edge():
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        self.G = [[] for i in range(V)]
        self._E = 0
        self._V = V

    @property
    def E(self):
        return self._E

    @property
    def V(self):
        return self._V

    def add_edge(self, _from, _to, _cost):
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        import heapq
        que = []
        d = [10**15] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost
                    heapq.heappush(que, (d[e.to], e.to))
        return d

#Z[i]:length of the longest list starting from S[i] which is also a prefix of S
#O(|S|)
def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

class BIT():
    def __init__(self,n,mod=0):
        self.BIT = [0]*(n+1)
        self.num = n
        self.mod = mod

    def query(self,idx):
        res_sum = 0
        mod = self.mod
        while idx > 0:
            res_sum += self.BIT[idx]
            if mod:
                res_sum %= mod
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        mod = self.mod
        while idx <= self.num:
            self.BIT[idx] += x
            if mod:
                self.BIT[idx] %= mod
            idx += idx&(-idx)
        return

class dancinglink():
    def __init__(self,n,debug=False):
        self.n = n
        self.debug = debug
        self._left = [i-1 for i in range(n)]
        self._right = [i+1 for i in range(n)]
        self.exist = [True for i in range(n)]

    def pop(self,k):
        if self.debug:
            assert self.exist[k]
        L = self._left[k]
        R = self._right[k]
        if L!=-1:
            if R!=self.n:
                self._right[L],self._left[R] = R,L
            else:
                self._right[L] = self.n
        elif R!=self.n:
            self._left[R] = -1
        self.exist[k] = False

    def left(self,idx,k=1):
        if self.debug:
            assert self.exist[idx]
        res = idx
        while k:
            res = self._left[res]
            if res==-1:
                break
            k -= 1
        return res

    def right(self,idx,k=1):
        if self.debug:
            assert self.exist[idx]
        res = idx
        while k:
            res = self._right[res]
            if res==self.n:
                break
            k -= 1
        return res

class SparseTable():
    def __init__(self,A,merge_func,ide_ele):
        N=len(A)
        n=N.bit_length()
        self.table=[[ide_ele for i in range(n)] for i in range(N)]
        self.merge_func=merge_func

        for i in range(N):
            self.table[i][0]=A[i]

        for j in range(1,n):
            for i in range(0,N-2**j+1):
                f=self.table[i][j-1]
                s=self.table[i+2**(j-1)][j-1]
                self.table[i][j]=self.merge_func(f,s)

    def query(self,s,t):
        b=t-s+1
        m=b.bit_length()-1
        return self.merge_func(self.table[s][m],self.table[t-2**m+1][m])

class BinaryTrie:
    class node:
        def __init__(self,val):
            self.left = None
            self.right = None
            self.max = val

    def __init__(self):
        self.root = self.node(-10**15)

    def append(self,key,val):
        pos = self.root
        for i in range(29,-1,-1):
            pos.max = max(pos.max,val)
            if key>>i & 1:
                if pos.right is None:
                    pos.right = self.node(val)
                    pos = pos.right
                else:
                    pos = pos.right
            else:
                if pos.left is None:
                    pos.left = self.node(val)
                    pos = pos.left
                else:
                    pos = pos.left
        pos.max = max(pos.max,val)

    def search(self,M,xor):
        res = -10**15
        pos = self.root
        for i in range(29,-1,-1):
            if pos is None:
                break

            if M>>i & 1:
                if xor>>i & 1:
                    if pos.right:
                        res = max(res,pos.right.max)
                    pos = pos.left
                else:
                    if pos.left:
                        res = max(res,pos.left.max)
                    pos = pos.right
            else:
                if xor>>i & 1:
                    pos = pos.right
                else:
                    pos = pos.left

        if pos:
            res = max(res,pos.max)
        return res

def solveequation(edge,ans,n,m):
    #edge=[[to,dire,id]...]
    x=[0]*m
    used=[False]*n
    for v in range(n):
        if used[v]:
            continue
        y = dfs(v)
        if y!=0:
            return False
    return x

    def dfs(v):
        used[v]=True
        r=ans[v]
        for to,dire,id in edge[v]:
            if used[to]:
                continue
            y=dfs(to)
            if dire==-1:
                x[id]=y
            else:
                x[id]=-y
            r+=y
        return r

class Matrix():
    mod=10**9+7

    def set_mod(m):
        Matrix.mod=m

    def __init__(self,L):
        self.row=len(L)
        self.column=len(L[0])
        self._matrix=L
        for i in range(self.row):
            for j in range(self.column):
                self._matridigit[i][j]%=Matrix.mod

    def __getitem__(self,item):
        if type(item)==int:
            raise IndexError("you must specific row and column")
        elif len(item)!=2:
            raise IndexError("you must specific row and column")

        i,j=item
        return self._matridigit[i][j]

    def __setitem__(self,item,val):
        if type(item)==int:
            raise IndexError("you must specific row and column")
        elif len(item)!=2:
            raise IndexError("you must specific row and column")

        i,j=item
        self._matridigit[i][j]=val

    def __add__(self,other):
        if (self.row,self.column)!=(other.row,other.column):
            raise SizeError("sizes of matrixes are different")

        res=[[0 for j in range(self.column)] for i in range(self.row)]
        for i in range(self.row):
            for j in range(self.column):
                res[i][j]=self._matridigit[i][j]+other._matridigit[i][j]
                res[i][j]%=Matrix.mod
        return Matrix(res)

    def __sub__(self,other):
        if (self.row,self.column)!=(other.row,other.column):
            raise SizeError("sizes of matrixes are different")

        res=[[0 for j in range(self.column)] for i in range(self.row)]
        for i in range(self.row):
            for j in range(self.column):
                res[i][j]=self._matridigit[i][j]-other._matridigit[i][j]
                res[i][j]%=Matrix.mod
        return Matrix(res)

    def __mul__(self,other):
        if type(other)!=int:
            if self.column!=other.row:
                raise SizeError("sizes of matrixes are different")

            res=[[0 for j in range(other.column)] for i in range(self.row)]
            for i in range(self.row):
                for j in range(other.column):
                    temp=0
                    for k in range(self.column):
                        temp+=self._matridigit[i][k]*other._matrix[k][j]
                    res[i][j]=temp%Matrix.mod
            return Matrix(res)
        else:
            n=other
            res=[[(n*self._matridigit[i][j])%Matrix.mod for j in range(self.column)] for i in range(self.row)]
            return Matrix(res)

    def __pow__(self,m):
        if self.column!=self.row:
            raise MatrixPowError("the size of row must be the same as that of column")

        n=self.row
        res=Matrix([[int(i==j) for i in range(n)] for j in range(n)])
        while m:
            if m%2==1:
                res=res*self
            self=self*self
            m//=2
        return res

    def __str__(self):
        res=[]
        for i in range(self.row):
            for j in range(self.column):
                res.append(str(self._matridigit[i][j]))
                res.append(" ")
            res.append("\n")
        res=res[:len(res)-1]
        return "".join(res)

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
mi = lambda :map(int,input().split())
li = lambda :list(mi())

n,m = mi()
edge = [set([]) for i in range(n)]
E = []
xor = 0
for _ in range(m):
    u,v,c = mi()
    edge[u-1].add(v-1)
    edge[v-1].add(u-1)
    E.append((u-1,v-1,c))
    xor ^= c

visited = [False for i in range(n)]
rest = [i for i in range(n)]

group = []
root = []
parent = [-1 for v in range(n)]

for v in range(n):
    if not visited[v]:
        g = set([v])
        root.append(v)
        visited[v] = True
        stack = [v]
        parent[v] = v
        while stack:
            u = stack.pop()
            for nv in rest:
                if nv==v:
                    continue
                if nv not in edge[u] and not visited[nv]:
                    visited[nv] = True
                    g.add(nv)
                    stack.append(nv)
                    parent[nv] = v
            rest = [nv for nv in rest if not visited[nv]]
        group.append(g)

uf = UnionFindVerSize(n)
G = len(group)
for i in range(G):
    p = root[i]
    for v in group[i]:
        uf.unite(p,v)

E.sort(key=lambda x:x[2])
alt = []
use = []
res = xor
for u,v,c in E:
    if not uf.is_same_group(u,v):
        res += c
        uf.unite(u,v)
        use.append((u,v))
    else:
        alt.append((u,v,c))

#tree_check
flag = True
for i in range(G):
    size = len(group[i])
    edge_cnt = size*(size-1)
    for v in group[i]:
        for nv in edge[v]:
            if nv in group[i]:
                edge_cnt -= 1
    if edge_cnt//2!=size-1:
        flag = False

#print(flag,group,res,xor)
base = res-xor
if not flag:
    print(base)
else:
    tree = [[] for i in range(n)]
    for i in range(G):
        size = len(group[i])
        edge_cnt = size*(size-1)
        for v in group[i]:
            for nv in group[i]:
                if nv not in edge[v] and nv!=v:
                    tree[v].append((nv,1))
    for u,v in use:
        tree[u].append((v,0))
        tree[v].append((u,0))

    deq = deque([0])
    cnt = [0 for i in range(n)]
    tree_parent = [-1 for v in range(n)]
    depth = [0 for i in range(n)]
    while deq:
        v = deq.popleft()
        for nv,c in tree[v]:
            if tree_parent[nv]==-1 and nv:
                tree_parent[nv] = v
                depth[nv] = depth[v] + 1
                cnt[nv] = cnt[v] + c
                deq.append(nv)

    N = n
    LV = (N-1).bit_length()
    def construct(prv):
        kprv = [prv]
        S = prv
        for k in range(LV):
            T = [0]*N
            for i in range(N):
                if S[i] is None:
                    continue
                T[i] = S[S[i]]
            kprv.append(T)
            S = T
        return kprv

    kprv=construct(tree_parent)

    def lca(u, v):
        dd = depth[v] - depth[u]
        if dd < 0:
            u, v = v, u
            dd = -dd

        # assert depth[u] <= depth[v]
        for k in range(LV+1):
            if dd & 1:
                v = kprv[k][v]
            dd >>= 1

        # assert depth[u] == depth[v]
        if u == v:
            return u

        for k in range(LV-1, -1, -1):
            pu = kprv[k][u]; pv = kprv[k][v]
            if pu != pv:
                u = pu; v = pv

        # assert kprv[0][u] == kprv[0][v]
        return kprv[0][u]

    plus = xor
    for u,v,c in alt:
        L = lca(u,v)
        t = cnt[u] + cnt[v] - 2 * cnt[L]
        assert t>=0
        if parent[u]==parent[v]:
            assert t
        if t:
            plus = min(plus,c)
    print(base+plus)

```


1534_D. Lost Tree

This is an interactive problem.

Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n.

The game master only allows him to ask one type of question:

  * Little Dormi picks a node r (1 ≤ r ≤ n), and the game master will reply with an array d_1, d_2, …, d_n, where d_i is the length of the shortest path from node r to i, for all 1 ≤ i ≤ n.

Additionally, to make the game unfair challenge Little Dormi the game master will allow at most ⌈n/2⌉ questions, where ⌈ x ⌉ denotes the smallest integer greater than or equal to x.

Faced with the stomach-churning possibility of not being able to guess the tree, Little Dormi needs your help to devise a winning strategy!

Note that the game master creates the tree before the game starts, and does not change it during the game.

Input

The first line of input contains the integer n (2 ≤ n ≤ 2 000), the number of nodes in the tree.

You will then begin interaction.

Output

When your program has found the tree, first output a line consisting of a single "!" followed by n-1 lines each with two space separated integers a and b, denoting an edge connecting nodes a and b (1 ≤ a, b ≤ n). Once you are done, terminate your program normally immediately after flushing the output stream.

You may output the edges in any order and an edge (a,b) is considered the same as an edge (b,a). Answering is not considered as a query.

Interaction

After taking input, you may make at most ⌈n/2⌉ queries. Each query is made in the format "? r", where r is an integer 1 ≤ r ≤ n that denotes the node you want to pick for that query.

You will then receive n space separated integers d_1, d_2, …, d_n, where d_i is the length of the shortest path from node r to i, followed by a newline.

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.

If at any point you make an invalid query or try to make more than ⌈ n/2 ⌉ queries, the interaction will terminate immediately and you will receive a Wrong Answer verdict.

Hacks

To hack a solution, use the following format.

The first line contains the integer n (2 ≤ n ≤ 2 000).

The next n−1 lines contain two integers u and v (1 ≤ u,v ≤ n) denoting an edge between u and v (u ≠ v). These n-1 edges must form a tree.

Examples

Input

4

0 1 2 2

1 0 1 1

Output

? 1

? 2

!
4 2
1 2
2 3

Input

5

2 2 1 1 0

Output

? 5

!
4 5
3 5
2 4
1 3

Note

Here is the tree from the first example.

<image>

Notice that the edges can be output in any order.

Additionally, here are the answers for querying every single node in example 1:

  * 1: [0,1,2,2]
  * 2: [1,0,1,1]
  * 3: [2,1,0,2]
  * 4: [2,1,2,0]

Below is the tree from the second example interaction.

<image>

Lastly, here are the answers for querying every single node in example 2:

  * 1: [0,4,1,3,2]
  * 2: [4,0,3,1,2]
  * 3: [1,3,0,2,1]
  * 4: [3,1,2,0,1]
  * 5: [2,2,1,1,0]

```python
res = []
n = int(input())
print('?', 1, flush=True)
arr = list(map(int, input().split()))
for v,d in enumerate(arr):
    if d==1:
        res.append([0,v])
one = [v for v,d in enumerate(arr) if d&1]
two = [v for v,d in enumerate(arr) if v and not (d&1)]
if len(one)>len(two):
    one, two = two, one
for u in one:
    print('?', u+1, flush=True)
    arr = list(map(int, input().split()))
    for v,d in enumerate(arr):
        if d==1 and v:
            res.append([u,v])

print('!')
for u, v in res:
    print(u+1, v+1)

```


181_B. Number of Triplets

You are given n points on a plane. All points are different.

Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.

The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are considered the same.

Input

The first line contains a single integer n (3 ≤ n ≤ 3000) — the number of points.

Next n lines contain the points. The i-th line contains coordinates of the i-th point: two space-separated integers xi, yi ( - 1000 ≤ xi, yi ≤ 1000).

It is guaranteed that all given points are different.

Output

Print the single number — the answer to the problem.

Examples

Input

3
1 1
2 2
3 3

Output

1

Input

3
0 0
-1 0
0 1

Output

0

```python
n = int(input())

points_array = []

cords = []
for i in range(2001):
	cords.append([False] * 2001)

for i in range(n):
    x, y = [a for a in input().split()]
    points_array.append([int(x), int(y)])
    cords[int(x)+1000][int(y)+1000] = True

count = 0
for i in range(n):
    for j in range(i+1, n):
        x1, y1 = points_array[i]
        x3, y3 = points_array[j]
        x2 = int((x1 + x3)/2)
        y2 = int((y1 + y3)/2)

        # print(p, q, r, s)
        if ((x1 + x3)%2 == 0 and (y1+y3)%2 == 0) and cords[x2+1000][y2+1000]:
            count += 1

print(count)

```


204_D. Little Elephant and Retro Strings

The Little Elephant has found a ragged old black-and-white string s on the attic.

The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is either letter "B", or letter "W". Unfortunately, the string is very old and some characters are damaged. The damaged positions are denoted as "X".

The Little Elephant in determined to restore the string and hang it on the wall. For that he needs to replace each character "X" by a "B" or a "W". The string must look good on the wall, so it must be beautiful. The Little Elephant considers a string beautiful if it has two non-intersecting substrings of a given length k, such that the left one fully consists of characters "B", and the right one fully consists of characters "W". More formally, there are four integers a, b, c, d (1 ≤ a ≤ b < c ≤ d ≤ |s|; b - a + 1 = d - c + 1 = k) such that si = "B" (a ≤ i ≤ b) and sj = "W" (c ≤ j ≤ d).

Help the Little Elephant find the number of different beautiful strings he can obtain from string s. Two strings are considered different if there is such position, where the character in the first string differs from the corresponding character in the second string. If this string doesn't contain characters «X» and it is already beautiful — the answer is 1.

As the answer can be rather large, print it modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 106). The second line contains string s. String s has length n and only consists of characters "W", "B" and "X".

Output

On a single line print an integer — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

3 2
XXX

Output

0

Input

4 2
XXXX

Output

1

Input

10 2
XXBXXWXXXX

Output

166


253_A. Boys and Girls

There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible.

Help the children and tell them how to form the line.

Input

The single line of the input contains two integers n and m (1 ≤ n, m ≤ 100), separated by a space.

Output

Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.

Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them.

Examples

Input

3 3

Output

GBGBGB

Input

4 2

Output

BGBGBB

Note

In the first sample another possible answer is BGBGBG.

In the second sample answer BBGBGB is also optimal.

```python
import os.path
import sys
if os.path.exists('input.txt'):
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
n,m=[int(x) for x in input().split(' ')]
x=min(n,m)
#print(x)
if n<m:
    ans=x*"GB"
else:
    ans=x*'BG'
n=n-x
m=m-x
#print(n,m)
if n!=0:
    ans+=n*'B'
if m!=0:
    ans+=m*'G'
print((ans))
```


278_B. New Problem

Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.

You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.

A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is string slsl + 1... sr.

String x = x1x2... xp is lexicographically smaller than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there exists such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The string characters are compared by their ASCII codes.

Input

The first line contains integer n (1 ≤ n ≤ 30) — the number of titles you've got to consider. Then follow n problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.

Output

Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.

Examples

Input

5
threehorses
goodsubstrings
secret
primematrix
beautifulyear

Output

j

Input

4
aa
bdefghijklmn
opqrstuvwxyz
c

Output

ab

Note

In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.

In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title.

```python
from itertools import *
alphabet="abcdefghijklmnopqrstuvwxyz";

def isValid(s, names):
    for name in names:
        if name.find(s)!=-1:
            return  False
    return True

def newProblem(names):
    for i in range(1,3):
        for s in product(alphabet, repeat=i):
            st=""
            for c in s:
                st+=c
            if isValid(st, names):
                return st

n=int(input())
names=[]
for i in range(0,n):
    name= input()
    names.append(name)
print(newProblem(names))

```


300_A. Array

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:

  1. The product of all numbers in the first set is less than zero ( < 0).
  2. The product of all numbers in the second set is greater than zero ( > 0).
  3. The product of all numbers in the third set is equal to zero.
  4. Each number from the initial array must occur in exactly one set.

Help Vitaly. Divide the given array.

Input

The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements.

Output

In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set.

In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set.

In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set.

The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.

Examples

Input

3
-1 2 0

Output

1 -1
1 2
1 0

Input

4
-1 -2 -3 0

Output

1 -1
2 -3 -2
1 0

```python
n=int(input())
a=list(map(int,input().split()))
b=[]
k=0
k1=0
for i in range(0,n):
    if(a[i]==0):
        b.append(a[i])
    elif(a[i]>0):
        if(k==0):
            k=a[i]
        else:
            b.append(a[i])
    elif(a[i]<0):
        if(k1==0):
            k1=a[i]
        else:
            b.append(a[i])
print(1,k1)
f=0
if(k==0):
    c=[]
    for i in range(0,n):
        if(b[i]<0):
            c.append(b[i])
            b[i]='@'
            f=f+1
        if(len(c)==2):
            break
    print(2)
    for i in range(0,2):
        print(c[i])
else:
    print(1,k)
print(len(b)-f)
for i in range(0,len(b)):
    if(b[i]!='@'):
        print(b[i])
```


372_A. Counting Kangaroos is Fun

There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.

Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.

The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.

Input

The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).

Output

Output a single integer — the optimal number of visible kangaroos.

Examples

Input

8
2
5
7
6
9
8
4
2

Output

5

Input

8
9
1
6
2
6
5
8
3

Output

5

```python
# Made By Mostafa_Khaled
bot = True
import math,sys

n=int(input());k=n

a=sorted([int(x) for x in sys.stdin.read().strip().split('\n')])

p1=math.floor((n-1)/2);p2=n-1

while p1>=0:

    if 2*a[p1]<=a[p2]:

        k-=1;a[p2]=0;p2-=1

    p1-=1

k=max(math.ceil(n/2),k)

sys.stdout.write(str(k))

# Made By Mostafa_Khaled
```


393_C. Blocked Points

Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:

  * the Euclidean distance between A and B is one unit and neither A nor B is blocked;
  * or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B.

Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?

Input

The first line contains an integer n (0 ≤ n ≤ 4·107).

Output

Print a single integer — the minimum number of points that should be blocked.

Examples

Input

1

Output

4

Input

2

Output

8

Input

3

Output

16

```python
from math import sqrt

n = int(input())
if n == 0:
    print(1)
else:
    print(4 * int(n * sqrt(2)))

```


416_D. Population Size

Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.

Polycarpus believes that if he writes out the population of the capital for several consecutive years in the sequence a1, a2, ..., an, then it is convenient to consider the array as several arithmetic progressions, written one after the other. For example, sequence (8, 6, 4, 2, 1, 4, 7, 10, 2) can be considered as a sequence of three arithmetic progressions (8, 6, 4, 2), (1, 4, 7, 10) and (2), which are written one after another.

Unfortunately, Polycarpus may not have all the data for the n consecutive years (a census of the population doesn't occur every year, after all). For this reason, some values of ai may be unknown. Such values are represented by number -1.

For a given sequence a = (a1, a2, ..., an), which consists of positive integers and values -1, find the minimum number of arithmetic progressions Polycarpus needs to get a. To get a, the progressions need to be written down one after the other. Values -1 may correspond to an arbitrary positive integer and the values ai > 0 must be equal to the corresponding elements of sought consecutive record of the progressions.

Let us remind you that a finite sequence c is called an arithmetic progression if the difference ci + 1 - ci of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression.

Input

The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).

Output

Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.

Examples

Input

9
8 6 4 2 1 4 7 10 2

Output

3

Input

9
-1 6 -1 2 -1 4 7 -1 2

Output

3

Input

5
-1 -1 -1 -1 -1

Output

1

Input

7
-1 -1 4 5 1 2 3

Output

2

```python
n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
    ans += 1
    i1 = i
    while i1 < n and a[i1] == -1:
        i1 += 1
    if i1 == n:
        break
    i2 = i1 + 1
    while i2 < n and a[i2] == -1:
        i2 += 1
    if i2 == n:
        break
    dist = i2 - i1
    step = (a[i2] - a[i1]) // dist
    if (a[i2] - a[i1]) % dist != 0 or (step > 0 and a[i1] - (i1 - i) * step <= 0):
        i = i2
        continue
    i3 = i2 + 1
    while i3 < n:
        nxt = a[i2] + step * (i3 - i2)
        if nxt <= 0 or (a[i3] != -1 and a[i3] != nxt):
            break
        i3 += 1

    i = i3
print(ans)

```


443_B. Kolya and Tandem Repeat

Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

See notes for definition of a tandem repeat.

Input

The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.

Output

Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

Examples

Input

aaba
2

Output

6

Input

aaabbbb
2

Output

6

Input

abracadabra
10

Output

20

Note

A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.

In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.

```python
s=input()
k=int(input())
n=len(s)

if k>=n:
    print(int(2*((n+k)//2)))
    raise SystemExit
ll=0
for i in range(k+1):
  for l in range((n+i)//2,i-1,-1):
    if s[n-(l-i):n]==s[n+i-2*l:n-l]:
        if l>ll:
            ll=l
        break

j=ll
while 2*j<=n:
    j=j+1
    for i in range(n-2*j):
        if s[i:i+j]==s[i+j:i+2*j]:
            ll=j
            break
print(int(2*ll))

```


465_C. No to Palindromes!

Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.

Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.

Input

The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).

Output

If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).

Examples

Input

3 3
cba

Output

NO

Input

3 4
cba

Output

cbd

Input

4 4
abcd

Output

abda

Note

String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti, si + 1 > ti + 1.

The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.

A palindrome is a string that reads the same forward or reversed.

```python
import sys

def main():
    # fin = open("input.txt", "r")
    fin = sys.stdin
    fout = sys.stdout

    L = list("abcdefghijklmnopqrstuvwxyz")

    n, p = map(int, fin.readline().split())
    A = list(fin.readline())

    for i in range(n - 1, 1, -1):
        pr = ord(A[i - 1]) - ord("a")
        pp = ord(A[i - 2]) - ord("a")
        cur = ord(A[i]) - ord("a") + 1
        # print pr, pp, cur
        while cur < p and (cur == pr or cur == pp):
            cur += 1
        if cur < p:
            A[i] = chr(cur + ord("a"))
            print("".join(A[:i]), end="")
            print(chr(cur + ord("a")), end="")
            for j in range(i + 1, n):
                pr = ord(A[j - 1]) - ord("a")
                pp = ord(A[j - 2]) - ord("a")
                cur = 0
                while cur < p and (cur == pr or cur == pp):
                    cur += 1
                print(chr(cur + ord("a")), end="")
                A[j] = chr(cur + ord("a"))
            return

    if n >= 2:
        i = 1
        pr = ord(A[i - 1]) - ord("a")
        pp = -1
        cur = ord(A[i]) - ord("a") + 1
        # print pr, pp, cur
        while cur < p and (cur == pr or cur == pp):
            cur += 1
        if cur < p:
            A[i] = chr(cur + ord("a"))
            print("".join(A[:i]), end="")
            print(chr(cur + ord("a")), end="")
            for j in range(i + 1, n):
                pr = ord(A[j - 1]) - ord("a")
                pp = ord(A[j - 2]) - ord("a")
                cur = 0
                while cur < p and (cur == pr or cur == pp):
                    cur += 1
                print(chr(cur + ord("a")), end="")
                A[j] = chr(cur + ord("a"))
            return

    i = 0
    pr = pp = -1
    cur = ord(A[i]) - ord("a") + 1
    # print pr, pp, cur
    while cur < p and (cur == pr or cur == pp):
        cur += 1
    if cur < p:
        A[i] = chr(cur + ord("a"))
        # print("".join(A[:i]), end="")
        print(chr(cur + ord("a")), end="")
        if n == 1:
            return
        j = 1
        pr = ord(A[j - 1]) - ord("a")
        pp = -1
        cur = 0
        while cur < p and (cur == pr or cur == pp):
            cur += 1
        print(chr(cur + ord("a")), end="")
        A[j] = chr(cur + ord("a"))
        for j in range(i + 2, n):
            pr = ord(A[j - 1]) - ord("a")
            pp = ord(A[j - 2]) - ord("a")
            cur = 0
            while cur < p and (cur == pr or cur == pp):
                cur += 1
            print(chr(cur + ord("a")), end="")
            A[j] = chr(cur + ord("a"))
        return

    print("NO")

    fin.close()
    fout.close()

main()
```