1362_D. Johnny and Contribution

Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the readers can notice that they are split just for more contribution. Set of blogs and bidirectional references between some pairs of them is called blogs network.

There are n different topics, numbered from 1 to n sorted by Johnny's knowledge. The structure of the blogs network is already prepared. Now Johnny has to write the blogs in some order. He is lazy, so each time before writing a blog, he looks at it's already written neighbors (the blogs referenced to current one) and chooses the topic with the smallest number which is not covered by neighbors. It's easy to see that this strategy will always allow him to choose a topic because there are at most n - 1 neighbors.

For example, if already written neighbors of the current blog have topics number 1, 3, 1, 5, and 2, Johnny will choose the topic number 4 for the current blog, because topics number 1, 2 and 3 are already covered by neighbors and topic number 4 isn't covered.

As a good friend, you have done some research and predicted the best topic for each blog. Can you tell Johnny, in which order he has to write the blogs, so that his strategy produces the topic assignment chosen by you?

Input

The first line contains two integers n (1 ≤ n ≤ 5 ⋅ 10^5) and m (0 ≤ m ≤ 5 ⋅ 10^5) — the number of blogs and references, respectively.

Each of the following m lines contains two integers a and b (a ≠ b; 1 ≤ a, b ≤ n), which mean that there is a reference between blogs a and b. It's guaranteed that the graph doesn't contain multiple edges.

The last line contains n integers t_1, t_2, …, t_n, i-th of them denotes desired topic number of the i-th blog (1 ≤ t_i ≤ n).

Output

If the solution does not exist, then write -1. Otherwise, output n distinct integers p_1, p_2, …, p_n (1 ≤ p_i ≤ n), which describe the numbers of blogs in order which Johnny should write them. If there are multiple answers, print any.

Examples

Input

3 3
1 2
2 3
3 1
2 1 3

Output

2 1 3

Input

3 3
1 2
2 3
3 1
1 1 1

Output

-1

Input

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

Output

2 5 1 3 4

Note

In the first example, Johnny starts with writing blog number 2, there are no already written neighbors yet, so it receives the first topic. Later he writes blog number 1, it has reference to the already written second blog, so it receives the second topic. In the end, he writes blog number 3, it has references to blogs number 1 and 2 so it receives the third topic.

Second example: There does not exist any permutation fulfilling given conditions.

Third example: First Johnny writes blog 2, it receives the topic 1. Then he writes blog 5, it receives the topic 1 too because it doesn't have reference to single already written blog 2. Then he writes blog number 1, it has reference to blog number 2 with topic 1, so it receives the topic 2. Then he writes blog number 3 which has reference to blog 2, so it receives the topic 2. Then he ends with writing blog number 4 which has reference to blog 5 and receives the topic 2.

```python
import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda: sys.stdin.buffer.readline().rstrip()

n,m=map(int,input().split())
g=[[] for i in range(n)]
for i in range(m):
	q,w=map(int,input().split())
	g[q-1].append(w-1)
	g[w-1].append(q-1)
a=list(map(int,input().split()))
e=sorted(list(range(n)),key=lambda k:a[k])
r=[1]*n
z=[]
for i in e:
	s=a[i]
	if r[i]!=s:
		print(-1)
		exit()
	for j in g[i]:
		if r[j]==s:
			r[j]+=1
	z.append(i+1)
print(*z)

```


1382_E. Mastermind

In the game of Mastermind, there are two players — Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exactly n+1 colors in the entire universe, numbered from 1 to n+1 inclusive.

When Bob guesses a code, Alice tells him some information about how good of a guess it is, in the form of two integers x and y.

The first integer x is the number of indices where Bob's guess correctly matches Alice's code. The second integer y is the size of the intersection of the two codes as multisets. That is, if Bob were to change the order of the colors in his guess, y is the maximum number of indices he could get correct.

For example, suppose n=5, Alice's code is [3,1,6,1,2], and Bob's guess is [3,1,1,2,5]. At indices 1 and 2 colors are equal, while in the other indices they are not equal. So x=2. And the two codes have the four colors 1,1,2,3 in common, so y=4.

<image> Solid lines denote a matched color for the same index. Dashed lines denote a matched color at a different index. x is the number of solid lines, and y is the total number of lines.

You are given Bob's guess and two values x and y. Can you find one possibility of Alice's code so that the values of x and y are correct?

Input

The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next 2t lines contain descriptions of test cases.

The first line of each test case contains three integers n,x,y (1≤ n≤ 10^5, 0≤ x≤ y≤ n) — the length of the codes, and two values Alice responds with.

The second line of each test case contains n integers b_1,…,b_n (1≤ b_i≤ n+1) — Bob's guess, where b_i is the i-th color of the guess.

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

Output

For each test case, on the first line, output "YES" if there is a solution, or "NO" if there is no possible secret code consistent with the described situation. You can print each character in any case (upper or lower).

If the answer is "YES", on the next line output n integers a_1,…,a_n (1≤ a_i≤ n+1) — Alice's secret code, where a_i is the i-th color of the code.

If there are multiple solutions, output any.

Example

Input

7
5 2 4
3 1 1 2 5
5 3 4
1 1 2 1 2
4 0 4
5 5 3 3
4 1 4
2 3 2 3
6 1 2
3 2 1 1 1 1
6 2 4
3 3 2 1 1 1
6 2 6
1 1 3 2 1 1

Output

YES
3 1 6 1 2
YES
3 1 1 1 2
YES
3 3 5 5
NO
YES
4 4 4 4 3 1
YES
3 1 3 1 7 7
YES
2 3 1 1 1 1

Note

The first test case is described in the statement.

In the second test case, x=3 because the colors are equal at indices 2,4,5. And y=4 because they share the colors 1,1,1,2.

In the third test case, x=0 because there is no index where the colors are the same. But y=4 because they share the colors 3,3,5,5.

In the fourth test case, it can be proved that no solution exists.

```python
from collections import defaultdict
from heapq import heapify, heappop, heappush
def solve():
    n, s, y = map(int, input().split())
    a = input().split()
    d = defaultdict(list)
    for i, x in enumerate(a):
        d[x].append(i)
    for i in range(1, n + 2):
        e = str(i)
        if e not in d:
            break
    q = [(-len(d[x]), x) for x in d.keys()]
    heapify(q)
    ans = [0] * n
    for i in range(s):
        l, x = heappop(q)
        ans[d[x].pop()] = x
        l += 1
        if l:
            heappush(q, (l, x))
    p = []
    while q:
        l, x = heappop(q)
        p.extend(d[x])
    if p:
        h = (n - s) // 2
        y = n - y
        q = p[h:] + p[:h]
        for x, z in zip(p, q):
            if a[x] == a[z]:
                if y:
                    ans[x] = e
                    y -= 1
                else:
                    print("NO")
                    return
            else:
                ans[x] = a[z]
        for i in range(n - s):
            if y and ans[p[i]] != e:
                ans[p[i]] = e
                y -= 1
    print("YES")
    print(' '.join(ans))

for t in range(int(input())):solve()
```


1425_E. Excitation of Atoms

Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it.

There are N atoms numbered from 1 to N. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom i requires D_i energy. When atom i is excited, it will give A_i energy. You can excite any number of atoms (including zero).

These atoms also form a peculiar one-way bond. For each i, (1 ≤ i < N), if atom i is excited, atom E_i will also be excited at no cost. Initially, E_i = i+1. Note that atom N cannot form a bond to any atom.

Mr. Chanek must change exactly K bonds. Exactly K times, Mr. Chanek chooses an atom i, (1 ≤ i < N) and changes E_i to a different value other than i and the current E_i. Note that an atom's bond can remain unchanged or changed more than once. Help Mr. Chanek determine the maximum energy that he can achieve!

note: You must first change exactly K bonds before you can start exciting atoms.

Input

The first line contains two integers N K (4 ≤ N ≤ 10^5, 0 ≤ K < N), the number of atoms, and the number of bonds that must be changed.

The second line contains N integers A_i (1 ≤ A_i ≤ 10^6), which denotes the energy given by atom i when on excited state.

The third line contains N integers D_i (1 ≤ D_i ≤ 10^6), which denotes the energy needed to excite atom i.

Output

A line with an integer that denotes the maximum number of energy that Mr. Chanek can get.

Example

Input

6 1
5 6 7 8 10 2
3 5 6 7 1 10

Output

35

Note

An optimal solution to change E_5 to 1 and then excite atom 5 with energy 1. It will cause atoms 1, 2, 3, 4, 5 be excited. The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10) - 1 = 35.

Another possible way is to change E_3 to 1 and then exciting atom 3 (which will excite atom 1, 2, 3) and exciting atom 4 (which will excite atom 4, 5, 6). The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10 + 2) - (6 + 7) = 25 which is not optimal.

```python

n, k = map(int, input().split())
a = list(map(int, input().split()))
d = list(map(int, input().split()))
pref=[0]
for i in range(n):
    pref.append(pref[-1]+a[i])
if k==0:
    ans=0
    for i in range(1,n+1):
        ans=max(ans,pref[-1]-pref[i-1]-d[i-1])
    print(ans)
elif k == 1:
    best = sum(a[:n-1]) - min(d[:n-1])

    other = sum(a)
    other -= sorted(d)[0]
    other -= sorted(d)[1]

    curr = sum(a)
    for i in range(n):
        if i:
            best = max(best, curr - d[i])
        curr -= a[i]

    o2 = sum(a) - min(a[1:]) - d[0]

    print(max((best,other,0, o2)))
else:
    print(max((sum(a) - min(d[:-1]),0,a[-1] - d[-1])))

```


1447_C. Knapsack

You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i.

You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈ W/2⌉ ≤ C ≤ W.

Output the list of items you will put into the knapsack or determine that fulfilling the conditions is impossible.

If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights of items in the knapsack.

Input

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

The first line of each test case contains integers n and W (1 ≤ n ≤ 200 000, 1≤ W ≤ 10^{18}).

The second line of each test case contains n integers w_1, w_2, ..., w_n (1 ≤ w_i ≤ 10^9) — weights of the items.

The sum of n over all test cases does not exceed 200 000.

Output

For each test case, if there is no solution, print a single integer -1.

If there exists a solution consisting of m items, print m in the first line of the output and m integers j_1, j_2, ..., j_m (1 ≤ j_i ≤ n, all j_i are distinct) in the second line of the output — indices of the items you would like to pack into the knapsack.

If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights items in the knapsack.

Example

Input

3
1 3
3
6 2
19 8 19 69 9 4
7 12
1 1 1 17 1 1 1

Output

1
1
-1
6
1 2 3 5 6 7

Note

In the first test case, you can take the item of weight 3 and fill the knapsack just right.

In the second test case, all the items are larger than the knapsack's capacity. Therefore, the answer is -1.

In the third test case, you fill the knapsack exactly in half.

```python
t=int(input())
for h in range(t):

    n,w=map(int,input().split())
    Wt=w
    arr=[int(x) for x in input().split()]
    arr3=[ [arr[i],i+1] for i in range(n)]
    arr3.sort(key= lambda x:x[0],reverse=True)
    ans=[]
    sumi=0

    for i in range(n):
        if arr3[i][0] <= w:
            w-=arr3[i][0]
            sumi+=arr3[i][0]
            ans.append(arr3[i][1])
        if Wt/2 <= sumi <= Wt:
            break

    if Wt/2 <= sumi <= Wt:
        print(len(ans))
        for i in ans:
            print(i,end=" ")
        print()
    else:
        print(-1)
```


1472_C. Long Jumps

Polycarp found under the Christmas tree an array a of n elements and instructions for playing with it:

  * At first, choose index i (1 ≤ i ≤ n) — starting position in the array. Put the chip at the index i (on the value a_i).
  * While i ≤ n, add a_i to your score and move the chip a_i positions to the right (i.e. replace i with i + a_i).
  * If i > n, then Polycarp ends the game.

For example, if n = 5 and a = [7, 3, 1, 2, 3], then the following game options are possible:

  * Polycarp chooses i = 1. Game process: i = 1 \overset{+7}{\longrightarrow} 8. The score of the game is: a_1 = 7.
  * Polycarp chooses i = 2. Game process: i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8. The score of the game is: a_2 + a_5 = 6.
  * Polycarp chooses i = 3. Game process: i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6. The score of the game is: a_3 + a_4 = 3.
  * Polycarp chooses i = 4. Game process: i = 4 \overset{+2}{\longrightarrow} 6. The score of the game is: a_4 = 2.
  * Polycarp chooses i = 5. Game process: i = 5 \overset{+3}{\longrightarrow} 8. The score of the game is: a_5 = 3.

Help Polycarp to find out the maximum score he can get if he chooses the starting index in an optimal way.

Input

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

The first line of each test case contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array a.

The next line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array a.

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

Output

For each test case, output on a separate line one number — the maximum score that Polycarp can get by playing the game on the corresponding array according to the instruction from the statement. Note that Polycarp chooses any starting position from 1 to n in such a way as to maximize his result.

Example

Input

4
5
7 3 1 2 3
3
2 1 4
6
2 1000 2 3 995 1
5
1 1 1 1 1

Output

7
6
1000
5

Note

The first test case is explained in the statement.

In the second test case, the maximum score can be achieved by choosing i = 1.

In the third test case, the maximum score can be achieved by choosing i = 2.

In the fourth test case, the maximum score can be achieved by choosing i = 1.

```python
for _ in range(int(input())):
    n = int(input())
    array = list(map(int, input().split()))
    for i in range(n-1, -1, -1):
        if i+array[i]<=n-1:
            array[i] += array[i+array[i]]
    print(max(array))
```


1498_D. Bananas in a Microwave

You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation.

Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following:

Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉.

Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉.

Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x.

At the i-th time-step, you must apply the i-th operation exactly once.

For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1.

Input

The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5).

Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m).

Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}.

For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m.

Output

Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible).

Examples

Input

3 20
1 300000 2
2 400000 2
1 1000000 3

Output

-1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3

Input

3 20
1 399999 2
2 412345 2
1 1000001 3

Output

-1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1

Note

In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0.

  * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6.
  * In timestep 2, we choose a_2=0, hence value of k remains unchanged.
  * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16.

It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations.

In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0.

  * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4.
  * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17.

It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.

```python
#!/usr/bin/env python
from __future__ import division, print_function
import math

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

BASE = int(10**5)

def main():
    n, m = map(int, input().split())
    answer = [-1 for i in range(m + 1)]
    answer[0] = 0
    for step in range(n):
        t, x, y = map(int, input().split())

        bfs = []
        dis = [-1 for i in range(m + 1)]
        cur = 0
        for i in range(m + 1):
            if answer[i] != -1:
                bfs.append(i)
                dis[i] = 0

        if len(bfs) == m + 1:
            break

        for u in bfs:
            if dis[u] == y:
                continue
            v = 0
            if t == 1:
                v = math.ceil(u + x / BASE)
            else:
                v = math.ceil(u * x / BASE)
            if v > m:
                continue
            if dis[v] == -1:
                dis[v] = dis[u] + 1
                bfs.append(v)
                answer[v] = step + 1

    print(' '.join(str(x) for x in answer[1:]))

# region fastio

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")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()
```


1520_C. Not Adjacent Matrix

We will consider the numbers a and b as adjacent if they differ by exactly one, that is, |a-b|=1.

We will consider cells of a square matrix n × n as adjacent if they have a common side, that is, for cell (r, c) cells (r, c-1), (r, c+1), (r-1, c) and (r+1, c) are adjacent to it.

For a given number n, construct a square matrix n × n such that:

  * Each integer from 1 to n^2 occurs in this matrix exactly once;
  * If (r_1, c_1) and (r_2, c_2) are adjacent cells, then the numbers written in them must not be adjacent.

Input

The first line contains one integer t (1 ≤ t ≤ 100). Then t test cases follow.

Each test case is characterized by one integer n (1 ≤ n ≤ 100).

Output

For each test case, output:

  * -1, if the required matrix does not exist;
  * the required matrix, otherwise (any such matrix if many of them exist).

The matrix should be outputted as n lines, where each line contains n integers.

Example

Input

3
1
2
3

Output

1
-1
2 9 7
4 6 3
1 8 5

```python
'''Author- Akshit Monga'''
from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
    n=int(input())
    mat=[[-1 for i in range(n)] for j in range(n)]
    k=1
    for i in range(n):
        for j in range(n):
            mat[i][j]=k
            k+=2
            if k>n*n:
                k=2
    if n==2:
        print(-1)
        continue
    for i in range(n):
        print(*mat[i])
```


154_A. Hometask

Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.

Sergey totally forgot about the task until half an hour before the next lesson and hastily scribbled something down. But then he recollected that in the last lesson he learned the grammar of N-ish. The spelling rules state that N-ish contains some "forbidden" pairs of letters: such letters can never occur in a sentence next to each other. Also, the order of the letters doesn't matter (for example, if the pair of letters "ab" is forbidden, then any occurrences of substrings "ab" and "ba" are also forbidden). Also, each pair has different letters and each letter occurs in no more than one forbidden pair.

Now Sergey wants to correct his sentence so that it doesn't contain any "forbidden" pairs of letters that stand next to each other. However, he is running out of time, so he decided to simply cross out some letters from the sentence. What smallest number of letters will he have to cross out? When a letter is crossed out, it is "removed" so that the letters to its left and right (if they existed), become neighboring. For example, if we cross out the first letter from the string "aba", we get the string "ba", and if we cross out the second letter, we get "aa".

Input

The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105.

The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters.

Next k lines contain descriptions of forbidden pairs of letters. Each line contains exactly two different lowercase Latin letters without separators that represent the forbidden pairs. It is guaranteed that each letter is included in no more than one pair.

Output

Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.

Examples

Input

ababa
1
ab

Output

2

Input

codeforces
2
do
cs

Output

1

Note

In the first sample you should remove two letters b.

In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.

```python
ans = 0

t = []
x = input()
y = int(input())
for i in range(y):
    z = input()
    t.append(z)

#x = codeforces
#y = 2
#t = [do, cs]
pt = -1
ln = len(x)
for i in t:
    a = i[0]
    b = i[1]
    pt = 0
    for j in range(ln):
        ded1=0
        ded2=0
        if j >= pt:
            if x[j] in [a,b]:
                pt = j
                while pt < ln and x[pt] in [a,b]:
                    if x[pt] == a:
                        ded1+=1
                    else:
                        ded2+=1
                    pt += 1

                ans += min(ded1, ded2)
print(ans)

```


196_A. Lexicographically Maximum Subsequence

You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.

We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.

Input

The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.

Output

Print the lexicographically maximum subsequence of string s.

Examples

Input

ababba

Output

bbba

Input

abbcbccacbbcbaaba

Output

cccccbba

Note

Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).

The first sample: aBaBBA

The second sample: abbCbCCaCbbCBaaBA

```python
s = input()
n = len(s)
temp = list(set(s))
x = {}
temp = sorted(temp,reverse=True)
i = 0
while(i < n ):
    x[s[i]] = i

    i +=1
string = ""
i = 0
j = 0

while(i< n and j < len(temp)):
    if  i <= x[temp[j]]:
        if s[i]== temp[j]:
            string += temp[j]
    if i== x[temp[j]]:

        j += 1
        if(len(temp) > 2):
            while(  j < len(temp)-1 and  x[temp[j]] < i):
                j+=1
    i+=1

print(string)

```


21_A. Jabber ID

Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where

  * <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.
  * <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.
  * <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive.

The content of square brackets is optional — it can be present or can be absent.

There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.

Your task is to write program which checks if given string is a correct Jabber ID.

Input

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

Output

Print YES or NO.

Examples

Input

mike@codeforces.com

Output

YES

Input

john.smith@codeforces.ru/contest.icpc/12

Output

NO


269_A. Magical Boxes

Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.

From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:

<image>

Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.

Input

The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.

Output

Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.

Examples

Input

2
0 3
1 5

Output

3

Input

1
0 4

Output

1

Input

2
1 10
2 2

Output

3

Note

Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.

In the second test case, we can put all four small boxes into a box with side length 2.

```python
from math import *
n = int(input())
mx = 0
for i in range(n):
    k, a = map(int, input().split())
    mx = max(mx, 2*k + log2(a))
    mx = max(mx, 2*(k+1))
print(int(ceil(mx/2)))

```


291_C. Network Mask

The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively.

Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separated by dots. For example, the record 0.255.1.123 shows a correct IP address and records 0.256.1.123 and 0.255.1.01 do not. In this problem an arbitrary group of four 8-bit numbers is a correct IP address.

Having worked as an administrator for some time, Polycarpus learned that if you know the IP address, you can use the subnet mask to get the address of the network that has this IP addess.

The subnet mask is an IP address that has the following property: if we write this IP address as a 32 bit string, that it is representable as "11...11000..000". In other words, the subnet mask first has one or more one bits, and then one or more zero bits (overall there are 32 bits). For example, the IP address 2.0.0.0 is not a correct subnet mask as its 32-bit record looks as 00000010000000000000000000000000.

To get the network address of the IP address, you need to perform the operation of the bitwise "and" of the IP address and the subnet mask. For example, if the subnet mask is 255.192.0.0, and the IP address is 192.168.1.2, then the network address equals 192.128.0.0. In the bitwise "and" the result has a bit that equals 1 if and only if both operands have corresponding bits equal to one.

Now Polycarpus wants to find all networks to which his IP addresses belong. Unfortunately, Polycarpus lost subnet mask. Fortunately, Polycarpus remembers that his IP addresses belonged to exactly k distinct networks. Help Polycarpus find the subnet mask, such that his IP addresses will belong to exactly k distinct networks. If there are several such subnet masks, find the one whose bit record contains the least number of ones. If such subnet mask do not exist, say so.

Input

The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 105) — the number of IP addresses and networks. The next n lines contain the IP addresses. It is guaranteed that all IP addresses are distinct.

Output

In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1.

Examples

Input

5 3
0.0.0.1
0.1.1.2
0.0.2.1
0.1.1.0
0.0.2.3

Output

255.255.254.0

Input

5 2
0.0.0.1
0.1.1.2
0.0.2.1
0.1.1.0
0.0.2.3

Output

255.255.0.0

Input

2 1
255.0.0.1
0.0.0.2

Output

-1

```python
def f(t):
    a, b, c, d = map(int, t.split('.'))
    return d + (c << 8) + (b << 16) + (a << 24)

def g(x):
    p = [0] * 4
    for i in range(4):
        p[3 - i] = str(x % 256)
        x //= 256
    return '.'.join(p)

n, k = map(int, input().split())
t = [f(input()) for i in range(n)]
p = [0] * n
x = 1 << 31
for i in range(32):
    for j, y in enumerate(t):
        if y & x: p[j] += x
    if len(set(p)) >= k: break
    x >>= 1
print(-1 if len(set(p)) != k else g((1 << 32) - x))
```


316_D3. PE Lesson

Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to n (by the demand of the inventory commission).

<image> Figure 1. The initial position for n = 5.

After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped.

<image> Figure 2. The example of a throw.

In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.

Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of n numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise.

Input

The first line contains a single number n — the number of students in the line and the number of balls. The next line contains exactly n space-separated integers. Each number corresponds to a student in the line (the i-th number corresponds to the i-th from the left student in the line) and shows the number of throws he can participate in.

The input limits for scoring 30 points are (subproblem D1):

  * 1 ≤ n ≤ 10.

The input limits for scoring 70 points are (subproblems D1+D2):

  * 1 ≤ n ≤ 500.

The input limits for scoring 100 points are (subproblems D1+D2+D3):

  * 1 ≤ n ≤ 1000000.

Output

The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109 + 7).

Examples

Input

5
1 2 2 1 2

Output

120

Input

8
1 2 2 1 2 1 1 2

Output

16800


33_A. What is for dinner?

In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".

For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).

It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.

Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.

As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.

We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.

Input

The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability.

It's guaranteed that each tooth row has positive amount of teeth.

Output

In the first line output the maximum amount of crucians that Valerie can consume for dinner.

Examples

Input

4 3 18
2 3
1 2
3 6
2 3

Output

11

Input

2 2 13
1 13
2 12

Output

13

```python
n, m, k = list(map(int,input().split()))
tooth = [[0,True]] * n
for i in range(n):
  r, c = list(map(int,input().split()))
  if tooth[r-1][0] > c or tooth[r-1][1] == True:
    tooth[r-1] = [c,False]
ad = 0
for i in tooth:
  ad += i[0]
print(min(ad,k))
```


362_C. Insertion Sort

Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decreasing order.

    for (int i = 1; i < n; i = i + 1)
    {
       int j = i;
       while (j > 0 && a[j] < a[j - 1])
       {
          swap(a[j], a[j - 1]); // swap elements a[j] and a[j - 1]
          j = j - 1;
       }
    }

Petya uses this algorithm only for sorting of arrays that are permutations of numbers from 0 to n - 1. He has already chosen the permutation he wants to sort but he first decided to swap some two of its elements. Petya wants to choose these elements in such a way that the number of times the sorting executes function swap, was minimum. Help Petya find out the number of ways in which he can make the swap and fulfill this requirement.

It is guaranteed that it's always possible to swap two elements of the input permutation in such a way that the number of swap function calls decreases.

Input

The first line contains a single integer n (2 ≤ n ≤ 5000) — the length of the permutation. The second line contains n different integers from 0 to n - 1, inclusive — the actual permutation.

Output

Print two integers: the minimum number of times the swap function is executed and the number of such pairs (i, j) that swapping the elements of the input permutation with indexes i and j leads to the minimum number of the executions.

Examples

Input

5
4 0 3 1 2

Output

3 2

Input

5
1 2 3 4 0

Output

3 4

Note

In the first sample the appropriate pairs are (0, 3) and (0, 4).

In the second sample the appropriate pairs are (0, 4), (1, 4), (2, 4) and (3, 4).

```python
arr = [0 for i in range(5001)]

def insertion_sort(n, a):
    def modify(t):
        while t > 0:
            arr[t] += 1
            t -= t & (-t)

    def query(t):
        res = 0
        while t < 5001:
            res += arr[t]
            t += t & (-t)
        return res

    s = 0
    ans = 0
    way = 0

    for i in range(n):
        a[i] += 1

    for i in range(n):
        global arr
        arr = [0 for j in range(5001)]
        for j in range(i + 1, n):
            if a[i] < a[j]:
                continue
            s += 1
            tmp = 1 + 2 * query(a[j])
            if tmp > ans:
                ans = tmp
                way = 1
            elif tmp == ans:
                way += 1
            modify(a[j])

    return s - ans, way

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    result = insertion_sort(n, a)
    print(*result)

```


386_A. Second-Price Auction

In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).

Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.

Input

The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.

Output

The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.

Examples

Input

2
5 7

Output

2 5

Input

3
10 2 8

Output

1 8

Input

6
3 8 2 9 4 14

Output

6 9

```python
a=int(input())
a=list(map(int,input().split()))
ind=a.index(max(a))
a.sort()
print(str(ind+1)+' '+str(a[-2]))

```


434_A. Ryouko's Memory Note

Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.

Though Ryouko is forgetful, she is also born with superb analyzing abilities. However, analyzing depends greatly on gathered information, in other words, memory. So she has to shuffle through her notebook whenever she needs to analyze, which is tough work.

Ryouko's notebook consists of n pages, numbered from 1 to n. To make life (and this problem) easier, we consider that to turn from page x to page y, |x - y| pages should be turned. During analyzing, Ryouko needs m pieces of information, the i-th piece of information is on page ai. Information must be read from the notebook in order, so the total number of pages that Ryouko needs to turn is <image>.

Ryouko wants to decrease the number of pages that need to be turned. In order to achieve this, she can merge two pages of her notebook. If Ryouko merges page x to page y, she would copy all the information on page x to y (1 ≤ x, y ≤ n), and consequently, all elements in sequence a that was x would become y. Note that x can be equal to y, in which case no changes take place.

Please tell Ryouko the minimum number of pages that she needs to turn. Note she can apply the described operation at most once before the reading. Note that the answer can exceed 32-bit integers.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 105).

The next line contains m integers separated by spaces: a1, a2, ..., am (1 ≤ ai ≤ n).

Output

Print a single integer — the minimum number of pages Ryouko needs to turn.

Examples

Input

4 6
1 2 3 4 3 2

Output

3

Input

10 5
9 4 3 8 8

Output

6

Note

In the first sample, the optimal solution is to merge page 4 to 3, after merging sequence a becomes {1, 2, 3, 3, 3, 2}, so the number of pages Ryouko needs to turn is |1 - 2| + |2 - 3| + |3 - 3| + |3 - 3| + |3 - 2| = 3.

In the second sample, optimal solution is achieved by merging page 9 to 4.

```python
def median(a):
    if len(a) == 0:
        return 0
    if len(a) % 2 == 1:
        return a[len(a) // 2]
    else:
        return (a[len(a) // 2] + a[(len(a) // 2) - 1]) // 2

def profit(a, old_val):
    a.sort()
    med = median(a)
    sum_old = 0
    sum_new = 0
    for i in a:
        sum_old += abs(i - old_val)
        sum_new += abs(i - med)
    return sum_old - sum_new

n, m = [int(c) for c in input().split()]
pages = [int(c) for c in input().split()]

count = {pages[0]: []}
current_page_switches = 0

for i in range(1, len(pages)):
    cur_i = pages[i]
    prev_i = pages[i - 1]
    if not(cur_i in count):
        count[cur_i] = []

    if cur_i != prev_i:
        count[cur_i].append(prev_i)
        count[prev_i].append(cur_i)
        current_page_switches += abs(cur_i - prev_i)

max_profit = 0

for i in count:
    if len(count[i]) > 0:
        tmp = profit(count[i], i)
        if tmp > max_profit:
            max_profit = tmp

print(current_page_switches - max_profit)

```


456_C. Boredom

Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.

Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player.

Alex is a perfectionist, so he decided to get as many points as possible. Help him.

Input

The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output

Print a single integer — the maximum number of points that Alex can earn.

Examples

Input

2
1 2

Output

2

Input

3
1 2 3

Output

4

Input

9
1 2 1 3 2 2 2 2 3

Output

10

Note

Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.


479_A. Expression

Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:

  * 1+2*3=7
  * 1*(2+3)=5
  * 1*2*3=6
  * (1+2)*3=9

Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.

It's easy to see that the maximum value that you can obtain is 9.

Your task is: given a, b and c print the maximum value that you can get.

Input

The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).

Output

Print the maximum value of the expression that you can obtain.

Examples

Input

1
2
3

Output

9

Input

2
10
3

Output

60

```python
a1 = int(input())
a2 = int(input())
a3 = int(input())

listValue = [a1*a2*a3, a1*(a2+a3), a1*a2+a3, a1+a2*a3, (a1+a2)*a3, a1+a2+a3]
maxValue = listValue[0]
for x in listValue:
    if x > maxValue:
        maxValue = x
print(maxValue)

```


501_A. Contest

Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points t minutes after the contest started, you get <image> points.

Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.

Input

The first line contains four integers a, b, c, d (250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).

It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).

Output

Output on a single line:

"Misha" (without the quotes), if Misha got more points than Vasya.

"Vasya" (without the quotes), if Vasya got more points than Misha.

"Tie" (without the quotes), if both of them got the same number of points.

Examples

Input

500 1000 20 30

Output

Vasya

Input

1000 1000 1 1

Output

Tie

Input

1500 1000 176 177

Output

Misha

```python
a,b,c,d=map(int,input().split())
x=max((3*a//10),(a-(a//250*c)))
y=max((3*b//10),(b-((b//250)*d)))
# print(x,y)
if y>x:
	print('Vasya')
elif x>y:
	print('Misha')
else:
	print('Tie')
```


552_B. Vanya and Books

Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.

Vanya wants to know how many digits he will have to write down as he labels the books.

Input

The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.

Output

Print the number of digits needed to number all the books.

Examples

Input

13

Output

17

Input

4

Output

4

Note

Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.

Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.


579_B. Finding Team Member

There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct.

Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people A and B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one.

Can you determine who will be each person’s teammate?

Input

There are 2n lines in the input.

The first line contains an integer n (1 ≤ n ≤ 400) — the number of teams to be formed.

The i-th line (i > 1) contains i - 1 numbers ai1, ai2, ... , ai(i - 1). Here aij (1 ≤ aij ≤ 106, all aij are distinct) denotes the strength of a team consisting of person i and person j (people are numbered starting from 1.)

Output

Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.

Examples

Input

2
6
1 2
3 4 5

Output

2 1 4 3

Input

3
487060
3831 161856
845957 794650 976977
83847 50566 691206 498447
698377 156232 59015 382455 626960

Output

6 5 4 3 2 1

Note

In the first sample, contestant 1 and 2 will be teammates and so do contestant 3 and 4, so the teammate of contestant 1, 2, 3, 4 will be 2, 1, 4, 3 respectively.

```python
def main():
    mode="filee"
    if mode=="file":f=open("test.txt","r")

    if mode=="file":n=int(f.readline())
    else:n=int(input())
    w=[]
    for i in range(2,2*n+1):
        if mode=="file":g=[int(x) for x in f.readline().split()]
        else:g=[int(x) for x in input().split()]
        for j in range(1,i):
            w.append([g[j-1],[i,j]])
    w.sort()
    free=2*n
    fr=[-1]*(free+1)
    w.reverse()
    for e,k in w:
        if fr[k[0]]==-1 and fr[k[1]]==-1:
            fr[k[0]]=k[1]
            fr[k[1]]=k[0]
            free-=1
            if free==0:
                break
    for i in fr[1:]:
        print(i,end=' ')

    if mode=="file":f.close()

if __name__=="__main__":
    main()

```


600_A. Extract Numbers

You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.

You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the string s).

Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.

For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".

Input

The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.

Output

Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34).

If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.

Examples

Input

aba,123;1a;0

Output

"123,0"
"aba,1a"

Input

1;;01,a0,

Output

"1"
",01,a0,"

Input

1

Output

"1"
-

Input

a

Output

-
"a"

Note

In the second example the string s contains five words: "1", "", "01", "a0", "".

```python
def main():
    str = input().replace(';', ',')
    input_list = str.split(',')

    def pred(x):
        return x.isdigit() and (x[0] != '0' or len(x) == 1)
    lA = list(filter(pred, input_list))
    lB = list(filter(lambda x: not pred(x), input_list))
    print('"{}"'.format(','.join(lA))) if lA else print("-")
    print('"{}"'.format(','.join(lB))) if lB else print("-")

if __name__ == '__main__':
    main()

```


622_D. Optimal Number Permutation

You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.

Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>.

Input

The only line contains integer n (1 ≤ n ≤ 5·105).

Output

Print 2n integers — the permuted array a that minimizes the value of the sum s.

Examples

Input

2

Output

1 1 2 2

Input

1

Output

1 1

```python
n = int(input())
A = [i for i in range(1, n+1, 2)]
B = [i for i in range(n-2 if n%2 else n-1, 0, -2)]
C = [i for i in range(2, n+1, 2)]
D = [i for i in range(n-1 if n%2 else n-2, 0, -2)]
ans = ' '.join(map(str, A+B+C+D+[n]))
print(ans)

```


670_F. Restore a Number

Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.

Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of n (a substring of n is a sequence of consecutive digits of the number n).

Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used).

Input

The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000.

The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes.

It is guaranteed that the input data is correct, and the answer always exists.

Output

Print the smalles integer n which Vasya could pass to Kate.

Examples

Input

003512
021

Output

30021

Input

199966633300
63

Output

3036366999

```python
a = input()
b = input()
d = [0] * 10
n = 0
for j in range(1000100):
    t = str(j)
    if len(t) + j == len(a):
        n = j
for x in str(n):
    d[ord(x) - ord('0')] -= 1
for x in a:
    d[ord(x) - ord('0')] += 1
for x in b:
    d[ord(x) - ord('0')] -= 1
if sum(d)==0:
    print(b)
else:
    A = []
    B = []
    C = []
    D = []
    if b[0] != '0':
        A = list(b)
        for j in range(10):
            for k in range(d[j]):
                A.append(chr(ord('0') + j))
    t = 1
    while t < len(d) and d[t] == 0:
        t += 1
    oo = ord('0')
    if t < len(d):
        B.append(chr(oo+t))
        d[t] -= 1
        for j in range(ord(b[0]) - oo):
            for k in range(d[j]):
                B.append(chr(ord('0') + j))
        B.extend(list(b))
        for j in range(ord(b[0]) - oo, 10):
            for k in range(d[j]):
                B.append(chr(ord('0') + j))

        C.append(chr(oo+t))
        for j in range(min(ord(b[0]) - oo+1, 10)):
            for k in range(d[j]):
                C.append(chr(ord('0') + j))
        C.extend(list(b))
        for j in range(ord(b[0]) - oo+1, 10):
            for k in range(d[j]):
                C.append(chr(ord('0') + j))

    ans = []
    if len(A) > 0:
        ans.append(''.join(A))

    if len(B) > 0:
        ans.append(''.join(B))

    if len(C) > 0:
        ans.append(''.join(C))

    print(min(ans))
```


696_C. PLEASE

As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup.

<image>

Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start.

After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right.

Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that

<image>

in other words, n is multiplication of all elements of the given array.

Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7.

Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7.

Input

The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you.

The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array.

Output

In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7.

Examples

Input

1
2

Output

1/2

Input

3
1 1 1

Output

0/1

```python
k = int(input())
n = list(map(int, input().split()))

for i in range(k):
    n[i] = bin(n[i])
    n[i] = n[i][2:]

magic = 1000000007

def par(s):
    if s[-1] == '0':
        return True
    else:
        return False

def mod_pow(x, s, p):
    ans = 1
    for i in range(len(s)):
        if s[i] == '1':
            ans = (((ans * ans) % p) * x) % p
        else:
            ans = (ans * ans) % p
    return ans

def div_in_field(a, b, p):
    b_op = pow(b, p - 2, p)
    return (b_op * a) % p

denominator = 2
n_par = False
for i in range(len(n)):
    denominator = mod_pow(denominator, n[i], magic)
    if par(n[i]):
        n_par = True

denominator = div_in_field(denominator, 2, magic)
numerator = 0
if n_par:
    numerator = div_in_field(1 + denominator, 3, magic)
else:
    numerator = div_in_field(-1 + denominator, 3, magic)
ans = str(numerator) + '/' + str(denominator)
print(ans)

```


717_D. Dexterina’s Lab

Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re both desperately trying to best the other in various games of wits. This time, Dexterina challenged Womandark to a game of Nim.

Nim is a two-player game in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects from a single heap. The player who can't make a turn loses. By their agreement, the sizes of piles are selected randomly from the range [0, x]. Each pile's size is taken independently from the same probability distribution that is known before the start of the game.

Womandark is coming up with a brand new and evil idea on how to thwart Dexterina’s plans, so she hasn’t got much spare time. She, however, offered you some tips on looking fabulous in exchange for helping her win in Nim. Your task is to tell her what is the probability that the first player to play wins, given the rules as above.

Input

The first line of the input contains two integers n (1 ≤ n ≤ 109) and x (1 ≤ x ≤ 100) — the number of heaps and the maximum number of objects in a heap, respectively. The second line contains x + 1 real numbers, given with up to 6 decimal places each: P(0), P(1), ... , P(X). Here, P(i) is the probability of a heap having exactly i objects in start of a game. It's guaranteed that the sum of all P(i) is equal to 1.

Output

Output a single real number, the probability that the first player wins. The answer will be judged as correct if it differs from the correct answer by at most 10 - 6.

Example

Input

2 2
0.500000 0.250000 0.250000

Output

0.62500000

```python

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

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

def mult(a,b):
    # compute a*b
    c=[0]*128
    for i in range(128):
        for j in range(128):
            c[i^j]+=a[i]*b[j]
    return c

def quickpow(a,b):
    # compute a**b
    if b==1:
        return a
    if b&1:
        return mult(quickpow(mult(a,a),b//2),a)
    return quickpow(mult(a,a),b//2)

prob=list(map(float,input().split()))
prob+=[0.0]*(128-len(prob))

print("%.9f"%(1-quickpow(prob,n)[0]))
```


761_E. Dasha and Puzzle

Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.

<image>

The tree is a non-oriented connected graph without cycles. In particular, there always are n - 1 edges in a tree with n vertices.

The puzzle is to position the vertices at the points of the Cartesian plane with integral coordinates, so that the segments between the vertices connected by edges are parallel to the coordinate axes. Also, the intersection of segments is allowed only at their ends. Distinct vertices should be placed at different points.

Help Dasha to find any suitable way to position the tree vertices on the plane.

It is guaranteed that if it is possible to position the tree vertices on the plane without violating the condition which is given above, then you can do it by using points with integral coordinates which don't exceed 1018 in absolute value.

Input

The first line contains single integer n (1 ≤ n ≤ 30) — the number of vertices in the tree.

Each of next n - 1 lines contains two integers ui, vi (1 ≤ ui, vi ≤ n) that mean that the i-th edge of the tree connects vertices ui and vi.

It is guaranteed that the described graph is a tree.

Output

If the puzzle doesn't have a solution then in the only line print "NO".

Otherwise, the first line should contain "YES". The next n lines should contain the pair of integers xi, yi (|xi|, |yi| ≤ 1018) — the coordinates of the point which corresponds to the i-th vertex of the tree.

If there are several solutions, print any of them.

Examples

Input

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

Output

YES
0 0
1 0
0 1
2 0
1 -1
-1 1
0 2

Input

6
1 2
2 3
2 4
2 5
2 6

Output

NO

Input

4
1 2
2 3
3 4

Output

YES
3 3
4 3
5 3
6 3

Note

In the first sample one of the possible positions of tree is: <image>

```python
n = int(input())
adj = [[] for _ in range(n)]

for _ in range(n - 1):
    u, v = map(int, input().split())
    adj[u - 1].append(v - 1)
    adj[v - 1].append(u - 1)

from collections import deque
def bfs(v):
    vis = [i == v for i in range(n)]
    paths = deque([[v]])

    while paths:
        p = paths.popleft()
        for nv in adj[p[-1]]:
            if not vis[nv]:
                vis[nv] = True
                paths.append(p + [nv])

    return p

diameter = bfs(0)
diameter = bfs(diameter[-1])
p = diameter[len(diameter) // 2]

start = (0, 0)
move = [(0, 1), (1, 0), (0, -1), (-1, 0)]
gpt = lambda pt, i, dis : (pt[0] + move[i][0] * dis, pt[1] + move[i][1] * dis)

vis = [False] * n
dis = 2 ** (len(diameter) + 1)

ans = [0] * n
q = deque([(p, start, -1, dis)])

while q:
    p, start, dr, dis = q.popleft()
    vis[p] = True
    ans[p] = start

    if len(adj[p]) > 4:
        print("NO")
        exit()

    if dr == -1:
        drs = [i for i in range(4)]
    else:
        drs = [i for i in range(4) if gpt(move[i], dr, 1) != (0, 0)]

    for nv in adj[p]:
        if not vis[nv]:
            vis[nv], dr = True, drs.pop()
            npt = gpt(start, dr, dis)
            q.append((nv, npt, dr, dis // 2))
            ans[nv] = npt

print("YES")
for pt in ans:
    print(*pt)

```


784_G. BF Calculator

In this problem you will write a simple generator of Brainfuck (<https://en.wikipedia.org/wiki/Brainfuck>) calculators.

You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.

We use a fairly standard Brainfuck interpreter for checking the programs:

  * 30000 memory cells.
  * memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.
  * console input (, command) is not supported, but it's not needed for this problem.

Input

The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).

Output

Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.

Examples

Input

2+3

Output

++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.

Input

9-7

Output

+++++++++>
+++++++>
<[<->-]<
++++++++++++++++++++++++++++++++++++++++++++++++.

Note

You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.

```python
for n in str(eval(input())):
	for _ in range(ord(n)):
		print('+',sep='',end='')
	print('.>')
```


831_A. Unimodal Array

Array of integers is unimodal, if:

  * it is strictly increasing in the beginning;
  * after that it is constant;
  * after that it is strictly decreasing.

The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

Write a program that checks if an array is unimodal.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

Output

Print "YES" if the given array is unimodal. Otherwise, print "NO".

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

Examples

Input

6
1 5 5 5 4 2

Output

YES

Input

5
10 20 30 20 10

Output

YES

Input

4
1 2 1 2

Output

NO

Input

7
3 3 3 3 3 3 3

Output

YES

Note

In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

```python
n=int(input())
arr=list(map(int,input().split()))
s,t,p=0,0,0
for i in range(1,n) :
    if arr[i] < arr[i - 1]: s = 1
    elif arr[i]==arr[i-1] and s: t=1
    elif arr[i]==arr[i-1] and not s: p=1
    if arr[i]>arr[i-1] and (s or p):t=1

if t:   print("NO")
else :  print("YES")
```


852_B. Neural Network country

Due to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly having many cities. They also have one entry, and one exit point.

There are exactly L layers, each having N cities. Let us look at the two adjacent layers L1 and L2. Each city from the layer L1 is connected to each city from the layer L2 with the traveling cost cij for <image>, and each pair of adjacent layers has the same cost in between their cities as any other pair (they just stacked the same layers, as usual). Also, the traveling costs to each city from the layer L2 are same for all cities in the L1, that is cij is the same for <image>, and fixed j.

Doctor G. needs to speed up his computations for this country so he asks you to find the number of paths he can take from entry to exit point such that his traveling cost is divisible by given number M.

Input

The first line of input contains N (1 ≤ N ≤ 106), L (2 ≤ L ≤ 105) and M (2 ≤ M ≤ 100), the number of cities in each layer, the number of layers and the number that travelling cost should be divisible by, respectively.

Second, third and fourth line contain N integers each denoting costs 0 ≤ cost ≤ M from entry point to the first layer, costs between adjacent layers as described above, and costs from the last layer to the exit point.

Output

Output a single integer, the number of paths Doctor G. can take which have total cost divisible by M, modulo 109 + 7.

Example

Input

2 3 13
4 6
2 1
3 4

Output

2

Note

<image>

This is a country with 3 layers, each layer having 2 cities. Paths <image>, and <image> are the only paths having total cost divisible by 13. Notice that input edges for layer cities have the same cost, and that they are same for all layers.

```python
from sys import stdin

input = stdin.readline

def main():

    mod = 10**9 + 7
    n,l,m = map(int,input().split())
    ar = [0 for i in range(m)]
    ar3 = [0 for i in range(m)]
    def f(num):
        return int(num) % m
    def f2(num):
        return num % 1000000007
    ai1 = list(map(f,input().split()))
    ai2 = list(map(f,input().split()))
    ai3 = list(map(f,input().split()))

    mm = m**2

    ar2 = [0 for i in range(mm)]

    def mult(m1,m2):
        ans = [0 for i in range(mm)]
        m12 = [0 for i in range(m)]

        for i in range(m):
            for j in range(m):
                m12[i] += m1[i+j*m]

        for i in range(m):
            for j in range(m):
                temp = (i+j)%m
                for j2 in range(m):
                    ans[temp+j2*m] += m12[i] * m2[j+j2*m]
        ans = list(map(f2,ans))
        return ans

    def mult2(m1,m2):
        ans = [0] * m

        for i in range(m):
            for j in range(m):
                ans[(i+j)%m] += m1[i] * m2[j]

        print(ans[0] % mod)

    def mult3(m1,m2):
        m12 = [0 for i in range(m)]

        for i in range(m):
            for j in range(m):
                m12[i] += m1[i+j*m]
                m12[i] %= mod

        m22 = [0 for i in range(m)]

        for i in range(m):
            for j in range(m):
                m22[i] += m2[i+j*m]
                m22[i] %= mod

        ans = [0 for i in range(mm)]
        for i in range(m):
            for j in range(m):
                ans[(i+j)%m] += m12[i] * m22[j]
                ans[(i+j)%m] %= mod

        return ans

    def power(number, n):
        n -= 1
        if n == -1:
            return number
        res = number
        number2 = [number[i] for i in range(mm)]

        while(n):
            if n & 1:
                res = mult3(res,number)
            number = mult3(number,number)
            n >>= 1

        return mult(res,number2)

    for i in range(n):
        ar[ai1[i]] += 1
        ar2[ai2[i] + ai3[i]* m] += 1
        ar3[ai2[i]] += 1

    if l == 1:
        mult2(ar,ar3)
        return
    ans = power(ar2,l-2)
    ar4 = [0] * m
    for i in range(m):
        for j in range(m):
            ar4[(i+j)%m] += ans[i + j*m]
    mult2(ar,ar4)
main()

```


876_C. Classroom Watch

Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.

Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

Input

The first line contains integer n (1 ≤ n ≤ 109).

Output

In the first line print one integer k — number of different values of x satisfying the condition.

In next k lines print these values in ascending order.

Examples

Input

21

Output

1
15

Input

20

Output

0

Note

In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.

In the second test case there are no such x.

```python
import sys
text = sys.stdin.read().strip()
n = int(text)
q = lambda x: sum([int(b) for b in str(x)])
e = []
for i in range(max(0, n-81), n):
    if i + q(i) == n:
        e.append(i)
print(len(e))
for z in e:
    print(z)

```


8_C. Looking for Order

Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.

You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.

Input

The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.

Output

In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.

In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.

Examples

Input

0 0
2
1 1
-1 1

Output

8
0 1 2 0

Input

1 1
3
4 3
3 4
0 0

Output

32
0 1 2 0 3 0

```python
import sys

def main():
    BITS = [1 << sh for sh in range(24)]
    B2N = {v: u for u, v in enumerate(BITS)}

    def getPt():
        return tuple(map(int, input().split()))

    def dist(ptA, ptB):
        return sum(((u - v) ** 2 for u, v in zip(ptA, ptB)))

    def getBits(val):
        return tuple(filter(lambda x: x & val, BITS))

    def chooseTwo(pool):
        n = len(pool)
        for i in range(n):
            for j in range(i + 1, n):
                yield (pool[i], pool[j])

    ori = getPt()
    pts = []
    N = int(input())

    for _ in range(N):
        pts.append(getPt())

    vis = set([0])
    mint = [0] + [1e8] * (1 << N)  # minimal time for dp
    pres = [None] * (1 << N)  # previous step for reconstruct path
    allb = (1 << N) - 1  # all objects contained state
    B2P = {BITS[u]: v for u, v in enumerate(pts)}
    B2P[0] = ori
    alld = {u: {v: dist(B2P[u], B2P[v]) for v in B2P} for u in B2P}

    getDP = lambda x: mint[x]
    newDist = lambda stt, p: mint[stt] + alld[p[0]][p[1]] \
                             + alld[p[0]][0] \
                             + alld[p[1]][0]

    for stt in range(1 << N):
        if stt not in vis:
            continue

        bits = getBits(~stt & allb)

        sb = bits[0] if bits else None

        for bit in bits:

            newstt = stt | sb | bit
            nd = newDist(stt, (sb, bit))
            if getDP(newstt) > nd:
                mint[newstt] = nd
                pres[newstt] = sb | bit
                vis.add(newstt)

    print(mint[allb])
    path = ['0']
    stt = allb

    while stt:

        bits = getBits(pres[stt])
        for bit in bits:
            path.append(str(B2N[bit] + 1))
        path.append('0')

        stt ^= pres[stt]

    print(' '.join(path))

main()

```


922_B. Magic Forest

Imp is in a magic forest, where xorangles grow (wut?)

<image>

A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest.

Formally, for a given integer n you have to find the number of such triples (a, b, c), that:

  * 1 ≤ a ≤ b ≤ c ≤ n;
  * <image>, where <image> denotes the [bitwise xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of integers x and y.
  * (a, b, c) form a non-degenerate (with strictly positive area) triangle.

Input

The only line contains a single integer n (1 ≤ n ≤ 2500).

Output

Print the number of xorangles of order n.

Examples

Input

6

Output

1

Input

10

Output

2

Note

The only xorangle in the first sample is (3, 5, 6).

```python
import math
n = int(input())
ans = 0
for a in range(1, n+1):
    for b in range(a, n+1):
        c= a^b
        if c < b or c > n:
            continue
        if a+b > c:
            ans += 1
print(ans)
```


94_C. Frames

Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.

This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good.

Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window.

Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.

Input

The only line contains four integers n, m, a, b (1 ≤ n, m ≤ 109, 1 ≤ a ≤ b ≤ n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.

Output

Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b.

Examples

Input

11 4 3 9

Output

3

Input

20 5 2 20

Output

2

Note

The images below illustrate statement tests.

The first test:

<image>

In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.

The second test:

<image>

In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones.

```python
import math
n,m,a,b=map(int,input().split())

if (a-1)//m==(b-1)//m:
    print(1)
elif (a-1)%m==0 and b%m==0:
    print(1)
elif (a-1)%m==0 and b==n or m==1:
    print(1)
elif (a-1)%m==0 or b%m==0 or b==n:
    print(2)
elif abs((a-1)//m - (b-1)//m)==1 or m==2:
    print(2)
elif (a-1)%m==b%m:
    print(2)
else:
    print(3)

```


978_A. Remove Duplicates

Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements.

Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of elements in Petya's array.

The following line contains a sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 1 000) — the Petya's array.

Output

In the first line print integer x — the number of elements which will be left in Petya's array after he removed the duplicates.

In the second line print x integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.

Examples

Input

6
1 5 5 1 6 1

Output

3
5 6 1

Input

5
2 4 2 4 4

Output

2
2 4

Input

5
6 6 6 6 6

Output

1
6

Note

In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2.

In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4.

In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.

```python
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
res = []
for a in A:
    C[a] -= 1
    if C[a] == 0:
        res.append(a)
print(len(res))
print(*res)

```


p02657 AtCoder Beginner Contest 169 - Multiplication 1

Compute A \times B.

Constraints

* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Examples

Input

2 5

Output

10

Input

100 100

Output

10000

```python
a, b = [int(_) for _ in input().split()]
print(a*b)
```


p02786 AtCoder Beginner Contest 153 - Caracal vs Monster

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

* If the monster's health is 1, it drops to 0.
* If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

* 1 \leq H \leq 10^{12}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Examples

Input

2

Output

3

Input

4

Output

7

Input

1000000000000

Output

1099511627775

```python
h = int(input())
ans = 2 ** (len(bin(h))-2) - 1
print(ans)
```


p02922 AtCoder Beginner Contest 139 - Power Socket

Takahashi's house has only one socket.

Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.

One power strip with A sockets can extend one empty socket into A empty sockets.

Find the minimum number of power strips required.

Constraints

* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of power strips required.

Examples

Input

4 10

Output

3

Input

8 9

Output

2

Input

8 8

Output

1

```python
a, b = map(int, input().split())
ans =-(-(b-a)//(a-1))+1
print(ans)
```


p03057 AtCoder Grand Contest 033 - Go around a Circle

Consider a circle whose perimeter is divided by N points into N arcs of equal length, and each of the arcs is painted red or blue. Such a circle is said to generate a string S from every point when the following condition is satisfied:

* We will arbitrarily choose one of the N points on the perimeter and place a piece on it.
* Then, we will perform the following move M times: move the piece clockwise or counter-clockwise to an adjacent point.
* Here, whatever point we choose initially, it is always possible to move the piece so that the color of the i-th arc the piece goes along is S_i, by properly deciding the directions of the moves.

Assume that, if S_i is `R`, it represents red; if S_i is `B`, it represents blue. Note that the directions of the moves can be decided separately for each choice of the initial point.

You are given a string S of length M consisting of `R` and `B`. Out of the 2^N ways to paint each of the arcs red or blue in a circle whose perimeter is divided into N arcs of equal length, find the number of ways resulting in a circle that generates S from every point, modulo 10^9+7.

Note that the rotations of the same coloring are also distinguished.

Constraints

* 2 \leq N \leq 2 \times 10^5
* 1 \leq M \leq 2 \times 10^5
* |S|=M
* S_i is `R` or `B`.

Input

Input is given from Standard Input in the following format:

N M
S

Output

Print the number of ways to paint each of the arcs that satisfy the condition, modulo 10^9+7.

Examples

Input

4 7
RBRRBRR

Output

2

Input

3 3
BBB

Output

4

Input

12 10
RRRRBRRRRB

Output

78

```python

"""

https://atcoder.jp/contests/agc033/tasks/agc033_e

Sの1文字目をRとしてよい

RB  から始まる場合　→ 全部交互以外無理(Nが奇数なら0)
RRB から始まる場合　→ Rは3連で置けば可能…

R*X + B*Y + R*Z …
とつながっていく

どこからスタートしても、RだけをX回移動したときにBの隣に来なくてはいけない
Rの長さが1なら可能

R*?,B,R*?,…
でつながっていく

最初のRがX個連続の時
片方の端との距離がX-2tでなくてはならない
Xが偶数の時、Rの連続長さはX+1以下の奇数
Xが奇数の時、端からスタートした奴は反対側に抜けなくてはいけないので
Rの連続長さはX以下の奇数？
結局は奇数個連続でしか置けない

●整理(Rから始まり、Bがある場合)：
Rは奇数個連続でしか置けない
Bは1個連続でしか置けない
→つまり、Nが奇数だとアウト

Bが来た以降を考えてみる
奇数だと、各点Rの左右のどちらかにしか抜けられない→対称的な移動になるはず
→つまり、最初のRを消化した後、全てのBの両端にいる場合が存在する

Bは奇数個の時のみ意味がある
→結局、Bの両端にいた場合が交換されるだけ
→よって、BはRの区切り以上の意味はない

Rが偶数個来るた場合、交互に移動すればおk
Rが奇数個来た場合、反対側に抜ける必要がある

結論：
RBがどちらも存在する場合、Nが偶数なら0、奇数の場合は
BでsplitしたRの個数の集合を考え,
r1,r2…,r? とする
Rは奇数個連続で置けて、その個数の最大は M = min( r1+1 , r? ) #r?が奇数の物
後は、M+1個以下の偶数個単位で区切る場合の数を調べればいい
dp→あらかじめ1番目の区間の位置に、ずれた分も考慮して値を入れておけばBITでもらうdpできる

RB片方の場合、Bが連続しないような置き方をすればいい
1番目がRの場合をdp → N番目までやる
1番目がBの場合をdp → N-1番目までやる(N番目は赤なので)

最後のRは意味がないので消しておく

REの原因究明したい
K < NNの場合？

"""

from sys import stdin
import sys
#0-indexed , 半開区間[a,b)
#calc変更で演算変更
class SegTree:

    def __init__(self,N,first):
        self.NO = 2**(N-1).bit_length()
        self.First = first
        self.data = [first] * (2*self.NO)

    def calc(self,l,r):
        return (l+r) % mod

    def update(self,ind,x):
        ind += self.NO - 1
        self.data[ind] = x
        while ind >= 0:
            ind = (ind - 1)//2
            self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2])

    def query(self,l,r):
        L = l + self.NO
        R = r + self.NO
        s = self.First
        while L < R:
            if R & 1:
                R -= 1
                s = self.calc(s , self.data[R-1])
            if L & 1:
                s = self.calc(s , self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def get(self , ind):
        ind += self.NO - 1
        return self.data[ind]

N,M = map(int,stdin.readline().split())
S = list(stdin.readline()[:-1])
mod = 10**9+7

if "R" in S and "B" in S:

    if N % 2 == 1:
        print (0)
        sys.exit()

    lis = []
    now = 0
    while S[-1] == S[0]: #最後のRを消す
        del S[-1]
    for i in S:
        if i == S[0]:
            now += 1
        elif now > 0:
            lis.append(now)
            now = 0
    #print (lis)

    nmax = 0
    for i in range(len(lis)):
        if i == 0:
            if lis[i] % 2 == 0:
                nmax = lis[i] + 1
            else:
                nmax = lis[i]
        elif lis[i] % 2 == 1:
            nmax = min(nmax , lis[i])

    NN   = N//2
    K    = (nmax+1)//2
    print (NN,K,file=sys.stderr)

    if NN <= K:
        print ((pow(2,NN,mod)-1) * 2 % mod)
        sys.exit()

    ST = SegTree(NN,0)
    for i in range(K):
        ST.update(i,i+1)

    for i in range(1,NN):
        now = ST.get(i)
        plus = ST.query( max(0,i-K),i )
        ST.update( i , (now+plus) % mod )

    print (ST.get(NN-1) * 2 % mod)

else:

    ans = 0
    #1番目がRの場合
    dp = [1,0]
    for i in range(N-1):
        ndp = [0,0]
        ndp[0] = (dp[0] + dp[1]) % mod
        ndp[1] = dp[0]
        dp = ndp

    ans += sum(dp)

    #1番目がBの場合
    dp = [0,1]
    for i in range(N-2):
        ndp = [0,0]
        ndp[0] = (dp[0] + dp[1]) % mod
        ndp[1] = dp[0]
        dp = ndp
    ans += sum(dp)

    print (ans % mod)
```


p03201 AtCoder Grand Contest 029 - Powers of two

Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.

Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Constraints

* 1 \leq N \leq 2\times 10^5
* 1 \leq A_i \leq 10^9
* A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2.

Examples

Input

3
1 2 3

Output

1

Input

5
3 11 14 5 13

Output

2

```python
from collections import Counter

N = int(input())
As = list(map(int, input().split()))

cnt = Counter(As)
As.sort(reverse=True)

Ps = [2]
for i in range(29):
    Ps.append(Ps[-1] * 2)

ans = 0
for A in As:
    if cnt[A] <= 0: continue
    cnt[A] -= 1

    while Ps[-1] > 2 * A:
        Ps.pop()

    if cnt[Ps[-1] - A] > 0:
        ans += 1
        cnt[Ps[-1] - A] -= 1

print(ans)

```


p03348 AtCoder Grand Contest 024 - Isomorphism Freak

Coloring of the vertices of a tree G is called a good coloring when, for every pair of two vertices u and v painted in the same color, picking u as the root and picking v as the root would result in isomorphic rooted trees.

Also, the colorfulness of G is defined as the minimum possible number of different colors used in a good coloring of G.

You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. We will construct a new tree T by repeating the following operation on this tree some number of times:

* Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge.

Find the minimum possible colorfulness of T. Additionally, print the minimum number of leaves (vertices with degree 1) in a tree T that achieves the minimum colorfulness.

Constraints

* 2 \leq N \leq 100
* 1 \leq a_i,b_i \leq N(1\leq i\leq N-1)
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

Print two integers with a space in between. First, print the minimum possible colorfulness of a tree T that can be constructed. Second, print the minimum number of leaves in a tree that achieves it.

It can be shown that, under the constraints of this problem, the values that should be printed fit into 64-bit signed integers.

Examples

Input

5
1 2
2 3
3 4
3 5

Output

2 4

Input

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

Output

3 4

Input

10
1 2
2 3
3 4
4 5
5 6
6 7
3 8
5 9
3 10

Output

4 6

Input

13
5 6
6 4
2 8
4 7
8 9
3 2
10 4
11 10
2 4
13 10
1 8
12 1

Output

4 12

```python
import sys
input = sys.stdin.readline

INF = (1<<60)

N = int(input())
graph = [[] for _ in range(N)]
Edges = []
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    Edges.append((a-1, b-1))

def bfs(s, noback):
    q = [s]
    D = [-1]*N
    D[s] = 0
    while q:
        qq = []
        for p in q:
            for np in graph[p]:
                if D[np] == -1 and np != noback:
                    D[np] = D[p] + 1
                    qq.append(np)
        q = qq

    Ds = [0]*(N+1)
    faraway = 0
    for i, d in enumerate(D):
        faraway = max(faraway, d)
        Ds[d] = max(Ds[d], len(graph[i])-1)
    return Ds, faraway

colorful = INF
nodes = INF

for n in range(N):
    M = [0]*(N+1)
    far = 0
    leaves = 0
    for s in graph[n]:
        leaves += 1
        Ds, faraway = bfs(s, n)
        far = max(far, faraway)
        for i, d in enumerate(Ds):
            M[i] = max(M[i], d)
    color = far + 2
    if color <= colorful:
        if color != colorful:
            nodes = INF
        colorful = color
        for f in range(far):
            leaves *= M[f]
        if leaves < nodes:
            nodes = leaves

for a, b in Edges:
    M = [0]*(N+1)
    leaves = 2
    D1, faraway1 = bfs(a, b)
    for i, d in enumerate(D1):
        M[i] = max(M[i], d)

    D2, faraway2 = bfs(b, a)
    for i, d in enumerate(D2):
        M[i] = max(M[i], d)

    far = max(faraway1, faraway2)
    color = far + 1
    if color <= colorful:
        if color != colorful:
            nodes = INF
        colorful = color
        for f in range(far):
            leaves *= M[f]
        if leaves < nodes:
            nodes = leaves

print(colorful, nodes)
```