1183_G. Candy Box (hard version)

This problem is a version of problem D from the same contest with some additional constraints and tasks.

There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n).

You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type 1 and two candies of type 2 is bad).

It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.

You really like some of the candies and don't want to include them into the gift, but you want to eat them yourself instead. For each candy, a number f_i is given, which is equal to 0 if you really want to keep i-th candy for yourself, or 1 if you don't mind including it into your gift. It is possible that two candies of the same type have different values of f_i.

You want your gift to be as large as possible, but you don't want to include too many of the candies you want to eat into the gift. So, you want to calculate the maximum possible number of candies that can be included into a gift, and among all ways to choose maximum number of candies, you want to maximize the number of candies having f_i = 1 in your gift.

You have to answer q independent queries.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

The first line of each query contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of candies.

Then n lines follow, each containing two integers a_i and f_i (1 ≤ a_i ≤ n, 0 ≤ f_i ≤ 1), where a_i is the type of the i-th candy, and f_i denotes whether you want to keep the i-th candy for yourself (0 if you want to keep it, 1 if you don't mind giving it away).

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

Output

For each query print two integers:

  * the maximum number of candies in a gift you can compose, according to the constraints in the statement;
  * the maximum number of candies having f_i = 1 in a gift you can compose that contains the maximum possible number of candies.

Example

Input

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

Output

3 3
3 3
9 5

Note

In the first query, you can include two candies of type 4 and one candy of type 5. All of them have f_i = 1 and you don't mind giving them away as part of the gift.

```python
from collections import defaultdict
from sys import stdin, stdout

q = int(stdin.readline())

for it in range(q):
    n = int(stdin.readline())
    d = [0]*n
    f = [0]*n
    for i in range(n):
        t, b = map(int, stdin.readline().split())
        d[t-1]+=1
        if b == 1:
            f[t-1] += 1

    d = [(x, i) for i, x in enumerate(d)]
    d.sort(reverse=True)
    s = set()
#    print(l)
    ans = 0
    ans_f = 0
    cur = n
    idx = 0
    while cur > 0:
        while idx < len(d) and d[idx][0] == cur:
            d1 = d[idx]
            s.add((f[d1[1]], d1[1]))
            idx += 1
        if s:
            ans += cur
            e = max(s)
            ans_f += min(cur, e[0])
            s.remove(e)
        cur -= 1

    stdout.write(str(ans)+" "+str(ans_f)+"\n")

```


1201_B. Zero Array

You are given an array a_1, a_2, …, a_n.

In one operation you can choose two elements a_i and a_j (i ≠ j) and decrease each of them by one.

You need to check whether it is possible to make all the elements equal to zero or not.

Input

The first line contains a single integer n (2 ≤ n ≤ 10^5) — the size of the array.

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

Output

Print "YES" if it is possible to make all elements zero, otherwise print "NO".

Examples

Input

4
1 1 2 2

Output

YES

Input

6
1 2 3 4 5 6

Output

NO

Note

In the first example, you can make all elements equal to zero in 3 operations:

  * Decrease a_1 and a_2,
  * Decrease a_3 and a_4,
  * Decrease a_3 and a_4

In the second example, one can show that it is impossible to make all elements equal to zero.

```python
n=int(input())
a=list(map(int, input().split()))
if(sum(a)<2*max(a) or sum(a)%2==1):
    print("NO")
else:
    print("YES")
```


1243_B1. Character Swap (Easy Version)

This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.

After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.

Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?

Note that he has to perform this operation exactly once. He has to perform this operation.

Input

The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.

For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.

Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.

Output

For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.

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

Example

Input

4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca

Output

Yes
No
No
No

Note

In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".

In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.

```python
t=int(input())
for ti in range(t):
    n=int(input())
    lia=[]
    lib=[]
    a=list(input())
    b=list(input())
    ctr=0
    for i in range(n):
        if a[i]!=b[i]:
            lia.append(a[i])
            lib.append(b[i])
            ctr+=1
        if ctr>2:
            print("No")
            break
    if ctr==2:
        if lia[0]==lia[1] and lib[0]==lib[1]:
            print("Yes")
        else:
            print("No")
    elif ctr==1:
        print("No")
```


1284_C. New Year and Permutation

Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

A sequence a is a subsegment of a sequence b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as [l, r], where l, r are two integers with 1 ≤ l ≤ r ≤ n. This indicates the subsegment where l-1 elements from the beginning and n-r elements from the end are deleted from the sequence.

For a permutation p_1, p_2, …, p_n, we define a framed segment as a subsegment [l,r] where max\\{p_l, p_{l+1}, ..., p_r\} - min\\{p_l, p_{l+1}, ..., p_r\} = r - l. For example, for the permutation (6, 7, 1, 8, 5, 3, 2, 4) some of its framed segments are: [1, 2], [5, 8], [6, 7], [3, 3], [8, 8]. In particular, a subsegment [i,i] is always a framed segments for any i between 1 and n, inclusive.

We define the happiness of a permutation p as the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n, and [l, r] is a framed segment. For example, the permutation [3, 1, 2] has happiness 5: all segments except [1, 2] are framed segments.

Given integers n and m, Jongwon wants to compute the sum of happiness for all permutations of length n, modulo the prime number m. Note that there exist n! (factorial of n) different permutations of length n.

Input

The only line contains two integers n and m (1 ≤ n ≤ 250 000, 10^8 ≤ m ≤ 10^9, m is prime).

Output

Print r (0 ≤ r < m), the sum of happiness for all permutations of length n, modulo a prime number m.

Examples

Input

1 993244853

Output

1

Input

2 993244853

Output

6

Input

3 993244853

Output

32

Input

2019 993244853

Output

923958830

Input

2020 437122297

Output

265955509

Note

For sample input n=3, let's consider all permutations of length 3:

  * [1, 2, 3], all subsegments are framed segment. Happiness is 6.
  * [1, 3, 2], all subsegments except [1, 2] are framed segment. Happiness is 5.
  * [2, 1, 3], all subsegments except [2, 3] are framed segment. Happiness is 5.
  * [2, 3, 1], all subsegments except [2, 3] are framed segment. Happiness is 5.
  * [3, 1, 2], all subsegments except [1, 2] are framed segment. Happiness is 5.
  * [3, 2, 1], all subsegments are framed segment. Happiness is 6.

Thus, the sum of happiness is 6+5+5+5+5+6 = 32.

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

fac = [1]
for i in range(1, n + 1):
    fac.append(i * fac[i - 1] % m)
ans = 0
for i in range(1, n+1):
    ans += (n - i + 1) * fac[i] * fac[n - i + 1]
    ans %= m
print(ans)

```


1303_E. Erase Subsequences

You are given a string s. You can build new string p from s using the following operation no more than two times:

  1. choose any subsequence s_{i_1}, s_{i_2}, ..., s_{i_k} where 1 ≤ i_1 < i_2 < ... < i_k ≤ |s|;
  2. erase the chosen subsequence from s (s can become empty);
  3. concatenate chosen subsequence to the right of the string p (in other words, p = p + s_{i_1}s_{i_2}... s_{i_k}).

Of course, initially the string p is empty.

For example, let s = ababcd. At first, let's choose subsequence s_1 s_4 s_5 = abc — we will get s = bad and p = abc. At second, let's choose s_1 s_2 = ba — we will get s = d and p = abcba. So we can build abcba from ababcd.

Can you build a given string t using the algorithm above?

Input

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

Next 2T lines contain test cases — two per test case. The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 400) — the initial string.

The second line contains string t consisting of lowercase Latin letters (1 ≤ |t| ≤ |s|) — the string you'd like to build.

It's guaranteed that the total length of strings s doesn't exceed 400.

Output

Print T answers — one per test case. Print YES (case insensitive) if it's possible to build t and NO (case insensitive) otherwise.

Example

Input

4
ababcd
abcba
a
b
defi
fed
xyz
x

Output

YES
NO
NO
YES

```python
# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO,IOBase
from math import inf,isinf

def solve(s,t):
    if len(t) == 1:
        if s.count(t[0]):
            return 'YES'
        return 'NO'
    for i in range(1,len(t)):
        dp = [[-inf]*(i+1) for _ in range(len(s)+1)]
        dp[0][0] = 0
        for j in range(len(s)):
            dp[j+1] = dp[j][:]
            for k in range(i+1):
                if k != i and s[j] == t[k]:
                    dp[j+1][k+1] = max(dp[j+1][k+1],dp[j][k])
                if dp[j][k]+i != len(t) and not isinf(dp[j][k]) and s[j] == t[dp[j][k]+i]:
                    dp[j+1][k] = max(dp[j+1][k],dp[j][k]+1)
        # print(*dp,sep='\n')
        # print('-----')
        for l in range(len(s)+1):
            if dp[l][-1] == len(t)-i:
                return 'YES'
    return 'NO'

def main():
    for _ in range(int(input())):
        s = input().strip()
        t = input().strip()
        print(solve(s,t))

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

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


1327_F. AND Segments

You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m).

Calculate the number of distinct arrays a, consisting of n integers such that:

  * 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n;
  * bitwise AND of numbers a[l_i] \& a[l_i + 1] \& ... \& a[r_i] = x_i for each 1 ≤ i ≤ m.

Two arrays a and b are considered different if there exists such a position i that a_i ≠ b_i.

The number can be pretty large so print it modulo 998244353.

Input

The first line contains three integers n, k and m (1 ≤ n ≤ 5 ⋅ 10^5, 1 ≤ k ≤ 30, 0 ≤ m ≤ 5 ⋅ 10^5) — the length of the array a, the value such that all numbers in a should be smaller than 2^k and the number of conditions, respectively.

Each of the next m lines contains the description of a condition l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i < 2^k) — the borders of the condition segment and the required bitwise AND value on it.

Output

Print a single integer — the number of distinct arrays a that satisfy all the above conditions modulo 998244353.

Examples

Input

4 3 2
1 3 3
3 4 6

Output

3

Input

5 2 3
1 3 2
2 5 0
3 3 3

Output

33

Note

You can recall what is a bitwise AND operation [here](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

In the first example, the answer is the following arrays: [3, 3, 7, 6], [3, 7, 7, 6] and [7, 3, 7, 6].

```python
def main():
    import sys
    input = sys.stdin.buffer.readline

    mod = 998244353
    N, K, M = map(int, input().split())
    cond = []
    for _ in range(M):
       cond.append(tuple(map(int, input().split())))

    ans = 1
    for k in range(K):
        one = [0] * (N+1)
        zero_cond = [0] * (N+1)
        for l, r, x in cond:
            if x >> k & 1:
                one[l-1] += 1
                one[r] -= 1
            else:
                zero_cond[r] = max(zero_cond[r], l)
        for i in range(N):
            one[i+1] += one[i]
        dp = [0] * (N+1)
        dp[0] = 1
        cs = [0] * (N+2)
        cs[1] = 1
        R = 0
        for i in range(N):
            if not one[i]:
                dp[i+1] = (cs[i+1] - cs[R])%mod
            cs[i+2] = (cs[i+1] + dp[i+1])%mod
            R = max(R, zero_cond[i+1])
        ans = (ans * (cs[-1] - cs[R])%mod)%mod
    print(ans)

if __name__ == '__main__':
    main()

```


1368_F. Lamps on a Circle

This is an interactive problem.

John and his imaginary friend play a game. There are n lamps arranged in a circle. Lamps are numbered 1 through n in clockwise order, that is, lamps i and i + 1 are adjacent for any i = 1, …, n - 1, and also lamps n and 1 are adjacent. Initially all lamps are turned off.

John and his friend take turns, with John moving first. On his turn John can choose to terminate the game, or to make a move. To make a move, John can choose any positive number k and turn any k lamps of his choosing on. In response to this move, John's friend will choose k consecutive lamps and turn all of them off (the lamps in the range that were off before this move stay off). Note that the value of k is the same as John's number on his last move. For example, if n = 5 and John have just turned three lamps on, John's friend may choose to turn off lamps 1, 2, 3, or 2, 3, 4, or 3, 4, 5, or 4, 5, 1, or 5, 1, 2.

After this, John may choose to terminate or move again, and so on. However, John can not make more than 10^4 moves.

John wants to maximize the number of lamps turned on at the end of the game, while his friend wants to minimize this number. Your task is to provide a strategy for John to achieve optimal result. Your program will play interactively for John against the jury's interactor program playing for John's friend.

Suppose there are n lamps in the game. Let R(n) be the number of turned on lamps at the end of the game if both players act optimally. Your program has to terminate the game with at least R(n) turned on lamps within 10^4 moves. Refer to Interaction section below for interaction details.

For technical reasons hacks for this problem are disabled.

Interaction

Initially your program will be fed a single integer n (1 ≤ n ≤ 1000) — the number of lamps in the game. Then the interactor will wait for your actions.

To make a move, print a line starting with an integer k (1 ≤ k ≤ n), followed by k distinct integers l_1, …, l_k (1 ≤ l_i ≤ n) — indices of lamps you want to turn on. The indices may be printed in any order. It is allowed to try to turn on a lamp that is already on (although this will have no effect).

If your move was invalid for any reason, or if you have made more than 10^4 moves, the interactor will reply with a line containing a single integer -1. Otherwise, the reply will be a line containing a single integer x (1 ≤ x ≤ n), meaning that the response was to turn off k consecutive lamps starting from x in clockwise order.

To terminate the game instead of making a move, print a line containing a single integer 0. The test will be passed if at this point there are at least R(n) lamps turned on (note that neither R(n), nor the verdict received are not communicated to your program in any way). This action does not count towards the number of moves (that is, it is legal to terminate the game after exactly 10^4 moves).

To receive the correct verdict, your program should terminate immediately after printing 0, or after receiving -1 as a response.

Don't forget to flush your output after every action.

Examples

Input

3

Output

0

Input

4

1

Output

2 1 3

0

Note

When n = 3, any John's move can be reversed, thus R(3) = 0, and terminating the game immediately is correct.

R(4) = 1, and one strategy to achieve this result is shown in the second sample case.

Blank lines in sample interactions are for clarity and should not be printed.

```python
from sys import stdout, exit
from traceback import format_exc

def main():
    n = int(input())
    on = [False] * n
    def query(ll):
        res = 0
        pvals = [i+1 for i in ll]
        print(len(ll), ' '.join(map(str,pvals)))
        stdout.flush()
        for i in ll:
            if not on[i]:
                res += 1
                on[i] = True
        x = int(input())
        if x == -1:
            exit()
        for i in range(x-1, x+len(ll)-1):
            if on[i%n]:
                res -= 1
                on[i%n] = False
        return res

    if n < 4:
        print(0)
        return
    max = -n
    mk = -1
    for k in range(2, n):
        x = n - k - ((n - 1) // k)
        if x > max:
            max = x
            mk = k
    blocked = []
    for i in range(n):
        if i%mk==0:
            blocked.append(True)
        else:
            blocked.append(False)
    while True:
        ll = []
        count = 0
        for i in range(n):
            if not on[i] and not blocked[i]:
                ll.append(i)
                count+=1
                if count == mk:
                    break
        res = query(ll)
        if res < 1:
            break

    print(0)
    stdout.flush()

if __name__ == "__main__":
    try:
        main()
    except:
        print(format_exc())
```


138_A. Literature Lesson

Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.

Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.

Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).

Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):

  * Clerihew (aabb);
  * Alternating (abab);
  * Enclosed (abba).

If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).

If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.

Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.

Input

The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.

If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.

Output

Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.

Examples

Input

1 1
day
may
sun
fun

Output

aabb

Input

1 1
day
may
gray
way

Output

aaaa

Input

2 1
a
a
a
a
a
a
e
e

Output

aabb

Input

2 1
day
may
sun
fun
test
hill
fest
thrill

Output

NO

Note

In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".

```python
n,k=list(map(int,input().split()))
def z(a,b):
    global k
    c=0
    d=''
    for i in range(len(a)-1,-1,-1):
        d+=a[i]
        if a[i] in ['a','e','i','o','u']:
            c+=1
        if c==k:
            break
    f=c==k
    c=0
    e=''
    for i in range(len(b)-1,-1,-1):
        e+=b[i]
        if b[i] in ['a','e','i','o','u']:
            c+=1
        if c==k:
            break
    return d==e and c==k and f
a=0
b=0
c=0
d=0
for i in range(n):
    e=input()
    f=input()
    g=input()
    h=input()
    a1=z(e,f)
    a2=z(e,g)
    a3=z(e,h)
    a4=z(f,g)
    a5=z(f,h)
    a6=z(g,h)
    if a1 and a2 and a3 and a4 and a5 and a6:
        d+=1
    elif a1 and a6:
        a+=1
    elif a2 and a5:
        b+=1
    elif a3 and a4:
        c+=1
if a+b+c+d!=n:
    print('NO')
elif b==0 and c==0:
    print('aaaa' if a==0 else 'aabb')
elif a==0 and c==0:
    print('aaaa' if b==0 else 'abab')
elif a==0 and b==0:
    print('aaaa' if c==0 else 'abba')
else:
    print('NO')
```


1454_E. Number of Simple Paths

You are given an undirected graph consisting of n vertices and n edges. It is guaranteed that the given graph is connected (i. e. it is possible to reach any vertex from any other vertex) and there are no self-loops and multiple edges in the graph.

Your task is to calculate the number of simple paths of length at least 1 in the given graph. Note that paths that differ only by their direction are considered the same (i. e. you have to calculate the number of undirected paths). For example, paths [1, 2, 3] and [3, 2, 1] are considered the same.

You have to answer t independent test cases.

Recall that a path in the graph is a sequence of vertices v_1, v_2, …, v_k such that each pair of adjacent (consecutive) vertices in this sequence is connected by an edge. The length of the path is the number of edges in it. A simple path is such a path that all vertices in it are distinct.

Input

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

The first line of the test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of vertices (and the number of edges) in the graph.

The next n lines of the test case describe edges: edge i is given as a pair of vertices u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), where u_i and v_i are vertices the i-th edge connects. For each pair of vertices (u, v), there is at most one edge between u and v. There are no edges from the vertex to itself. So, there are no self-loops and multiple edges in the graph. The graph is undirected, i. e. all its edges are bidirectional. The graph is connected, i. e. it is possible to reach any vertex from any other vertex by moving along the edges of the graph.

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

Output

For each test case, print one integer: the number of simple paths of length at least 1 in the given graph. Note that paths that differ only by their direction are considered the same (i. e. you have to calculate the number of undirected paths).

Example

Input

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

Output

6
11
18

Note

Consider the second test case of the example. It looks like that:

<image>

There are 11 different simple paths:

  1. [1, 2];
  2. [2, 3];
  3. [3, 4];
  4. [2, 4];
  5. [1, 2, 4];
  6. [1, 2, 3];
  7. [2, 3, 4];
  8. [2, 4, 3];
  9. [3, 2, 4];
  10. [1, 2, 3, 4];
  11. [1, 2, 4, 3].

```python
import sys
input=sys.stdin.readline
from collections import defaultdict,deque
t=int(input())
for _ in range(t):
    n=int(input())
    ct=[1]*(n+1)
    deg=[0]*(n+1)
    d=defaultdict(set)
    for _ in range(n):
        u,v=map(int,input().split())
        d[u].add(v)
        d[v].add(u)
        deg[u]+=1
        deg[v]+=1
    hp=deque()
    for i in range(n+1):
        if deg[i]==1:
            hp.append(i)
    while hp:
        x=hp.popleft()
        y=d[x].pop()
        d[y].remove(x)
        deg[y]-=1
        if deg[y]==1:
            hp.append(y)
        ct[y]+=ct[x]
        ct[x]=0
    ans=0
    for i in range(1,n+1):
        ans+=(ct[i]*(ct[i]-1))//2+ct[i]*(n-ct[i])

    print(ans)
```


1478_C. Nezzar and Symmetric Array

Long time ago there was a symmetric array a_1,a_2,…,a_{2n} consisting of 2n distinct integers. Array a_1,a_2,…,a_{2n} is called symmetric if for each integer 1 ≤ i ≤ 2n, there exists an integer 1 ≤ j ≤ 2n such that a_i = -a_j.

For each integer 1 ≤ i ≤ 2n, Nezzar wrote down an integer d_i equal to the sum of absolute differences from a_i to all integers in a, i. e. d_i = ∑_{j = 1}^{2n} {|a_i - a_j|}.

Now a million years has passed and Nezzar can barely remember the array d and totally forget a. Nezzar wonders if there exists any symmetric array a consisting of 2n distinct integers that generates the array d.

Input

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

The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5).

The second line of each test case contains 2n integers d_1, d_2, …, d_{2n} (0 ≤ d_i ≤ 10^{12}).

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

Output

For each test case, print "YES" in a single line if there exists a possible array a. Otherwise, print "NO".

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

Example

Input

6
2
8 12 8 12
2
7 7 9 11
2
7 11 7 11
1
1 1
4
40 56 48 40 80 56 80 48
6
240 154 210 162 174 154 186 240 174 186 162 210

Output

YES
NO
NO
NO
NO
YES

Note

In the first test case, a=[1,-3,-1,3] is one possible symmetric array that generates the array d=[8,12,8,12].

In the second test case, it can be shown that there is no symmetric array consisting of distinct integers that can generate array d.

```python
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

# ------------------- fast io --------------------
from math import gcd, ceil

def prod(a, mod=10**9+7):
    ans = 1
    for each in a:
        ans = (ans * each) % mod
    return ans

def lcm(a, b): return a * b // gcd(a, b)

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

for _ in range(int(input()) if True else 1):
    n = int(input())
    #n, k = map(int, input().split())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    #b = list(map(int, input().split()))
    #s = input()
    c = [a[i] for i in range(1, len(a), 2)][::-1]
    a = [a[i] for i in range(0, len(a), 2)][::-1]
    if c != a:
        print("NO")
        continue
    total = 0
    pos = True
    b = []
    for i in range(len(a)):
        if (a[i] - total) % (2*(n-i)):
            pos = False
            break
        b += [((a[i] - total) // (2*(n-i)))]
        total += 2 * ((a[i] - total) // (2*(n-i)))
    print("YES" if pos and len(b) == len(set(b)) and min(b) > 0 else "NO")
```


1505_F. Math

<image> <image>

*The two images are equivalent, feel free to use either one.

Input

The input contains a single integer a (-100 ≤ a ≤ 100).

Output

Output the result – an integer number.

Example

Input

1

Output

1

```python
s=int(input())
print(2-s**2)
```


15_E. Triangles

Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels, where n is an even number.

In the local council you were given an area map, where the granny's house is marked by point H, parts of dense forest are marked grey (see the picture to understand better).

After a long time at home Peter decided to yield to his granny's persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics:

  * it starts and ends in the same place — the granny's house;
  * the route goes along the forest paths only (these are the segments marked black in the picture);
  * the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
  * the route cannot cross itself;
  * there shouldn't be any part of dense forest within the part marked out by this route;

You should find the amount of such suitable oriented routes modulo 1000000009.

<image>

The example of the area map for n = 12 is given in the picture. Since the map has a regular structure, you can construct it for other n by analogy using the example.

Input

The input data contain the only even integer n (2 ≤ n ≤ 106).

Output

Output the only number — the amount of Peter's routes modulo 1000000009.

Examples

Input

2

Output

10

Input

4

Output

74


17_B. Hierarchy

Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.

Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.

Input

The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.

Output

Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.

Examples

Input

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

Output

11

Input

3
1 2 3
2
3 1 2
3 1 3

Output

-1

Note

In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.

```python
import sys
import math
import collections
import heapq
input=sys.stdin.readline
n=int(input())
l=[int(i) for i in input().split()]
m=int(input())
s=0
d={}
for i in range(m):
    a,b,c=(int(i) for i in input().split())
    if(b in d):
        d[b]=min(d[b],c)
    else:
        d[b]=c
c1=0
for i in range(1,n+1):
    if(i not in d):
        c1+=1
if(c1>1):
    print(-1)
else:
    for i in d:
        s+=d[i]
    print(s)
```


202_C. Clear Symmetry

Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.

Let's call matrix A clear if no two cells containing ones have a common side.

Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i, j) (1 ≤ i, j ≤ n) both of the following conditions must be met: Ai, j = An - i + 1, j and Ai, j = Ai, n - j + 1.

Let's define the sharpness of matrix A as the number of ones in it.

Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x.

Input

The only line contains a single integer x (1 ≤ x ≤ 100) — the required sharpness of the matrix.

Output

Print a single number — the sought value of n.

Examples

Input

4

Output

3

Input

9

Output

5

Note

The figure below shows the matrices that correspond to the samples:

<image>

```python
'''input
3
'''
from sys import stdin
import math

def make_dp():
	dp = [0] * 1001
	dp[1] = 1
	dp[3] = 5
	for i in range(5, 100, 2):
		dp[i] = dp[i - 2] + i + i - 2

	return dp

# main starts
x = int(stdin.readline().strip())

if x == 3:
	print(5)
	exit()
dp = make_dp()
for i in range(1, len(dp)):
	if x <= dp[i]:
		print(i)
		break

```


227_B. Effective Approach

Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.

According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.

Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to n) and ending with the n-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the n-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.

To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to n, and generated m queries of the form: find element with value bi in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.

But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the elements of array.

The third line contains integer m (1 ≤ m ≤ 105) — the number of queries. The last line contains m space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n) — the search queries. Note that the queries can repeat.

Output

Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Examples

Input

2
1 2
1
1

Output

1 2

Input

2
2 1
1
1

Output

2 1

Input

3
3 1 2
3
1 2 3

Output

6 6

Note

In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).

In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).

```python
def editorial(n, a, m, b):
    c = [None] * n
    for i, x in enumerate(a):
        c[x - 1] = i + 1
    vasya = 0
    petya = 0
    for x in b:
        i = c[x - 1]
        vasya += i
        petya += n - i + 1
    return (vasya, petya)

if __name__ == '__main__':
    n = int(input())
    a = [int(x) for x in input().split()]
    m = int(input())
    b = [int(x) for x in input().split()]
    result = editorial(n, a, m, b)
    print(result[0], result[1])
```


250_E. Mad Joe

Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.

Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that each floor is surrounded by a concrete wall on the left and on the right.

Now Joe is on the n-th floor and in the first cell, counting from left to right. At each moment of time, Joe has the direction of his gaze, to the right or to the left (always one direction of the two). Initially, Joe looks to the right.

Joe moves by a particular algorithm. Every second he makes one of the following actions:

  * If the cell directly under Joe is empty, then Joe falls down. That is, he moves to this cell, the gaze direction is preserved.
  * Otherwise consider the next cell in the current direction of the gaze.
    * If the cell is empty, then Joe moves into it, the gaze direction is preserved.
    * If this cell has bricks, then Joe breaks them with his forehead (the cell becomes empty), and changes the direction of his gaze to the opposite.
    * If this cell has a concrete wall, then Joe just changes the direction of his gaze to the opposite (concrete can withstand any number of forehead hits).

Joe calms down as soon as he reaches any cell of the first floor.

The figure below shows an example Joe's movements around the house.

<image>

Determine how many seconds Joe will need to calm down.

Input

The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 104).

Next n lines contain the description of Joe's house. The i-th of these lines contains the description of the (n - i + 1)-th floor of the house — a line that consists of m characters: "." means an empty cell, "+" means bricks and "#" means a concrete wall.

It is guaranteed that the first cell of the n-th floor is empty.

Output

Print a single number — the number of seconds Joe needs to reach the first floor; or else, print word "Never" (without the quotes), if it can never happen.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 5
..+.#
#+..+
+.#+.

Output

14

Input

4 10
...+.##+.+
+#++..+++#
++.#++++..
.+##.++#.+

Output

42

Input

2 2
..
++

Output

Never

```python
n, m = [int(i) for i in input().split()]
current_floor = list(input())

x, t, direction = 0, 0, 1

for i in range(n-1):
    floor = list(input())
    l, r = x, x
    wall = 0
    while True:
        t += 1
        if floor[x] == '.':
            break
        if (x + direction == m) or (x + direction < 0) or (current_floor[x+direction] == '#'):
            wall += 1
            direction = -direction
            if wall == 2:
                print("Never")
                exit(0)
        elif current_floor[x+direction] == '+':
            wall = 0
            current_floor[x+direction] = '.'
            direction = -direction
        elif l <= x+direction and x+direction <= r:
            if direction == 1:
                t += r-x-1
                x = r
            else:
                t += x-l-1
                x = l
        else:
            x += direction
            r = max(r, x)
            l = min(l, x)
    current_floor, floor = floor, current_floor
print(t)

```


276_A. Lunch Rush

Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.

The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch in the i-th restaurant. If time ti exceeds the time k that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal fi - (ti - k). Otherwise, the Rabbits get exactly fi units of joy.

Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.

Input

The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the characteristics of the i-th restaurant.

Output

In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.

Examples

Input

2 5
3 3
4 5

Output

4

Input

4 6
5 8
3 6
2 3
2 2

Output

3

Input

1 5
1 7

Output

-1

```python
n, k = map(int,input().split())
f = t = 0
maxf = -1000000000
for i in range(n):
    f, t = map(int,input().split())
    if t > k: f -= (t - k)
    if f > maxf: maxf = f
print(maxf)
```


299_C. Weird Game

Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.

Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string.

Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper.

The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw.

You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well.

Input

The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word.

It is guaranteed that both words consist of 2·n characters "0" and "1".

Output

Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes.

Examples

Input

2
0111
0001

Output

First

Input

3
110110
001001

Output

First

Input

3
111000
000111

Output

Draw

Input

4
01010110
00101101

Output

First

Input

4
01100000
10010011

Output

Second

```python
#!/usr/bin/python3

n = int(input())
s = list(input())
l = list(input())
a = len([_ for _ in zip(s, l) if _ == ('1', '1')])
b = len([_ for _ in zip(s, l) if _ == ('1', '0')])
c = len([_ for _ in zip(s, l) if _ == ('0', '1')])
f = b + (a + 1) // 2
s = c + a // 2
if f > s:
    print('First')
elif f + 1 < s:
    print('Second')
else:
    print('Draw')

```


322_A. Ciel and Dancing

Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:

  * either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before);
  * or the girl in the dancing pair must dance for the first time.

Help Fox Ciel to make a schedule that they can dance as many songs as possible.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room.

Output

In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m.

Examples

Input

2 1

Output

2
1 1
2 1

Input

2 2

Output

3
1 1
1 2
2 2

Note

In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).

And in test case 2, we have 2 boys with 2 girls, the answer is 3.

```python
n, m = map(int, input().split())
print(n + m - 1)
for i in range (1, n + 1): print(i, 1)
for i in range (1, m): print(1, i + 1)
```


441_A. Valera and Antique Items

Valera is a collector. Once he wanted to expand his collection with exactly one antique item.

Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.

Unfortunately, Valera has only v units of money. Help him to determine which of the n sellers he can make a deal with.

Input

The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has.

Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki (104 ≤ sij ≤ 106) — the current prices of the items of the i-th seller.

Output

In the first line, print integer p — the number of sellers with who Valera can make a deal.

In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.

Examples

Input

3 50000
1 40000
2 20000 60000
3 10000 70000 190000

Output

3
1 2 3

Input

3 50000
1 50000
3 100000 120000 110000
3 120000 110000 120000

Output

0

Note

In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.

In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.

```python
r = lambda: list(map(int, input().split()))[1:]
n,c = map(int, input().split())

d = []
for _ in range(n):
    for i in r():
        if i<c:
            d.append(str(_+1))
            break
print (len(d))
print (' '.join(d))
```


463_B. Caisa and Pylons

Caisa solved the problem with the sugar and now he is on the way back to home.

Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.

Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?

Input

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons.

Output

Print a single number representing the minimum number of dollars paid by Caisa.

Examples

Input

5
3 4 3 2 4

Output

4

Input

3
4 4 4

Output

4

Note

In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.

```python
n=int(input())
s=list(map(int,input().split()))
m,h,d=0,0,0
for i in range(n):
    m+=h-s[i]
    if(m<0):
        d-=m
        m=0
    h=s[i]
print(d)
```


487_A. Fight the Monster

A monster is attacking the Cyberland!

Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).

During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.

Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF.

Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

Input

The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang.

The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster.

The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF.

All numbers in input are integer and lie between 1 and 100 inclusively.

Output

The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.

Examples

Input

1 2 1
1 100 1
1 100 100

Output

99

Input

100 100 100
1 1 1
1 1 1

Output

0

Note

For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.

For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.

```python
from math import *
#from bisect import *
#from collections import *
#from random import *
#from decimal import *"""
#from heapq import *
#from random import *
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(3*(10**5))
global flag
def inp():
    return int(input())
def st():
    return input().rstrip('\n')
def lis():
    return list(map(int,input().split()))
def ma1():
    return map(int,input().split())
t=1
while(t):
    t-=1
    yh,ya,yd=ma1()
    mh,ma,md=ma1()
    h,a,d=ma1()
    mi=1000000000
    for i in range(1):
        for j in range(300):
            for k in range(200):
                newya,newyd=j+ya,k+yd
                if(newya-md <=0):
                    continue
                if((ma-newyd)<=0):
                    mi=min(mi,a*j + d*k)
                    continue
                t1=ceil(yh/(ma-newyd))
                t2=ceil(mh/(newya-md))
                need=0
                newyh=yh
                while(ceil(newyh/(ma-newyd))<=t2):
                    need+=1
                    newyh+=1
                mi=min(mi,h*need + a*j + d*k)
    print(mi)

```


535_A. Tavas and Nafas

Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.

His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.

<image>

He ate coffee mix without water again, so right now he's really messed up and can't think.

Your task is to help him by telling him what to type.

Input

The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.

Output

In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.

Examples

Input

6

Output

six

Input

99

Output

ninety-nine

Input

20

Output

twenty

Note

You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .

```python
l=['','-one','-two','-three','-four','-five','-six','-seven','-eight','-nine']
l1=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
l2=['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
l3=['zero','one','two','three','four','five','six','seven','eight','nine']

a=input()
if len(a)>1:
    print(l1[int(a[1])] if a[0]=='1' else l2[int(a[0])-2]+l[int(a[1])])
else:
    print(l3[int(a)])
```


55_B. Smallest number

Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.

Input

First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication)

Output

Output one integer number — the minimal result which can be obtained.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Examples

Input

1 1 1 1
+ + *

Output

3

Input

2 2 2 2
* * +

Output

8

Input

1 2 3 4
* + +

Output

9

```python
import math,sys
from itertools import permutations
from collections import defaultdict,deque
import bisect as bi
def yes():print('YES')
def no():print('NO')
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(sys.stdin.readline()))
def In():return(map(int,sys.stdin.readline().split()))
def Sn():return sys.stdin.readline().strip()
#sys.setrecursionlimit(1500)
def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d
def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bi.bisect_left(a, x)
    if i != len(a):
        return i
    else:
        return -1
def check(l,s):
    mul=0
    zero=0
    for x in s:
        if x=='*':
            t1= l.pop(0)
            t2 = l.pop(0)
            if t1==0 or t2==0:
                zero+=1
            l.append(t1*t2)
            mul+=1
        else:
            t1=l.pop()
            t2=l.pop()
            if t1==0 or t2==0:
                zero+=1
            l.append(t1+t2)
        l.sort()
    if mul and zero:
        return(0)
    return(l[0])

def main():
    try:
        l=list(In())
        n=len(l)
        s=Sn().split()
        z=list(permutations(l))
        ans=check(l,s)
        for x in z:
            ans=min(check(list(x),s),ans)
        print(ans)

    except:
        pass

M = 998244353
P = 1000000007

if __name__ == '__main__':
    # for _ in range(I()):main()
    for _ in range(1):main()
#End#

#        ******************* All The Best *******************   #

```


629_D. Babaei and Birthday Cake

As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.

Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.

However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.

Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.

Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.

Output

Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.

Examples

Input

2
100 30
40 10

Output

942477.796077000

Input

4
1 1
9 7
1 4
10 7

Output

3983.539484752

Note

In first sample, the optimal way is to choose the cake number 1.

In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.

```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353

# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

# -------------------game starts now----------------------------------------------------import math
class TreeNode:
    def __init__(self, k, v):
        self.key = k
        self.value = v
        self.left = None
        self.right = None
        self.parent = None
        self.height = 1
        self.num_left = 1
        self.num_total = 1

class AvlTree:

    def __init__(self):
        self._tree = None

    def add(self, k, v):
        if not self._tree:
            self._tree = TreeNode(k, v)
            return
        node = self._add(k, v)
        if node:
            self._rebalance(node)

    def _add(self, k, v):
        node = self._tree
        while node:
            if k < node.key:
                if node.left:
                    node = node.left
                else:
                    node.left = TreeNode(k, v)
                    node.left.parent = node
                    return node.left
            elif node.key < k:
                if node.right:
                    node = node.right
                else:
                    node.right = TreeNode(k, v)
                    node.right.parent = node
                    return node.right
            else:
                node.value = v
                return

    @staticmethod
    def get_height(x):
        return x.height if x else 0

    @staticmethod
    def get_num_total(x):
        return x.num_total if x else 0

    def _rebalance(self, node):

        n = node
        while n:
            lh = self.get_height(n.left)
            rh = self.get_height(n.right)
            n.height = max(lh, rh) + 1
            balance_factor = lh - rh
            n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
            n.num_left = 1 + self.get_num_total(n.left)

            if balance_factor > 1:
                if self.get_height(n.left.left) < self.get_height(n.left.right):
                    self._rotate_left(n.left)
                self._rotate_right(n)
            elif balance_factor < -1:
                if self.get_height(n.right.right) < self.get_height(n.right.left):
                    self._rotate_right(n.right)
                self._rotate_left(n)
            else:
                n = n.parent

    def _remove_one(self, node):
        """
        Side effect!!! Changes node. Node should have exactly one child
        """
        replacement = node.left or node.right
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = replacement
            else:
                node.parent.right = replacement
            replacement.parent = node.parent
            node.parent = None
        else:
            self._tree = replacement
            replacement.parent = None
        node.left = None
        node.right = None
        node.parent = None
        self._rebalance(replacement)

    def _remove_leaf(self, node):
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = None
            else:
                node.parent.right = None
            self._rebalance(node.parent)
        else:
            self._tree = None
        node.parent = None
        node.left = None
        node.right = None

    def remove(self, k):
        node = self._get_node(k)
        if not node:
            return
        if AvlTree._is_leaf(node):
            self._remove_leaf(node)
            return
        if node.left and node.right:
            nxt = AvlTree._get_next(node)
            node.key = nxt.key
            node.value = nxt.value
            if self._is_leaf(nxt):
                self._remove_leaf(nxt)
            else:
                self._remove_one(nxt)
            self._rebalance(node)
        else:
            self._remove_one(node)

    def get(self, k):
        node = self._get_node(k)
        return node.value if node else -1

    def _get_node(self, k):
        if not self._tree:
            return None
        node = self._tree
        while node:
            if k < node.key:
                node = node.left
            elif node.key < k:
                node = node.right
            else:
                return node
        return None

    def get_at(self, pos):
        x = pos + 1
        node = self._tree
        while node:
            if x < node.num_left:
                node = node.left
            elif node.num_left < x:
                x -= node.num_left
                node = node.right
            else:
                return (node.key, node.value)
        raise IndexError("Out of ranges")

    @staticmethod
    def _is_left(node):
        return node.parent.left and node.parent.left == node

    @staticmethod
    def _is_leaf(node):
        return node.left is None and node.right is None

    def _rotate_right(self, node):
        if not node.parent:
            self._tree = node.left
            node.left.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.left
            node.left.parent = node.parent
        else:
            node.parent.right = node.left
            node.left.parent = node.parent
        bk = node.left.right
        node.left.right = node
        node.parent = node.left
        node.left = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    def _rotate_left(self, node):
        if not node.parent:
            self._tree = node.right
            node.right.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.right
            node.right.parent = node.parent
        else:
            node.parent.right = node.right
            node.right.parent = node.parent
        bk = node.right.left
        node.right.left = node
        node.parent = node.right
        node.right = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    @staticmethod
    def _get_next(node):
        if not node.right:
            return node.parent
        n = node.right
        while n.left:
            n = n.left
        return n

# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
    def __init__(self, data, default=2**51, func=lambda a, b: a & b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]

class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)

    z = [x for _, x in sorted(zipped_pairs)]

    return z

# --------------------------------------------------product----------------------------------------
def product(l):
    por = 1
    for i in range(len(l)):
        por *= l[i]
    return por

# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        # Check if middle element is
        # less than or equal to key
        if (arr[mid] < key):
            count = mid + 1
            left = mid + 1

        # If key is smaller, ignore right half
        else:
            right = mid - 1

    return count

# --------------------------------------------------binary----------------------------------------
def countdig(n):
    c = 0
    while (n > 0):
        n //= 10
        c += 1
    return c
def binary(x, length):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)

# --------------------------------------------------binary------------------------------------
n=int(input())
l=[]
vol=set()
ind=defaultdict(int)
for i in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
    vol.add(a*a*b)
vol=sorted(vol)
for i in range(len(vol)):
    ind[vol[i]]=i
e=[0]*n
s=SegmentTree(e)
ans=0
for i in range(n):
    a,b=l[i]
    cur=a*a*b
    index=ind[cur]
    dp=s.query(0,index-1)+cur
    s.__setitem__(index,dp+cur)
    ans=max(ans,dp+cur)
print((ans*math.pi)/2)
```


653_E. Bear and Forgotten Tree 2

A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n.

Limak is a little polar bear. He once had a tree with n vertices but he lost it. He still remembers something about the lost tree though.

You are given m pairs of vertices (a1, b1), (a2, b2), ..., (am, bm). Limak remembers that for each i there was no edge between ai and bi. He also remembers that vertex 1 was incident to exactly k edges (its degree was equal to k).

Is it possible that Limak remembers everything correctly? Check whether there exists a tree satisfying the given conditions.

Input

The first line of the input contains three integers n, m and k (<image>) — the number of vertices in Limak's tree, the number of forbidden pairs of vertices, and the degree of vertex 1, respectively.

The i-th of next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th pair that is forbidden. It's guaranteed that each pair of vertices will appear at most once in the input.

Output

Print "possible" (without quotes) if there exists at least one tree satisfying the given conditions. Otherwise, print "impossible" (without quotes).

Examples

Input

5 4 2
1 2
2 3
4 2
4 1

Output

possible

Input

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

Output

impossible

Note

In the first sample, there are n = 5 vertices. The degree of vertex 1 should be k = 2. All conditions are satisfied for a tree with edges 1 - 5, 5 - 2, 1 - 3 and 3 - 4.

In the second sample, Limak remembers that none of the following edges existed: 1 - 2, 1 - 3, 1 - 4, 1 - 5 and 1 - 6. Hence, vertex 1 couldn't be connected to any other vertex and it implies that there is no suitable tree.

```python
import sys
import math
from heapq import *;
input = sys.stdin.readline
from functools import cmp_to_key;

def pi():
    return(int(input()))
def pl():
    return(int(input(), 16))
def ti():
    return(list(map(int,input().split())))
def ts():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
mod = 1000000007;
f = [];
def fact(n,m):
    global f;
    f = [1 for i in range(n+1)];
    f[0] = 1;
    for i in range(1,n+1):
        f[i] = (f[i-1]*i)%m;

def fast_mod_exp(a,b,m):
    res = 1;
    while b > 0:
        if b & 1:
            res = (res*a)%m;
        a = (a*a)%m;
        b = b >> 1;
    return res;

def inverseMod(n,m):
    return fast_mod_exp(n,m-2,m);

def ncr(n,r,m):
    if n < 0 or r < 0 or r > n: return 0;
    if r == 0: return 1;
    return ((f[n]*inverseMod(f[n-r],m))%m*inverseMod(f[r],m))%m;

def main():
    E();

mp = [{''} for i in range(300005)];
def canConnect(a,b):
    return b not in mp[a];

remaining = {''};
def dfs(a):
    temp = [];
    for b in remaining:
        if canConnect(a,b): temp.append(b);
    for b in temp:
        remaining.remove(b);
    for b in temp:
        dfs(b);

def E():
    [n,m,k] = ti();
    mxDegreePossible = n-1;
    for i in range(m):
        [a,b] = ti();
        mp[a].add(b);
        mp[b].add(a);
        if a == 1 or b == 1:
            mxDegreePossible -= 1;

    if mxDegreePossible < k:
        print("impossible");
        return;

    for i in range(2,n+1):
        remaining.add(i);

    components = 0;
    for i in range(2,n+1):
        if i in remaining and canConnect(1,i):
            remaining.remove(i);
            dfs(i);
            components += 1;
    remaining.remove('');
    if components > k or len(remaining) > 0:
        print('impossible');
        return;
    print('possible');

main();
```


701_D. As Fast As Possible

On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit more than k people at the same time) and the speed equal to v2. In order to avoid seasick, each of the pupils want to get into the bus no more than once.

Determine the minimum time required for all n pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.

Input

The first line of the input contains five positive integers n, l, v1, v2 and k (1 ≤ n ≤ 10 000, 1 ≤ l ≤ 109, 1 ≤ v1 < v2 ≤ 109, 1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.

Output

Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10 - 6.

Examples

Input

5 10 1 2 5

Output

5.0000000000

Input

3 6 1 2 1

Output

4.7142857143

Note

In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.


723_E. One-Way Reform

There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads.

The road minister decided to make a reform in Berland and to orient all roads in the country, i.e. to make each road one-way. The minister wants to maximize the number of cities, for which the number of roads that begins in the city equals to the number of roads that ends in it.

Input

The first line contains a positive integer t (1 ≤ t ≤ 200) — the number of testsets in the input.

Each of the testsets is given in the following way. The first line contains two integers n and m (1 ≤ n ≤ 200, 0 ≤ m ≤ n·(n - 1) / 2) — the number of cities and the number of roads in Berland.

The next m lines contain the description of roads in Berland. Each line contains two integers u and v (1 ≤ u, v ≤ n) — the cities the corresponding road connects. It's guaranteed that there are no self-loops and multiple roads. It is possible that there is no way along roads between a pair of cities.

It is guaranteed that the total number of cities in all testset of input data doesn't exceed 200.

Pay attention that for hacks, you can only use tests consisting of one testset, so t should be equal to one.

Output

For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it.

In the next m lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there are several answers, print any of them. It is allowed to print roads in each test in arbitrary order. Each road should be printed exactly once.

Example

Input

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

Output

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

```python
import sys
from collections import defaultdict

rlines = sys.stdin.readlines()
lines = (l.strip() for l in rlines)

def eucycle(n,m,adj):
	dir_edges = []
	us = list(adj.keys())
	for u in us:
		while adj[u]:
			v0 = u
			v1 = adj[v0].pop()
			adj[v1].remove(v0)
			dir_edges.append((v0, v1))
			while v1 != u:
				v0 = v1
				v1 = adj[v0].pop()
				adj[v1].remove(v0)
				dir_edges.append((v0, v1))
	return dir_edges

def solve(n,m,edges):
	adj = defaultdict(set)
	for u, v in edges:
		adj[u].add(v)
		adj[v].add(u)

	odds = set(u for u in adj if len(adj[u])%2==1)

	for odd in odds:
 		adj[odd].add(n+1)
 		adj[n+1].add(odd)
	total = n - len(odds)
	dir_edges = eucycle(n+1, m, adj)
	return total, dir_edges

t = int(next(lines))

for ti in range(t):
	n,m = [int(s) for s in next(lines).split()]
	edges = []
	for ei in range(m):
		u,v = [int(s) for s in next(lines).split()]
		edges.append((u,v))
	total, ans = solve(n,m,edges)
	print(total)
	print('\n'.join(str(u)+ ' '+ str(v) for u, v in ans if u != n+1 and v!= n+1))
```


745_D. Hongcow's Game

This is an interactive problem. In the interaction section below you will see the information about flushing the output.

In this problem, you will be playing a game with Hongcow. How lucky of you!

Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n.

The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>.

To do this, you can ask Hongcow some questions.

A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj.

You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered.

When you are ready to answer, print out a single integer  - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question.

You will get Wrong Answer verdict if

  * Your question or answers are not in the format described in this statement.
  * You ask strictly more than 20 questions.
  * Your question contains duplicate indices.
  * The value of k in your question does not lie in the range from 1 to n, inclusive.
  * Your final answer is not correct.

You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below).

Input

The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000).

Output

To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer!

Interaction

To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response.

Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k.

You may only ask a question at most 20 times, otherwise, you will get Wrong Answer.

To flush you can use (just after printing an integer and end-of-line):

  * fflush(stdout) in C++;
  * System.out.flush() in Java;
  * stdout.flush() in Python;
  * flush(output) in Pascal;
  * See the documentation for other languages.

Hacking To hack someone, use the following format

    n
    M_{1,1} M_{1,2} ... M_{1,n}
    M_{2,1} M_{2,2} ... M_{2,n}
    ...
    M_{n,1} M_{n,2} ... M_{n,n}

Of course, contestant programs will not be able to see this input.

Examples

Input

3
0 0 0
2 7 0
0 0 4
3 0 8
0 5 4

Output

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

Input

2
0 0
0 0

Output

1
2
1
1
-1
0 0

Note

In the first sample, Hongcow has the hidden matrix

    [
     [0, 3, 2],
     [5, 0, 7],
     [4, 8 ,0],
    ]

Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant.

    3
                  3
                  1 2 3
    0 0 0
                  1
                  3
    2 7 0
                  2
                  1 2
    0 0 4
                  1
                  2
    3 0 8
                  1
                  1
    0 5 4
                  -1
                  2 5 4

For the second sample, it is possible for off-diagonal elements of the matrix to be zero.

```python
import sys

n = int(input())

MAX = 2000 * 1000 * 1000

res = [MAX] * n

k = 1
while k < n:
    x = [0] * n
    output = []
    sz = 0
    for i in range(0, n, 2 * k):
        for j in range(0, min(n - i, k)):
            output.append(i + j + 1)
            sz += 1
            #print(i + j + 1, end = ' ')
            x[i + j] = 1
    print(sz, end = ' ')
    print(' '.join(map(str, output)))
    sys.stdout.flush()
    a = list(map(int, input().split()))
    for i in range(len(a)):
        if a[i] != 0 or x[i] == 0:
            res[i] = min(res[i], a[i])
    x = [0] * n
    output = []
    sz = 0
    for i in range(k, n, 2 * k):
        for j in range(0, min(n - i, k)):
            output.append(i + j + 1)
            #print(i + j + 1, end = ' ')
            x[i + j] = 1
            sz += 1
    print(sz, end = ' ')
    print(' '.join(map(str, output)))
    sys.stdout.flush()
    a = list(map(int, input().split()))
    for i in range(len(a)):
        if a[i] != 0 or x[i] == 0:
            res[i] = min(res[i], a[i])
    k *= 2
print(-1)
for i in range(n):
    if res[i] != MAX:
        print(res[i], end = ' ')
    else:
        print(0, end = ' ')
print()
sys.stdout.flush()

# 0 0 0 0 0
# 1 0 2 3 1
# 1 2 0 1 0
# 5 5 5 0 5
# 2 3 4 5 0
```


768_F. Barrels and boxes

Tarly has two different type of items, food boxes and wine barrels. There are f food boxes and w wine barrels. Tarly stores them in various stacks and each stack can consist of either food boxes or wine barrels but not both. The stacks are placed in a line such that no two stacks of food boxes are together and no two stacks of wine barrels are together.

The height of a stack is defined as the number of items in the stack. Two stacks are considered different if either their heights are different or one of them contains food and other contains wine.

Jon Snow doesn't like an arrangement if any stack of wine barrels has height less than or equal to h. What is the probability that Jon Snow will like the arrangement if all arrangement are equiprobably?

Two arrangement of stacks are considered different if exists such i, that i-th stack of one arrangement is different from the i-th stack of the other arrangement.

Input

The first line of input contains three integers f, w, h (0 ≤ f, w, h ≤ 105) — number of food boxes, number of wine barrels and h is as described above. It is guaranteed that he has at least one food box or at least one wine barrel.

Output

Output the probability that Jon Snow will like the arrangement. The probability is of the form <image>, then you need to output a single integer p·q - 1 mod (109 + 7).

Examples

Input

1 1 1

Output

0

Input

1 2 1

Output

666666672

Note

In the first example f = 1, w = 1 and h = 1, there are only two possible arrangement of stacks and Jon Snow doesn't like any of them.

In the second example f = 1, w = 2 and h = 1, there are three arrangements. Jon Snow likes the (1) and (3) arrangement. So the probabilty is <image>.

<image>

```python
import sys
def factorial():
    global mod
    fac = [1] * int(3e5 + 1)
    for i in range(1, int(3e5)):
        fac[i] = i*fac[i-1] % mod
    return fac
def inverse(x):
    global mod
    return pow(x, mod-2, mod)
def C(n, r):
    global fac
    if n < 0 or n < r:
        return 0
    return fac[n]*inverse(fac[r])*inverse(fac[n-r]) % mod
def calc(f, w, h):
    global mod
    if w == 0:
        return 1
    ans = 0
    for k in range(1, min(w//(h+1),f+1)+1):
        ans += C(f+1, k) * C(w-k*h-1, k-1) % mod
        ans %= mod
    return ans
f, w, h = map(int,sys.stdin.readline().split(' '))
mod = int(1e9 + 7)
fac = factorial()
cnt = calc(f, w, h)
sys.stdout.write(str(cnt*inverse(C(f+w, w)) % mod))

```


792_E. Colored Balls

There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains ai balls, all of which have color i. You have to write a program that will divide all balls into sets such that:

  * each ball belongs to exactly one of the sets,
  * there are no empty sets,
  * there is no set containing two (or more) balls of different colors (each set contains only balls of one color),
  * there are no two sets such that the difference between their sizes is greater than 1.

Print the minimum possible number of sets.

Input

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

The second line contains n integer numbers a1, a2, ... , an (1 ≤ ai ≤ 109).

Output

Print one integer number — the minimum possible number of sets.

Examples

Input

3
4 7 8

Output

5

Input

2
2 7

Output

4

Note

In the first example the balls can be divided into sets like that: one set with 4 balls of the first color, two sets with 3 and 4 balls, respectively, of the second color, and two sets with 4 balls of the third color.

```python
import time
import sys
from math import sqrt

n = int(input())
a = list(map(int, input().split()))

sq = int(sqrt(a[0]))+2
s = set()

for box in range(1, sq):
    if a[0] % box == 0:
        s.add(a[0] // box)
        s.add(a[0] // box - 1)
    else:
        s.add(a[0] // box)

for balls in range(1, sq):
    if a[0] % balls <= a[0] // balls:
        s.add(balls)

for size in sorted(s, reverse=True):
    ans = 0
    for x in a:
        if x / size >= x % size:
            ans += (x+size) // (size+1)
        else:
            break
    else:
        print(ans)
        exit()

```


813_B. The Golden Age

Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers.

For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it.

Such interval of years that there are no unlucky years in it is called The Golden Age.

You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.

Input

The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).

Output

Print the maximum length of The Golden Age within the interval [l, r].

If all years in the interval [l, r] are unlucky then print 0.

Examples

Input

2 3 1 10

Output

1

Input

3 5 10 22

Output

8

Input

2 3 3 5

Output

0

Note

In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].

In the second example the longest Golden Age is the interval [15, 22].

```python
x, y, l, r = map(int, input().split())

def gen_list(var):
    cur = 1
    while cur <= r:
        yield cur
        cur *= var

x_list = list(gen_list(x))
# print(x_list)
y_list = list(gen_list(y))
# print(y_list)

numbers = [l-1, r+1]
for _x in x_list:
    for _y in y_list:
        n = _x + _y
        if n < l or n > r:
            continue
        numbers.append(n)

numbers = sorted(set(numbers))
# print(numbers)

if len(numbers) < 2:
    print('0')
    exit()

max_happy = max([numbers[i+1]-numbers[i]-1 for i in range(len(numbers) - 1)], default=0)

print(max_happy)

```